updates to thunderbird report and meshify drivers

This commit is contained in:
Nico Melone
2024-11-12 08:40:28 -06:00
parent ac8f419707
commit 3fda556b3e
36 changed files with 10284 additions and 54 deletions

View File

@@ -1,12 +1,14 @@
{
"files": {
"file3": "channel.py",
"file3": "Channel.py",
"file2": "utilities.py",
"file1": "transferlite.py",
"file4": "file_logger.py"
"file4": "file_logger.py",
"file5": "sendToMA.py",
"file6": "persistence.py"
},
"deviceName": "transferlite",
"driverId": "0230",
"releaseVersion": "5",
"releaseVersion": "7",
"driverFileName": "transferlite.py"
}

View File

@@ -0,0 +1,45 @@
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)

View File

@@ -10,7 +10,7 @@ from device_base import deviceBase
from channel import PLCChannel, read_tag, write_tag,TAG_DATAERROR_SLEEPTIME
from utilities import get_public_ip_address
from file_logger import filelogger as log
from sendToMA import send
_ = None
log.info("transferlite startup")
@@ -45,6 +45,7 @@ IP_CHECK_PERIOD = 60
WATCHDOG_ENABLE = True
WATCHDOG_CHECK_PERIOD = 60
WATCHDOG_SEND_PERIOD = 3600 # Seconds, the longest amount of time before sending the watchdog status
REPORT_PERIOD = 600
PLC_IP_ADDRESS = "192.168.1.10"
CHANNELS = [
PLCChannel(PLC_IP_ADDRESS, "ft01_flowmeter_bpd", "FT01_Flowmeter_BPD", "REAL", 100.0, 600),
@@ -81,7 +82,7 @@ class start(threading.Thread, deviceBase):
mqtt=mqtt, Nodes=Nodes)
self.daemon = True
self.version = "5"
self.version = "7"
self.finished = threading.Event()
self.force_send = False
self.public_ip_address = ""
@@ -116,17 +117,18 @@ class start(threading.Thread, deviceBase):
now = time.time()
if self.force_send:
log.warning("FORCE SEND: TRUE")
if int(time.time()) % 600 == 0 or self.force_send:
if int(time.time()) % REPORT_PERIOD == 0 or self.force_send:
if self.force_send:
payload = {"ts": time.time()*1000, "values": {}}
else:
payload = {"ts": round(time.time()/600)*600*1000, "values": {}}
payload = {"ts": round(time.time()/REPORT_PERIOD)*REPORT_PERIOD*1000, "values": {}}
for chan in CHANNELS:
val = chan.read()
payload["values"][chan.mesh_name] = val
payload["values"]["public_ip_address"] = self.public_ip_address
self.sendToTB(json.dumps(payload))
self.sendToTBAttributes(json.dumps({"latestReportTime": round(time.time()/600)*600*1000}))
send(payload)
self.sendToTBAttributes(json.dumps({"latestReportTime": round(time.time()/REPORT_PERIOD)*REPORT_PERIOD*1000}))
# print("transferlite driver still alive...")
if self.force_send: