keep the driver up and running if something fails

This commit is contained in:
Patrick McDonagh
2016-04-26 16:31:20 -05:00
parent ab125a721e
commit 7436996f7d

View File

@@ -267,6 +267,7 @@ class start(threading.Thread, deviceBase):
time.sleep(sleep_timer)
def checkBackup(self):
try:
backupList = json.loads(requests.get(self.device_address + "/json/backups").text)
file = backupList["backups"][0]
data = json.loads(requests.get(self.device_address + "/json/backups/" + file).text)
@@ -276,8 +277,11 @@ class start(threading.Thread, deviceBase):
self.wellSetup = data
with open('wellSetup.p', 'wb') as handle:
pickle.dump(self.wellSetup, handle)
except Exception, e:
print("checkBackup Error: {}".format(e))
def checkEvents(self):
try:
data = json.loads(requests.get(self.device_address + "/json/event_list").text)
events = data["events"]
for event in events:
@@ -290,8 +294,11 @@ class start(threading.Thread, deviceBase):
del self.eventIds[0]
with open('eventIds.p', 'wb') as handle:
pickle.dump(self.eventIds, handle)
except Exception, e:
print("checkEvents Error: {}".format(e))
def checkNotes(self):
try:
data = json.loads(requests.get(self.device_address + "/json/notes/get").text)
notes = data["notes"]
for note in notes:
@@ -304,8 +311,11 @@ class start(threading.Thread, deviceBase):
del self.noteIDs[0]
with open('noteIDs.p', 'wb') as handle:
pickle.dump(self.noteIDs, handle)
except Exception, e:
print("checkNotes Error: {}".format(e))
def checkFluidShots(self):
try:
data = json.loads(requests.get(self.device_address + "/json/fluid_shot/get").text)
fluid_shots = data["fluid_shots"]
for shot in fluid_shots:
@@ -318,8 +328,11 @@ class start(threading.Thread, deviceBase):
del self.fluidshotIDs[0]
with open('fluidshotIDs.p', 'wb') as handle:
pickle.dump(self.fluidshotIDs, handle)
except Exception, e:
print("checkFluidShots Error: {}".format(e))
def checkWellTests(self):
try:
data = json.loads(requests.get(self.device_address + "/json/well_test/get").text)
well_tests = data["well_tests"]
for test in well_tests:
@@ -332,8 +345,11 @@ class start(threading.Thread, deviceBase):
del self.welltestIDs[0]
with open('welltestIDs.p', 'wb') as handle:
pickle.dump(self.welltestIDs, handle)
except Exception, e:
print("checkWellTests Error: {}".format(e))
def checkStatus(self):
try:
global status
statusMap = {
0: 'Stopped',
@@ -367,8 +383,11 @@ class start(threading.Thread, deviceBase):
# timestamp = calendar.timegm(dt.timetuple())
self.sendtodb("status", status_read, 0)
status.last_value = status_read
except Exception, e:
print("checkStatus Error: {}".format(e))
def checkDailyTotals(self):
try:
data = json.loads(requests.get(self.device_address + "/json/totals").text)
if data['status'] == "OK":
totals = data["totals"]
@@ -379,8 +398,11 @@ class start(threading.Thread, deviceBase):
self.sendtodb(dt_channels[val['name']].mesh_name, dt_channels[val['name']].value, timestamp)
else:
print("checkDailyTotalsError: {0}".format(data.message))
except Exception, e:
print("checkDailyTotals Error: {}".format(e))
def checkGaugeOffData(self):
try:
data = json.loads(requests.get(self.device_address + "/json/history").text)
day = data["hist"]
date = day['gauge_date']
@@ -394,8 +416,11 @@ class start(threading.Thread, deviceBase):
if entry in go_channels:
if go_channels[entry].checkSend(day[entry], False):
self.sendtodb(go_channels[entry].mesh_name, day[entry], timestamp)
except Exception, e:
print("checkGaugeOffData Error: {}".format(e))
def checkLatestCard(self, numCards = 1):
try:
latest = ""
if numCards == 1:
latest = json.loads(requests.get(self.device_address + "/json/latestcard").text)
@@ -428,6 +453,8 @@ class start(threading.Thread, deviceBase):
return
else:
self.process_card(card, timestamp, card_timestamp, sendCards=False)
except Exception, e:
print("checkLatestCard Error: {}".format(e))
def process_card(self, data, data_timestamp, card_timestamp, sendCards=False):
@@ -474,6 +501,7 @@ class start(threading.Thread, deviceBase):
self.sendtodb("dc", newDc, card_timestamp)
def checkStoredValues(self, forceSend):
try:
data = json.loads(requests.get(self.device_address + "/json/tagvalues").text)
if data['status'] == "OK":
vals = data['vals']
@@ -481,8 +509,11 @@ class start(threading.Thread, deviceBase):
if val['name'] in tag_channels:
if tag_channels[val['name']].checkSend(val['val'], forceSend):
self.sendtodbJSON(tag_channels[val['name']].mesh_name, tag_channels[val['name']].value, 0)
except Exception, e:
print("checkStoredValues Error: {}".format(e))
def getLatestXCards(self, numCards):
try:
data = json.loads(requests.get(self.device_address + "/json/latest/" + str(int(numCards))).text)
for card in data['cards']:
card_data = json.loads(requests.get(self.device_address + "/json/" + data['folder'] + "/" + card).text)
@@ -497,8 +528,11 @@ class start(threading.Thread, deviceBase):
channels["card_history"]["last_value"] = (data['folder'] + "/" + card)
self.sendtodb("card_history", (data['folder'] + "/" + card), card_timestamp)
self.process_card(card_data, timestamp, card_timestamp, sendCards=True)
except Exception, e:
print("getLatestXCards Error: {}".format(e))
def getDataLoggerStatus(self):
try:
data = json.loads(requests.get(self.device_address + "/json/pythonstatus/").text)
al_status = "Not OK"
if data['status']['alarmLogger']:
@@ -514,6 +548,8 @@ class start(threading.Thread, deviceBase):
if al_status != self.dl_status_last:
self.sendtodb("datalogger_status", dl_status, 0)
self.dl_status_last = dl_status
except Exception, e:
print("getDataLoggerStatus Error: {}".format(e))
def poc_get_card(self, name, value):
self.getcard(value)