Initial commit
This commit is contained in:
62
submonitor/python-driver/submonitor.py
Normal file
62
submonitor/python-driver/submonitor.py
Normal file
@@ -0,0 +1,62 @@
|
||||
"""Driver for submonitor"""
|
||||
|
||||
import threading
|
||||
import sys
|
||||
from device_base import deviceBase
|
||||
import time
|
||||
import logging
|
||||
|
||||
_ = None
|
||||
|
||||
# LOGGING SETUP
|
||||
from logging.handlers import RotatingFileHandler
|
||||
|
||||
log_formatter = logging.Formatter('%(asctime)s %(levelname)s %(funcName)s(%(lineno)d) %(message)s')
|
||||
logFile = './submonitor.log'
|
||||
my_handler = RotatingFileHandler(logFile, mode='a', maxBytes=500*1024, backupCount=2, encoding=None, delay=0)
|
||||
my_handler.setFormatter(log_formatter)
|
||||
my_handler.setLevel(logging.INFO)
|
||||
logger = logging.getLogger('submonitor')
|
||||
logger.setLevel(logging.INFO)
|
||||
logger.addHandler(my_handler)
|
||||
|
||||
console_out = logging.StreamHandler(sys.stdout)
|
||||
console_out.setFormatter(log_formatter)
|
||||
logger.addHandler(console_out)
|
||||
|
||||
logger.info("submonitor startup")
|
||||
|
||||
|
||||
class start(threading.Thread, deviceBase):
|
||||
"""Start class required by Meshify."""
|
||||
|
||||
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 = "2"
|
||||
self.finished = threading.Event()
|
||||
self.forceSend = False
|
||||
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):
|
||||
"""Register the driver."""
|
||||
# self.sendtodb("log", "BOOM! Booted.", 0)
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
"""Actually run the driver."""
|
||||
wait_sec = 60
|
||||
for i in range(0, wait_sec):
|
||||
print("submonitor driver will start in {} seconds".format(wait_sec - i))
|
||||
time.sleep(1)
|
||||
logger.info("BOOM! Starting submonitor driver...")
|
||||
|
||||
while True:
|
||||
time.sleep(15)
|
||||
print("submonitor driver still alive...")
|
||||
|
||||
Reference in New Issue
Block a user