46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
import client as paho
|
|
import json
|
|
from uuid import getnode as get_mac
|
|
def get_mac_address():
|
|
try:
|
|
provision = {}
|
|
deviceMap = {}
|
|
with open("/root/python_firmware/provision.json", "r") as f:
|
|
provision = json.load(f)
|
|
with open("/root/python_firmware/drivers/deviceMap.json", "r") as f:
|
|
deviceMap = json.load(f)
|
|
if provision and deviceMap:
|
|
deviceName = provision.get("deviceName")
|
|
if deviceName:
|
|
mac = deviceMap.keys()[deviceMap.values().index(deviceName)]
|
|
if mac:
|
|
return mac
|
|
except Exception as e:
|
|
print("Didn't find mac in deviceMap: {}".format(e))
|
|
try:
|
|
mac = get_mac()
|
|
mac = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))
|
|
return str(mac).lower()
|
|
except:
|
|
mac = "12:34:56:78:91:23"
|
|
return mac
|
|
mac = get_mac_address()
|
|
|
|
|
|
topic_base = "meshify/db/194/_/transferlite/" + mac + ":01:99/"
|
|
topic_meshify = "meshify/db/194/_/mainHP/" + mac + ":00:00/connected"
|
|
c = paho.Client(client_id=mac, clean_session=True)
|
|
c.username_pw_set("admin", "columbus")
|
|
c.will_set(topic_meshify, json.dumps([{"value": False}]), 2)
|
|
c.connect("mq194.imistaway.net", 1883, keepalive=900)
|
|
c.loop_start()
|
|
|
|
def send(payload):
|
|
c.publish(topic_meshify, json.dumps([{"value": True}]), 1)
|
|
for key,value in payload["values"].items():
|
|
topic = topic_base + key
|
|
print(topic)
|
|
print(value)
|
|
c.publish(topic, json.dumps([{"value": value}]), 1)
|
|
|