@@ -67,13 +67,10 @@ class ESP_ATcontrol:
6767 TLS_MODE = "SSL"
6868 STATUS_APCONNECTED = 2 # CIPSTATUS method
6969 STATUS_WIFI_APCONNECTED = 2 # CWSTATE method
70-
7170 STATUS_SOCKETOPEN = 3 # CIPSTATUS method
7271 STATUS_SOCKET_OPEN = 3 # CIPSTATE method
73-
7472 STATUS_SOCKETCLOSED = 4 # CIPSTATUS method
7573 STATUS_SOCKET_CLOSED = 4 # CIPSTATE method
76-
7774 STATUS_NOTCONNECTED = 5 # CIPSTATUS method
7875 STATUS_WIFI_NOTCONNECTED = 1 # CWSTATE method
7976 STATUS_WIFI_DISCONNECTED = 4 # CWSTATE method
@@ -116,7 +113,6 @@ def __init__(
116113 self ._ifconfig = []
117114 self ._initialized = False
118115 self ._conntype = None
119-
120116 self ._use_cipstatus = use_cipstatus
121117
122118 def begin (self ) -> None :
@@ -400,7 +396,6 @@ def socket_receive(self, timeout: int = 5) -> bytearray:
400396 i = 0 # reset the input buffer now that we know the size
401397 elif i > 20 :
402398 i = 0 # Hmm we somehow didnt get a proper +IPD packet? start over
403-
404399 else :
405400 self .hw_flow (False ) # stop the flow
406401 # read as much as we can!
@@ -491,29 +486,11 @@ def is_connected(self) -> bool:
491486 print ("is_connected(): status says not connected" )
492487 return False
493488
489+ # pylint: disable=too-many-branches
490+ # pylint: disable=too-many-return-statements
494491 @property
495492 def status (self ) -> Union [int , None ]:
496493 """The IP connection status number (see AT+CIPSTATUS datasheet for meaning)"""
497- # Note that CIPSTATUS, at least in the esp32-c3 version of espressif AT firmware
498- # is considered deprecated and you should use AT+CWSTATE for wifi state
499- # and AT+CIPSTATE for socket connection statuses.
500- #
501- # if CWSTATE/CIPSTATE are available, this function uses those and generates
502- # a return code compatible with CIPSTATUS. For more fine grain control
503- # you can use status_wifi and status_socket
504- # if CWSTATE/CIPSTATE are not available, this falls back to using CIPSTATUS
505- # (e.g. - ILabs Challenger RP2040 Wifi which has an onboard ESP8285 with older
506- # firmware)
507- # CIPSTATUS status messages:
508- #<stat>: status of the ESP32-C3 station interface.
509- # 0: The ESP32-C3 station is not initialized.
510- # 1: The ESP32-C3 station is initialized, but not started a Wi-Fi connection yet.
511- # 2: The ESP32-C3 station is connected to an AP and its IP address is obtained.
512- # 3: The ESP32-C3 station has created a TCP/SSL transmission.
513- # 4: All of the TCP/UDP/SSL connections of the ESP32-C3 station are disconnected.
514- # 5: The ESP32-C3 station started a Wi-Fi connection, but was not connected
515- # to an AP or disconnected from an AP.
516-
517494 if self ._use_cipstatus :
518495 replies = self .at_response ("AT+CIPSTATUS" , timeout = 5 ).split (b"\r \n " )
519496 for reply in replies :
@@ -531,12 +508,17 @@ def status(self) -> Union[int, None]:
531508 for reply in replies :
532509 if reply .startswith (b"STATUS:" ):
533510 cipstatus = int (reply [7 :8 ])
534- print (f"STATUS: CWSTATE: { status_w } , CIPSTATUS: { cipstatus } , CIPSTATE: { status_s } " )
511+ print (
512+ f"STATUS: CWSTATE: { status_w } , CIPSTATUS: { cipstatus } , CIPSTATE: { status_s } "
513+ )
535514
536515 # Produce a cipstatus-compatible status code
537516 # Codes are not the same between CWSTATE/CIPSTATUS so in some combinations
538517 # we just pick what we hope is best.
539- if status_w in (self .STATUS_WIFI_NOTCONNECTED , self .STATUS_WIFI_DISCONNECTED ):
518+ if status_w in (
519+ self .STATUS_WIFI_NOTCONNECTED ,
520+ self .STATUS_WIFI_DISCONNECTED ,
521+ ):
540522 if self ._debug :
541523 print (f"STATUS returning { self .STATUS_NOTCONNECTED } " )
542524 return self .STATUS_NOTCONNECTED
@@ -546,31 +528,26 @@ def status(self) -> Union[int, None]:
546528 print (f"STATUS returning { self .STATUS_SOCKETOPEN } " )
547529 return self .STATUS_SOCKETOPEN
548530
549- # Sometimes you get a CIPSTATUS=4 when CWSTATE=2/CIPSTATE=4 and sometimes you
550- # get CIPSTATUS=2 when CWSTATE=2/CIPSTATE=4
551- # if status_w == self.STATUS_WIFI_APCONNECTED and status_s == self.STATUS_SOCKET_CLOSED:
552- # if self._debug:
553- # print(f"STATUS returning {self.STATUS_SOCKETCLOSED}")
554- # return self.STATUS_SOCKETCLOSED
555-
556531 if status_w == self .STATUS_WIFI_APCONNECTED :
557532 if self ._debug :
558533 print (f"STATUS returning { self .STATUS_APCONNECTED } " )
559534 return self .STATUS_APCONNECTED
560535
561536 # handle extra codes from CWSTATE
562- if status_w == 0 : # station has not started any Wi-Fi connection.
537+ if status_w == 0 : # station has not started any Wi-Fi connection.
563538 if self ._debug :
564539 print ("STATUS returning 1" )
565540 return 1 # this cipstatus had no previous handler variable
566541
567542 # pylint: disable=line-too-long
568- if status_w == 1 : # station has connected to an AP, but does not get an IPv4 address yet.
543+ if (
544+ status_w == 1
545+ ): # station has connected to an AP, but does not get an IPv4 address yet.
569546 if self ._debug :
570547 print ("STATUS returning 1" )
571- return 1 # this cipstatus had no previous handler variable
548+ return 1 # this cipstatus had no previous handler variable
572549
573- if status_w == 3 : # station is in Wi-Fi connecting or reconnecting state.
550+ if status_w == 3 : # station is in Wi-Fi connecting or reconnecting state.
574551 if self ._debug :
575552 print (f"STATUS returning { self .STATUS_NOTCONNECTED } " )
576553 return self .STATUS_NOTCONNECTED
@@ -585,16 +562,6 @@ def status(self) -> Union[int, None]:
585562 @property
586563 def status_wifi (self ) -> Union [int , None ]:
587564 """The WIFI connection status number (see AT+CWSTATE datasheet for meaning)"""
588- # Note that as of 2022-Nov CIPSTATUS is deprecated and replaced with CWSTATE and CIPSTATE
589- # and the CWSTATE <state> codes are different than the old CIPSTATUS codes.
590- # CWSTATE:
591- # <state>: current Wi-Fi state.
592- # 0: ESP32-C3 station has not started any Wi-Fi connection.
593- # 1: ESP32-C3 station has connected to an AP, but does not get an IPv4 address yet.
594- # 2: ESP32-C3 station has connected to an AP, and got an IPv4 address.
595- # 3: ESP32-C3 station is in Wi-Fi connecting or reconnecting state.
596- # 4: ESP32-C3 station is in Wi-Fi disconnected state.
597- # <”ssid”>: the SSID of the target AP.
598565 replies = self .at_response ("AT+CWSTATE?" , timeout = 5 ).split (b"\r \n " )
599566 for reply in replies :
600567 if reply .startswith (b"+CWSTATE:" ):
@@ -609,20 +576,6 @@ def status_wifi(self) -> Union[int, None]:
609576 @property
610577 def status_socket (self ) -> Union [int , None ]:
611578 """The Socket connection status number (see AT+CIPSTATE for meaning)"""
612- # +CIPSTATE:<link ID>,<"type">,<"remote IP">,<remote port>,<local port>,<tetype>
613- # OK
614- # When there is no connection, AT returns:
615- # OK
616- # Parameters
617- # <link ID>: ID of the connection (0~4), used for multiple connections.
618- # <”type”>: string parameter showing the type of transmission: “TCP”, “TCPv6”,
619- # “UDP”, “UDPv6”, “SSL”, or “SSLv6”.
620- # <”remote IP”>: string parameter showing the remote IPv4 address or IPv6 address.
621- # <remote port>: the remote port number.
622- # <local port>: the local port number.
623- # <tetype>:
624- # 0: ESP32-C3 runs as a client.
625- # 1: ESP32-C3 runs as a server.
626579 replies = self .at_response ("AT+CIPSTATE?" , timeout = 5 ).split (b"\r \n " )
627580 for reply in replies :
628581 # If there are any +CIPSTATE lines that means it's an open socket
@@ -740,6 +693,7 @@ def join_AP( # pylint: disable=invalid-name
740693 return
741694
742695 # pylint: disable=invalid-name
696+ # pylint: disable=too-many-arguments
743697 def join_AP_Enterprise (
744698 self ,
745699 ssid : str ,
@@ -755,7 +709,6 @@ def join_AP_Enterprise(
755709 # Not sure how to verify certificates so we set that to not verify.
756710 certificate_security = 0 # Bit0: Client certificate.Bit1: Server certificate.
757711
758- # First make sure we're in 'station' mode so we can connect to AP's
759712 if self ._debug :
760713 print ("In join_AP_Enterprise()" )
761714 if self .mode != self .MODE_STATION :
@@ -765,9 +718,6 @@ def join_AP_Enterprise(
765718 if router and router [0 ] == ssid :
766719 return # we're already connected!
767720 reply = self .at_response (
768- # from https://docs.espressif.com/projects/esp-at/en/latest/
769- # esp32c3/AT_Command_Set/Wi-Fi_AT_Commands.html#cmd-jeap
770- # AT+CWJEAP=<ssid>,<method>,<identity>,<username>,<password>,<security>[,<jeap_timeout>]
771721 'AT+CWJEAP="'
772722 + ssid
773723 + '",'
@@ -807,9 +757,7 @@ def disconnect(self, timeout: int = 5, retries: int = 3):
807757 else :
808758 wait_for_disconnect = False
809759 if self ._debug is True :
810- print (
811- "disconnect(): Not connected, not waiting for disconnect message"
812- )
760+ print ("disconnect(): Not connected, not waiting for disconnect message" )
813761 reply = self .at_response ("AT+CWQAP" , timeout = timeout , retries = retries )
814762 # Don't bother waiting for disconnect message if we weren't connected already
815763 # sometimes the "WIFI DISCONNECT" shows up in the reply and sometimes it doesn't.
@@ -835,7 +783,6 @@ def disconnect(self, timeout: int = 5, retries: int = 3):
835783 print (
836784 f"disconnect(): Timed out wating for WIFI DISCONNECT: { response } "
837785 )
838- return
839786
840787 def scan_APs ( # pylint: disable=invalid-name
841788 self , retries : int = 3
0 commit comments