Guest User

Untitled

a guest
Feb 10th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. from time import sleep
  2. import ssl
  3. import json
  4. import os
  5. from paho.mqtt.client import Client
  6.  
  7. username = "your VRM email"
  8. password = "your VRM pasword"
  9. portal_id = "your VRM portal ID"
  10.  
  11. def on_message(client, userdata, message):
  12. val = json.loads(message.payload)
  13. print message.topic, " = ", val["value"]
  14. val = json.loads(message.payload)
  15. if val["value"] == 1:
  16. client.loop_stop()
  17. client.disconnect()
  18. os._exit(0)
  19.  
  20.  
  21. def on_connect(client, userdata, rc, *args):
  22. client.subscribe("N/%s/system/0/Relay/0/State" % portal_id)
  23. client.publish("W/%s/system/0/Relay/0/State" % portal_id, json.dumps({"value": 1}))
  24.  
  25. client = Client("P1")
  26. client.tls_set(cert_reqs=ssl.CERT_NONE)
  27. client.tls_insecure_set(True)
  28. client.username_pw_set(username, password=password)
  29. client.connect("mqtt.victronenergy.com", port=8883)
  30. client.on_connect = on_connect
  31. client.on_message = on_message
  32.  
  33. client.loop_start()
  34.  
  35. while True:
  36. sleep(1)
Add Comment
Please, Sign In to add comment