From 4997fa9838b90e2eb3d7c1c77d8ae9cfaaec6e28 Mon Sep 17 00:00:00 2001 From: hans-jurgen Date: Wed, 25 Jun 2025 16:50:02 +0200 Subject: [PATCH] 2025-05-2501 Wegen des GRAD Zeichen viel pobiert. --- platformio.ini | 2 +- src/main.cpp | 89 +++++++++++++++++++++++++++++++------------------- 2 files changed, 56 insertions(+), 35 deletions(-) diff --git a/platformio.ini b/platformio.ini index fbdc7af..f88c4bf 100644 --- a/platformio.ini +++ b/platformio.ini @@ -41,7 +41,7 @@ build_flags = ${env.build_flags} -Dmqtt_port=61883 -DINNEN=\"hjk/devices/TEMPWOHNZIM/telemetry/temperature\" ;-DFLUR=\"hjk/devices/TEMPFLUR/telemetry/temperature\" - -DCO2=\"hjk/devices/257923/telemetry/co2\" + ;-DCO2=\"hjk/devices/257923/telemetry/co2\" -DAKKU=\"hjk/devices/WETTERSTATION/telemetry/battery\" -DWETTER=\"hjk/devices/WETTERSTATION/telemetry/temperature_Htu_21\" -DLUFTDRUCK=\"hjk/devices/WETTERSTATION/telemetry/pressure\" diff --git a/src/main.cpp b/src/main.cpp index b1e3752..9b94e65 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,9 +67,9 @@ PubSubClient client(espClient); #define matrix_width 64 #define matrix_height 32 -// This defines the 'on' time of the display is us. The larger this number, -// the brighter the display. If too large the ESP will crash -uint8_t display_draw_time=10; //30-70 is usually fine +// This defines the 'on' time of the display is us. The larger this number, ---> Dies definiert die Einschaltzeit des Displays. Je größer diese Zahl, +// the brighter the display. If too large the ESP will crash ---> desto heller das Display. Wenn zu groß, stürzt das ESP ab +uint8_t display_draw_time=45; //30-70 is usually fine ---> 30-70 ist normalerweise in Ordnung //PxMATRIX display(32,16,P_LAT, P_OE,P_A,P_B,P_C); PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D); @@ -198,7 +198,7 @@ void print_wifi_status() { Serial.print(rssi); Serial.println(" dBm"); display.clearDisplay(); - scroll_text(64-16,40,"IP Adress: " + WiFi.localIP().toString()+ " signal strength (RSSI): " + String(rssi, DEC) + " dBm", 96,96,0, false); + scroll_text(matrix_height-16,40,"IP Adress: " + WiFi.localIP().toString()+ " signal strength (RSSI): " + String(rssi, DEC) + " dBm", 96,96,0, false); } void display_update_enable(bool is_enable) @@ -477,13 +477,13 @@ void Test() } void setup() { - startTime = millis(); - Serial.begin(115200); - //WiFi.mode( WIFI_OFF ); - delay( 10 ); - Serial.println("Start"); - // initialise_wifi(); - setup_wifi(); + startTime = millis(); + Serial.begin(115200); + //WiFi.mode( WIFI_OFF ); + Serial.println("Start"); + // initialise_wifi(); + setup_wifi(); + // Define your display layout here, e.g. 1/8 step, and optional SPI pins begin(row_pattern, CLK, MOSI, MISO, SS) display.begin(SCAN); // Rows-scan pattern 1/32 @@ -520,27 +520,25 @@ void setup() { // Set the brightness of the panels (default is 255) display.setBrightness(Helligkeit); - display_update_enable(true); + - display.clearDisplay(); + /* display.clearDisplay(); display.setTextColor(myRED); display.setCursor(0,0); display.print("Pixel"); display.setTextColor(myGREEN); display.setCursor(30,0); - display.print("Time"); + display.print("Time"); */ //---------------------- - display.setTextColor(myBLUE); + /* display.setTextColor(myBLUE); display.setCursor(2,matrix_height-8); display.print("Pixel"); display.setTextColor(myYELLOW); display.setCursor(30,matrix_height-8); - display.print("1234"); + display.print("1234"); */ + display_update_enable(true); //-------------------------------------------------- //-------------------------------------------------- - - delay(1000); - print_wifi_status(); configTime(0, 0, NTP_SERVER); // See https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv for Timezone codes for your region setenv("TZ", TZ_INFO, 1); @@ -551,8 +549,10 @@ void setup() { delay(5000); ESP.restart(); } + display.clearDisplay(); lastNTPtime = time(&now); lastEntryTime = millis(); + print_wifi_status(); } @@ -643,14 +643,21 @@ void scroll_text2(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t void scroll_Grad(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB, boolean blink) { - uint16_t text_length = text.length() +2; - display.setTextWrap(false); // we don't wrap text so it scrolls nicely + uint16_t text_length = text.length(); + text_length = text_length + 2; + uint16_t HV = matrix_width + (((text_length) * 5)); + if (text_length == 19){ + HV = HV -55; + } + else HV = HV - 50; + Serial.printf("Stringlänge : %d %d\r\n",text_length, HV); + display.setTextWrap(false); // we don't wrap text so it scrolls nicely --> Wir brechen den Text nicht um, damit er gut scrollt display.setTextSize(1); display.setRotation(0); display.setTextColor(display.color565(colorR,colorG,colorB)); // Asuming 5 pixel average character width - for (int xpos=matrix_width; xpos>-(matrix_width+text_length*5); xpos--) + for (int xpos=matrix_width; xpos>-(matrix_width+(text_length*5)); xpos--) { if (millis() - lastTime >= 1000) { @@ -665,15 +672,15 @@ void scroll_Grad(uint8_t ypos, unsigned long scroll_delay, String text, uint8_t display.fillRect(TimeX + 30, TimeY - 8, 2, 15, myBLACK); } } - + //Serial.printf("XPOS = %d\r\n", xpos); display.setTextColor(display.color565(colorR,colorG,colorB)); display.fillRect(xpos, ypos-1, 64-xpos, 9, (myBLACK)); display.setCursor(xpos,ypos); display.print(text); - display.setCursor(xpos+132, ypos-5); + display.setCursor(xpos+HV, ypos-5); display.setFont(&Picopixel); display.print("o"); - display.setCursor(xpos+136, ypos+6); + display.setCursor(xpos+HV+4, ypos+6); display.setFont(); // ........... display.println("C"); @@ -688,7 +695,11 @@ static void setup_wifi() { long ErrCount = 0; - delay(10); + WiFi.mode( WIFI_OFF ); + delay( 10 ); + /* WiFi.persistent( false ); + WiFi.setHostname(hostname.c_str()); //define hostname */ + //WiFi.mode( WIFI_STA ); // We start by connecting to a WiFi network if (!ip.fromString(MYIP)) { // try to parse into the IPAddress Serial.println("UnParsable IP"); @@ -705,6 +716,11 @@ static void setup_wifi() { if (!subnet.fromString(SUBNET)) { // try to parse into the IPAddress Serial.println("UnParsable GATEWAY"); } + + /* IPAddress ip( 192, 168, 127, 53); + IPAddress gateway( 192, 168, 127, 1 ); + IPAddress subnet( 255, 255, 255, 0 ); + IPAddress dns(192, 168, 127, 1); */ if (!WiFi.config(ip, gateway, subnet, dns, secondarDNS)) { Serial.println("STA Failed to configure"); @@ -718,9 +734,9 @@ static void setup_wifi() { Serial.print("."); ErrCount ++; if (ErrCount >= MaxErrCount){ - endTime = millis(); - unsigned long Pause = stoerung -((endTime - startTime) * 1000); // Pause - ESP.deepSleep(Pause); // Pause + /* endTime = millis(); + unsigned long Pause = stoerung -((endTime - startTime) * 1000); // Pause */ + ESP.restart(); delay(100); } } @@ -747,7 +763,9 @@ void loop() { ZeigeDatum(timeinfo, 1, 0); ZeigeZeit(timeinfo, TimeX, TimeY); //ZeigeZeit(timeinfo, 1,40); + #ifdef Co2 ZeigeCO(1,CoY); + #endif /* if ((timeinfo.tm_min % 10) == 0){ /* if (Covid19 != 0){ scroll_text(matrix_height-8,20,"Landkreis Heilbronn", 30,30,30, true); @@ -779,8 +797,7 @@ void loop() { scroll_text2(matrix_height-24,20,"ich w\201nsche Euch allen ein", 128,128,0, true); scroll_text2(matrix_height-24,20,"Frohes neues Jahr 2022.", 128,255,0, true); */ - ZeigeWetter(double(TempWohn), WetterY,WetterX); - //Serial.println("START"); + //ZeigeWetter(double(TempWohn), WetterY,WetterX); if (Aussentemp > -99.9){ char szWetter[10]; #ifdef FLUR @@ -795,7 +812,6 @@ void loop() { /* eingeführt werden, sonst kommt es zu einen Socket Fehler !!!! */ scroll_text(matrix_height-8,30,"Luftdruck: " + String(Pressure) + " hPa", 0,0,255, true); - dtostrf(Aussentemp, 4, 1, szWetter); //Serial.print(Aussentemp); Serial.print(" "); Serial.println(szWetter); /* Achtung sehr wichtig, wenn das gesamt Laufschrift mehr @@ -803,7 +819,8 @@ void loop() { client.loop(); /* eingeführt werden, sonst kommt es zu einen Socket Fehler !!!! */ - scroll_Grad(matrix_height-8,30,"Aussentemperatur: " + String(szWetter), 0,0,64, true); + dtostrf(Aussentemp, 4, 1, szWetter); + scroll_Grad(matrix_height-8,30,"Aussentemperatur: " + String(szWetter), 0,0,255, true); /* Achtung sehr wichtig, wenn das gesamt Laufschrift mehr als 30 Sekunden Dauert muss ein .... */ @@ -811,7 +828,11 @@ void loop() { /* eingeführt werden, sonst kommt es zu einen Socket Fehler !!!! */ dtostrf(Luftfeuchtigkeit, 4, 1, szWetter); - scroll_text(matrix_height-8,30,"Luftfeuchtigkeit: " + String(szWetter) + " %", 0,0,64, true); + scroll_text(matrix_height-8,30,"Luftfeuchtigkeit: " + String(szWetter) + " %", 0,0,255, true); + client.loop(); + dtostrf(TempWohn, 5, 1, szWetter); + scroll_Grad(matrix_height-8,30,"Wohnzimmer: " + String(szWetter), 0, 255, 0, true); + client.loop(); } if ((Akku <= GRENZWERT) && (Akku > 0)){ scroll_text(matrix_height-8,40,"Akku: " + String(Akku) + " Volt", 255, 0, 0, true);