def publishData(data): writeflush('Publishing data to web...') handler = urllib2.urlopen('%s/setstat/temp/%s/mode/%s/output/%s/outputRes/%s' % (config.url, data['temp'], data['mode'], data['output'], data['outputRes'])) if handler.getcode() == 200: print ok() return True print fail() return False
def getSettingsFromWeb(): writeflush('Fetching settings from web...') handler = urllib2.urlopen('%s/getsettings' % config.url) if handler.getcode() == 200: print ok() return handler.read() print fail() return False
def readFromArduino(ser): writeflush('Reading data from Arduino...') buffer = "" while buffer.count('{') < 1: line = ser.readline() buffer += line buffer = buffer.strip('\n').strip('\r').replace('\'', '"') try: arduinoDataObject = json.loads(buffer) except ValueError as e: print fail() return False if 'id' in arduinoDataObject: print ok() return arduinoDataObject print fail() return False