def connect_sensors(sensors, uids, ipcon): """ Creates Bricklet Instances :param sensors: connected sensors, as dictionary :param uids: bricklets uids, as dictionary :param ipcon: ipconnection from tinkerforge :return: Dictionary with all instances from connected sensors """ # Dictionary with all connected sensors con_sensors = {} for sensor in sensors: if sensor == "ambient_light": al = BrickletAmbientLightV2(uids["ambient_light"], ipcon) con_sensors.update({"ambient_light": al}) if sensor == "barometer": barometer = BrickletBarometer(uids["barometer"], ipcon) con_sensors.update({"barometer": barometer}) if sensor == "humidity": humidity = BrickletHumidity(uids["humidity"], ipcon) con_sensors.update({"humidity": humidity}) if sensor == "lcd": lcd = BrickletLCD20x4(uids["lcd"], ipcon) con_sensors.update({"lcd": lcd}) if sensor == "moisture": moisture = BrickletMoisture(uids["moisture"], ipcon) con_sensors.update({"moisture": moisture}) if sensor == "temperature": temperature = BrickletTemperature(uids["temperature"], ipcon) con_sensors.update({"temperature": temperature}) if sensor == "thermocouple": thermo = BrickletThermocouple(uids["thermocouple"], ipcon) con_sensors.update({"thermocouple": thermo}) return con_sensors
def connect_sensors(): global al global barometer global humidity global lcd global moisture global temperature global thermo if sensors["ambient_light"] == 1: al = BrickletAmbientLightV2(UID_AMBIENT, ipcon) if sensors["barometer"] == 1: barometer = BrickletBarometer(UID_BAROMETER, ipcon) if sensors["humidity"] == 1: humidity = BrickletHumidity(UID_HUMIDITY, ipcon) if sensors["lcd"] == 1: lcd = BrickletLCD20x4(UID_LCD, ipcon) if sensors["moisture"] == 1: moisture = BrickletMoisture(UID_MOISTURE, ipcon) if sensors["temperature"] == 1: temperature = BrickletTemperature(UID_TEMPERATURE, ipcon) if sensors["thermo_couple"] == 1: thermo = BrickletThermocouple(UID_THERMO, ipcon)
HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your Thermocouple Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_thermocouple import BrickletThermocouple # Callback function for temperature reached callback def cb_temperature_reached(temperature): print("Temperature: " + str(temperature / 100.0) + " °C") if __name__ == "__main__": ipcon = IPConnection() # Create IP connection t = BrickletThermocouple(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Get threshold callbacks with a debounce time of 10 seconds (10000ms) t.set_debounce_period(10000) # Register temperature reached callback to function cb_temperature_reached t.register_callback(t.CALLBACK_TEMPERATURE_REACHED, cb_temperature_reached) # Configure threshold for temperature "greater than 30 °C" t.set_temperature_callback_threshold(">", 30 * 100, 0) input("Press key to exit\n") # Use raw_input() in Python 2 ipcon.disconnect()
HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your Thermocouple Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_thermocouple import BrickletThermocouple # Callback function for temperature callback (parameter has unit °C/100) def cb_temperature(temperature): print("Temperature: " + str(temperature / 100.0) + " °C") if __name__ == "__main__": ipcon = IPConnection() # Create IP connection t = BrickletThermocouple(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Register temperature callback to function cb_temperature t.register_callback(t.CALLBACK_TEMPERATURE, cb_temperature) # Set period for temperature callback to 1s (1000ms) # Note: The temperature callback is only called every second # if the temperature has changed since the last call! t.set_temperature_callback_period(1000) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()
# -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your Thermocouple Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_thermocouple import BrickletThermocouple # Callback function for temperature reached callback (parameter has unit °C/100) def cb_temperature_reached(temperature): print("Temperature: " + str(temperature/100.0) + " °C") if __name__ == "__main__": ipcon = IPConnection() # Create IP connection t = BrickletThermocouple(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Get threshold callbacks with a debounce time of 10 seconds (10000ms) t.set_debounce_period(10000) # Register temperature reached callback to function cb_temperature_reached t.register_callback(t.CALLBACK_TEMPERATURE_REACHED, cb_temperature_reached) # Configure threshold for temperature "greater than 30 °C" (unit is °C/100) t.set_temperature_callback_threshold(">", 30*100, 0) 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 Thermocouple Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_thermocouple import BrickletThermocouple if __name__ == "__main__": ipcon = IPConnection() # Create IP connection t = BrickletThermocouple(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Get current temperature (unit is °C/100) temperature = t.get_temperature() print("Temperature: " + str(temperature / 100.0) + " °C") raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()
def create_instance(self, uid, ipcon): return BrickletThermocouple(uid, ipcon)
HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your Thermocouple Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_thermocouple import BrickletThermocouple # Callback function for temperature callback def cb_temperature(temperature): print("Temperature: " + str(temperature / 100.0) + " °C") if __name__ == "__main__": ipcon = IPConnection() # Create IP connection t = BrickletThermocouple(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Register temperature callback to function cb_temperature t.register_callback(t.CALLBACK_TEMPERATURE, cb_temperature) # Set period for temperature callback to 1s (1000ms) # Note: The temperature callback is only called every second # if the temperature has changed since the last call! t.set_temperature_callback_period(1000) input("Press key to exit\n") # Use raw_input() in Python 2 ipcon.disconnect()
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your Thermocouple Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_thermocouple import BrickletThermocouple if __name__ == "__main__": ipcon = IPConnection() # Create IP connection t = BrickletThermocouple(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Get current temperature (unit is °C/100) temperature = t.get_temperature() print("Temperature: " + str(temperature/100.0) + " °C") raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()