fixed driver so code will run.
still concerning that I have to call self.run()
This commit is contained in:
@@ -24,24 +24,10 @@ except:
|
||||
|
||||
channels = {}
|
||||
min_upload_time = 30
|
||||
addr = '192.168.1.20'
|
||||
addr = '10.10.10.31'
|
||||
|
||||
|
||||
|
||||
def setupChannels():
|
||||
with open('vfd_ipp_channels.p', 'rb') as ch_f:
|
||||
channels = pickle.load(ch_f)
|
||||
# tagJSObj = json.loads(requests.get(addr + "/json/tag").text)
|
||||
# if tagJSObj['status'] == "OK":
|
||||
# for t in tagJSObj['tags']:
|
||||
# channel_name = re.sub(r'\W+', '', t['vanityName']).lower()
|
||||
# channels[str(channel_name)] = {
|
||||
# 'tagID': t['id'],
|
||||
# 'last_value': -999,
|
||||
# 'data_type': "float",
|
||||
# 'last_time_uploaded': 0,
|
||||
# 'change_amount': (t['maxExpected'] - t['minExpected']) / 20,
|
||||
# 'min_time_between_uploads': min_upload_time
|
||||
# }
|
||||
|
||||
|
||||
class start(threading.Thread, deviceBase):
|
||||
@@ -50,6 +36,14 @@ class start(threading.Thread, deviceBase):
|
||||
print("GPS found me at {0}".format(gps))
|
||||
self.sendtodb("gps", gps, 0)
|
||||
|
||||
def setupChannels(self):
|
||||
with open('vfd_ipp_channels.p', 'rb') as ch_f:
|
||||
self.channels = pickle.load(ch_f)
|
||||
print("Channel List\n================")
|
||||
for x in self.channels.keys():
|
||||
print x
|
||||
print("================")
|
||||
|
||||
def __init__(self, name=None, number=None, mac=None, Q=None, mcu=None, companyId=None, offset=None, mqtt=None, Nodes=None):
|
||||
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)
|
||||
@@ -60,32 +54,45 @@ class start(threading.Thread, deviceBase):
|
||||
self.finished = threading.Event()
|
||||
threading.Thread.start(self)
|
||||
self.sendtodbJSON("device_address", self.device_address, 0)
|
||||
setupChannels()
|
||||
self.setupChannels()
|
||||
self.run()
|
||||
|
||||
|
||||
# self.updateGPS()
|
||||
# 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):
|
||||
channels["status"]["last_value"] = ""
|
||||
self.channels["status"]["last_value"] = ""
|
||||
|
||||
def run(self):
|
||||
self.runLoopStatus = ""
|
||||
last_OK_state = 0
|
||||
while True:
|
||||
if len(channels) > 0:
|
||||
if len(self.channels) > 0:
|
||||
try:
|
||||
for i in channels:
|
||||
for i in self.channels:
|
||||
runLoopStatus = i
|
||||
valData = u800.readMicroTag(self.device_address, channels[i]['tag'])
|
||||
print("reading {0}".format(i))
|
||||
valData = u800.readMicroTag(self.device_address, self.channels[i]['tag'])
|
||||
print(valData)
|
||||
if valData:
|
||||
nowVal = valData[0]
|
||||
ch = channels[i]
|
||||
ch = self.channels[i]
|
||||
if ch['data_type'] == "BOOL":
|
||||
if (not (ch['last_value'] == nowVal)) or ((time.time() - ch['last_time_uploaded']) > ch['min_time_between_uploads']):
|
||||
if ch['last_value'] == "":
|
||||
self.sendtodbJSON(i, nowVal, 0)
|
||||
ch['last_time_uploaded'] = time.time()
|
||||
ch['last_value'] = nowVal
|
||||
elif (not (ch['last_value'] == nowVal)) or ((time.time() - ch['last_time_uploaded']) > ch['min_time_between_uploads']):
|
||||
self.sendtodbJSON(i, nowVal, 0)
|
||||
ch['last_time_uploaded'] = time.time()
|
||||
ch['last_value'] = nowVal
|
||||
if (ch['data_type'] == "REAL") or (ch['data_type'][-3:] == "INT"):
|
||||
if (abs(ch['last_value'] - nowVal) > ch['change_amount']) or ((time.time() - ch['last_time_uploaded']) > ch['min_time_between_uploads']):
|
||||
if ch['last_value'] == "":
|
||||
self.sendtodbJSON(i, nowVal, 0)
|
||||
ch['last_time_uploaded'] = time.time()
|
||||
ch['last_value'] = nowVal
|
||||
elif (abs(ch['last_value'] - nowVal) > ch['change_amount']) or ((time.time() - ch['last_time_uploaded']) > ch['min_time_between_uploads']):
|
||||
self.sendtodbJSON(i, nowVal, 0)
|
||||
ch['last_time_uploaded'] = time.time()
|
||||
ch['last_value'] = nowVal
|
||||
@@ -101,10 +108,12 @@ class start(threading.Thread, deviceBase):
|
||||
if not OK_state == last_OK_state:
|
||||
self.sendtodbJSON("driver_ok", OK_state, 0)
|
||||
last_OK_state = OK_state
|
||||
sleep_timer = 20
|
||||
sleep_timer = 30
|
||||
print "Error during {0} of run loop: {1}\nWill try again in {2} seconds...".format(runLoopStatus, e, sleep_timer)
|
||||
time.sleep(sleep_timer)
|
||||
else:
|
||||
print("Apparently no channels... length shows {0}".format(len(self.channels)))
|
||||
print self.channels
|
||||
setupChannels()
|
||||
time.sleep(30)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user