@@ -133,7 +133,7 @@ def _init_fona(self):
133
133
self ._uart .reset_input_buffer ()
134
134
135
135
self .uart_write (b"ATI\r \n " )
136
- self ._read_line (multiline = True )
136
+ self .read_line (multiline = True )
137
137
138
138
if self ._buf .find (b"SIM808 R14" ) != - 1 :
139
139
self ._fona_type = FONA_808_V2
@@ -147,7 +147,7 @@ def _init_fona(self):
147
147
if self ._fona_type == FONA_800_L :
148
148
# determine if SIM800H
149
149
self .uart_write (b"AT+GMM\r \n " )
150
- self ._read_line (multiline = True )
150
+ self .read_line (multiline = True )
151
151
152
152
if self ._buf .find (b"SIM800H" ) != - 1 :
153
153
self ._fona_type = FONA_800_H
@@ -188,15 +188,15 @@ def iemi(self):
188
188
self ._uart .reset_input_buffer ()
189
189
190
190
self .uart_write (b"AT+GSN\r \n " )
191
- self ._read_line (multiline = True )
191
+ self .read_line (multiline = True )
192
192
iemi = self ._buf [0 :15 ]
193
193
return iemi .decode ("utf-8" )
194
194
195
195
@property
196
196
def local_ip (self ):
197
197
"""Returns the local IP Address, False if not set."""
198
198
self .uart_write (b"AT+CIFSR\r \n " )
199
- self ._read_line ()
199
+ self .read_line ()
200
200
try :
201
201
ip_addr = self .pretty_ip (self ._buf )
202
202
except ValueError :
@@ -209,9 +209,9 @@ def iccid(self):
209
209
if self ._debug :
210
210
print ("ICCID" )
211
211
self .uart_write (b"AT+CCID\r \n " )
212
- self ._read_line (timeout = 2000 ) # 6.2.23, 2sec max. response time
212
+ self .read_line (timeout = 2000 ) # 6.2.23, 2sec max. response time
213
213
iccid = self ._buf .decode ()
214
- self ._read_line () # eat 'OK'
214
+ self .read_line () # eat 'OK'
215
215
return iccid
216
216
217
217
@property
@@ -240,7 +240,7 @@ def set_gprs(self, apn=None, enable=True):
240
240
# enable multi connection mode (3,1)
241
241
if not self ._send_check_reply (b"AT+CIPMUX=1" , reply = REPLY_OK ):
242
242
return False
243
- self ._read_line ()
243
+ self .read_line ()
244
244
245
245
# enable receive data manually (7,2)
246
246
if not self ._send_check_reply (b"AT+CIPRXGET=1" , reply = REPLY_OK ):
@@ -348,7 +348,7 @@ def rssi(self):
348
348
rssi = map_range (reply_num , 2 , 30 , - 110 , - 54 )
349
349
350
350
# read out the 'ok'
351
- self ._read_line ()
351
+ self .read_line ()
352
352
return rssi
353
353
354
354
@property
@@ -367,7 +367,7 @@ def gps(self):
367
367
status = int (self ._buf [10 :11 ].decode ("utf-8" ))
368
368
if status == 1 :
369
369
status = 3 # assume 3D fix
370
- self ._read_line ()
370
+ self .read_line ()
371
371
elif self ._fona_type == FONA_3G_A or self ._fona_type == FONA_3G_E :
372
372
raise NotImplementedError (
373
373
"FONA 3G not currently supported by this library."
@@ -396,14 +396,14 @@ def gps(self, gps_on=False):
396
396
if self ._fona_type == FONA_808_V2 :
397
397
if not self ._send_parse_reply (b"AT+CGPSPWR?" , b"+CGPSPWR: " , ":" ):
398
398
return False
399
- self ._read_line ()
399
+ self .read_line ()
400
400
if not self ._send_parse_reply (b"AT+CGNSPWR?" , b"+CGNSPWR: " , ":" ):
401
401
return False
402
402
403
403
state = self ._buf
404
404
405
405
if gps_on and not state :
406
- self ._read_line ()
406
+ self .read_line ()
407
407
if self ._fona_type == FONA_808_V2 :
408
408
# try GNS
409
409
if not self ._send_check_reply (b"AT+CGNSPWR=1" , reply = REPLY_OK ):
@@ -438,9 +438,9 @@ def get_host_by_name(self, hostname):
438
438
return False
439
439
440
440
# attempt to parse a response
441
- self ._read_line ()
441
+ self .read_line ()
442
442
while not self ._parse_reply (b"+CDNSGIP:" , idx = 2 ):
443
- self ._read_line ()
443
+ self .read_line ()
444
444
445
445
return self ._buf
446
446
@@ -487,23 +487,23 @@ def send_sms(self, phone_number, message):
487
487
return False
488
488
489
489
self .uart_write (b'AT+CMGS="+' + str (phone_number ).encode () + b'"' + b"\r " )
490
- self ._read_line ()
490
+ self .read_line ()
491
491
492
492
# expect >
493
493
if self ._buf [0 ] != 62 :
494
494
# promoting mark ('>') not found
495
495
return False
496
- self ._read_line ()
496
+ self .read_line ()
497
497
498
498
# write out message and ^z
499
499
self .uart_write ((message + chr (26 )).encode ())
500
500
501
501
if self ._fona_type == FONA_3G_A or self ._fona_type == FONA_3G_E :
502
502
# eat 2x CRLF
503
- self ._read_line (200 )
504
- self ._read_line (200 )
503
+ self .read_line (200 )
504
+ self .read_line (200 )
505
505
# read +CMGS, wait ~10sec.
506
- self ._read_line (10000 )
506
+ self .read_line (10000 )
507
507
508
508
if not "+CMGS" in self ._buf :
509
509
return False
@@ -531,18 +531,18 @@ def num_sms(self, sim_storage=True):
531
531
):
532
532
return self ._buf
533
533
534
- self ._read_line () # eat OK
534
+ self .read_line () # eat OK
535
535
if self ._send_parse_reply (b"AT+CPMS?" , b'"SM",' , idx = 1 ):
536
536
return self ._buf
537
537
538
- self ._read_line () # eat OK
538
+ self .read_line () # eat OK
539
539
if self ._send_parse_reply (b"AT+CPMS?" , b'"SM_P",' , idx = 1 ):
540
540
return self ._buf
541
541
return False
542
542
543
543
def delete_all_sms (self ):
544
544
"""Deletes all SMS messages on the FONA SIM."""
545
- self ._read_line ()
545
+ self .read_line ()
546
546
if not self ._send_check_reply (b"AT+CMGF=1" , reply = REPLY_OK ):
547
547
return False
548
548
@@ -579,7 +579,7 @@ def read_sms(self, sms_slot):
579
579
return False
580
580
581
581
self .uart_write (b"AT+CMGR=" + str (sms_slot ).encode () + b"\r \n " )
582
- self ._read_line (1000 )
582
+ self .read_line (1000 )
583
583
resp = self ._buf
584
584
585
585
# get sender
@@ -597,7 +597,7 @@ def read_sms(self, sms_slot):
597
597
self ._uart .readinto (self ._buf )
598
598
message = bytes (self ._buf ).decode ()
599
599
self ._uart .reset_input_buffer ()
600
- self ._read_line () # eat 'OK'
600
+ self .read_line () # eat 'OK'
601
601
602
602
return sender , message
603
603
@@ -611,19 +611,19 @@ def get_socket(self):
611
611
print ("*** Get socket" )
612
612
613
613
self .uart_write (b"AT+CIPSTATUS\r \n " )
614
- self ._read_line (100 ) # OK
615
- self ._read_line (100 ) # table header
614
+ self .read_line (100 ) # OK
615
+ self .read_line (100 ) # table header
616
616
617
617
allocated_socket = 0
618
618
for sock in range (0 , FONA_MAX_SOCKETS ): # check if INITIAL state
619
- self ._read_line (100 )
619
+ self .read_line (100 )
620
620
self ._parse_reply (b"C:" , idx = 5 )
621
621
if self ._buf .strip ('"' ) == "INITIAL" or self ._buf .strip ('"' ) == "CLOSED" :
622
622
allocated_socket = sock
623
623
break
624
624
# read out the rest of the responses
625
625
for _ in range (allocated_socket , FONA_MAX_SOCKETS ):
626
- self ._read_line (100 )
626
+ self .read_line (100 )
627
627
if self ._debug :
628
628
print ("Allocated socket #%d" % allocated_socket )
629
629
return allocated_socket
@@ -638,7 +638,7 @@ def remote_ip(self, sock_num):
638
638
), "Provided socket exceeds the maximum number of \
639
639
sockets for the FONA module."
640
640
self .uart_write (b"AT+CIPSTATUS=" + str (sock_num ).encode () + b"\r \n " )
641
- self ._read_line (100 )
641
+ self .read_line (100 )
642
642
643
643
self ._parse_reply (b"+CIPSTATUS:" , idx = 3 )
644
644
return self ._buf
@@ -654,10 +654,10 @@ def socket_status(self, sock_num):
654
654
sockets for the FONA module."
655
655
if not self ._send_check_reply (b"AT+CIPSTATUS" , reply = REPLY_OK , timeout = 100 ):
656
656
return False
657
- self ._read_line ()
657
+ self .read_line ()
658
658
659
659
for state in range (0 , sock_num + 1 ): # read "C: <n>" for each active connection
660
- self ._read_line ()
660
+ self .read_line ()
661
661
if state == sock_num :
662
662
break
663
663
self ._parse_reply (b"C:" , idx = 5 )
@@ -666,7 +666,7 @@ def socket_status(self, sock_num):
666
666
667
667
# eat the rest of the sockets
668
668
for _ in range (sock_num , FONA_MAX_SOCKETS ):
669
- self ._read_line ()
669
+ self .read_line ()
670
670
671
671
if not "CONNECTED" in state :
672
672
return False
@@ -691,8 +691,8 @@ def socket_available(self, sock_num):
691
691
if self ._debug :
692
692
print ("\t {} bytes available." .format (self ._buf ))
693
693
694
- self ._read_line ()
695
- self ._read_line ()
694
+ self .read_line ()
695
+ self .read_line ()
696
696
697
697
return data
698
698
@@ -727,7 +727,7 @@ def socket_connect(self, sock_num, dest, port, conn_mode=TCP_MODE):
727
727
728
728
# Query local IP Address
729
729
self .uart_write (b"AT+CIFSR\r \n " )
730
- self ._read_line ()
730
+ self .read_line ()
731
731
732
732
# Start connection
733
733
self .uart_write (b"AT+CIPSTART=" + str (sock_num ).encode ())
@@ -760,7 +760,7 @@ def socket_close(self, sock_num, quick_close=1):
760
760
761
761
self .uart_write (b"AT+CIPCLOSE=" + str (sock_num ).encode () + b"," )
762
762
self .uart_write (str (quick_close ).encode () + b"\r \n " )
763
- self ._read_line ()
763
+ self .read_line ()
764
764
if not self ._parse_reply (b"CLOSE OK" , idx = 0 ):
765
765
return False
766
766
return True
@@ -784,7 +784,7 @@ def socket_read(self, sock_num, length):
784
784
self .uart_write (b"," )
785
785
self .uart_write (str (length ).encode () + b"\r \n " )
786
786
787
- self ._read_line ()
787
+ self .read_line ()
788
788
789
789
if not self ._parse_reply (b"+CIPRXGET:" ):
790
790
return False
@@ -799,7 +799,7 @@ def socket_write(self, sock_num, buffer):
799
799
:param bytes buffer: Bytes to write to socket.
800
800
801
801
"""
802
- self ._read_line ()
802
+ self .read_line ()
803
803
assert (
804
804
sock_num < FONA_MAX_SOCKETS
805
805
), "Provided socket exceeds the maximum number of \
@@ -808,14 +808,14 @@ def socket_write(self, sock_num, buffer):
808
808
self ._uart .reset_input_buffer ()
809
809
self .uart_write (b"AT+CIPSEND=" + str (sock_num ).encode ())
810
810
self .uart_write (b"," + str (len (buffer )).encode () + b"\r \n " )
811
- self ._read_line ()
811
+ self .read_line ()
812
812
813
813
if self ._buf [0 ] != 62 :
814
814
# promoting mark ('>') not found
815
815
return False
816
816
817
817
self .uart_write (buffer + b"\r \n " )
818
- self ._read_line (3000 )
818
+ self .read_line (3000 )
819
819
820
820
if "SEND OK" not in self ._buf .decode ():
821
821
return False
@@ -829,15 +829,6 @@ def in_waiting(self):
829
829
"""Returns number of bytes available to be read in the input buffer."""
830
830
return self ._uart .in_waiting
831
831
832
- def uart_readinto (self , buf ):
833
- """Reads len(buf) bytes into a provided buf.
834
- :param bytearray buf: bytes object.
835
- """
836
- self ._uart .readinto (buf )
837
- if self ._debug :
838
- print ("\t UARTREAD ::" , buf )
839
- return buf
840
-
841
832
def uart_write (self , buffer ):
842
833
"""UART ``write`` with optional debug that prints
843
834
the buffer before sending.
@@ -855,7 +846,7 @@ def _send_parse_reply(self, send_data, reply_data, divider=",", idx=0):
855
846
:param str divider: Separator
856
847
857
848
"""
858
- self ._read_line ()
849
+ self .read_line ()
859
850
self ._get_reply (send_data )
860
851
861
852
if not self ._parse_reply (reply_data , divider , idx ):
@@ -877,7 +868,7 @@ def _get_reply(
877
868
else :
878
869
self .uart_write (prefix + suffix + b"\r \n " )
879
870
880
- return self ._read_line (timeout )
871
+ return self .read_line (timeout )
881
872
882
873
def _parse_reply (self , reply , divider = "," , idx = 0 ):
883
874
"""Attempts to find reply in UART buffer, reads up to divider.
@@ -903,7 +894,7 @@ def _parse_reply(self, reply, divider=",", idx=0):
903
894
904
895
return True
905
896
906
- def _read_line (self , timeout = FONA_DEFAULT_TIMEOUT_MS , multiline = False ):
897
+ def read_line (self , timeout = FONA_DEFAULT_TIMEOUT_MS , multiline = False ):
907
898
"""Reads one or multiple lines into the buffer. Optionally prints the buffer
908
899
after reading.
909
900
:param int timeout: Time to wait for UART serial to reply, in seconds.
@@ -952,7 +943,7 @@ def _send_check_reply(
952
943
:param bytes reply: Expected response from module.
953
944
954
945
"""
955
- self ._read_line ()
946
+ self .read_line ()
956
947
if send is None :
957
948
if not self ._get_reply (prefix = prefix , suffix = suffix , timeout = timeout ):
958
949
return False
@@ -995,14 +986,14 @@ def _get_reply_quoted(self, prefix, suffix, timeout):
995
986
996
987
self .uart_write (prefix + b'"' + suffix + b'"\r \n ' )
997
988
998
- return self ._read_line (timeout )
989
+ return self .read_line (timeout )
999
990
1000
991
def _expect_reply (self , reply , timeout = 10000 ):
1001
992
"""Reads line from FONA module and compares to reply from FONA module.
1002
993
:param bytes reply: Expected reply from module.
1003
994
1004
995
"""
1005
- self ._read_line (timeout )
996
+ self .read_line (timeout )
1006
997
if reply not in self ._buf :
1007
998
return False
1008
999
return True
0 commit comments