diff --git a/ESP32/TempHumLoggerHomeKit/TempHumLogVizualization.xlsx b/ESP32/TempHumLoggerHomeKit/TempHumLogVizualization.xlsx new file mode 100644 index 0000000..4004a3d Binary files /dev/null and b/ESP32/TempHumLoggerHomeKit/TempHumLogVizualization.xlsx differ diff --git a/ESP32/TempHumLoggerHomeKit/TempHumLoggerHomeKit.ino b/ESP32/TempHumLoggerHomeKit/TempHumLoggerHomeKit.ino index 6b488e4..03dfefe 100644 --- a/ESP32/TempHumLoggerHomeKit/TempHumLoggerHomeKit.ino +++ b/ESP32/TempHumLoggerHomeKit/TempHumLoggerHomeKit.ino @@ -9,7 +9,7 @@ #include "SD.h" #include "SPI.h" -#define Version "0.1" +#define Version "0.11" #define WIRE Wire #define DHTTYPE DHT22 #define DHTPIN 4 @@ -52,6 +52,12 @@ float batteryVoltage = 0; int batteryBarWidth = 0; char dateString[21]; +String formatNumber(float number, int decimalPlaces = 1 ) { + String str = String(number, decimalPlaces); + str.replace('.', ','); + return str; +} + void setup() { Serial.begin(115200); Wire.begin(21, 22); @@ -80,6 +86,15 @@ void setup() { pinMode(BTN_UP, INPUT_PULLDOWN ); pinMode(BTN_ENTER, INPUT_PULLDOWN ); pinMode(BTN_DOWN, INPUT_PULLDOWN ); + rtc.now(); + DateTime now = rtc.now(); + years = now.year(); + months = now.month(); + dayss = now.day(); + hourss = now.hour(); + mins = now.minute(); + secs = now.second(); + display.clearDisplay(); display.setCursor(0,0); if (!SD.begin(SD_CS)) { @@ -90,21 +105,34 @@ void setup() { Serial.println("Karta SD wykryta!"); } display.setCursor(0,16); - - // Tworzenie pliku - File file = SD.open("/TempHumLog.txt", FILE_APPEND); - if (file) { - file.println("Dane zapisane z ESP32! V2"); - file.println(Version); - file.println("DataCzas; Temp; Humi; Feel"); - file.close(); - display.println("Plik utworzony!"); + + if (SD.exists("/TempHumLog.txt")) { } else { - display.println("Blad zapisu pliku!"); - display.display(); - delay(1000); - } + File file = SD.open("/TempHumLog.txt", FILE_APPEND); + file.println("Data; Godzina; Temp; Humi; Feel"); + file.close(); + + } + sprintf(dateString, "%02d/%02d/%4d %02d:%02d:%02d", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second()); + if (SD.exists("/GeneralLog.txt")) { + } else { + File file = SD.open("/GeneralLog.txt", FILE_APPEND); + file.print("Utworzono: "); + file.print(dateString); + file.print(" Wersja: "); + file.println(Version); + file.close(); + } + File file = SD.open("/GeneralLog.txt", FILE_APPEND); + file.print("Uruchomienie: "); + file.print(dateString); + file.print(" Wersja: "); + file.println(Version); + file.close(); + + + display.display(); delay(500); @@ -135,27 +163,10 @@ void loop() { hourss = now.hour(); mins = now.minute(); secs = now.second(); -sprintf(dateString, "%02d/%02d/%4d %02d:%02d:%02d", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second()); + sprintf(dateString, "%02d/%02d/%4d %02d:%02d:%02d", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second()); + - if (mins % 1 == 0 && secs == 0) { - - - File file = SD.open("/TempHumLog.txt", FILE_APPEND); - if (file) { - display.fillRect(0, 0, 124, 64, SSD1306_WHITE); - file.print(dateString); - file.print("; "); - file.print(temp, 1); - file.print("; "); - file.print(hum, 1); - file.print("; "); - file.println(heat_idx, 1); - file.close(); - delay(1000); - } - } -//zapis na SD: if (menuL0 == 10 ) { // ############# MENU TEMP @@ -307,9 +318,7 @@ sprintf(dateString, "%02d/%02d/%4d %02d:%02d:%02d", now.day(), now.month(), no if (menuL0 == 8 ) { display.setCursor(0, 0); display.print("MENU TECH"); - adcVoltValue = analogRead(VOLT_IN); // Odczyt wartości ADC z GPIO36 - measuredVoltage = (adcVoltValue * adcMaxVoltage) / adcResolution; - batteryVoltage = (measuredVoltage * voltageDividerFactor)+0.1; + display.setCursor(70,0); display.print("V:"); display.setCursor(85, 0); @@ -380,11 +389,66 @@ sprintf(dateString, "%02d/%02d/%4d %02d:%02d:%02d", now.day(), now.month(), no hoursToSet = hoursToSet - 1; } } + + adcVoltValue = analogRead(VOLT_IN); // Odczyt wartości ADC z GPIO36 + measuredVoltage = (adcVoltValue * adcMaxVoltage) / adcResolution; + batteryVoltage = (measuredVoltage * voltageDividerFactor)+0.1; + +// Log napiećia docelowoe procent baterii +// kiedy zaden przycisk nie jest wcisniety + if (mins % 1 == 0 && secs == 0) { + File file = SD.open("/GeneralLog.txt", FILE_APPEND); + if (file) { + display.fillRect(0, 0, 124, 64, SSD1306_WHITE); + file.print(dateString); + file.print(" Battery V: "); + file.println(formatNumber(batteryVoltage, 2)); + file.close(); + } + } + + + //zapis na SD: + if (mins % 1 == 0 && secs == 0) { + File file = SD.open("/TempHumLog.txt", FILE_APPEND); + if (file) { + display.fillRect(0, 0, 124, 64, SSD1306_WHITE); + file.print(leadZero(dayss)); + file.print("/"); + file.print(leadZero(months)); + file.print("/"); + file.print(years); + file.print("; "); + file.print(hourss); + file.print(":"); + file.print(leadZero(mins)); + file.print("; "); + file.print(formatNumber(temp)); + file.print("; "); + file.print(formatNumber(hum)); + file.print("; "); + file.println(formatNumber(heat_idx)); + file.close(); + delay(1000); + } + } display.display(); delay(150); yield(); } + +String leadZero(float number) { + String str = String(int(number)); + str.trim(); + if (number < 10) { + str = "0" + str; + } + return str; +} + + + // //float interpolate(float x, float x0, float x1, float y0, float y1) { // return y0 + (x - x0) * (y1 - y0) / (x1 - x0);