Example #1
0
 def print_debug_log(self, line):
     try:  # debug message received
         expandedMessage = expandLogMessage.expandLogMessage(line[2:])
         printStdErr(expandedMessage)
     except Exception as e:  # catch all exceptions, because out of date file could cause errors
         printStdErr("\nError while expanding log message: {0}".format(str(e)))
         printStdErr(("%(a)s debug message: " % msg_map) + line[2:])
 def print_debug_log(self, line):
     try:  # debug message received
         expandedMessage = expandLogMessage.expandLogMessage(line[2:])
         printStdErr(expandedMessage)
     except Exception, e:  # catch all exceptions, because out of date file could cause errors
         printStdErr("Error while expanding log message: " + str(e))
         printStdErr(("%(a)s debug message: " % msg_map) + line[2:])
Example #3
0
 def reset_settings(self, ser):
     printStdErr("Resetting EEPROM to default settings")
     ser.write('E')
     time.sleep(5)  # resetting EEPROM takes a while, wait 5 seconds
     line = ser.readline()
     if line:  # line available?
         if line[0] == 'D':
             # debug message received
             try:
                 expandedMessage = expandLogMessage.expandLogMessage(line[2:])
                 printStdErr(("%(a)s debug message: " % msg_map) + expandedMessage)
             except Exception, e:  # catch all exceptions, because out of date file could cause errors
                 printStdErr("Error while expanding log message: " + str(e))
                 printStdErr(("%(a)s debug message was: " % msg_map) + line[2:])
                     "Your Arduino is either not programmed yet or running a very old version of BrewPi. "
                     "Arduino will be reset to defaults."))
    else:
        printStdErr("Checking new version: Found " + avrVersionNew.toExtendedString() +
                    " on port " + port + "\n")

    printStdErr("Resetting EEPROM to default settings")
    ser.write('E')
    time.sleep(5)  # resetting EEPROM takes a while, wait 5 seconds
    while 1:  # read all lines on serial interface
        line = ser.readline()
        if line:  # line available?
            if line[0] == 'D':
                # debug message received
                try:
                    expandedMessage = expandLogMessage.expandLogMessage(line[2:])
                    printStdErr("Arduino debug message: " + expandedMessage)
                except Exception, e:  # catch all exceptions, because out of date file could cause errors
                    printStdErr("Error while expanding log message: " + str(e))
                    printStdErr("Arduino debug message was: " + line[2:])
        else:
            break

    if avrVersionNew is None:
        printStdErr(("Warning: Cannot receive version number from Arduino after programming. " +
                     "Something must have gone wrong. Restoring settings/devices settings failed.\n"))
        return 0
    if avrVersionOld is None:
        printStdErr("Could not receive version number from old board, " +
                    "No settings/devices are restored.")
        return 0
Example #5
0
    ser = serial.Serial(config['port'], 57600, timeout=1)
except (OSError, serial.SerialException) as e:
    print e
    exit()

while 1:
    if msvcrt.kbhit():
        received = msvcrt.getch()
        if received == 's':
            print "type the string you want to send to the Arduino: "
            userInput = raw_input()
            print "sending: " + userInput
            ser.write(userInput)
        elif received == 'q':
            ser.close()
            exit()

    line = ser.readline()
    if line:
        if(line[0]=='D'):
            try:
                decoded = json.loads(line[2:])
                print "debug message received: " + expandLogMessage.expandLogMessage(line[2:])
            except json.JSONDecodeError:
                # print line normally, is not json
                print "debug message received: " + line[2:]

        else:
            print line

Example #6
0
                        deviceList['installed'] = json.loads(line[2:])
                        oldListState = deviceList['listState']
                        deviceList['listState'] = oldListState.strip('d') + "d"
                        logMessage("Installed devices received: " + json.dumps(deviceList['installed']).encode('utf-8'))
                    elif line[0] == 'U':
                        logMessage("Device updated to: " + line[2:])
                    else:
                        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()
Example #7
0
ser = util.setupSerial(config)

if not ser:
    exit(1)

while 1:
    if msvcrt.kbhit():
        received = msvcrt.getch()
        if received == 's':
            print "type the string you want to send to the Arduino: "
            userInput = raw_input()
            print "sending: " + userInput
            ser.write(userInput)
        elif received == 'q':
            ser.close()
            exit()

    line = ser.readline()
    if line:
        if (line[0] == 'D'):
            try:
                decoded = json.loads(line[2:])
                print "debug message received: " + expandLogMessage.expandLogMessage(
                    line[2:])
            except json.JSONDecodeError:
                # print line normally, is not json
                print "debug message received: " + line[2:]

        else:
            print line
Example #8
0
            ser.close()
            break
        elif received == 's':
            termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
            fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
            userInput = input(
                "Type the string you want to send to the controller: ")
            print("Sending: " + userInput)
            ser.write(userInput.encode(encoding="cp437"))

        line = ser.readline()
        line = util.asciiToUnicode(line)
        line = line.decode(encoding="cp437")
        if line:
            if (line[0] == 'D'):
                try:
                    decoded = json.loads(line[2:])
                    print("Debug message received: " +
                          expandLogMessage.expandLogMessage(line[2:]))
                except json.JSONDecodeError:
                    # Print line normally, is not json
                    print("Debug message received: " + line[2:])

            else:
                print(line)

finally:
    # Reset the terminal:
    termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
    fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
Example #9
0
                        deviceList['listState'] = oldListState.strip('d') + "d"
                        logMessage("Installed devices received: " + json.dumps(
                            deviceList['installed']).encode('utf-8'))
                    elif line[0] == 'U':
                        logMessage("Device updated to: " + line[2:])
                    else:
                        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))
Example #10
0
                                       json.dumps(newRow['FridgeAnn']) + ';' +
                                       json.dumps(newRow['State']) + ';' +
                                       json.dumps(newRow['RoomTemp']) + '\n')
                        csvFile.write(lineToWrite)
                        if 'brewLoggaUser' in config:
                            logMessage("Send this to brewLogga server: %s" % str(lineToWrite))
                    except KeyError, e:
                        logMessage("KeyError in line from controller: %s" % str(e))

                    csvFile.close()
                    shutil.copyfile(localCsvFileName, wwwCsvFileName)

                elif line[0] == 'D':
                    # debug message received
                    try:
                        expandedMessage = expandLogMessage.expandLogMessage(line[2:])
                        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 '" + line[2:] + "'" + str(e))

                elif line[0] == 'L':
                    # lcd content received
                    prevLcdUpdate = time.time()
                    lcdText = json.loads(line[2:])
                elif line[0] == 'C':
                    # Control constants received
                    cc = json.loads(line[2:])
                elif line[0] == 'S':
                    # Control settings received
                    prevSettingsUpdate = time.time()
                    cs = json.loads(line[2:])