Skip to content

Commit 808019e

Browse files
author
brentru
committed
fixup sms parsing, check ri before uart
1 parent c88d973 commit 808019e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

adafruit_fona/adafruit_fona.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,15 +441,18 @@ def enable_sms_notification(self, enable=True):
441441
def receive_sms(self):
442442
"""Checks for a message notification from the FONA module,
443443
replies back with the a tuple containing (sender, message).
444+
NOTE: This method needs to be polled consistently due to the lack
445+
of hw-based interrupts in CircuitPython. Adding time.sleep delays
446+
may cause missed messages if using the RI pin instead of UART.
444447
445448
"""
446449
if self._ri is not None: # poll the RI pin
447-
if not self._ri.value:
448-
return False, False
449-
else: # poll the UART instead
450-
if not self._uart.in_waiting:
450+
if self._ri.value:
451451
return False, False
452452

453+
if not self._uart.in_waiting: # otherwise, poll the UART
454+
return False, False
455+
453456
self._read_line() # parse the rcv'd URC
454457
if not self._parse_reply(b"+CMTI: ", idx=1):
455458
return False, False
@@ -597,6 +600,7 @@ def get_host_by_name(self, hostname):
597600
"""Converts a hostname to a packed 4-byte IP address.
598601
Returns a 4 bytearray.
599602
:param str hostname: Destination server.
603+
600604
"""
601605
self._read_line()
602606
if self._debug:
@@ -609,11 +613,9 @@ def get_host_by_name(self, hostname):
609613
):
610614
return False
611615

612-
# attempt to parse a response
613616
self._read_line()
614617
while not self._parse_reply(b"+CDNSGIP:", idx=2):
615618
self._read_line()
616-
617619
return self._buf
618620

619621
def get_socket(self):

examples/fona_sms_response.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@
4040
if not fona.send_sms(int(sender), "Hey, I got your text!"):
4141
print("SMS Send Failed")
4242
print("SMS Sent!")
43+
time.sleep(1)

0 commit comments

Comments
 (0)