From be8d28a2f9e7399874917326d7b7f1005dcc3213 Mon Sep 17 00:00:00 2001 From: Pierrick C Date: Sat, 4 Aug 2018 19:29:49 +0200 Subject: [PATCH] Update to use new data from feather m0 express (UART->MQTT) --- raspberry/python/cameteo.conf | 2 +- raspberry/python/mqtt2epaper.py | 51 ++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/raspberry/python/cameteo.conf b/raspberry/python/cameteo.conf index c5b4424..081365c 100644 --- a/raspberry/python/cameteo.conf +++ b/raspberry/python/cameteo.conf @@ -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 diff --git a/raspberry/python/mqtt2epaper.py b/raspberry/python/mqtt2epaper.py index eda7938..f902134 100644 --- a/raspberry/python/mqtt2epaper.py +++ b/raspberry/python/mqtt2epaper.py @@ -33,7 +33,7 @@ def update_epd(): #rotation de l'image de 90° + 180° si le paramètre epd_rotate est différent de 0 # la translation permet de rattraper un petit décalage en cas de rotation de 90+180° screen = image.rotate(90 + (epd_rotate * 180), expand=True, translate=(-6*epd_rotate, 0)) - #Mis en memoire de l'image à afficher et affichage de l'image + #Mis en memoire de l'image à afficher et affichage de l'image epd.set_frame_memory(screen, 0, 0) epd.display_frame() @@ -52,7 +52,7 @@ def on_connect(client, userdata, flags, rc): (camera_mqtt_topic + "/#", 0)] ) print("OK") - + """ Callback de gestion des messages arrivant au MQTT : affichage et enregistrement en base de données @@ -60,49 +60,55 @@ affichage et enregistrement en base de données 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 + + + #Test présence et cohérence de la valeur try: val['value'] = float(val['value'] ) except: print("Value error: {}".format(val['value'])) val['value'] = float('nan') - + #Gestion du symbole des degrés parfois difficile pour certaines sources val['unit'] = val['unit'].replace('deg', '°') - + #Affichage des données coord_type = { 'AT' : (12, 50), 'RH' : (137, 50), - 'MSLP' : (12, 72), - 'ALTI' : (137, 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 new values - draw.text(coord_type[val['type']], "{:6.1f}{} ".format(val['value'], val['unit']), font=font20_bold, fill=black) - + 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) + """ -Callback managing date and time from MQTT broker +Callback managing date and time from MQTT broker """ def on_message_date(client, userdata, msg): payload = msg.payload.decode() print("Date : " + payload) - + try: #Mise en forme de la date et heure reçu pour fuseau horaire configuré dt_texte = datetime.strftime(datetime.strptime(payload, "%H:%M:%S %d/%m/%Y") + TimeZone.utcoffset(None), "%d/%m/%Y %H:%M:%S") except: dt_texte = payload - + #Affichage du résultat - draw.rectangle((0, 34, epd2in13.EPD_HEIGHT, 48), fill=white) + draw.rectangle((0, 34, epd2in13.EPD_HEIGHT, 48), fill=white) draw.text((0, 34), dt_texte, font=font14, fill=black) update_epd() @@ -112,14 +118,14 @@ last photo) """ def on_message_camera(client, userdata, msg): pl = msg.payload.decode() - print("{} : {} ({})".format(msg.topic, pl, type(pl))) - + print("{} : {} ({})".format(msg.topic, pl, type(pl))) + # Photo en cours if pl == "1" and msg.topic == camera_mqtt_topic + "/shooting" : draw.rectangle((0, 106, epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), fill=white) draw.text((0, 106), "Shooting photo... ", font=font14, fill=black) update_epd() - + #Dernière photo prise if msg.topic == camera_mqtt_topic + "/last_photo": draw.rectangle((0, 106, epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), fill=white) @@ -195,4 +201,3 @@ print(mqtt_host + ":" + str(mqtt_port)) mqtt_client.connect(mqtt_host, int(mqtt_port), 60) mqtt_client.loop_forever() -