Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. from umqtt.simple import MQTTClient
  2. import ubinascii
  3. import machine
  4.  
  5. client_id = 'esp8266-light' + ubinascii.hexlify(machine.unique_id()).decode('utf-8')
  6. state_topic = 'home/woonkamer/tafel'
  7. command_topic = 'home/woonkamer/tafel/set'
  8.  
  9.  
  10. class lightstrip():
  11.  
  12. def __init__(self, stop = state_topic, ctop = command_topic):
  13. self.state_topic = stop
  14. self.command_topic = ctop
  15. self.light_client = MQTTClient(client_id, mqtt_server_ip)
  16. print('connected to', mqtt_server_ip, 'as', client_id)
  17. self.light_client.set_callback(self._mqtt_on_message)
  18. self.light_client.connect()
  19. self.light_client.subscribe(self.command_topic)
  20.  
  21. self._mqtt_publish_state()
  22.  
  23. while True:
  24. self.light_client.wait_msg()
  25.  
  26. if __name__ == '__main__':
  27. light = lightstrip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement