def index(): ipcon = IPConnection() # Create IP connection humidity_bricklet = BrickletHumidityV2(HUMIDITY_UID, ipcon) # Create device object barometer_bricklet = BrickletBarometer(BAROMETER_UID, ipcon) ambient_light_bricklet = BrickletAmbientLightV2(AMBIENT_LIGHT_UID, ipcon) ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected temperature = humidity_bricklet.get_temperature()/100.0 humidity = humidity_bricklet.get_humidity()/100.0 air_pressure = barometer_bricklet.get_air_pressure()/1000.0 illuminance = ambient_light_bricklet.get_illuminance()/100.0 ipcon.disconnect() return render_template('index.html', temperature=temperature, humidity=humidity, illuminance=illuminance, air_pressure=air_pressure)
success = client.publish(topic, payload, qos=0, retain=False) print("{}: {}".format(topic, payload)) if __name__ == "__main__": # Tinkerforge setup ipcon = IPConnection() tempBricklet = BrickletTemperature(TEMPUID, ipcon) barometerBricklet = BrickletBarometer(BARUID, ipcon) gpsBricklet = BrickletGPSV2(GPSUID, ipcon) ipcon.connect(HOST, PORT) # MQTT Setup client = mqtt.Client(client_id=client_id) client.on_connect = on_connect client.on_disconnect = on_disconnect client.tls_set("dapo.pem") client.username_pw_set("rpi", "p00rT7daH7Lnb0HzMfA0d+zY2fAOo3") client.connect("dapo.0x80.ch", 8883, 30) # Send loop while(True): time.sleep(5) try: latitude, _, longitude, _ = gpsBricklet.get_coordinates() altitude = gpsBricklet.get_altitude() temperature = tempBricklet.get_temperature() air_pressure = barometerBricklet.get_air_pressure() sendMessage(client, air_pressure,temperature,longitude,latitude,altitude) except e: print(e)
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your Barometer Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_barometer import BrickletBarometer if __name__ == "__main__": ipcon = IPConnection() # Create IP connection b = BrickletBarometer(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Get current air pressure air_pressure = b.get_air_pressure() print("Air Pressure: " + str(air_pressure/1000.0) + " mbar") # Get current altitude altitude = b.get_altitude() print("Altitude: " + str(altitude/100.0) + " m") raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your Barometer Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_barometer import BrickletBarometer if __name__ == "__main__": ipcon = IPConnection() # Create IP connection b = BrickletBarometer(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Get current air pressure (unit is mbar/1000) air_pressure = b.get_air_pressure() print("Air Pressure: " + str(air_pressure/1000.0) + " mbar") # Get current altitude (unit is cm) altitude = b.get_altitude() print("Altitude: " + str(altitude/100.0) + " m") raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()