fix typos introduced in refactoring
This commit is contained in:
parent
30c065abd6
commit
87de3ac61c
|
@ -34,7 +34,7 @@ def send_heartbeat(): # function for heartbeat reporting, adjust according to se
|
|||
|
||||
# on connection callback, used to subscirbe to the set up topic after connecting to the broker
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
print("connected: " + str(rc))
|
||||
print("connected: " + str(rc))
|
||||
mqttc.subscribe(MQTT_Topic, 0)
|
||||
print("subscribed!")
|
||||
|
||||
|
@ -46,15 +46,15 @@ def on_message(mosq, obj, msg):
|
|||
# out of range value check, replaces erroneous values with no value
|
||||
# included as a precaution, the sensors could malfunction and the communication between the devices is not always perfect
|
||||
# the ranges are set to what can be reasonably expected in an interior environment, can be tweaked if desired
|
||||
if float(dec_msg[0]) > 45 or float(dec_msg[0] < 0): # temperature
|
||||
if float(dec_msg[0]) > 45 or float(dec_msg[0]) < 0: # temperature
|
||||
dec_msg[0] = "NULL"
|
||||
if float(dec_msg[1]) < 0 or float(dec_msg[1] > 100): # relative humidity
|
||||
if float(dec_msg[1]) < 0 or float(dec_msg[1]) > 100: # relative humidity
|
||||
dec_msg[1] = "NULL"
|
||||
if int(dec_msg[2]) < 900 or int(dec_msg[2]) > 1100: # pressure
|
||||
dec_msg[2] = "NULL"
|
||||
if dec_msg[3] == "-1": # co2, value of -1 indicates a measurement error
|
||||
dec_msg[3] = "NULL"
|
||||
|
||||
|
||||
except Exception as ex:
|
||||
print("Excp: %s" % ex) # print exceptions
|
||||
|
||||
|
@ -68,12 +68,12 @@ def on_message(mosq, obj, msg):
|
|||
\"co2\" int(5) DEFAULT NULL)" % DB_TABLE
|
||||
write_db(sql0)
|
||||
# formulate sql string with values
|
||||
sql = "INSERT INTO %s (timestamp, temp, hum, pres, co2) VALUES (\"%s\", %s, %s, %s, %s)" % (DB_TABLE, datetime.datetime.now().strftime(f), procdm[0], procdm[1], procdm[2], procdm[3])
|
||||
sql = "INSERT INTO %s (timestamp, temp, hum, pres, co2) VALUES (\"%s\", %s, %s, %s, %s)" % (DB_TABLE, datetime.datetime.now().strftime(f), dec_msg[0], dec_msg[1], dec_msg[2], dec_msg[3])
|
||||
write_db(sql) # execute the sql string
|
||||
send_heartbeat() # send heartbeat
|
||||
|
||||
mqttc = mqtt.Client() # instantiate the client class
|
||||
mqttc.on_message = on_message
|
||||
mqttc.on_message = on_message
|
||||
mqttc.on_connect = on_connect # set up callbacks
|
||||
mqttc.username_pw_set(MQTT_Auth['username'], MQTT_Auth['password']) # set mqtt credentials
|
||||
mqttc.connect(MQTT_Broker, int(MQTT_Port), int(Keep_Alive_Interval)) # connect to the broker using provided settings
|
||||
|
|
Loading…
Reference in New Issue