def get_light(self): try: uvl = BrickletUVLight(self.LIGHT_UID, self.ipcon) self.ipcon.connect(self.HOST, self.PORT) self.ipcon.disconnect() return float(uv_light) except: return None
# -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your UV Light Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_uv_light import BrickletUVLight # Callback function for UV light callback (parameter has unit µW/cm²) def cb_uv_light(uv_light): print("UV Light: " + str(uv_light) + " µW/cm²") if __name__ == "__main__": ipcon = IPConnection() # Create IP connection uvl = BrickletUVLight(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Register UV light callback to function cb_uv_light uvl.register_callback(uvl.CALLBACK_UV_LIGHT, cb_uv_light) # Set period for UV light callback to 1s (1000ms) # Note: The UV light callback is only called every second # if the UV light has changed since the last call! uvl.set_uv_light_callback_period(1000) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()
from tinkerforge.bricklet_uv_light import BrickletUVLight from tinkerforge.bricklet_motion_detector import BrickletMotionDetector from tinkerforge.bricklet_humidity_v2 import HumidityV2 import time from datetime import datetime if __name__ == "__main__": ipcon = IPConnection() # Create IP connection co2 = BrickletCO2(CO2_UID, ipcon) # Create device object humidity = HumidityV2(HUMIDITY_UID, ipcon) sound_intensity = SoundIntensity(SOUND_INTENSITY_UID, ipcon) dust_density = DustDetector(DUST_UID, ipcon) temperature = Temperature(TEMPERATURE_UID, ipcon) ambientlight = AmbientLight(AMBIENTLIGHT_UID, ipcon) uvlight = BrickletUVLight(UVLIGHT_UID, ipcon) motiondetect = BrickletMotionDetector(MOTIONDETECTOR_UID, ipcon) ipcon.connect(HOST, PORT) # Connect to brickd while (True): curtime = datetime.now() print("Time: " + curtime.strftime('%Y/%m/%d %H:%M:%S')) motion = motiondetect.get_motion_detected() print("Motion: " + str(motion)) illuminance = ambientlight.get_illuminance() / 10.0 print("Illuminance: " + str(illuminance)) uv_light = uvlight.get_uv_light()
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your UV Light Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_uv_light import BrickletUVLight if __name__ == "__main__": ipcon = IPConnection() # Create IP connection uvl = BrickletUVLight(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Get current UV light (unit is µW/cm²) uv_light = uvl.get_uv_light() print("UV Light: " + str(uv_light) + " µW/cm²") raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()
PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your UV Light Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_uv_light import BrickletUVLight # Callback function for UV light reached callback (parameter has unit µW/cm²) def cb_uv_light_reached(uv_light): print("UV Light: " + str(uv_light) + " µW/cm²") print("UV Index > 3. Use sunscreen!") if __name__ == "__main__": ipcon = IPConnection() # Create IP connection uvl = BrickletUVLight(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) uvl.set_debounce_period(10000) # Register UV light reached callback to function cb_uv_light_reached uvl.register_callback(uvl.CALLBACK_UV_LIGHT_REACHED, cb_uv_light_reached) # Configure threshold for UV light "greater than 750 µW/cm²" (unit is µW/cm²) uvl.set_uv_light_callback_threshold(">", 750, 0) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()
def create_instance(self, uid, ipcon): return BrickletUVLight(uid, ipcon)
HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your UV Light Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_uv_light import BrickletUVLight # Callback function for UV light callback def cb_uv_light(uv_light): print("UV Light: " + str(uv_light / 10.0) + " mW/m²") if __name__ == "__main__": ipcon = IPConnection() # Create IP connection uvl = BrickletUVLight(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Register UV light callback to function cb_uv_light uvl.register_callback(uvl.CALLBACK_UV_LIGHT, cb_uv_light) # Set period for UV light callback to 1s (1000ms) # Note: The UV light callback is only called every second # if the UV light has changed since the last call! uvl.set_uv_light_callback_period(1000) 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 UV Light Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_uv_light import BrickletUVLight # Callback function for UV light reached callback (parameter has unit µW/cm²) def cb_uv_light_reached(uv_light): print("UV Light: " + str(uv_light) + " µW/cm²") print("UV Index > 3. Use sunscreen!") if __name__ == "__main__": ipcon = IPConnection() # Create IP connection uvl = BrickletUVLight(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) uvl.set_debounce_period(10000) # Register UV light reached callback to function cb_uv_light_reached uvl.register_callback(uvl.CALLBACK_UV_LIGHT_REACHED, cb_uv_light_reached) # Configure threshold for UV light "greater than 750 µW/cm²" (unit is µW/cm²) uvl.set_uv_light_callback_threshold(">", 750, 0) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()