Update to use new data from feather m0 express (UART->MQTT)

This commit is contained in:
Pierrick C 2018-08-04 19:29:49 +02:00
parent b7205f397f
commit be8d28a2f9
2 changed files with 29 additions and 24 deletions

View File

@ -15,7 +15,7 @@ mqtt_client_id = cameteo
mqtt_user = arofarn
mqtt_pass = WaKaW9XMGUZ3rRJD
mqtt_qos = 2
mqtt_topic = huzzah0/#
mqtt_topic = feather0/#
[FLASK]
http_host = 0.0.0.0

View File

@ -61,11 +61,11 @@ def on_message(client, userdata, msg):
top=msg.topic[len(mqtt_topic)-1:].strip()
subtopics = top.split("/")
if subtopics[0] == "AdaBME280_1":
if subtopics[0] == "BME":
payload = msg.payload.decode()
print(payload)
val = json.loads(payload)
#Test présence et cohérence de la valeur
try:
val['value'] = float(val['value'] )
@ -79,14 +79,20 @@ def on_message(client, userdata, msg):
#Affichage des données
coord_type = { 'AT' : (12, 50),
'RH' : (137, 50),
'MSLP' : (12, 72),
'AP' : (12, 72),
'ALTI' : (137, 72),
}
print(val)
if val['type'] in coord_type:
#erase former text
draw.rectangle(coord_type[val['type']] + (coord_type[val['type']][0] + 112, coord_type[val['type']][1] + 20), fill=white)
draw.rectangle(coord_type[val['type']] + (coord_type[val['type']][0] + 112,
coord_type[val['type']][1] + 20),
fill=white)
#draw new values
draw.text(coord_type[val['type']], "{:6.1f}{} ".format(val['value'], val['unit']), font=font20_bold, fill=black)
draw.text(coord_type[val['type']],
"{:6.1f}{} ".format(val['value'], val['unit']),
font=font20_bold,
fill=black)
"""
Callback managing date and time from MQTT broker
@ -195,4 +201,3 @@ print(mqtt_host + ":" + str(mqtt_port))
mqtt_client.connect(mqtt_host, int(mqtt_port), 60)
mqtt_client.loop_forever()