-
Notifications
You must be signed in to change notification settings - Fork 19
/
get_modem_data.py
45 lines (37 loc) · 966 Bytes
/
get_modem_data.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
#!/usrdata/micropython/micropython
import sys
# Remove the home directory from sys.path.
if "~/.micropython/lib" in sys.path:
sys.path.remove("~/.micropython/lib")
sys.path.append("/usrdata/micropython")
import serial
import uos
# Do not put AT in front. The System place it for you
statusCommands=[
"+QSPN",
"+CEREG=2;+CEREG?;+CEREG=0",
"+C5GREG=2;+C5GREG?;+C5GREG=0",
"+CSQ",
"+QENG=\"servingcell\"",
"+QRSRP",
"+QCAINFO",
"+QNWPREFCFG=\"mode_pref\"",
"+QTEMP"
]
# Build AT Command by joining together calls
cmd = 'AT' + ';'.join(statusCommands) + "\r\n"
# Open Serial & Fire Command
ser = serial.Serial("/dev/ttyOUT", baudrate=115200)
ser.write(cmd)
uos.system("sleep 0.025s")
# Write out serial data
out=b''
while ser.in_waiting > 0:
out += ser.read(1)
if "OK" not in str(out):
print('HRM we dont have an OK in here')
sys.exit(1)
f = open('/tmp/modemstatus.txt', 'w')
f.write(out)
f.close()
ser.close()