From 23813a0eb97a12eec760dfbc3c4b3bc1abd2d079 Mon Sep 17 00:00:00 2001 From: Patrick McDonagh Date: Mon, 16 Oct 2017 11:40:17 -0500 Subject: [PATCH] Adds period (hourly) send of watchdog value --- POCloud/advvfdipp.py | 20 +++++++++++++------- POCloud/config.txt | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/POCloud/advvfdipp.py b/POCloud/advvfdipp.py index 12cb567..c746c12 100644 --- a/POCloud/advvfdipp.py +++ b/POCloud/advvfdipp.py @@ -1,4 +1,4 @@ - +"""Max Water System driver code.""" import threading import time from random import randint @@ -6,35 +6,41 @@ from Channel import write_tag, read_tag from device_base import deviceBase PLC_IP_ADDRESS = "192.168.1.10" +WATCHDOG_SEND_PERIOD = 3600 # seconds + class start(threading.Thread, deviceBase): + """Driver class.""" + def __init__(self, name=None, number=None, mac=None, Q=None, mcu=None, companyId=None, offset=None, mqtt=None, Nodes=None): + """Initialize the driver.""" threading.Thread.__init__(self) deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes) self.daemon = True - self.version = "" + self.version = "7" self.finished = threading.Event() threading.Thread.start(self) - # this is a required function for all drivers, its goal is to upload some piece of data - # about your device so it can be seen on the web def register(self): + """Required function for all drivers, its goal is to upload some piece of data about your device so it can be seen on the web.""" self.channels["status"]["last_value"] = "" def run(self): + """Run the driver.""" watchdog = self.advvfdipp_watchdog() self.sendtodbDev(1, 'watchdog', watchdog, 0) - # print("SENDING WATCHDOG: {}".format(watchdog)) + watchdog_send_timestamp = time.time() watchdog_loops = 0 watchdog_check_after = 5000 + while True: watchdog_loops += 1 if (watchdog_loops >= watchdog_check_after): test_watchdog = self.advvfdipp_watchdog() - if test_watchdog != watchdog: + if test_watchdog != watchdog or (time.time() - watchdog_send_timestamp) > WATCHDOG_SEND_PERIOD: self.sendtodbDev(1, 'watchdog', test_watchdog, 0, 'advvfdipp') - # print("SENDING WATCHDOG: {}".format(test_watchdog)) + watchdog_send_timestamp = time.time() watchdog = test_watchdog watchdog_loops = 0 diff --git a/POCloud/config.txt b/POCloud/config.txt index dd2aece..281f78d 100644 --- a/POCloud/config.txt +++ b/POCloud/config.txt @@ -3,7 +3,7 @@ "driverFileName":"advvfdipp.py", "deviceName":"advvfdipp", "driverId":"0100", -"releaseVersion":"6", +"releaseVersion":"7", "files": { "file1":"advvfdipp.py", "file2":"modbusMap.p",