Actualiser mqtt-python.py
This commit is contained in:
parent
42f7f3331d
commit
8c9f015b08
|
@ -49,9 +49,13 @@ def addData(time, numero_grappe, numero_capteur, temp, hum, batterie): # ajoute
|
||||||
Headers = {"Authorization": f"Token {influx_token}"}
|
Headers = {"Authorization": f"Token {influx_token}"}
|
||||||
|
|
||||||
#data envoye a l'api
|
#data envoye a l'api
|
||||||
|
int_time = int(time)
|
||||||
|
#if (int_time > 1817589156):
|
||||||
|
# time = str(int_time - 368384901)
|
||||||
Data=f"{numero_grappe},numero_capteur={numero_capteur} temperature={temp},humidite={hum},batterie={batterie} {time}"
|
Data=f"{numero_grappe},numero_capteur={numero_capteur} temperature={temp},humidite={hum},batterie={batterie} {time}"
|
||||||
|
print(Data)
|
||||||
response = requests.post(influx_url, headers=Headers, data=Data)
|
response = requests.post(influx_url, headers=Headers, data=Data)
|
||||||
|
print(response.status_code)
|
||||||
#debug api, fonctionne correctement malgres le code retour 204, quand il y a un code 204 le json response fait une erreur
|
#debug api, fonctionne correctement malgres le code retour 204, quand il y a un code 204 le json response fait une erreur
|
||||||
#print("Status Code", response.status_code)
|
#print("Status Code", response.status_code)
|
||||||
#print("JSON Response ", response.json())
|
#print("JSON Response ", response.json())
|
||||||
|
@ -76,6 +80,7 @@ def on_message(client, userdata, message):
|
||||||
addData(time, tab[1], "capteur" + str(i+1), temp[i], hum[i], batterie)
|
addData(time, tab[1], "capteur" + str(i+1), temp[i], hum[i], batterie)
|
||||||
#log("---------")
|
#log("---------")
|
||||||
|
|
||||||
|
#envois la valeur message pour le debug
|
||||||
#dump_log(message)
|
#dump_log(message)
|
||||||
|
|
||||||
client = mqttClient.Client(nom_client, False)
|
client = mqttClient.Client(nom_client, False)
|
||||||
|
@ -93,3 +98,11 @@ except KeyboardInterrupt:
|
||||||
print ("exiting")
|
print ("exiting")
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
client.loop_stop()
|
client.loop_stop()
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print ("exiting")
|
||||||
|
client.disconnect()
|
||||||
|
client.loop_stop()
|
Loading…
Reference in a new issue