Skip to content

Commit

Permalink
Added robot_util.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bwookieeeee committed Sep 6, 2018
1 parent bc3fdd4 commit 10d4a67
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions robot_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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()

#while ser.in_waiting > 0:
# print "read:", ser.read()

#ser.close()

0 comments on commit 10d4a67

Please sign in to comment.