Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
def sendDataToArduino(ser, data):
	writeflush('Sending data to Arduino...')
	ser.write(data.encode())
	print ok()