Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from umqtt.simple import MQTTClient
- import ubinascii
- import machine
- client_id = 'esp8266-light' + ubinascii.hexlify(machine.unique_id()).decode('utf-8')
- state_topic = 'home/woonkamer/tafel'
- command_topic = 'home/woonkamer/tafel/set'
- class lightstrip():
- def __init__(self, stop = state_topic, ctop = command_topic):
- self.state_topic = stop
- self.command_topic = ctop
- self.light_client = MQTTClient(client_id, mqtt_server_ip)
- print('connected to', mqtt_server_ip, 'as', client_id)
- self.light_client.set_callback(self._mqtt_on_message)
- self.light_client.connect()
- self.light_client.subscribe(self.command_topic)
- self._mqtt_publish_state()
- while True:
- self.light_client.wait_msg()
- if __name__ == '__main__':
- light = lightstrip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement