Skip to content

Commit 58df7a6

Browse files
author
brentru
committed
add response example
1 parent 2351ff1 commit 58df7a6

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

examples/fona_sms_response.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import time
2+
import board
3+
import busio
4+
import digitalio
5+
from adafruit_fona.adafruit_fona import FONA
6+
7+
print("FONA SMS Response")
8+
9+
# Create a serial connection for the FONA connection
10+
uart = busio.UART(board.TX, board.RX)
11+
rst = digitalio.DigitalInOut(board.D5)
12+
13+
# Initialize FONA module (this may take a few seconds)
14+
fona = FONA(uart, rst)
15+
16+
# Enable FONA debug output
17+
fona.debug=True
18+
19+
# Initialize Network
20+
while fona.network_status != 1:
21+
print("Connecting to network...")
22+
time.sleep(1)
23+
print("Connected to network!")
24+
print("RSSI: %ddB" % fona.rssi)
25+
26+
# Enable FONA SMS notification
27+
fona.enable_sms_notification = True
28+
29+
# store incoming notification info
30+
notification_buf = bytearray(64)
31+
32+
print("FONA Ready!")
33+
while True:
34+
if fona.in_waiting: # data is available from FONA
35+
notification_buf = fona._read_line()[1]
36+
# Split out the sms notification slot num.
37+
notification_buf = notification_buf.decode()
38+
sms_slot = notification_buf.split(",")[1]
39+
40+
print("NEW SMS!\n\t Slot: ", sms_slot)
41+
42+
# Get sms message and address
43+
sender, message = fona.read_sms(sms_slot)
44+
print("FROM: ", sender)
45+
print("MSG: ", message)

0 commit comments

Comments
 (0)