|
@@ -246,7 +246,7 @@ try:
|
|
|
try:
|
|
|
serLine = serLine.decode('ascii')
|
|
|
except:
|
|
|
- serLine = ""
|
|
|
+ serLine = False
|
|
|
|
|
|
if(serLine):
|
|
|
if serLine.find('OK 9') != -1:
|
|
@@ -268,204 +268,212 @@ try:
|
|
|
|
|
|
serLineParts = serLine.split(' ')
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- addr = int(serLineParts[2])
|
|
|
- addrhex = "{0:x}".format(int(serLineParts[2]))
|
|
|
-
|
|
|
-
|
|
|
- lastUpdate = sensors_lastUpdate.get(addr, None)
|
|
|
- lastTemp = sensors_lastTemp.get(addr, None)
|
|
|
- lastHum = sensors_lastHum.get(addr, None)
|
|
|
-
|
|
|
- currentsensor_name = sensors_id_to_name.get(addr, None)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if int(serLineParts[3]) >= 128:
|
|
|
- batt_new = 1
|
|
|
- type = int(serLineParts[3]) - 128
|
|
|
- else:
|
|
|
- batt_new = 0
|
|
|
- type = int(serLineParts[3])
|
|
|
-
|
|
|
- temp = (int(serLineParts[4])*256 + int(serLineParts[5]) - 1000)/10.0
|
|
|
-
|
|
|
- if int(serLineParts[6]) >= 128:
|
|
|
- batt_low = 1
|
|
|
- hum = int(serLineParts[6]) - 128
|
|
|
- else:
|
|
|
- batt_low = 0
|
|
|
- hum = int(serLineParts[6])
|
|
|
- if hum > 100:
|
|
|
- hum = 100
|
|
|
-
|
|
|
- if batt_new == 1:
|
|
|
- sensors_batteryState[addr] = 2
|
|
|
- elif batt_low == 1:
|
|
|
- sensors_batteryState[addr] = 1
|
|
|
- else:
|
|
|
- sensors_batteryState[addr] = 0
|
|
|
-
|
|
|
- lastValues_lastIndex = sensors_lastValues_lastIndex.get(addr, None)
|
|
|
+
|
|
|
|
|
|
- if sensors_lastValues_temp.get(addr, None) == None:
|
|
|
- sensors_lastValues_temp[addr] = [None] * average_value_steps
|
|
|
+ if(len(serLineParts) == 7):
|
|
|
|
|
|
- if sensors_lastValues_hum.get(addr, None) == None:
|
|
|
- sensors_lastValues_hum[addr] = [None] * average_value_steps
|
|
|
-
|
|
|
- data_okay = False
|
|
|
-
|
|
|
- if sensors_lastReceivedValue_temp.get(addr, None) == None:
|
|
|
-
|
|
|
- if verbosemode: print("first received from sensor",str(addr))
|
|
|
- sensors_lastReceivedValue_temp[addr] = temp
|
|
|
- sensors_lastReceivedTime[addr] = int(time.time())
|
|
|
-
|
|
|
- else:
|
|
|
- lastValue = sensors_lastReceivedValue_temp.get(addr, None)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ addr = int(serLineParts[2])
|
|
|
+ addrhex = "{0:x}".format(int(serLineParts[2]))
|
|
|
+
|
|
|
|
|
|
- max_off_value = float(config['sensors'].get('max_off_value'))
|
|
|
- ignore_off_value_timeout = int(config['sensors'].get('ignore_off_value_timeout'))
|
|
|
+ lastUpdate = sensors_lastUpdate.get(addr, None)
|
|
|
+ lastTemp = sensors_lastTemp.get(addr, None)
|
|
|
+ lastHum = sensors_lastHum.get(addr, None)
|
|
|
|
|
|
- if lastValue != None and ((temp >= (lastValue - max_off_value) and temp <= (lastValue + max_off_value)) or ((int(time.time()) - sensors_lastReceivedTime.get(addr)) > ignore_off_value_timeout)):
|
|
|
- sensors_lastReceivedValue_temp[addr] = temp
|
|
|
- sensors_lastReceivedTime[addr] = int(time.time())
|
|
|
-
|
|
|
- data_okay = True
|
|
|
+ currentsensor_name = sensors_id_to_name.get(addr, None)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if int(serLineParts[3]) >= 128:
|
|
|
+ batt_new = 1
|
|
|
+ type = int(serLineParts[3]) - 128
|
|
|
else:
|
|
|
- if verbosemode: print("skipped sensor reading - Last Value=",lastValue,"currValue=",temp)
|
|
|
-
|
|
|
-
|
|
|
- if data_okay:
|
|
|
- if lastValues_lastIndex == None:
|
|
|
- lastValues_lastIndex = 0
|
|
|
- elif lastValues_lastIndex == (average_value_steps - 1):
|
|
|
- lastValues_lastIndex = 0
|
|
|
+ batt_new = 0
|
|
|
+ type = int(serLineParts[3])
|
|
|
+
|
|
|
+ temp = (int(serLineParts[4])*256 + int(serLineParts[5]) - 1000)/10.0
|
|
|
+
|
|
|
+ if int(serLineParts[6]) >= 128:
|
|
|
+ batt_low = 1
|
|
|
+ hum = int(serLineParts[6]) - 128
|
|
|
else:
|
|
|
- lastValues_lastIndex += 1
|
|
|
- if verbosemode: print("lastValues_lastIndex =", lastValues_lastIndex)
|
|
|
+ batt_low = 0
|
|
|
+ hum = int(serLineParts[6])
|
|
|
+ if hum > 100:
|
|
|
+ hum = 100
|
|
|
|
|
|
- sensors_lastValues_lastIndex[addr] = lastValues_lastIndex
|
|
|
- sensors_lastValues_temp[addr][lastValues_lastIndex] = temp
|
|
|
- sensors_lastValues_hum[addr][lastValues_lastIndex] = hum
|
|
|
+ if batt_new == 1:
|
|
|
+ sensors_batteryState[addr] = 2
|
|
|
+ elif batt_low == 1:
|
|
|
+ sensors_batteryState[addr] = 1
|
|
|
+ else:
|
|
|
+ sensors_batteryState[addr] = 0
|
|
|
|
|
|
- sensors_lastUpdate[addr] = int(time.time())
|
|
|
+ lastValues_lastIndex = sensors_lastValues_lastIndex.get(addr, None)
|
|
|
|
|
|
- if verbosemode: print("sensors_lastValues_temp =", sensors_lastValues_temp[addr])
|
|
|
+ if sensors_lastValues_temp.get(addr, None) == None:
|
|
|
+ sensors_lastValues_temp[addr] = [None] * average_value_steps
|
|
|
|
|
|
-
|
|
|
- if currentsensor_name is None:
|
|
|
- if batt_new == 1 and not sensors_new_alreadyNotified.get('addr', False):
|
|
|
- notifystr = "NEW sensor with ID " + str(addr)
|
|
|
- mqttc.publish(mqtt_topic_prefix+"/" + mqtt_subtopic_notify, notifystr, qos=0, retain=False)
|
|
|
+ if sensors_lastValues_hum.get(addr, None) == None:
|
|
|
+ sensors_lastValues_hum[addr] = [None] * average_value_steps
|
|
|
+
|
|
|
+ data_okay = False
|
|
|
+
|
|
|
+ if sensors_lastReceivedValue_temp.get(addr, None) == None:
|
|
|
+
|
|
|
+ if verbosemode: print("first received from sensor",str(addr))
|
|
|
+ sensors_lastReceivedValue_temp[addr] = temp
|
|
|
+ sensors_lastReceivedTime[addr] = int(time.time())
|
|
|
+
|
|
|
+ else:
|
|
|
+ lastValue = sensors_lastReceivedValue_temp.get(addr, None)
|
|
|
|
|
|
- if not os.path.exists(log_path+'/new'):
|
|
|
- os.makedirs(log_path+'/new')
|
|
|
+ max_off_value = float(config['sensors'].get('max_off_value'))
|
|
|
+ ignore_off_value_timeout = int(config['sensors'].get('ignore_off_value_timeout'))
|
|
|
+
|
|
|
+ if lastValue != None and ((temp >= (lastValue - max_off_value) and temp <= (lastValue + max_off_value)) or ((int(time.time()) - sensors_lastReceivedTime.get(addr)) > ignore_off_value_timeout)):
|
|
|
+ sensors_lastReceivedValue_temp[addr] = temp
|
|
|
+ sensors_lastReceivedTime[addr] = int(time.time())
|
|
|
+
|
|
|
+ data_okay = True
|
|
|
+ else:
|
|
|
+ if verbosemode: print("skipped sensor reading - Last Value=",lastValue,"currValue=",temp)
|
|
|
|
|
|
- fname = log_path + '/new/' + str(addr)
|
|
|
- if not os.path.exists(fname):
|
|
|
- try:
|
|
|
- touch(fname)
|
|
|
- except:
|
|
|
- pass
|
|
|
+
|
|
|
+ if data_okay:
|
|
|
+ if lastValues_lastIndex == None:
|
|
|
+ lastValues_lastIndex = 0
|
|
|
+ elif lastValues_lastIndex == (average_value_steps - 1):
|
|
|
+ lastValues_lastIndex = 0
|
|
|
+ else:
|
|
|
+ lastValues_lastIndex += 1
|
|
|
+ if verbosemode: print("lastValues_lastIndex =", lastValues_lastIndex)
|
|
|
+
|
|
|
+ sensors_lastValues_lastIndex[addr] = lastValues_lastIndex
|
|
|
+ sensors_lastValues_temp[addr][lastValues_lastIndex] = temp
|
|
|
+ sensors_lastValues_hum[addr][lastValues_lastIndex] = hum
|
|
|
+
|
|
|
+ sensors_lastUpdate[addr] = int(time.time())
|
|
|
|
|
|
- try:
|
|
|
- f = open(log_path+'/'+logfile_new_sensors, 'a')
|
|
|
- f.write(str(datetime.now())+": "+notifystr+"\n")
|
|
|
- f.close()
|
|
|
- except:
|
|
|
-
|
|
|
- pass
|
|
|
+ if verbosemode: print("sensors_lastValues_temp =", sensors_lastValues_temp[addr])
|
|
|
+
|
|
|
+
|
|
|
+ if currentsensor_name is None:
|
|
|
+ if batt_new == 1 and not sensors_new_alreadyNotified.get('addr', False):
|
|
|
+ notifystr = "NEW sensor with ID " + str(addr)
|
|
|
+ mqttc.publish(mqtt_topic_prefix+"/" + mqtt_subtopic_notify, notifystr, qos=0, retain=False)
|
|
|
+
|
|
|
+ if not os.path.exists(log_path+'/new'):
|
|
|
+ os.makedirs(log_path+'/new')
|
|
|
+
|
|
|
+ fname = log_path + '/new/' + str(addr)
|
|
|
+ if not os.path.exists(fname):
|
|
|
+ try:
|
|
|
+ touch(fname)
|
|
|
+ except:
|
|
|
+ pass
|
|
|
|
|
|
- sensors_new_alreadyNotified[addr] = True
|
|
|
- else:
|
|
|
- if not os.path.exists(log_path+'/unknown'):
|
|
|
- os.makedirs(log_path+'/unknown')
|
|
|
- fname = log_path + '/unknown/' + str(addr)
|
|
|
- if not os.path.exists(fname):
|
|
|
try:
|
|
|
- touch(fname)
|
|
|
+ f = open(log_path+'/'+logfile_new_sensors, 'a')
|
|
|
+ f.write(str(datetime.now())+": "+notifystr+"\n")
|
|
|
+ f.close()
|
|
|
except:
|
|
|
+
|
|
|
pass
|
|
|
-
|
|
|
+
|
|
|
+ sensors_new_alreadyNotified[addr] = True
|
|
|
+ else:
|
|
|
+ if not os.path.exists(log_path+'/unknown'):
|
|
|
+ os.makedirs(log_path+'/unknown')
|
|
|
+ fname = log_path + '/unknown/' + str(addr)
|
|
|
+ if not os.path.exists(fname):
|
|
|
+ try:
|
|
|
+ touch(fname)
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+
|
|
|
+ if verbosemode:
|
|
|
+ print("unknown sensor ID " + str(addr))
|
|
|
+
|
|
|
if verbosemode:
|
|
|
- print("unknown sensor ID " + str(addr))
|
|
|
-
|
|
|
- if verbosemode:
|
|
|
- print("addr: " + str(addr) + " = 0x" + str(addrhex) + " batt_new: " + str(batt_new) + " type: " + str(type) + " batt_low: " + str(batt_low) + " temp: " + str(temp) + " hum: " + str(hum) + " Name: " + str(currentsensor_name))
|
|
|
- print()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ print("addr: " + str(addr) + " = 0x" + str(addrhex) + " batt_new: " + str(batt_new) + " type: " + str(type) + " batt_low: " + str(batt_low) + " temp: " + str(temp) + " hum: " + str(hum) + " Name: " + str(currentsensor_name))
|
|
|
+ print()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ else:
|
|
|
+ if verbosemode: print("ignored invalid sized data")
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
|