Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // A video of this project on youtube: https://youtu.be/iKTeAz46-Ds
- //
- // Board Manager --> ESP32 ver.3.02
- // Arduino ESP 32 Boards 2.0.13
- #include <Arduino_GFX_Library.h> //ver. 1.4.7
- #include <Adafruit_GFX.h> //ver. 1.11.9
- #include <Fonts/FreeSans12pt7b.h>
- #include <Fonts/FreeSans18pt7b.h>
- #include <Fonts/FreeSans24pt7b.h>
- #include <Fonts/FreeSans9pt7b.h>
- #include <SPI.h>
- #include <ArduinoJson.h>
- #include <WiFi.h>
- #include <HTTPClient.h>
- #include "time.h"
- #define ESP32_8048S070
- #if defined(ESP32_8048S070)
- #define TFT_BL 2
- Arduino_ESP32RGBPanel* bus = new Arduino_ESP32RGBPanel(
- GFX_NOT_DEFINED /* CS */, GFX_NOT_DEFINED /* SCK */, GFX_NOT_DEFINED /* SDA */,
- 41 /* DE */, 40 /* VSYNC */, 39 /* HSYNC */, 42 /* PCLK */,
- 14 /* R0 */, 21 /* R1 */, 47 /* R2 */, 48 /* R3 */, 45 /* R4 */,
- 9 /* G0 */, 46 /* G1 */, 3 /* G2 */, 8 /* G3 */, 16 /* G4 */, 1 /* G5 */,
- 15 /* B0 */, 7 /* B1 */, 6 /* B2 */, 5 /* B3 */, 4 /* B4 */
- );
- Arduino_RPi_DPI_RGBPanel* gfx = new Arduino_RPi_DPI_RGBPanel(
- bus,
- 800 /* width */, 0 /* hsync_polarity */, 210 /* hsync_front_porch */, 30 /* hsync_pulse_width */, 16 /* hsync_back_porch */,
- 480 /* height */, 0 /* vsync_polarity */, 22 /* vsync_front_porch */, 13 /* vsync_pulse_width */, 10 /* vsync_back_porch */,
- 1 /* pclk_active_neg */, 16000000 /* prefer_speed */, true /* auto_flush */
- );
- #endif
- const char* ssid = "WIFI SSID"; // Your Wifi network name
- const char* password = "*WIFI PASSWORD"; // Your Wifi network password
- // Your Home Assistant server IP Your Home Assistant Sensor
- const char* haApiUrl = "http://192.168.xxx.xxx:8123/api/states/sensor.xxxxxxxxxx";
- const char* haApiUrl2 = "http://192.168.xxx.xxx:8123/api/states/sensor.xxxxxxxxxx";
- const char* haApiUrl3 = "http://192.168.xxx.xxx:8123/api/states/sensor.xxxxxxxxxx";
- const char* haApiUrl4 = "http://192.168.xxx.xxx:8123/api/states/sensor.xxxxxxxxxx";
- const char* haApiUrl5 = "http://192.168.xxx.xxx:8123/api/states/sensor.xxxxxxxxxx";
- const char* haApiUrl6 = "http://192.168.xxx.xxx:8123/api/states/sensor.xxxxxxxxxx";
- // Example: I used these sensors, with these links.
- //const char* haApiUrl = "http://192.168.0.103:8123/api/states/sensor.power_meter_active_power";
- //const char* haApiUrl2 = "http://192.168.0.103:8123/api/states/sensor.inverter_active_power";
- //const char* haApiUrl3 = "http://192.168.0.103:8123/api/states/sensor.difference_power_entities";
- //const char* haApiUrl4 = "http://192.168.0.103:8123/api/states/sensor.inverter_daily_yield";
- //const char* haApiUrl5 = "http://192.168.0.103:8123/api/states/sensor.inverter_internal_temperature";
- //const char* haApiUrl6 = "http://192.168.0.103:8123/api/states/sensor.power_meter_tensiune";
- const char* haApiToken = "xxxxxxxxxxxxxxxxxxxx"; //Your Home Assistant token, details in this video: https://youtu.be/p7ZOHrjYuNU
- int activePower;
- int solarPower;
- int houseConsumption;
- int ProdusAstazi;
- int Temperatura;
- int Tensiune;
- float ProdusAstazi2;
- float Temperatura2;
- float Tensiune2;
- float houseConsumption2;
- float currentSolarPower;
- float currentProduction;
- uint16_t mainColor = (activePower >= 0) ? GREEN : RED;
- uint16_t houseColor = (activePower >= 0) ? GREEN : RED;
- uint16_t solarColor = (solarPower > 0) ? GREEN : BLACK;
- int centerX = gfx->width() / 2;
- int centerY = gfx->height() / 2;
- int radius = 50;
- int mainRadius = radius * 2;
- unsigned long previousMillis = 0;
- const long interval = 15000;
- unsigned long currentSageataMillis;
- unsigned long previousSageataMillis;
- int SageataInterval;
- int SageataX;
- int SageataY;
- int SageataDistanta;
- uint16_t SageataCuloare;
- int SageataViteza;
- int SageataDimensiune;
- int i;
- unsigned long currentSageataMillis2;
- unsigned long previousSageataMillis2;
- int SageataInterval2;
- int SageataX2;
- int SageataY2;
- int SageataDistanta2;
- uint16_t SageataCuloare2;
- int SageataViteza2;
- int SageataDimensiune2;
- int i2;
- unsigned long currentSageataMillis3;
- unsigned long previousSageataMillis3;
- int SageataInterval3;
- int SageataX3;
- int SageataY3;
- int SageataDistanta3;
- uint16_t SageataCuloare3;
- int SageataViteza3;
- int SageataDimensiune3;
- int i3;
- unsigned long currentSageataMillis4;
- unsigned long previousSageataMillis4;
- int SageataInterval4;
- int SageataX4;
- int SageataY4;
- int SageataDistanta4;
- uint16_t SageataCuloare4;
- int SageataViteza4;
- int SageataDimensiune4;
- int i4;
- unsigned long currentSageataMillis5;
- unsigned long previousSageataMillis5;
- int SageataInterval5;
- int SageataX5;
- int SageataY5;
- int SageataDistanta5;
- uint16_t SageataCuloare5;
- int SageataViteza5;
- int SageataDimensiune5;
- int i5;
- int VitezaInjectie;
- int VitezaRetea;
- int VitezaConsum;
- const char* ntpServer = "pool.ntp.org";
- const long gmtOffset_sec = 7200;
- const int daylightOffset_sec = 3600;
- unsigned long currentTimp = 0;
- unsigned long previousTimp = 0;
- int IntervalTimp = 1000;
- int Cadran = 1;
- int prevHour = -1;
- int prevMinute = -1;
- int prevSecond = -1;
- int StergeEcranulOdata = 0;
- int currentHour = 0;
- int currentMinute = 0;
- int currentSecond = 0;
- void setup()
- {
- Serial.begin(115200);
- gfx->begin();
- #ifdef TFT_BL
- pinMode(TFT_BL, OUTPUT);
- analogWrite(TFT_BL, 100);
- #endif
- gfx->setTextSize(2);
- gfx->fillScreen(BLACK);
- gfx->setTextColor(YELLOW);
- gfx->setCursor(10,110);
- gfx->print("Display --> OK!");
- connectToWiFi();
- configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
- CitesteDatele();
- AfiseazaDatele();
- }
- void loop()
- {
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= interval)
- {
- previousMillis = currentMillis;
- Cadran++;
- if (Cadran > 2) Cadran = 1;
- if (solarPower == 0 ) Cadran = 2;
- if (Cadran == 1)
- {
- FadeDown();
- checkWiFiConnection();
- CitesteDatele();
- StergeCompletEcranul();
- AfiseazaDatele();
- AfiseazaOra();
- FadeIn();
- StergeEcranulOdata = 0;
- }
- if (Cadran == 2)
- {
- if(solarPower > 0)
- {
- FadeDown();
- }
- prevHour = -1;
- prevMinute = -1;
- prevSecond = -1;
- checkWiFiConnection();
- CitesteProductiaSolara();
- if (solarPower > 0)
- {
- StergeCompletEcranul();
- } else
- {
- if (StergeEcranulOdata == 0)
- {
- StergeCompletEcranul();
- StergeEcranulOdata = 1;
- }
- }
- AfiseazaDatele2();
- if(solarPower > 0)
- {
- FadeIn();
- }
- }
- }
- if (Cadran == 1)
- {
- AfiseazaAnimatiiCadran1();
- AfiseazaOra();
- }
- if (Cadran == 2)
- {
- AfiseazaDatele2();
- }
- }
- void CitesteProductiaSolara()
- {
- delay(50);
- HTTPClient http;
- http.begin(haApiUrl2);
- http.addHeader("Authorization", "Bearer " + String(haApiToken));
- int httpCode = http.GET();
- if (httpCode > 0)
- {
- String payload = http.getString();
- DynamicJsonDocument doc(1024);
- deserializeJson(doc, payload);
- float currentSolarPower = doc["state"].as<float>();
- solarPower = currentSolarPower;
- Serial.print("Productie Solara: ");
- Serial.println(currentSolarPower);
- } else
- {
- Serial.println("Nu am reusit sa citesc Productia Solara!");
- }
- http.end();
- }
- void FadeDown()
- {
- for(int i = 100; i >= 0; i--)
- {
- analogWrite(TFT_BL, i);
- delay(10);
- }
- }
- void FadeIn()
- {
- for(int i = 0; i <= 100; i++)
- {
- analogWrite(TFT_BL, i);
- delay(10);
- }
- }
- void AfiseazaAnimatiiCadran1()
- {
- VitezaInjectie = 55 - activePower / 100;
- VitezaConsum = 55 - houseConsumption / 100;
- VitezaRetea = 55 + activePower / 100;
- if (solarPower > 0)
- {
- AfiseazaSageata(425, 325, 135, GREEN, VitezaConsum, 10);
- AfiseazaSageata5(415, 230, 90, GREEN, VitezaConsum, 10);
- }
- if (activePower > 0)
- {
- AfiseazaSageata2(235, 325, 135, GREEN, VitezaInjectie, 10);
- AfiseazaSageata4(385, 230, 90, GREEN, VitezaInjectie, 10);
- }
- if (activePower < 0)
- {
- AfiseazaSageata3(235, 355, 335, RED, VitezaRetea, 10);
- }
- if (currentTimp - previousTimp >= IntervalTimp)
- {
- previousTimp = currentTimp;
- AfiseazaOra();
- }
- }
- void AfiseazaDatele2()
- {
- char buffer[3];
- struct tm timeinfo;
- if (getLocalTime(&timeinfo))
- {
- currentHour = timeinfo.tm_hour;
- currentMinute = timeinfo.tm_min;
- currentSecond = timeinfo.tm_sec;
- if (currentHour != prevHour)
- {
- Serial.printf("Ora: %02d\n", currentHour);
- prevHour = currentHour;
- gfx->fillRect(0 , 110, 365, 230, BLACK);
- gfx->setCursor(0, 320);
- gfx->setTextColor(BLUE);
- gfx->setTextSize(6);
- //gfx->print(currentHour);
- sprintf(buffer, "%02d:", currentHour);
- gfx->print(buffer);
- }
- if (currentMinute != prevMinute)
- {
- Serial.printf("Minute: %02d\n", currentMinute);
- prevMinute = currentMinute;
- gfx->fillRect(365 , 110, 335, 230, BLACK);
- gfx->setCursor(365, 320);
- gfx->setTextColor(BLUE);
- gfx->setTextSize(6);
- sprintf(buffer, "%02d", currentMinute);
- gfx->print(buffer);
- }
- if (currentSecond != prevSecond)
- {
- Serial.printf("Secunde: %02d\n", currentSecond);
- prevSecond = currentSecond;
- gfx->fillRect(685 , 110, 120, 100, BLACK);
- gfx->setCursor(685, 185);
- gfx->setTextColor(RED);
- //gfx->setTextColor(gfx->color565(255, 120, 35));
- gfx->setTextSize(2);
- sprintf(buffer, "%02d", currentSecond);
- gfx->print(buffer);
- delay(500);
- }
- } else
- {
- Serial.println("Eroare la obtinerea timpului.");
- }
- }
- void StergeCompletEcranul()
- {
- gfx->fillRect(0 , 0, centerX * 2, centerY * 2, BLACK);
- }
- void AfiseazaOra()
- {
- currentTimp = millis();
- if (currentTimp - previousTimp >= IntervalTimp)
- {
- previousTimp = currentTimp;
- struct tm timeinfo;
- getLocalTime(&timeinfo);
- gfx->setTextSize(1);
- gfx->fillRect(308 , 398, 200, 50, BLACK);
- gfx->setTextColor(WHITE);
- gfx->setCursor(320, 440);
- gfx->print(&timeinfo, "%H:%M:%S");
- Serial.print(".");
- }
- }
- void AfiseazaSageata5(int SageataX5, int SageataY5, int SageataDistanta5, uint16_t SageataCuloare5, int SageataViteza5, int SageataDimensiune5)
- {
- currentSageataMillis5 = millis();
- if (currentSageataMillis5 - previousSageataMillis5 >= SageataViteza5)
- {
- if (i5 > SageataDistanta5)
- {
- gfx->fillTriangle(SageataX5, SageataY5 + SageataDistanta5, SageataX5 - SageataDimensiune5, SageataY5 + SageataDistanta5 - SageataDimensiune5, SageataX5 + SageataDimensiune5, SageataY5 + SageataDistanta5 - SageataDimensiune5, BLACK);
- i5 = 0;
- }
- gfx->fillTriangle(SageataX5, SageataY5 + i5, SageataX5 - SageataDimensiune5, SageataY5 - SageataDimensiune5 + i5, SageataX5 + SageataDimensiune5, SageataY5 - SageataDimensiune5 + i5, SageataCuloare5);
- gfx->fillRect(SageataX5 - SageataDimensiune5 - 2, SageataY5 - SageataDimensiune5 - 1 + i5, SageataDimensiune5 * 2 + 4, 2, BLACK);
- i5++;
- previousSageataMillis5 = currentSageataMillis5;
- }
- gfx->drawLine(centerX + 15, centerY + 85, centerX + 15, centerY - 25, WHITE);
- }
- void AfiseazaSageata4(int SageataX4, int SageataY4, int SageataDistanta4, uint16_t SageataCuloare4, int SageataViteza4, int SageataDimensiune4)
- {
- currentSageataMillis4 = millis();
- if (currentSageataMillis4 - previousSageataMillis4 >= SageataViteza4)
- {
- if (i4 > SageataDistanta4)
- {
- gfx->fillTriangle(SageataX4, SageataY4 + SageataDistanta4, SageataX4 - SageataDimensiune4, SageataY4 + SageataDistanta4 - SageataDimensiune4, SageataX4 + SageataDimensiune4, SageataY4 + SageataDistanta4 - SageataDimensiune4, BLACK);
- i4 = 0;
- }
- gfx->fillTriangle(SageataX4, SageataY4 + i4, SageataX4 - SageataDimensiune4, SageataY4 - SageataDimensiune4 + i4, SageataX4 + SageataDimensiune4, SageataY4 - SageataDimensiune4 + i4, SageataCuloare4);
- gfx->fillRect(SageataX4 - SageataDimensiune4 - 2, SageataY4 - SageataDimensiune4 - 1 + i4, SageataDimensiune4 * 2 + 4, 2, BLACK);
- i4++;
- previousSageataMillis4 = currentSageataMillis4;
- }
- gfx->drawLine(centerX - 15, centerY + 85, centerX - 15, centerY - 25, WHITE);
- }
- void AfiseazaSageata3(int SageataX3, int SageataY3, int SageataDistanta3, uint16_t SageataCuloare3, int SageataViteza3, int SageataDimensiune3)
- {
- currentSageataMillis3 = millis();
- if (currentSageataMillis3 - previousSageataMillis3 >= SageataViteza3)
- {
- if (i3 > SageataDistanta3)
- {
- gfx->fillTriangle(SageataX3 + SageataDistanta3 + 1, SageataY3 - SageataDimensiune3, SageataX3 + SageataDistanta3 + 1, SageataY3 + SageataDimensiune3, SageataX3 + SageataDimensiune3 + i3 + 1, SageataY3, BLACK);
- i3 = 0;
- }
- gfx->fillTriangle(SageataX3 + i3, SageataY3 - SageataDimensiune3, SageataX3 + i3, SageataY3 + SageataDimensiune3, SageataX3 + SageataDimensiune3 + i3, SageataY3, SageataCuloare3);
- gfx->fillRect(SageataX3 + i3 - 1, SageataY3 - SageataDimensiune3, 2, SageataDimensiune3 * 2 + 1, BLACK);
- i3++;
- previousSageataMillis3 = currentSageataMillis3;
- }
- gfx->drawLine(centerX / 2 + 15, centerY + 115, centerX / 2 + centerX - 15, centerY + 115, WHITE);
- }
- void AfiseazaSageata2(int SageataX2, int SageataY2, int SageataDistanta2, uint16_t SageataCuloare2, int SageataViteza2, int SageataDimensiune2)
- {
- currentSageataMillis2 = millis();
- if (currentSageataMillis2 - previousSageataMillis2 >= SageataViteza2)
- {
- if (i2 > SageataDistanta2)
- {
- gfx->fillTriangle(SageataX2 - SageataDimensiune2, SageataY2, SageataX2, SageataY2 - SageataDimensiune2, SageataX2, SageataY2 + SageataDimensiune2, BLACK);
- i2 = 0;
- }
- gfx->fillTriangle(SageataX2 + SageataDistanta2 - SageataDimensiune2 - i2, SageataY2, SageataX2 + SageataDistanta2 - i2, SageataY2 - SageataDimensiune2, SageataX2 + SageataDistanta2 - i2, SageataY2 + SageataDimensiune2, GREEN);
- gfx->fillRect(SageataX2 + SageataDistanta2 - i2 + 1, SageataY2 - SageataDimensiune2, 2, SageataDimensiune2 * 2 + 1, BLACK);
- i2++;
- previousSageataMillis2 = currentSageataMillis2;
- }
- gfx->drawLine(centerX / 2 + 15, centerY + 85, centerX - 15, centerY + 85, WHITE);
- }
- void AfiseazaSageata(int SageataX, int SageataY, int SageataDistanta, uint16_t SageataCuloare, int SageataViteza, int SageataDimensiune)
- {
- currentSageataMillis = millis();
- if (currentSageataMillis - previousSageataMillis >= SageataViteza)
- {
- if (i > SageataDistanta)
- {
- gfx->fillTriangle(SageataX + SageataDistanta + 1, SageataY - SageataDimensiune, SageataX + SageataDistanta + 1, SageataY + SageataDimensiune, SageataX + SageataDimensiune + i + 1, SageataY, BLACK);
- i = 0;
- }
- gfx->fillTriangle(SageataX + i, SageataY - SageataDimensiune, SageataX + i, SageataY + SageataDimensiune, SageataX + SageataDimensiune + i, SageataY, GREEN);
- gfx->fillRect(SageataX + i - 1, SageataY - SageataDimensiune, 2, SageataDimensiune * 2 + 1, BLACK);
- i++;
- previousSageataMillis = currentSageataMillis;
- }
- gfx->drawLine(centerX + 15, centerY + 85, centerX / 2 + centerX - 15, centerY + 85, WHITE);
- }
- void CitesteDatele()
- {
- HTTPClient http;
- http.begin(haApiUrl);
- http.addHeader("Authorization", "Bearer " + String(haApiToken));
- int httpCode = http.GET();
- if (httpCode > 0)
- {
- String payload = http.getString();
- DynamicJsonDocument doc(1024);
- deserializeJson(doc, payload);
- currentProduction = doc["state"].as<float>();
- activePower = currentProduction;
- Serial.print("Putere Activa: ");
- Serial.println(currentProduction);
- } else
- {
- Serial.println("Nu am reusit sa citesc Putere Activa!");
- }
- delay(50); // If it fails to read the data from Home Assistant, try to increase the duration of this delay.
- http.begin(haApiUrl2);
- http.addHeader("Authorization", "Bearer " + String(haApiToken));
- httpCode = http.GET();
- if (httpCode > 0)
- {
- String payload = http.getString();
- DynamicJsonDocument doc(1024);
- deserializeJson(doc, payload);
- currentSolarPower = doc["state"].as<float>();
- solarPower = currentSolarPower;
- Serial.print("Productie Solara: ");
- Serial.println(currentSolarPower);
- } else
- {
- Serial.println("Nu am reusit sa citesc Productia Solara!");
- }
- delay(50); // If it fails to read the data from Home Assistant, try to increase the duration of this delay.
- http.begin(haApiUrl3);
- http.addHeader("Authorization", "Bearer " + String(haApiToken));
- httpCode = http.GET();
- if (httpCode > 0)
- {
- String payload = http.getString();
- DynamicJsonDocument doc(1024);
- deserializeJson(doc, payload);
- houseConsumption2 = doc["state"].as<float>();
- houseConsumption = houseConsumption2;
- Serial.print("Consum casa: ");
- Serial.println(houseConsumption);
- } else
- {
- Serial.println("Nu am reusit sa citesc Consumul casei!");
- }
- delay(50); // If it fails to read the data from Home Assistant, try to increase the duration of this delay.
- http.begin(haApiUrl4);
- http.addHeader("Authorization", "Bearer " + String(haApiToken));
- httpCode = http.GET();
- if (httpCode > 0)
- {
- String payload = http.getString();
- DynamicJsonDocument doc(1024);
- deserializeJson(doc, payload);
- ProdusAstazi2 = doc["state"].as<float>();
- ProdusAstazi = ProdusAstazi2;
- Serial.print("Produs Astazi: ");
- Serial.println(ProdusAstazi2);
- } else
- {
- Serial.println("Nu am reusit sa citesc Productia pe Astazi!");
- }
- delay(50); // If it fails to read the data from Home Assistant, try to increase the duration of this delay.
- http.begin(haApiUrl5);
- http.addHeader("Authorization", "Bearer " + String(haApiToken));
- httpCode = http.GET();
- if (httpCode > 0)
- {
- String payload = http.getString();
- DynamicJsonDocument doc(1024);
- deserializeJson(doc, payload);
- Temperatura2 = doc["state"].as<float>();
- Temperatura = Temperatura2;
- Serial.print("Temperatura inverter: ");
- Serial.println(Temperatura2);
- } else
- {
- Serial.println("Nu am reusit sa citesc Temperatura Inverter!");
- }
- delay(50); // If it fails to read the data from Home Assistant, try to increase the duration of this delay.
- http.begin(haApiUrl6);
- http.addHeader("Authorization", "Bearer " + String(haApiToken));
- httpCode = http.GET();
- if (httpCode > 0)
- {
- String payload = http.getString();
- DynamicJsonDocument doc(1024);
- deserializeJson(doc, payload);
- Tensiune2 = doc["state"].as<float>();
- Tensiune = Tensiune2;
- Serial.print("Tensiune retea: ");
- Serial.println(Tensiune2);
- } else
- {
- Serial.println("Nu am reusit sa citesc Tensiune Retea!");
- }
- //delay(50); // If it fails to read the data from Home Assistant, try to increase the duration of this delay.
- http.end();
- }
- void AfiseazaDatele()
- {
- AcoperaSagetile();
- gfx->drawCircle(centerX, centerY - 130, mainRadius + 1, WHITE);
- gfx->drawCircle(centerX, centerY - 130, mainRadius + 2, WHITE);
- if (solarPower > 0) solarColor = GREEN;
- else solarColor = BLACK;
- drawCircleWithValue(centerX, centerY - 130, mainRadius + 0, solarPower, solarColor);
- gfx->drawCircle(centerX / 2 - 90, centerY + 100, mainRadius + 1, WHITE);
- gfx->drawCircle(centerX / 2 - 90, centerY + 100, mainRadius + 2, WHITE);
- if (activePower >= 0) mainColor = GREEN;
- else mainColor = RED;
- drawCircleWithValue(centerX / 2 - 90, centerY + 100, mainRadius + 0, activePower, mainColor);
- gfx->drawCircle(centerX / 2 + centerX + 90, centerY + 100, mainRadius + 1, WHITE);
- gfx->drawCircle(centerX / 2 + centerX + 90, centerY + 100, mainRadius + 2, WHITE);
- if (activePower >= 0) houseColor = GREEN;
- else houseColor = RED;
- drawCircleWithValue(centerX / 2 + centerX + 90, centerY + 100, mainRadius + 0, houseConsumption, houseColor);
- String ProdusAstaziS = String(ProdusAstazi2, 2) + " kWh";
- drawTextWithOutline(800, 50, ProdusAstaziS, WHITE, GREEN);
- String TensiuneS = String(Tensiune2, 1) + " V";
- drawTextWithOutline(800, 100, TensiuneS, WHITE, GREEN);
- String TemperaturaS = String(Temperatura2, 1) + " *C";
- drawTextWithOutline(800, 150, TemperaturaS, WHITE, GREEN);
- // linii intre cercuri
- gfx->drawLine(centerX + 15, centerY + 85, centerX + 15, centerY - 25, WHITE);
- gfx->drawLine(centerX - 15, centerY + 85, centerX - 15, centerY - 25, WHITE);
- gfx->drawLine(centerX + 15, centerY + 85, centerX / 2 + centerX - 15, centerY + 85, WHITE);
- gfx->drawLine(centerX / 2 + 15, centerY + 85, centerX - 15, centerY + 85, WHITE);
- gfx->drawLine(centerX / 2 + 15, centerY + 115, centerX / 2 + centerX - 15, centerY + 115, WHITE);
- // casa
- gfx->fillTriangle(485, 245, 530, 185, 580, 245, RED);
- gfx->fillRect(500, 246, 65, 60, YELLOW);
- //stalp
- gfx->fillRect(220, 210, 5, 100, WHITE);
- gfx->fillRect(210, 220, 25, 5, WHITE);
- gfx->fillRect(210, 230, 25, 5, WHITE);
- gfx->fillRect(210, 240, 25, 5, WHITE);
- //panouri
- gfx->drawLine(105, 10, 305, 10, WHITE);
- gfx->drawLine(80, 60, 280, 60, WHITE);
- gfx->drawLine(80, 60, 105, 10, WHITE);
- gfx->drawLine(120, 60, 145, 10, WHITE);
- gfx->drawLine(160, 60, 185, 10, WHITE);
- gfx->drawLine(200, 60, 225, 10, WHITE);
- gfx->drawLine(240, 60, 265, 10, WHITE);
- gfx->drawLine(280, 60, 305, 10, WHITE);
- }
- void AcoperaSagetile()
- {
- gfx->fillRect(centerX / 2 + 15, centerY + 74, 160, 24, BLACK);
- gfx->fillRect(centerX + 25, centerY + 74, 160, 24, BLACK);
- gfx->fillRect(centerX / 2 + 15, centerY + 104, 370, 24, BLACK);
- gfx->fillRect(centerX - 25, centerY - 25, 24, 120, BLACK);
- gfx->fillRect(centerX + 5, centerY - 25, 24, 120, BLACK);
- }
- void drawCircleWithValue(int x, int y, int radius, int value, uint16_t color)
- {
- gfx->fillCircle(x, y, radius, color);
- gfx->setTextColor(BLACK);
- gfx->setFont(&FreeSans24pt7b);
- gfx->setTextSize(1);
- char valueStr[10];
- sprintf(valueStr, "%d", value);
- int16_t x1, y1;
- uint16_t textWidth, textHeight;
- gfx->getTextBounds(valueStr, 0, 0, &x1, &y1, &textWidth, &textHeight);
- int16_t textX = x - textWidth / 2;
- int16_t textY = y + textHeight / 2;
- gfx->setCursor(textX, textY);
- gfx->print(valueStr);
- }
- void drawTextWithOutline(int x, int y, String text, uint16_t color, uint16_t outlineColor)
- {
- gfx->setFont(&FreeSans24pt7b);
- gfx->setTextSize(1);
- int16_t x1, y1;
- uint16_t textWidth, textHeight;
- gfx->getTextBounds(text, x, y, &x1, &y1, &textWidth, &textHeight);
- int16_t textX = x - textWidth;
- int16_t textY = y + textHeight / 2;
- gfx->fillRect(textX - 80, y - textHeight / 2, textWidth + 80, textHeight + 3, BLACK);
- gfx->setTextColor(color);
- gfx->setCursor(textX - 20, textY);
- gfx->print(text);
- }
- void checkWiFiConnection()
- {
- if (WiFi.status() != WL_CONNECTED)
- {
- Serial.println("WiFi connection lost. Reconnecting...");
- connectToWiFi();
- gfx->setTextColor(YELLOW);
- gfx->setCursor(10,50);
- gfx->print("WiFi connection lost. Reconnecting...");
- } else
- {
- Serial.println("CHECK WIFI --> OK!");
- }
- }
- void connectToWiFi()
- {
- gfx->setTextColor(YELLOW);
- gfx->setCursor(10, 130);
- gfx->print("WIFI");
- WiFi.begin(ssid, password);
- int attempt = 0;
- while (WiFi.status() != WL_CONNECTED && attempt < 10)
- {
- delay(500);
- Serial.print(".");
- gfx->print(".");
- attempt++;
- }
- if (WiFi.status() == WL_CONNECTED)
- {
- Serial.println("\nConnected to WiFi");
- gfx->print("OK!");
- IPAddress ip = WiFi.localIP();
- Serial.print("IP Address: ");
- Serial.println(ip);
- gfx->setTextColor(YELLOW);
- gfx->setCursor(10, 150);
- gfx->print("IP: ");
- gfx->print(ip);
- int32_t rssi = WiFi.RSSI();
- Serial.print("Signal strength (RSSI): ");
- Serial.println(rssi);
- gfx->setTextColor(YELLOW);
- gfx->setCursor(10, 170);
- gfx->print("Wifi Signal: ");
- gfx->print(rssi);
- gfx->print(" dBm");
- } else
- {
- Serial.println("\nFailed to connect to WiFi. Check your credentials or network.");
- gfx->setTextColor(RED);
- gfx->print("Failed!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement