Exemplo n.º 1
0
def startTempSensor():

    tempSensorLogger = initLogging('/var/log/fireV3/tempSensor.log')

    #bluetooth_adr = sys.argv[1] # 'A0:E6:F8:AF:3C:06'
    bluetooth_adr = "A0:E6:F8:AF:3C:06"
    print "connecting to " + bluetooth_adr

    startUSB = pexpect.spawn('sudo hciconfig hci0 up')
    tool = pexpect.spawn('gatttool -b ' + bluetooth_adr + ' --interactive')
    tool.expect('\[LE\]>')
    j = 1
    count = 0
    while True:
        #print "Preparing to connect. You might need to press the side button..."
        #tool.sendline('connect')
        # test for success of connect
        #j = tool.expect([pexpect.TIMEOUT, 'Connection successful'], timeout=60)

        j = connectSensor(tool)
        if j == 1:
            print "Connection successful"
            writeData('datafiles/systemStatus.txt', "GOOD")
            tool.expect('\[LE\]>')
            goodConnection = True
            while goodConnection == True:
                # Switch on  Temp sensor
                tool.sendline('char-write-cmd 0x0027 01')
                time.sleep(1)
                # Read the temp data
                tool.sendline('char-read-hnd 0x0024')
                i = 1
                i = tool.expect([pexpect.TIMEOUT, 'descriptor: .*'], timeout=5)
                if i == 1:
                    rVal = tool.after.split()
                    rObjTemp = floatfromhex(rVal[2] + rVal[1])

                    rAmbTemp = floatfromhex(rVal[4] + rVal[3])

                    objTemp = calcTemp(rObjTemp)
                    ambTemp = calcTemp(rAmbTemp)

                    # print "Obj: " + "%.2f C" % objTemp + " Amb:  " + "%.2f " % ambTemp + "%"
                    #tempSensorLogger.debug ( "Obj: " + "%.2fC" % objTemp + " Amb:  " + "%.2fC" % ambTemp)
                    writeData('datafiles/measuredTemperature.txt',
                              "%.1f" % ambTemp)
                    #TODO, only save temperature to file every 5 minutes
                    if count >= 100:
                        saveAmbTempToFile(str(ambTemp))
                        count = 0
                    else:
                        count += 1
                    # Now read the battery life
                    tool.sendline('char-read-hnd 0x001e')
                    k = tool.expect([pexpect.TIMEOUT, 'descriptor: .*'],
                                    timeout=5)
                    if k == 1:
                        rVal = tool.after.split()
                        #print "Battery: " + str(floatfromhex(rVal[1]))
                        writeData('datafiles/batteryLife.txt',
                                  "%.0f" % floatfromhex(rVal[1]))
                    else:
                        goodConnection = False
                        writeData('datafiles/systemStatus.txt', "BTEr")

                else:
                    print "Bad Connection"
                    goodConnection = False
                    writeData('datafiles/systemStatus.txt', "BTEr")
                # Switch off the temp sensor
                tool.sendline('char-write-cmd 0x0027 00')
                time.sleep(1)
        else:
            print "Bad Connection"
            goodConnection = False
            writeData('datafiles/systemStatus.txt', "BTEr")
            time.sleep(1)
Exemplo n.º 2
0
                writeData ('datafiles/timeOverride.txt', 'OFF')

                if event.code == REMOTE_KEY_RED:
                    updateOn()
                elif event.code == REMOTE_KEY_GREEN:
                    updateOff()
                elif event.code == REMOTE_KEY_YELLOW:
                    updateAuto()
                elif event.code == REMOTE_KEY_BLUE:
                    toggleDisplayMode()
                elif event.code == REMOTE_KEY_UP:
                    desiredTemperatureUp()
                elif event.code == REMOTE_KEY_DOWN:
                    desiredTemperatureDown()
                elif event.code == REMOTE_KEY_NONE:
                    pass
                elif event.code == LED_BRIGHTNESS_KEY_UP:
                    ledBrightnessUp()
                elif event.code == LED_BRIGHTNESS_KEY_DOWN:
                    ledBrightnessDown()
                else:
                    # TODO Up/DOWN for desired temperature
                    print "Code: " + str (event.code)


remoteControlLogger = initLogging('/var/log/fireV3/remoteControl.log')

if __name__ == "__main__":
    print "Executing remoteControl.py test code"
    startRemoteScanning()
Exemplo n.º 3
0
            self.runAutoControlAlgorithm()


fire = cFire()
print 'My PID is:', os.getpid()  # Remove after initial debug or move to a log


# For debugging purposes, send kill -USR1 <pid> to see classes internals
def receiveSignal(signum, stack):
    fire.printDebugToScreen()
    fire.printDebugToFile()


signal.signal(signal.SIGUSR1, receiveSignal)

controlFireLogger = initLogging('/var/log/fireV3/controlFire.log')

remoteControlThread = Thread(target=startRemoteScanning, args=())
remoteControlThread.daemon = True
remoteControlThread.start()

temperatureOverrideThread = Thread(target=startTemperatureOverride, args=())
temperatureOverrideThread.daemon = True
temperatureOverrideThread.start()

temperatureSensorThread = Thread(target=startTempSensor, args=())
temperatureSensorThread.daemon = True
temperatureSensorThread.start()

# Control what gets sent to the alphanumeric display
showMessageThread = Thread(target=startShowStatus, args=())
Exemplo n.º 4
0
        try:
            currentOverrideCount = int(readData('datafiles/overrideCount.txt'))
            currentOverrideCount -= 1
            writeData('datafiles/overrideCount.txt', str(currentOverrideCount))
        except:
            pass

        if currentOverrideCount == 0:
            currentOverrideCount = 30
            localtime = datetime.datetime.time(datetime.datetime.now())
            start = datetime.time(16, 0, 0)  # 4pm
            end = datetime.time(22, 0, 0)  # 10pm

            if not (time_in_range(start, end, localtime)):
                # switch the fire off
                tempOverrideLogger.warning(
                    'Switch fire OFF as outside time range at: ' +
                    str(localtime))
                updateOff()
                # Tell the world we are in override mode.
                writeData('datafiles/timeOverride.txt', 'ON')

        time.sleep(60 * 1)  # sleep for 1 minute


tempOverrideLogger = initLogging('/var/log/fireV3/tempOverride.log')

if __name__ == "__main__":
    print "Executing tempOverride.py test code"
    startTemperatureOverride()
Exemplo n.º 5
0
Arquivo: piIO.py Projeto: grimt/fireV3
    display.set_brightness (bright)

# General IO
init_GPIO()

#Alphanumeric Display

# Create display instance on default I2C address (0x70) and bus number.
display = AlphaNum4.AlphaNum4()


# Initialize the display. Must be called once before using the display.
display.begin()

# Logging
piHwIoLogger = initLogging('/var/log/fireV3/piIO.log')

if __name__ == "__main__":
    print "Executing remoteControl.py test code"
    print "Switch relay on: "
    switchFireRelay(ON)
    print "Wait for 1 seconds"
    time.sleep(1)
    print "Switch relay off: "
    switchFireRelay(OFF)

    print "Now test the Alphanumeric"
    printMessage ('KISS')
    time.sleep(5)
    printMessage ('ME')
    time.sleep(5)