elif messageType == "setFridge": # new constant fridge temperature received newTemp = float(value) if(newTemp > cc['tempSettingMin'] and newTemp < cc['tempSettingMax']): cs['mode'] = 'f' cs['fridgeSetting'] = round(newTemp, 2) ser.write("j{mode:f, beerSetting:" + str(cs['fridgeSetting'])) time.sleep(1) # sleep shortly, or something could be added to the string print >> sys.stderr, (time.strftime("%b %d %Y %H:%M:%S ") + "Notification: Fridge temperature set to " + str(cs['fridgeSetting']) + " degrees in web interface") raise socket.timeout # go to serial communication to update Arduino elif messageType == "setProfile": # cs['mode'] set to profile # read temperatures from currentprofile.csv cs['mode'] = 'p' cs['beerSetting'] = temperatureProfile.getNewTemp() ser.write("j{mode:p, beerSetting:" + str(cs['beerSetting'])) time.sleep(1) # sleep shortly, or something could be added to the string print >> sys.stderr, (time.strftime("%b %d %Y %H:%M:%S ") + "Notification: Profile mode enabled") raise socket.timeout # go to serial communication to update Arduino elif messageType == "setOff": # new constant fridge temperature received cs['mode'] = 'o' ser.write("j{mode:o}") print >> sys.stderr, (time.strftime("%b %d %Y %H:%M:%S ") + "Notification: Temperature control disabled") elif messageType == "lcd": # lcd contents requested conn.send(lcdText) elif messageType == "interval": # new interval received newInterval = int(value) if(newInterval > 5 and newInterval < 5000):
except json.decoder.JSONDecodeError, e: logMessage("JSON decode error: %s" % str(e)) logMessage("Line received was: " + line) if message is not None: try: expandedMessage = expandLogMessage.expandLogMessage( message) logMessage("Controller debug message: " + expandedMessage) except Exception, e: # catch all exceptions, because out of date file could cause errors logMessage("Error while expanding log message '" + message + "'" + str(e)) # Check for update from temperature profile if cs['mode'] == 'p': newTemp = temperatureProfile.getNewTemp(util.scriptPath()) if newTemp != cs['beerSet']: cs['beerSet'] = newTemp # if temperature has to be updated send settings to controller bg_ser.write("j{beerSet:" + json.dumps(cs['beerSet']) + "}") except socket.error as e: logMessage("Socket error(%d): %s" % (e.errno, e.strerror)) traceback.print_exc() if bg_ser: bg_ser.stop() if ser: if ser.isOpen(): ser.close() # close port
logMessage("Cannot process line from controller: " + line) # end or processing a line except json.decoder.JSONDecodeError, e: logMessage("JSON decode error: %s" % str(e)) logMessage("Line received was: " + line) if message is not None: try: expandedMessage = expandLogMessage.expandLogMessage(message) logMessage("Controller debug message: " + expandedMessage) except Exception, e: # catch all exceptions, because out of date file could cause errors logMessage("Error while expanding log message '" + message + "'" + str(e)) # Check for update from temperature profile if cs['mode'] == 'p': newTemp = temperatureProfile.getNewTemp(util.scriptPath()) if newTemp != cs['beerSet']: cs['beerSet'] = newTemp # if temperature has to be updated send settings to controller bg_ser.write("j{beerSet:" + json.dumps(cs['beerSet']) + "}") except socket.error as e: logMessage("Socket error(%d): %s" % (e.errno, e.strerror)) traceback.print_exc() if bg_ser: bg_ser.stop() #Stop monitoring the brewometer if brewometer: brewometer.stop()
and newTemp < cc['tempSettingMax']): cs['mode'] = 'f' cs['fridgeSetting'] = round(newTemp, 2) ser.write("j{mode:f, beerSetting:" + str(cs['fridgeSetting'])) time.sleep( 1 ) # sleep shortly, or something could be added to the string print >> sys.stderr, ( time.strftime("%b %d %Y %H:%M:%S ") + "Notification: Fridge temperature set to " + str(cs['fridgeSetting']) + " degrees in web interface") raise socket.timeout # go to serial communication to update Arduino elif messageType == "setProfile": # cs['mode'] set to profile # read temperatures from currentprofile.csv cs['mode'] = 'p' cs['beerSetting'] = temperatureProfile.getNewTemp() ser.write("j{mode:p, beerSetting:" + str(cs['beerSetting'])) time.sleep( 1) # sleep shortly, or something could be added to the string print >> sys.stderr, (time.strftime("%b %d %Y %H:%M:%S ") + "Notification: Profile mode enabled") raise socket.timeout # go to serial communication to update Arduino elif messageType == "setOff": # new constant fridge temperature received cs['mode'] = 'o' ser.write("j{mode:o}") print >> sys.stderr, (time.strftime("%b %d %Y %H:%M:%S ") + "Notification: Temperature control disabled") elif messageType == "lcd": # lcd contents requested conn.send(lcdText) elif messageType == "interval": # new interval received newInterval = int(value)
logMessage("Installed devices received: " + str(deviceList['installed'])) elif line[0] == 'U': logMessage("Device updated to: " + line[2:]) else: logMessage("Cannot process line from Arduino: " + line) # end or processing a line except json.decoder.JSONDecodeError, e: logMessage("JSON decode error: %s" % str(e)) logMessage("Line received was: " + line) except UnicodeDecodeError as e: logMessage("Unicode decode error: %s" % str(e)) logMessage("Line received was: " + line) # Check for update from temperature profile if cs['mode'] == 'p': newTemp = temperatureProfile.getNewTemp(config['scriptPath']) if newTemp != cs['beerSet']: cs['beerSet'] = newTemp if cc['tempSetMin'] < newTemp < cc['tempSetMax']: # if temperature has to be updated send settings to arduino ser.write("j{beerSet:" + str(cs['beerSet']) + "}") elif newTemp is None: # temperature control disabled by profile logMessage("Temperature control disabled by empty cell in profile.") ser.write("j{beerSet:-99999}") # send as high negative value that will result in INT_MIN on Arduino except socket.error as e: logMessage("Socket error(%d): %s" % (e.errno, e.strerror)) traceback.print_exc() if ser:
newTemp = int(data[1:]) if(newTemp>0 and newTemp<300): mode='beer' modeChanged=1; temperatureSetting=newTemp print >> sys.stderr, time.strftime("%b %d %Y %H:%M:%S ") + "Notification: Beer temperature set to " + str(float(newTemp)/10) + " degrees Celcius" elif(data[0]=='f'): #new constant fridge temperature received newTemp = int(data[1:]) if(newTemp>0 and newTemp<300): mode='fridge' modeChanged=1; temperatureSetting=newTemp print >> sys.stderr, time.strftime("%b %d %Y %H:%M:%S ") + "Notification: Fridge temperature set to " + str(float(newTemp)/10) + " degrees Celcius" elif(data[0]=='p'): #mode set to profile, read temperatures from currentprofile.csv mode='profile' temperatureSetting = temperatureProfile.getNewTemp() modeChanged=1; print >> sys.stderr, time.strftime("%b %d %Y %H:%M:%S ") + "Notification: Profile mode enabled" elif(data[0]=='l'): #lcd contents requested conn.send(lcdText) elif(data[0]=='i'): #new interval received newInterval = int(data[1:]) if(newInterval>5 and newInterval<5000): serialRequestInterval=float(newInterval); intervalFile = open('/mnt/uberfridge/settings/interval.txt',"w") intervalFile.write(str(newInterval)) intervalFile.close() print >> sys.stderr, time.strftime("%b %d %Y %H:%M:%S ") + "Notification: Interval changed to " + str(newInterval) + " seconds" elif(data[0]=='n'): #new beer name newName = data[1:] if(len(newName)>3): #shorter names are probably invalid
float(newTemp) / 10) + " degrees Celcius" elif (data[0] == 'f'): #new constant fridge temperature received newTemp = int(data[1:]) if (newTemp > 0 and newTemp < 300): mode = 'fridge' modeChanged = 1 temperatureSetting = newTemp print >> sys.stderr, time.strftime( "%b %d %Y %H:%M:%S " ) + "Notification: Fridge temperature set to " + str( float(newTemp) / 10) + " degrees Celcius" elif ( data[0] == 'p' ): #mode set to profile, read temperatures from currentprofile.csv mode = 'profile' temperatureSetting = temperatureProfile.getNewTemp() modeChanged = 1 print >> sys.stderr, time.strftime( "%b %d %Y %H:%M:%S ") + "Notification: Profile mode enabled" elif (data[0] == 'l'): #lcd contents requested conn.send(lcdText) elif (data[0] == 'i'): #new interval received newInterval = int(data[1:]) if (newInterval > 5 and newInterval < 5000): serialRequestInterval = float(newInterval) intervalFile = open('/mnt/uberfridge/settings/interval.txt', "w") intervalFile.write(str(newInterval)) intervalFile.close() print >> sys.stderr, time.strftime( "%b %d %Y %H:%M:%S "
+ str(cc["tempSetMax"]) ) elif messageType == "setFridge": # new constant fridge temperature received newTemp = float(value) if cc["tempSetMin"] < newTemp < cc["tempSetMax"]: cs["mode"] = "f" cs["fridgeSet"] = round(newTemp, 2) ser.write("j{mode:f, fridgeSet:" + str(cs["fridgeSet"]) + "}") logMessage( "Notification: Fridge temperature set to " + str(cs["fridgeSet"]) + " degrees in web interface" ) raise socket.timeout # go to serial communication to update Arduino elif messageType == "setProfile": # cs['mode'] set to profile # read temperatures from currentprofile.csv cs["mode"] = "p" cs["beerSet"] = temperatureProfile.getNewTemp(config["scriptPath"]) ser.write("j{mode:p, beerSet:" + str(cs["beerSet"]) + "}") logMessage("Notification: Profile mode enabled") raise socket.timeout # go to serial communication to update Arduino elif messageType == "setOff": # cs['mode'] set to OFF cs["mode"] = "o" ser.write("j{mode:o}") logMessage("Notification: Temperature control disabled") raise socket.timeout elif messageType == "setParameters": # receive JSON key:value pairs to set parameters on the Arduino try: decoded = json.loads(value) ser.write("j" + json.dumps(decoded)) if "tempFormat" in decoded: changeWwwSetting("tempFormat", decoded["tempFormat"]) # change in web interface settings too.