@@ -473,11 +473,13 @@ def status(self) -> Union[int, None]:
473
473
# Note that CIPSTATUS, at least in the esp32-c3 version of espressif AT firmware
474
474
# is considered deprecated and you should use AT+CWSTATE for wifi state
475
475
# and AT+CIPSTATE for socket connection statuses.
476
- # This muddies things with regards to how the original version of this routine
477
- # ran the status responses since wifi + socket were mixed, so this has been broken
478
- # out in to status_wifi() and status_socket() with their own constants for status
479
- # This is here for legacy reasons like the the ESP8285 version of the espressif
480
- # AT commands which is on the Challenger RP2040 Wifi feather.
476
+ #
477
+ # if CWSTATE/CIPSTATE are available, this function uses those and generates
478
+ # a return code compatible with CIPSTATUS. For more fine grain control
479
+ # you can use status_wifi and status_socket
480
+ # if CWSTATE/CIPSTATE are not available, this falls back to using CIPSTATUS
481
+ # (e.g. - ILabs Challenger RP2040 Wifi which has an onboard ESP8285 with older
482
+ # firmware)
481
483
# CIPSTATUS status messages:
482
484
#<stat>: status of the ESP32-C3 station interface.
483
485
# 0: The ESP32-C3 station is not initialized.
@@ -487,21 +489,6 @@ def status(self) -> Union[int, None]:
487
489
# 4: All of the TCP/UDP/SSL connections of the ESP32-C3 station are disconnected.
488
490
# 5: The ESP32-C3 station started a Wi-Fi connection, but was not connected
489
491
# to an AP or disconnected from an AP.
490
- # STATUS_APCONNECTED = 2 # CIPSTATUS method
491
- # STATUS_WIFI_APCONNECTED = 2 # CWSTATE method
492
-
493
- # STATUS_SOCKETOPEN = 3 # CIPSTATUS method
494
- # STATUS_SOCKET_OPEN = 3 # CIPSTATE method
495
-
496
- # STATUS_SOCKETCLOSED = 4 # CIPSTATUS method
497
- # STATUS_SOCKET_CLOSED = 4 # CIPSTATE method
498
-
499
- # STATUS_NOTCONNECTED = 5 # CIPSTATUS method
500
- # STATUS_WIFI_NOTCONNECTED = 1 # CWSTATE method
501
- # STATUS_WIFI_DISCONNECTED = 4 # CWSTATE method
502
- # CIPSTATUS responses without magic codes:
503
- # 0
504
- # 1
505
492
506
493
if self ._use_cipstatus :
507
494
replies = self .at_response ("AT+CIPSTATUS" , timeout = 5 ).split (b"\r \n " )
@@ -514,7 +501,7 @@ def status(self) -> Union[int, None]:
514
501
status_w = self .status_wifi
515
502
status_s = self .status_socket
516
503
517
- # Check CIPSTATUS messages against CWSTATE/CIPSTATE
504
+ # debug only, Check CIPSTATUS messages against CWSTATE/CIPSTATE
518
505
if self ._debug :
519
506
replies = self .at_response ("AT+CIPSTATUS" , timeout = 5 ).split (b"\r \n " )
520
507
for reply in replies :
@@ -523,6 +510,8 @@ def status(self) -> Union[int, None]:
523
510
print (f"STATUS: CWSTATE: { status_w } , CIPSTATUS: { cipstatus } , CIPSTATE: { status_s } " )
524
511
525
512
# Produce a cipstatus-compatible status code
513
+ # Codes are not the same between CWSTATE/CIPSTATUS so in some combinations
514
+ # we just pick what we hope is best.
526
515
if status_w in (self .STATUS_WIFI_NOTCONNECTED , self .STATUS_WIFI_DISCONNECTED ):
527
516
if self ._debug :
528
517
print (f"STATUS returning { self .STATUS_NOTCONNECTED } " )
@@ -549,13 +538,13 @@ def status(self) -> Union[int, None]:
549
538
if status_w == 0 : # station has not started any Wi-Fi connection.
550
539
if self ._debug :
551
540
print ("STATUS returning 1" )
552
- return 1
541
+ return 1 # this cipstatus had no previous handler variable
553
542
554
543
# pylint: disable=line-too-long
555
544
if status_w == 1 : # station has connected to an AP, but does not get an IPv4 address yet.
556
545
if self ._debug :
557
546
print ("STATUS returning 1" )
558
- return 1
547
+ return 1 # this cipstatus had no previous handler variable
559
548
560
549
if status_w == 3 : # station is in Wi-Fi connecting or reconnecting state.
561
550
if self ._debug :
0 commit comments