Skip to content

Commit 3934aac

Browse files
committed
comments reflect current state of status function
1 parent 5675642 commit 3934aac

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

adafruit_espatcontrol/adafruit_espatcontrol.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,13 @@ def status(self) -> Union[int, None]:
473473
# Note that CIPSTATUS, at least in the esp32-c3 version of espressif AT firmware
474474
# is considered deprecated and you should use AT+CWSTATE for wifi state
475475
# 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)
481483
# CIPSTATUS status messages:
482484
#<stat>: status of the ESP32-C3 station interface.
483485
# 0: The ESP32-C3 station is not initialized.
@@ -487,21 +489,6 @@ def status(self) -> Union[int, None]:
487489
# 4: All of the TCP/UDP/SSL connections of the ESP32-C3 station are disconnected.
488490
# 5: The ESP32-C3 station started a Wi-Fi connection, but was not connected
489491
# 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
505492

506493
if self._use_cipstatus:
507494
replies = self.at_response("AT+CIPSTATUS", timeout=5).split(b"\r\n")
@@ -514,7 +501,7 @@ def status(self) -> Union[int, None]:
514501
status_w = self.status_wifi
515502
status_s = self.status_socket
516503

517-
# Check CIPSTATUS messages against CWSTATE/CIPSTATE
504+
# debug only, Check CIPSTATUS messages against CWSTATE/CIPSTATE
518505
if self._debug:
519506
replies = self.at_response("AT+CIPSTATUS", timeout=5).split(b"\r\n")
520507
for reply in replies:
@@ -523,6 +510,8 @@ def status(self) -> Union[int, None]:
523510
print(f"STATUS: CWSTATE: {status_w}, CIPSTATUS: {cipstatus}, CIPSTATE: {status_s}")
524511

525512
# 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.
526515
if status_w in (self.STATUS_WIFI_NOTCONNECTED, self.STATUS_WIFI_DISCONNECTED):
527516
if self._debug:
528517
print(f"STATUS returning {self.STATUS_NOTCONNECTED}")
@@ -549,13 +538,13 @@ def status(self) -> Union[int, None]:
549538
if status_w == 0: # station has not started any Wi-Fi connection.
550539
if self._debug:
551540
print("STATUS returning 1")
552-
return 1
541+
return 1 # this cipstatus had no previous handler variable
553542

554543
# pylint: disable=line-too-long
555544
if status_w == 1: # station has connected to an AP, but does not get an IPv4 address yet.
556545
if self._debug:
557546
print("STATUS returning 1")
558-
return 1
547+
return 1 # this cipstatus had no previous handler variable
559548

560549
if status_w == 3: # station is in Wi-Fi connecting or reconnecting state.
561550
if self._debug:

0 commit comments

Comments
 (0)