6969
7070FONA_MAX_SOCKETS = const (6 )
7171
72- # Connection modes
73- TCP_MODE = const (0 )
74- UDP_MODE = const (1 )
75-
7672# pylint: enable=bad-whitespace
7773
7874# pylint: disable=too-many-instance-attributes
@@ -84,6 +80,10 @@ class FONA:
8480
8581 """
8682
83+ # Connection modes
84+ TCP_MODE = const (0 )
85+ UDP_MODE = const (1 )
86+
8787 # pylint: disable=too-many-arguments
8888 def __init__ (self , uart , rst , debug = False ):
8989 self ._buf = b"" # shared buffer
@@ -545,14 +545,16 @@ def get_socket(self):
545545 self ._read_line (100 ) # OK
546546 self ._read_line (100 ) # table header
547547
548+ allocated_socket = 0
548549 for sock in range (0 , FONA_MAX_SOCKETS ):
549550 # parse and check for INITIAL client state
550551 self ._read_line (100 )
551552 self ._parse_reply (b"C:" , idx = 5 )
552553 if self ._buf .strip ('"' ) == "INITIAL" or self ._buf .strip ('"' ) == "CLOSED" :
554+ allocated_socket = sock
553555 break
554556 # read out the rest of the responses
555- for _ in range (sock , FONA_MAX_SOCKETS ):
557+ for _ in range (allocated_socket , FONA_MAX_SOCKETS ):
556558 self ._read_line (100 )
557559 return sock
558560
@@ -662,7 +664,7 @@ def socket_connect(self, sock_num, dest, port, conn_mode=TCP_MODE):
662664 # Start connection
663665 self ._uart .write (b"AT+CIPSTART=" )
664666 self ._uart .write (str (sock_num ).encode ())
665- if conn_mode == TCP_MODE :
667+ if conn_mode == 0 :
666668 if self ._debug :
667669 print ('\t --->AT+CIPSTART="TCP","{}",{}' .format (dest , port ))
668670 self ._uart .write (b',"TCP","' )
0 commit comments