#include "scr_st77916.h" #include "SD_MMC.h" // https://randomnerdtutorials.com/esp32-client-server-wi-fi/ #include #include const char* ssid = "ESP32-Access-Point"; const char* password = "123456789"; void my_print(const char* buf) { Serial.println(buf); // Print logs to the serial monitor } void display_animation() { lv_obj_t* img; img = lv_gif_create(lv_scr_act()); Serial.print("Available Heap before: "); Serial.println(esp_get_free_heap_size()); lv_mem_monitor_t mem_mon; lv_mem_monitor(&mem_mon); printf("Free memory: %d bytes\n", mem_mon.free_size); lv_fs_file_t file; if (lv_fs_open(&file, "A:wallpaper.gif", LV_FS_MODE_RD) == LV_FS_RES_OK) { lv_fs_close(&file); // File exists, proceed with loading lv_gif_set_src(img, "A:wallpaper.gif"); Serial.println("GIF Loaded Successfully"); } else { Serial.println("Failed to Load GIF: File not found or inaccessible"); } Serial.print("Available Heap after: "); Serial.println(esp_get_free_heap_size()); lv_mem_monitor(&mem_mon); printf("Free memory: %d bytes\n", mem_mon.free_size); lv_obj_align(img, LV_ALIGN_CENTER, 0, 0); } lv_obj_t* label1; void display_text() { // Create a style for the text static lv_style_t style_text; lv_style_init(&style_text); // Set the text color to white lv_style_set_text_color(&style_text, lv_color_white()); // // Set the shadow color to black (this will simulate the outline) // lv_style_set_shadow_color(&style_text, lv_color_black()); // // Set the shadow width to create the outline effect // lv_style_set_shadow_width(&style_text, 2); // Adjust for desired outline thickness // // Set the shadow offset to 0 so it surrounds the text evenly // lv_style_set_shadow_ofs_x(&style_text, 0); // lv_style_set_shadow_ofs_y(&style_text, 0); label1 = lv_label_create(lv_scr_act()); // Apply the style to the label lv_obj_add_style(label1, &style_text, LV_PART_MAIN); // lv_style_set_text_font(&label1, &Montserrat); /*Set a larger font*/ lv_label_set_long_mode(label1, LV_LABEL_LONG_WRAP); /*Break the long lines*/ lv_label_set_text(label1, "0"); lv_obj_set_width(label1, 150); /*Set smaller width to make the lines wrap*/ lv_obj_set_style_text_align(label1, LV_TEXT_ALIGN_CENTER, 0); lv_obj_align(label1, LV_ALIGN_CENTER, 0, 0); // lv_obj_set_style_transform_zoom(label1, 256 * 2, 0); // Zoom: 256 = 1x scale (default) } void connectToWifi() { WiFi.begin(ssid, password); Serial.println("Connecting"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to WiFi network with IP Address: "); Serial.println(WiFi.localIP()); } void setup() { delay(200); Serial.begin(115200); scr_lvgl_init(); //lv_log_register_print_cb(my_print); // Register print function for LVGL logs // Get the active screen (root object for the display) lv_obj_t* screen = lv_scr_act(); // Set the background color of the entire screen to black lv_obj_set_style_bg_color(screen, lv_color_black(), 0); // 0 is the part ID for the main part lv_obj_set_style_bg_opa(screen, LV_OPA_COVER, 0); // Set opacity to fully opaque // Configure the SDMMC host SD_MMC.setPins(SD_MMC_CLK_PIN, SD_MMC_CMD_PIN, SD_MMC_D0_PIN, SD_MMC_D1_PIN, SD_MMC_D2_PIN, SD_MMC_D3_PIN); if (!SD_MMC.begin()) { Serial.println("Card Mount Failed"); return; } uint8_t cardType = SD_MMC.cardType(); if (cardType == CARD_NONE) { Serial.println("No SD card attached"); return; } Serial.println("SD Card initialized successfully."); connectToWifi(); // display_animation(); display_text(); } void loop() { lv_timer_handler(); vTaskDelay(5); lv_mem_monitor_t mem_mon; lv_mem_monitor(&mem_mon); printf("Free memory: %d bytes\n", mem_mon.free_size); Serial.print("Available Heap: "); Serial.println(esp_get_free_heap_size()); if (WiFi.status() == WL_CONNECTED) { String speed = httpGETRequest("http://192.168.4.1/speed"); Serial.print("Speed: "); Serial.println(speed); lv_label_set_text(label1, speed.c_str()); } else { Serial.println("WiFi Disconnected"); connectToWifi(); } } String httpGETRequest(const char* serverName) { WiFiClient client; HTTPClient http; // Your Domain name with URL path or IP address with path http.begin(client, serverName); // Send HTTP POST request int httpResponseCode = http.GET(); String payload = "--"; if (httpResponseCode > 0) { Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); payload = http.getString(); } else { Serial.print("Error code: "); Serial.println(httpResponseCode); } // Free resources http.end(); return payload; }