python reading and sending to influx
This commit is contained in:
parent
863e486944
commit
0576b54da1
@ -92,13 +92,14 @@ def read_temp (ip, port, influx_client, write_api):
|
|||||||
return data.decode().strip()
|
return data.decode().strip()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
influx_client, write_api = init_influxdb(URL, TOKEN, ORG)
|
influx_client, write_api = init_influxdb(URL, TOKEN, ORG)
|
||||||
setup_logger ("PhillipsDeskTemp.")
|
setup_logger ("FerDy_exp_table_Temp.")
|
||||||
logging.info ("Reading the temperature on Phillip's desk")
|
logging.info ("Reading the temperature on exp. table in FerDy")
|
||||||
with socket.socket (socket.AF_INET, socket.SOCK_STREAM) as s:
|
with socket.socket (socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||||
s.bind ((ip, port))
|
s.bind ((ip, port))
|
||||||
s.listen()
|
s.listen()
|
||||||
@ -113,19 +114,24 @@ if __name__ == "__main__":
|
|||||||
message = data.decode().strip()
|
message = data.decode().strip()
|
||||||
#T = read_temp (ip, port, influx_client, write_api)
|
#T = read_temp (ip, port, influx_client, write_api)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (message is not None and temp_or_hum == "T"):
|
if (message is not None and temp_or_hum == "T" and message <= "9" and message >= "0"):
|
||||||
|
#if type (message) != int:
|
||||||
|
# continue
|
||||||
print (str (datetime.now () )[:19] + ": Temp is " + message)
|
print (str (datetime.now () )[:19] + ": Temp is " + message)
|
||||||
T = float (message)
|
T = float (message)
|
||||||
p1 = influxdb_client.Point ("FerDy").tag("Climate_control", "temperature").field ("temp_Eilons_desk", T)
|
p1 = influxdb_client.Point ("FerDy").tag("Climate_control", "temperature").field ("temp_exp_table", T)
|
||||||
temp_or_hum = "a"
|
temp_or_hum = "a"
|
||||||
influx_client, write_api = write_data_to_influxDB (influx_client, write_api, p1)
|
influx_client, write_api = write_data_to_influxDB (influx_client, write_api, p1)
|
||||||
time.sleep (update_interval/2)
|
time.sleep (update_interval/2)
|
||||||
|
|
||||||
elif (message is not None and temp_or_hum == "H"):
|
elif (message is not None and temp_or_hum == "H" and message <= "9" and message >= "0"):
|
||||||
|
# if type (message) != int:
|
||||||
|
# continue
|
||||||
print (str (datetime.now () )[:19] + ": humidity is " + message)
|
print (str (datetime.now () )[:19] + ": humidity is " + message)
|
||||||
H = float (message)
|
H = float (message)
|
||||||
p1 = influxdb_client.Point ("FerDy").tag("Climate_control", "humidity").field ("hum_Eilons_desk", H)
|
p1 = influxdb_client.Point ("FerDy").tag("Climate_control", "humidity").field ("hum_exp_table", H)
|
||||||
temp_or_hum = "a"
|
temp_or_hum = "a"
|
||||||
influx_client, write_api = write_data_to_influxDB (influx_client, write_api, p1)
|
influx_client, write_api = write_data_to_influxDB (influx_client, write_api, p1)
|
||||||
time.sleep (update_interval/2)
|
time.sleep (update_interval/2)
|
Loading…
Reference in New Issue
Block a user