forked from runmyrobot/runmyrobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot_util.py
executable file
·57 lines (40 loc) · 1.19 KB
/
robot_util.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
import os
import time
import traceback
import ssl
import urllib2
import getpass
import json
ConfigFilename = "/home/pi/config_" + getpass.getuser() + ".json"
def getWithRetry(url, secure=True):
for retryNumber in range(2000):
try:
print "GET", url
if secure:
response = urllib2.urlopen(url).read()
else:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
response = urllib2.urlopen(url, context=ctx).read()
break
except:
print "could not open url", url
traceback.print_exc()
time.sleep(2)
return response
def sendSerialCommand(ser, command):
print(ser.name) # check which port was really used
ser.nonblocking()
# loop to collect input
#s = "f"
#print "string:", s
print str(command.lower())
ser.write(command.lower().encode("utf8") + "\r\n") # write a string
#ser.write(s)
ser.flush()
#ser.reset_input_buffer()
#ser.reset_output_buffer()
#while ser.in_waiting > 0:
#print "read:", ser.read()
#ser.close()