From c62ad455ba7fd87f37898ab232084ae34e9ee525 Mon Sep 17 00:00:00 2001 From: Pierrick C Date: Sun, 19 Aug 2018 00:02:45 +0200 Subject: [PATCH] Better management of data to display --- raspberry/python/mqtt2epaper.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/raspberry/python/mqtt2epaper.py b/raspberry/python/mqtt2epaper.py index 3f592e6..5741959 100644 --- a/raspberry/python/mqtt2epaper.py +++ b/raspberry/python/mqtt2epaper.py @@ -76,13 +76,6 @@ def on_message(client, userdata, msg): payload = msg.payload.decode() val = json.loads(payload) - #Is value consistent ? - try: - val['value'] = float(val['value'] ) - except: - print("Value error: {}".format(val['value'])) - val['value'] = float('nan') - #Manage special character "degree" val['unit'] = val['unit'].replace('deg', '°') @@ -92,8 +85,19 @@ def on_message(client, userdata, msg): 'AP' : (1, data2_line), 'VBAT' : (inkyphat.WIDTH / 2 + 12, data2_line), } + print(val) if val['type'] in coord_type: + + #Manage special character "degree" + val['unit'] = val['unit'].replace('deg', '°') + #Is value consistent ? + try: + val['value'] = float(val['value'] ) + except: + print("Value error: {}".format(val['value'])) + val['value'] = float('nan') + #Erase old data inkyphat.rectangle(coord_type[val['type']] + (coord_type[val['type']][0] + inkyphat.WIDTH / 2 - 2, coord_type[val['type']][1] + 16), @@ -104,13 +108,9 @@ def on_message(client, userdata, msg): font=data_font, fill=black) new_data_flag = True - update_display() # Print feather's date and time on epaper display - elif subtopics[0] == "SYS": - payload = msg.payload.decode() - val = json.loads(payload) - if val['type'] == "TIME": + elif val['type'] == "TIME": try: #Check the date and time and offset to the right timezone dt_texte = datetime.strftime(datetime.strptime(val['value'], "%Y/%m/%d_%H:%M:%S") + TimeZone.utcoffset(None), @@ -123,7 +123,7 @@ def on_message(client, userdata, msg): # and draw the new date inkyphat.text((0, 31), dt_texte, font=font12, fill=black) new_data_flag = True - update_display() + def on_message_camera(client, userdata, msg): """Update display with info from camera (camera shooting new picture or name