예제 #1
0
def __main__():
    # check if 1-Wire is setup in the kernel
    if not oneWire.setupOneWire(str(oneWireGpio)):
        print(
            "Kernel module could not be inserted. Please reboot and try again."
        )
        return -1

    # get the address of the temperature sensor
    #   it should be the only device connected in this experiment
    sensorAddress = oneWire.scanOneAddress()

    # instantiate the temperature sensor object
    sensor = TemperatureSensor("oneWire", {
        "address": sensorAddress,
        "gpio": oneWireGpio
    })
    if not sensor.ready:
        print(
            "Sensor was not set up correctly. Please make sure that your sensor is firmly connected to the GPIO specified above and try again."
        )
        return -1

    # infinite loop - runs main program code continuously
    while 1:
        # check and print the temperature
        value = sensor.readValue()
        print("T = " + str(value) + " C")
        time.sleep(pollingInterval)
예제 #2
0
def __main__():
    # initialize oled
    oledHelper.init(dirName)

    device = ubidots.UbidotsDevice(token, deviceName)

    if not oneWire.setupOneWire(str(oneWireGpio)):
        print "Kernel module could not be inserted. Please reboot and try again."
        return -1

    # get the address of the temperature sensor
    # 	it should be the only device connected in this experiment
    sensorAddress = oneWire.scanOneAddress()

    # instantiate the temperature sensor object
    sensor = temperatureSensor.TemperatureSensor("oneWire", {
        "address": sensorAddress,
        "gpio": oneWireGpio
    })
    if not sensor.ready:
        print "Sensor was not set up correctly. Please make sure that your sensor is firmly connected to the GPIO specified above and try again."
        return -1

    # check and print the temperature
    temperature = sensor.readValue()
    dataPoint = {"temperature": temperature}
    device.pushDataPoint(dataPoint)

    # write to oled screen
    oledHelper.writeMeasurements(temperature)
예제 #3
0
    def setupSensor(self):
        if not self.oneWireStatus:
            return False
        if not self.sensorAddress:
            self.sensorAddress = oneWire.scanOneAddress()
            self.logger.info('Found logger with address: {}'.format(
                self.sensorAddress
                ))

        if not self.sensorAddress:
            return False
        self.sensor = SensorInitiator('oneWire', {
            'address': self.sensorAddress,
            'gpio':    self.configs.tempSensorPin
            })

        if not self.sensor.ready:
            self.logger.warning(
                'Sensor was not set up correctly. Please make '
                'sure that your sensor is firmly connected '
                'to the GPIO {} and try again.'.format(
                    self.configs.tempSensorPin
                    )
                )
        self.lastTemperature = self.sensor.readValue()
        return True
예제 #4
0
def __main__():

    if not oneWire.setupOneWire(str(oneWireGpio)):
        print "Kernel module could not be inserted. Please reboot and try again."
        return -1

    # get the address of the temperature sensor
    # 	it should be the only device connected in this experiment
    sensorAddress = oneWire.scanOneAddress()

    # instantiate the temperature sensor object
    sensor = temperatureSensor.TemperatureSensor("oneWire", {
        "address": sensorAddress,
        "gpio": oneWireGpio
    })
    if not sensor.ready:
        print "Sensor was not set up correctly. Please make sure that your sensor is firmly connected to the GPIO specified above and try again."
        return -1

    # check and print the temperature
    temperature = sensor.readValue()
    dataPoint = {"temperature": temperature}

    # temperature is in deg C
    # To change to deg F, add following line:
    temperature = temperature * (9.0 / 5.0) + 32.0

    # Post to Twitter
    twitter.update_status(status="Current Omega2 temperature: " +
                          str(temperature)) + "F"
예제 #5
0
def getTemp():
    # check if 1-Wire was setup in the kernel
    if not oneWire.setupOneWire(str(oneWireGpio)):
        print "Kernel module could not be inserted. Please reboot and try again."
        return -1
    # get the address of the temp sensor
    # it should be the only device connected to this experiment
    sensorAddress = oneWire.scanOneAddress()

    sensor = TemperatureSensor("oneWire", { "address": sensorAddress, "gpio": oneWireGpio })
    if not sensor.ready:
        print "Sensor was not set up correctly. Please make sure that your sensor is firmly connected to the GPIO specified above and try again."
        return -1

    return sensor.readValue()
예제 #6
0
def __main__():
    # check if 1-Wire is setup in the kernel
    if not oneWire.setupOneWire(str(oneWireGpio)):
        print(
            "Kernel module could not be inserted. Please reboot and try again."
        )
        return -1

    # get the address of the temperature sensor
    #   it should be the only device connected in this experiment
    sensorAddress = oneWire.scanOneAddress(
    )  # NEED TO CHANGE THIS FOR HANDLING MORE THAN ONE SERVICE

    # instantiate the temperature sensor object
    sensor = TemperatureSensor()
    sensor.add_sensor("oneWire", {
        "address": sensorAddress,
        "gpio": oneWireGpio
    })
    ok_to_talk = sensor.ask_status(sensorAddress)
    if not ok_to_talk:
        print(
            "Sensor was not set up correctly. Please make sure that your sensor is firmly connected to the GPIO specified above and try again."
        )
        return -1

    client = mqtt.Client(c_name)
    #client.on_message=on_message # attaching function to grab callback
    client.connect(b_name)
    client.loop_start()
    client.subscribe(mqtt_service)  # a/b/c - sensor
    print('connected to {} and subscribed to {}'.format(b_name, mqtt_service))
    print('loop started')
    # infinite loop - runs main program code continuously
    try:
        while True:
            # check and print the temperature
            value = sensor.read_sensor(sensorAddress)
            rp = {'sensor': mqtt_service, 'reading': str(value)}
            rpj = json.dumps(rp)
            client.publish(mqtt_service, rpj)
            print("T = " + str(value) + " C")
            time.sleep(pollingInterval)  # should be at least 4-5 seconds
    except (ValueError, EOFError, KeyboardInterrupt) as e:
        print('encountered {}'.format(e))
        client.loop_stop()
        client.disconnect()
        print('shutdown')

#I/O and PWM set up
os.system('omega2-ctrl gpiomux set uart1 gpio')
os.system('omega2-ctrl gpiomux set pwm0 pwm')
LampPin = 1
FoggerPin = 45
StirPin = 15
LampObj = onionGpio.OnionGpio(LampPin)
StirObj = onionGpio.OnionGpio(StirPin)
FoggerObj = onionGpio.OnionGpio(FoggerPin)

#1-Wire Init
if not oneWire.setupOneWire(str(oneWireGpio)):
    print("Kernel mdule could not be inserted. Try again!")
sensorAddress = oneWire.scanOneAddress()
sensor = TemperatureSensor("oneWire", {
    "address": sensorAddress,
    "gpio": oneWireGpio
})
if not sensor.ready:
    print("Sensore was not set up correctly.")

os.system('onion pwm 0 0 1000')
LampObj.setOutputDirection(0)
FoggerObj.setOutputDirection(0)
StirObj.setOutputDirection(1)

foggSet = True

now = datetime.now()