99#include " ESPAsyncWebServer.h"
1010#include " DHTesp.h"
1111#include < ArduinoJson.h>
12+ #include < WiFiClientSecure.h>
13+ #include < HTTPClient.h>
1214#include < Wire.h>
1315#include < Adafruit_GFX.h>
1416#include < Adafruit_SSD1306.h>
@@ -27,6 +29,9 @@ KASAUtil kasaUtil; // Kasa utilit
2729KASASmartPlug *intakePlug = NULL ; // Smart plug pointers (Intake)
2830KASASmartPlug *exhaustPlug = NULL ; // Smart plug pointers (Exhaust)
2931KASASmartPlug *humidifierPlug = NULL ; // Smart plug pointers (Humidifier)
32+ WiFiClientSecure client; // Secure WiFi client
33+ HTTPClient http; // HTTP client
34+ uint8_t bitmap_data[1024 ]; // Buffer for the image data
3035// ============================================================================
3136
3237// ============================================================================
@@ -332,10 +337,38 @@ void showStart() {
332337 display.clearDisplay ();
333338}
334339
340+ // Function to fetchBitmap from server
341+ bool fetchBitmap () {
342+ client.setInsecure (); // Disables SSL certificate verification (Not secure for production)
343+ http.begin (client, image_url);
344+ int httpCode = http.GET ();
345+ if (httpCode == HTTP_CODE_OK) {
346+ WiFiClient* stream = http.getStreamPtr ();
347+ int index = 0 ;
348+ while (http.connected () && stream->available () && index < sizeof (bitmap_online_data)) {
349+ bitmap_online_data[index++] = stream->read ();
350+ }
351+
352+ http.end ();
353+ Serial.println (" Image downloaded successfully!" );
354+ return true ;
355+ } else {
356+ Serial.printf (" Failed to fetch image. HTTP Code: %d\n " , httpCode);
357+ return false ;
358+ }
359+ }
360+
361+
362+
335363// Function to show bitmap image
336364void showBitmap () {
337365 display.clearDisplay ();
338- display.drawBitmap (0 , 0 , bitmap_image, SCREEN_WIDTH, SCREEN_HEIGHT, SSD1306_WHITE);
366+ if (fetchBitmap ()) {
367+ display.drawBitmap (0 , 0 , bitmap_online_data, SCREEN_WIDTH, SCREEN_HEIGHT, SSD1306_WHITE);
368+
369+ } else {
370+ display.drawBitmap (0 , 0 , bitmap_image, SCREEN_WIDTH, SCREEN_HEIGHT, SSD1306_WHITE);
371+ }
339372 display.display ();
340373 delay (SCREEN_STARTUP_DISPLAY_TIME);
341374
0 commit comments