def publish_as_json(topic, payload, *args, **kwargs): client.publish(topic, json.dumps(payload, separators=(',', ':')), *args, **kwargs) if __name__ == "__main__": # Create IP connection ipcon = IPConnection() # CREATE DEVICE OBJECTS ######################################### # Create BUTTON device object db = BrickletDualButton(pset.UIDdualbutton, ipcon) # Create PIEZO SPEAKER device object ps = BrickletPiezoSpeaker(pset.UIDpiezo, ipcon) # Create device object imu = BrickIMUV2(pset.UIDimu, ipcon) # Create device object # Connect to brickd ipcon.connect(HOST, PORT) # Don't use device before ipcon is connected # Connect to Cloud client = mqtt.Client() client.username_pw_set('miro', '1234') #client.connect('m21.cloudmqtt.com', 13840, 60) # Register state changed callback to function cb_state_changed db.register_callback(db.CALLBACK_STATE_CHANGED, cb_state_changed) ticks = time.time() # Anz. Sekunden für activity timer
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your Piezo Speaker Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_piezo_speaker import BrickletPiezoSpeaker if __name__ == "__main__": ipcon = IPConnection() # Create IP connection ps = BrickletPiezoSpeaker(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Morse SOS with a frequency of 2kHz ps.morse_code("... --- ...", 2000) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()