-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsigfox.py
More file actions
54 lines (47 loc) · 1.24 KB
/
Copy pathsigfox.py
File metadata and controls
54 lines (47 loc) · 1.24 KB
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
import serial
import time
import os
def readlineCR(port):
rv = ""
while True:
ch = port.read()
rv += ch
if ch == '\r' or ch == '':
return rv
def detect_sigfox():
for i in range(0, 6):
if(os.path.exists('/dev/ttyUSB' + str(i))):
print("ttyUSB " + str(i) + " exists")
ser = serial.Serial(port = '/dev/ttyUSB' + str(i), baudrate = 9600, timeout = 0.2)
ser.write("AT\r\n")
rcv = readlineCR(ser)
ser.flushInput()
ser.close()
if rcv[:2] == "OK":
break
else:
print("ttyUSB " + str(i) + " not exists")
return i
out_num = detect_sigfox()
print(out_num)
port = serial.Serial("/dev/ttyUSB" + str(out_num), baudrate=9600, timeout=3.0)
port.write("AT\r\n")
time.sleep(0.5)
rcv = readlineCR(port)
print(rcv)
while True:
port.write("AT$I=10\r\n")
time.sleep(0.5)
rcv = readlineCR(port)[3:9]
print(rcv)
port.write("AT$GI?\r\n")
time.sleep(0.5)
rcv = readlineCR(port)
print(rcv)
print "sent msg"
port.write("AT$SF=3103C8133039010504800000\r\n")
time.sleep(5)
port.write("AT$RC\r\n")
time.sleep(0.5)
rcv = readlineCR(port)
print(rcv)