@@ -229,7 +229,6 @@ def iccid(self):
229
229
@property
230
230
def gprs (self ):
231
231
"""Returns module's GPRS state."""
232
- self ._read_line ()
233
232
234
233
if not self ._send_parse_reply (b"AT+CGATT?" , b"+CGATT: " , ":" ):
235
234
return False
@@ -330,24 +329,15 @@ def set_gprs(self, apn=None, enable=True):
330
329
331
330
@property
332
331
def network_status (self ):
333
- """Returns cellular/ network status"""
332
+ """Returns cellular network status"""
334
333
if self ._debug :
335
334
print ("Network status" )
336
335
if not self ._send_parse_reply (b"AT+CREG?" , b"+CREG: " , idx = 1 ):
337
336
return False
338
- if self ._buf == 0 : # Not Registered
339
- return self ._buf
340
- if self ._buf == 1 : # Registered (home)
341
- return self ._buf
342
- if self ._buf == 2 : # Not Registered (searching)
343
- return self ._buf
344
- if self ._buf == 3 : # Denied
345
- return self ._buf
346
- if self ._buf == 4 : # Unknown
347
- return self ._buf
348
- if self ._buf == 5 : # Registered Roaming
349
- return self ._buf
350
- return False
337
+ status = self ._buf
338
+ if not 0 <= self ._buf <= 5 :
339
+ status = - 1
340
+ return status
351
341
352
342
@property
353
343
def rssi (self ):
@@ -451,7 +441,6 @@ def get_host_by_name(self, hostname):
451
441
"""
452
442
if self ._debug :
453
443
print ("*** Get host by name" )
454
- self ._read_line ()
455
444
if isinstance (hostname , str ):
456
445
hostname = bytes (hostname , "utf-8" )
457
446
@@ -527,7 +516,7 @@ def num_sms(self, sim_storage=True):
527
516
if not self ._send_check_reply (b"AT+CMGF=1" , reply = REPLY_OK ):
528
517
return False
529
518
530
- if sim_storage : # ask how many SMS are stored
519
+ if sim_storage : # ask how many SMS are stored
531
520
if self ._send_parse_reply (b"AT+CPMS?" , FONA_SMS_STORAGE_SIM + b"," , idx = 1 ):
532
521
return self ._buf
533
522
else :
@@ -562,7 +551,6 @@ def delete_sms(self, sms_slot):
562
551
:param int sms_slot: SMS SIM or FONA memory slot number.
563
552
564
553
"""
565
- self ._read_line ()
566
554
if not self ._send_check_reply (b"AT+CMGF=1" , reply = REPLY_OK ):
567
555
return False
568
556
@@ -579,7 +567,6 @@ def read_sms(self, sms_slot):
579
567
:param int sms_slot: SMS SIM or FONA memory slot number.
580
568
581
569
"""
582
- self ._read_line ()
583
570
if not self ._send_check_reply (b"AT+CMGF=1" , reply = REPLY_OK ):
584
571
return False
585
572
if not self ._send_check_reply (b"AT+CSDH=1" , reply = REPLY_OK ):
@@ -620,7 +607,7 @@ def get_socket(self):
620
607
self ._read_line (100 ) # table header
621
608
622
609
allocated_socket = 0
623
- for sock in range (0 , FONA_MAX_SOCKETS ): # check if INITIAL state
610
+ for sock in range (0 , FONA_MAX_SOCKETS ): # check if INITIAL state
624
611
self ._read_line (100 )
625
612
self ._parse_reply (b"C:" , idx = 5 )
626
613
if self ._buf .strip ('"' ) == "INITIAL" or self ._buf .strip ('"' ) == "CLOSED" :
@@ -661,7 +648,7 @@ def socket_status(self, sock_num):
661
648
return False
662
649
self ._read_line ()
663
650
664
- for state in range (0 , sock_num + 1 ): # read "C: <n>" for each active connection
651
+ for state in range (0 , sock_num + 1 ): # read "C: <n>" for each active connection
665
652
self ._read_line ()
666
653
if state == sock_num :
667
654
break
@@ -762,7 +749,6 @@ def socket_close(self, sock_num, quick_close=1):
762
749
sock_num < FONA_MAX_SOCKETS
763
750
), "Provided socket exceeds the maximum number of \
764
751
sockets for the FONA module."
765
- self ._read_line ()
766
752
767
753
self .uart_write (b"AT+CIPCLOSE=" + str (sock_num ).encode () + b"," )
768
754
self .uart_write (str (quick_close ).encode () + b"\r \n " )
@@ -782,7 +768,6 @@ def socket_read(self, sock_num, length):
782
768
sock_num < FONA_MAX_SOCKETS
783
769
), "Provided socket exceeds the maximum number of \
784
770
sockets for the FONA module."
785
- self ._read_line ()
786
771
if self ._debug :
787
772
print ("* socket read" )
788
773
@@ -807,7 +792,6 @@ def socket_write(self, sock_num, buffer):
807
792
808
793
"""
809
794
self ._read_line ()
810
- self ._read_line ()
811
795
assert (
812
796
sock_num < FONA_MAX_SOCKETS
813
797
), "Provided socket exceeds the maximum number of \
@@ -849,6 +833,7 @@ def _send_parse_reply(self, send_data, reply_data, divider=",", idx=0):
849
833
:param str divider: Separator
850
834
851
835
"""
836
+ self ._read_line ()
852
837
self ._get_reply (send_data )
853
838
854
839
if not self ._parse_reply (reply_data , divider , idx ):
@@ -914,9 +899,9 @@ def _read_line(self, timeout=FONA_DEFAULT_TIMEOUT_MS, multiline=False):
914
899
if char == b"\r " :
915
900
continue
916
901
if char == b"\n " :
917
- if reply_idx == 0 : # ignore first '\n'
902
+ if reply_idx == 0 : # ignore first '\n'
918
903
continue
919
- if not multiline : # second '\n' is EOL
904
+ if not multiline : # second '\n' is EOL
920
905
timeout = 0
921
906
break
922
907
self ._buf += char
@@ -945,6 +930,7 @@ def _send_check_reply(
945
930
:param bytes reply: Expected response from module.
946
931
947
932
"""
933
+ self ._read_line ()
948
934
if send is None :
949
935
if not self ._get_reply (prefix = prefix , suffix = suffix , timeout = timeout ):
950
936
return False
0 commit comments