diff --git a/get_data.py b/get_data.py index 94f8da7..b2e36dd 100755 --- a/get_data.py +++ b/get_data.py @@ -4,7 +4,7 @@ import serial, time, os.path, urllib, re #from urllib import urlopen -debug = True +debug = False path_to_files = '/tmp/' @@ -30,6 +30,7 @@ #arduino.close() time.sleep(2.5) +arduino_temp_values = [None] * 2 main_temp_values = [None] * 2 humidity_values = [None] * 2 voltage_values = [None] * 2 @@ -58,12 +59,9 @@ def debug_print(text): output = arduino.readline().rstrip("\r\n".encode()) debug_print("DEBUG: Arduino temperature " + str(x) + ": " + output.decode()) if float(output) <= 70 and float(output) >= -50: - main_temp_values[x] = round(float(output), 1) + arduino_temp_values[x] = round(float(output), 1) else: - main_temp_values[x] = u"---" - local_temps_file = open(path_to_files + 'local_temps', 'w') - local_temps_file.write("%s\n" % main_temp_values[x]) - local_temps_file.close() + arduino_temp_values[x] = u"---" arduino.readline() arduino.write("h".encode()) for x in range(0, 1): # Can be deleted after transitioning to BME (or other external humidity) @@ -78,22 +76,40 @@ def debug_print(text): humidity_file.close() arduino.readline() - # Teploty z kotelny - temps_file = open(path_to_files + 'temps', 'w') - try: - data = urllib.urlopen("http://control.pavoukovo.cz/temps").read().decode() # Otevrit soubor - if data.find("html") == -1: - temps_file.write(data) - debug_print("DEBUG: HTTP temps read ok") - else: - for i in range(0, 8): - temps_file.write("%s\n" % u"---") # Kdyz se nepodari otevrit soubor, zapsat --- - debug_print("DEBUG: " + time.strftime("%H:%M:%S") + " HTTP temps read failed, remote file not found") - except: - for i in range(0, 8): - temps_file.write("%s\n" % u"---") # Kdyz se nepodari otevrit soubor, zapsat --- - debug_print("DEBUG: " + time.strftime("%H:%M:%S") + " HTTP temps read failed") - temps_file.close() + # Dallas teplotni cidla + for i in range(0, len(dallas_address)): # Smycka pro cteni podle zadanych adres + try: + temp_file = open('/sys/bus/w1/devices/' + dallas_address[i] + '/w1_slave', 'r') # Otevrit soubor s daty + file_lines = temp_file.read().splitlines() + crc = re.compile('crc=.. (.*)') + crc_value = crc.search(file_lines[0]) + debug_print(crc_value.group(1)) + if crc_value.group(1) == "YES": # Overit kontrolni soucet + temp = re.compile('t=(.*)') + temp_value = temp.search(file_lines[1]) + debug_print(temp_value.group(1)) + if temp_value.group(1) != "85000": # Pokud neukazuje 85 stupnu, coz je chybovy stav + temps_values[i] = float(temp_value.group(1)) / 1000 # Ulozit teplotu + else: + temps_values[i] = u"---" # Kdyby ukazoval 85, tak ulozit --- + else: + temps_values[i] = u"---" # Kdyz neni kontrolni souce v poradku, zapsat --- + except: + temps_values[i] = u"---" # Kdyz se nepovede otevrit soubor s daty, zapsat --- + debug_print("DEBUG: " + "/sys/bus/w1/devices/" + dallas_address[i] + "/w1_slave" + " Temp read failed") + dallas_file = open(path_to_files + 'dallas', 'w') # Otevrit soubor pro zapsani teplot + for i in range(0, len(temps_values) + 1): + if i < len(temps_values) and temps_values[i] == u"---": # Kdyz je misto teploty ulozeno ---, nejde zaokrouhlit (aby nespadl program) + dallas_file.write("%s\n" % temps_values[i]) # Ulozit rovnou --- + elif i < len(temps_values): + dallas_file.write("%s\n" % round(temps_values[i], 1)) # Ulozit zaokrouhlenou teplotu + elif arduino_temp_values[0] == u"---" or (u"---" in temps_values and i == len(temps_values)): # Vyjimka, pokud je nekde ulozeno ---, nepocitat prumer (aby nespadl program) + #dallas_file.write("%s\n" % u"---") + main_temp_values[0] = u"---" + elif i == len(temps_values): # DO posledniho radku ulozit prumer teplot + main_temp_values[0] = round((temps_values[0] + temps_values[1] + temps_values[2] + arduino_temp_values[0]) / 4, 1) + #dallas_file.write("%s\n" % round((temps_values[0] + temps_values[1] + temps_values[2] + main_temp_values[0]) / 4, 1)) # Prumer se pocita z teplot v obyvaku, pokoji a "hlavni teploty" (na vypinaci v kuchyni) + dallas_file.close() # Udaje z bazenu/meteobudky meteo_file = open(path_to_files + 'meteo', 'w') @@ -101,6 +117,11 @@ def debug_print(text): data = urllib.urlopen("http://meteo.pavoukovo.cz/meteo").read().decode() # Otevrit soubor if data.find("html") == -1: meteo_file.write(data) + lines = data.splitlines() + if lines[2] != u"---": + main_temp_values[1] = round(float(lines[2]), 1) + else: + main_temp_values[1] = u"---" debug_print("DEBUG: HTTP meteo read ok") else: for i in range(0, 7): @@ -112,6 +133,28 @@ def debug_print(text): debug_print("DEBUG: " + time.strftime("%H:%M:%S") + " HTTP meteo read failed") meteo_file.close() + main_temps_file = open(path_to_files + 'main_temps', 'w') + main_temps_file.write("%s\n" % main_temp_values[0]) + main_temps_file.write("%s\n" % main_temp_values[1]) + main_temps_file.close() + + # Teploty z kotelny + temps_file = open(path_to_files + 'temps', 'w') + try: + data = urllib.urlopen("http://control.pavoukovo.cz/temps").read().decode() # Otevrit soubor + if data.find("html") == -1: + temps_file.write(data) + debug_print("DEBUG: HTTP temps read ok") + else: + for i in range(0, 8): + temps_file.write("%s\n" % u"---") # Kdyz se nepodari otevrit soubor, zapsat --- + debug_print("DEBUG: " + time.strftime("%H:%M:%S") + " HTTP temps read failed, remote file not found") + except: + for i in range(0, 8): + temps_file.write("%s\n" % u"---") # Kdyz se nepodari otevrit soubor, zapsat --- + debug_print("DEBUG: " + time.strftime("%H:%M:%S") + " HTTP temps read failed") + temps_file.close() + # Rychlost vetru wind_file = open(path_to_files + 'wind', 'w') try: @@ -134,36 +177,4 @@ def debug_print(text): debug_print("DEBUG: " + time.strftime("%H:%M:%S") + " HTTP wind read failed") wind_file.close() - # Dallas teplotni cidla - for i in range(0, len(dallas_address)): # Smycka pro cteni podle zadanych adres - try: - temp_file = open('/sys/bus/w1/devices/' + dallas_address[i] + '/w1_slave', 'r') # Otevrit soubor s daty - file_lines = temp_file.read().splitlines() - crc = re.compile('crc=.. (.*)') - crc_value = crc.search(file_lines[0]) - debug_print(crc_value.group(1)) - if crc_value.group(1) == "YES": # Overit kontrolni soucet - temp = re.compile('t=(.*)') - temp_value = temp.search(file_lines[1]) - debug_print(temp_value.group(1)) - if temp_value.group(1) != "85000": # Pokud neukazuje 85 stupnu, coz je chybovy stav - temps_values[i] = float(temp_value.group(1)) / 1000 # Ulozit teplotu - else: - temps_values[i] = u"---" # Kdyby ukazoval 85, tak ulozit --- - else: - temps_values[i] = u"---" # Kdyz neni kontrolni souce v poradku, zapsat --- - except: - temps_values[i] = u"---" # Kdyz se nepovede otevrit soubor s daty, zapsat --- - debug_print("DEBUG: " + "/sys/bus/w1/devices/" + dallas_address[i] + "/w1_slave" + " Temp read failed") - dallas_file = open(path_to_files + 'dallas', 'w') # Otevrit soubor pro zapsani teplot - for i in range(0, len(temps_values) + 1): - if i < len(temps_values) and temps_values[i] == u"---": # Kdyz je misto teploty ulozeno ---, nejde zaokrouhlit (aby nespadl program) - dallas_file.write("%s\n" % temps_values[i]) # Ulozit rovnou --- - elif i < len(temps_values): - dallas_file.write("%s\n" % round(temps_values[i], 1)) # Ulozit zaokrouhlenou teplotu - elif main_temp_values[0] == u"---" or (u"---" in temps_values and i == len(temps_values)): # Vyjimka, pokud je nekde ulozeno ---, nepocitat prumer (aby nespadl program) - dallas_file.write("%s\n" % u"---") - elif i == len(temps_values): # DO posledniho radku ulozit prumer teplot - dallas_file.write("%s\n" % round((temps_values[0] + temps_values[1] + main_temp_values[0]) / 3, 1)) # Prumer se pocita jen z teplot v obyvaku a "hlavni teploty" (na vypinaci v kuchyni) - dallas_file.close() time.sleep(5) diff --git a/gui.py b/gui.py index 2436820..ee63114 100755 --- a/gui.py +++ b/gui.py @@ -152,28 +152,33 @@ def compass_line(color, angle, length, width): # Rework needed - add repeated reads if one fails; rework may not be needed if FPS is 5 # 2022 - rework probably not needed, backend reworked instead def read_data(): - global main_temp_values, humidity_values, temp_values, temp_names, wind_values + global local_temp_values, humidity_values, temp_values, temp_names, wind_values try: - with open(path_to_files + 'local_temps', 'r') as main_temp_file: + with open(path_to_files + 'main_temps', 'r') as main_temp_file: main_temp_lines = main_temp_file.read().splitlines() main_temp_values[0] = main_temp_lines[0] + main_temp_values[1] = main_temp_lines[1] main_temp_file.close() #if (len(main_temp_values) == 0): # main_temp_values[0] = u"---" except: main_temp_values[0] = u"---" - debug_print("DEBUG: " + strftime("%H:%M:%S") + " " + path_to_files + "local_temps read failed") + debug_print("DEBUG: " + strftime("%H:%M:%S") + " " + path_to_files + "dallas read failed or reading sensors failed") pass + try: with open(path_to_files + 'meteo', 'r') as meteo_file: meteo_lines = meteo_file.read().splitlines() meteo_file.close() - main_temp_values[1] = str(round(float(meteo_lines[2]), 1)) + # Tenhle radek netreba + # main_temp_values[1] = str(round(float(meteo_lines[2]), 1)) pool_temp_values[0] = str(round(float(meteo_lines[0]), 1)) pool_temp_values[1] = str(round(float(meteo_lines[1]), 1)) except: main_temp_values[1] = u"---" + pool_temp_values[0] = u"---" + pool_temp_values[1] = u"---" debug_print("DEBUG: " + strftime("%H:%M:%S") + " " + path_to_files + "meteo temp read failed") pass @@ -301,11 +306,14 @@ def window_main(window_type, mouse_click): button_on_off(1, u"Ruční topení", heating_time_show, white, main_temp_vertical_divider + border, 0 + border + 35 + border, 130, 45, red_dark, red, green_dark, green) # Button for pool - if float(pool_temp_values[1]) - float(pool_temp_values[0]) >= 0: - temp_string = str(pool_temp_values[0]) + u"\u00b0" + "C (+" + str(float(pool_temp_values[1]) - float( pool_temp_values[0])) + ")" + if pool_temp_values[0] == u"---" and pool_temp_values[1] == u"---": + temp_string = "---" else: - temp_string = str(pool_temp_values[0]) + u"\u00b0" + "C (-" + str(abs(float(pool_temp_values[1]) - float( pool_temp_values[0]))) + ")" -# temp_string = str(pool_temp_values[0]) + u"(" + "-" + str(abs(float(pool_temp_values[1]) - float( pool_temp_values[0]))) + " " + u"\u00b0" + "C)" + if float(pool_temp_values[1]) - float(pool_temp_values[0]) >= 0: + temp_string = str(pool_temp_values[0]) + u"\u00b0" + "C (+" + str(float(pool_temp_values[1]) - float( pool_temp_values[0])) + ")" + else: + temp_string = str(pool_temp_values[0]) + u"\u00b0" + "C (-" + str(abs(float(pool_temp_values[1]) - float( pool_temp_values[0]))) + ")" +# temp_string = str(pool_temp_values[0]) + u"(" + "-" + str(abs(float(pool_temp_values[1]) - float( pool_temp_values[0]))) + " " + u"\u00b0" + "C)" button_on_off(2, u"Bazén", temp_string, white, main_temp_vertical_divider + border, 0 + border + 35 + border + 35 + border, 130, 45, red_dark, red, green_dark, green) # Compass for wind direction and speed @@ -345,8 +353,6 @@ def window_main(window_type, mouse_click): pygame.display.update(); -time.sleep(10) - while True: # global x, y, heating_time, heating_time_end for event in pygame.event.get(): diff --git a/write_data.py b/write_data.py index 3c4aaeb..1e8d446 100755 --- a/write_data.py +++ b/write_data.py @@ -4,7 +4,7 @@ import time, os.path from datetime import datetime -debug = True +debug = False path_to_files = '/tmp/'