forked from doniks/pycom-examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlte_sms.py
132 lines (110 loc) · 3.13 KB
/
lte_sms.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from network import LTE
import time
import socket
import machine
import pycom
# todo:
# send/recv sms
# wakup from psm deepsleep via sms, nb: some networks might not queue&deliver, e.g., ATT
def at(cmd):
response = lte.send_at_cmd(cmd).split('\r\n')
for line in response:
if ( len(line) == 0 ):
continue
else:
print(line)
def atv(cmd):
response = lte.send_at_cmd(cmd).split('\r\n')
for line in response:
if ( len(line) == 0 ):
continue
elif line == "OK":
continue
elif line == "ERROR":
continue
else:
print(line)
return line
def sleep(timeout):
while timeout:
print(timeout, end=" ")
time.sleep(1)
timeout -= 1
print("X")
def attach():
if lte.isattached():
print("already attached")
else:
print("attach")
start = time.time()
lte.attach(band=20, apn="spe.inetd.vodafone.nbiot")
print("attach() finished after", time.time() - start, "seconds")
# lte.init(debug=False)
while not lte.isattached():
# AT OK
# AT+CGATT? :0
# AT+CEREG? :2,2
# AT+CFUN? :1
# ....
# AT
# +CEREG: 5,"2E1D","01905667",9
# +CREG: 5,"2E1D","01905667",9
# AT+CGATT?
# +CGATT: 1
print('.', end='')
time.sleep(1)
print()
# lte.init(debug=True)
print("isattached() after", time.time() - start, "seconds")
p = lte.psm()
pretty_print_psm(p)
def connect():
print("connect")
start = time.time()
lte.connect()
print("connect() finished after", time.time() - start, "seconds")
while not lte.isconnected():
print('.', end='')
time.sleep(0.5)
print()
print("isconnected() after", time.time() - start, "seconds")
############################################
pycom.heartbeat(False)
pycom.rgbled(0x000003)
sleep(1)
from network import LTE
print("new")
lte = LTE(debug=True)
# at('AT+CEDRX?')
# [AT] AT+CEDRX?
# [AT-OK]
# ERROR
# at('AT+SQNEDRX=?')
# +SQNEDRX: (0-3),(5),("0000"-"1111"),("0000"-"1111")
at('AT+SQNEDRX?')
# [AT] AT+SQNEDRX?
# [AT-OK]
# +SQNEDRX: 0,5,"1111","0000"
# <mode>[,<Requested_eDRX_value>,<Requested_ptw_value>]
attach()
# at('AT+COPS=?')
at('AT+CPIN?')
at('AT+CREG?') # registered? 2,5,"2E1D","01905667",9
at('AT+COPS?') # network 0,2,"20404",9
at('AT+CSQ')
at('AT+CGEREP=2,0')
at('AT+CMGF=1')
at('AT+CMGF?')
at('AT+CMGS="+<<<PHONENR>>>"\rHullo'+chr(26))
r = lte.send_at_cmd('AT+CMGS="+<<<PHONENR>>>",145\rHullo'+chr(26))
print(r)
r = lte.send_at_cmd('AT+CMGS="<<<PHONENR>>>"\rHullo'+chr(26))
print(r)
r = lte.send_at_cmd('AT+CMGS="<<<PHONENR>>>",129\rHullo'+chr(26))
print(r)
at('AT+CNMI?') # how newly arrived SMS messages should be handled
# connect()
lte.send_at_cmd('AT+CGPADDR')
'\r\n+CGPADDR: 1,"10.175.211.94"\r\n\r\nOK\r\n'
>>> lte.send_at_cmd('AT+CGCONTRDP=1')
'\r\n+CGCONTRDP: 1,5,"spe.inetd.vodafone.nbiot.mnc028.mcc901.gprs","10.175.211.94.255.255.255.255","","10.105.16.254","10.105.144.254","",""\r\n\r\nOK\r\n'