-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskywire_sms_chat.py
47 lines (39 loc) · 1.46 KB
/
skywire_sms_chat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /usr/bin/env python
"""
This code will demonstrate how to use SMS to control a Beagle Bone Green using a Nimbelink Skywire modem.
"""
import sys
import gps_modem
import grove_dht
from datetime import datetime
def process_message(modem, from_number, message):
lc_m = message.lower()
print("Processing message: {}".format(lc_m))
if lc_m.startswith('what time is it'):
reply = datetime.now().strftime('Hi! According to my watch the time is %I:%M:%S %p UTC')
elif lc_m.startswith('what is the temp'):
try:
hum, temp = grove_dht.read()
reply = 'The temperature is {.2f} celsius with a humidity of {}%'.format(temp, hum)
except Exception as e:
print("Failed to read temperature: {}".format(e.message))
reply = 'Sorry, I seem to be broken. :('
else:
print("Unknown message: {}".format(message))
reply = 'Sorry. I am not that smart. Roses are red...'
modem.write_message(from_number, reply)
def main():
modem = gps_modem.GPSModem()
modem.set_text_mode()
while True:
try:
mt_message, sender = modem.pop_message()
if mt_message is not None and sender is not None:
process_message(modem, sender, mt_message)
except KeyboardInterrupt:
print("Caught keyboard interrupt. Bye!")
if modem is not None:
modem.reset_modem()
sys.exit()
if __name__ == '__main__':
main()