Skip to content

Display Reboot when try to use Wi-Fi #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
razarahil opened this issue Apr 29, 2025 · 2 comments
Open

Display Reboot when try to use Wi-Fi #193

razarahil opened this issue Apr 29, 2025 · 2 comments

Comments

@razarahil
Copy link

razarahil commented Apr 29, 2025

I've created the UI using Squareline and added the UI to the code with the help of lvgl port.
When I run just UI, it works fine and as soon as I add Wi-Fi code, the display start rebooting.

lvgl v8.4.4
esp display panel: v1.0.0
esp32 aduino core: v3.1.3
Display: Waveshare ESP32S3-LCD-Touch-5B

`#include <Arduino.h>
#include <esp_display_panel.hpp>
#include <lvgl.h>
#include "lvgl_v8_port.h"
#include <ui.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>

using namespace esp_panel::drivers;
using namespace esp_panel::board;

// WiFi configuration
const char* ssid = "YOUR_WIFI_SSID"; // Replace with your WiFi SSID
const char* password = "YOUR_WIFI_PASSWORD"; // Replace with your WiFi password

// Home Assistant configuration
const char* ha_url = "https://homeassistant.local";
const char* ha_token = "YOUR_LONG_LIVED_TOKEN"; // Replace with your Home Assistant long-lived token

// Sensor IDs
const char* outdoor_humidity_id = "sensor.outdoor_outside_humidity";
const char* outdoor_temp_id = "sensor.outdoor_outside_temperature";
const char* indoor_temp_id = "sensor.sonoff_temperature_temperature";
const char* indoor_humidity_id = "sensor.sonoff_temperature_humidity";
const char* energy_consumption_id = "sensor.tapo_this_month_s_consumption";

// Update interval (10 minutes = 600000 milliseconds)
const unsigned long updateInterval = 600000;
unsigned long lastUpdateTime = 0;

// Function declarations
void connectWiFi();
void fetchHAData();
String getSensorValue(const char* sensorId);

void setup() {
String title = "LVGL porting example";

Serial.begin(115200);
Serial.println("Initializing board");

// Initialize board
Board *board = new Board();
board->init();

#if LVGL_PORT_AVOID_TEARING_MODE
auto lcd = board->getLCD();
// When avoid tearing function is enabled, the frame buffer number should be set in the board driver
lcd->configFrameBufferNumber(LVGL_PORT_DISP_BUFFER_NUM);

#if ESP_PANEL_DRIVERS_BUS_ENABLE_RGB && CONFIG_IDF_TARGET_ESP32S3
auto lcd_bus = lcd->getBus();
/**

  • As the anti-tearing feature typically consumes more PSRAM bandwidth, for the ESP32-S3, we need to utilize the
  • "bounce buffer" functionality to enhance the RGB data bandwidth.
  • This feature will consume bounce_buffer_size * bytes_per_pixel * 2 of SRAM memory.
    */
    if (lcd_bus->getBasicAttributes().type == ESP_PANEL_BUS_TYPE_RGB) {
    static_cast<BusRGB *>(lcd_bus)->configRGB_BounceBufferSize(lcd->getFrameWidth() * 10);
    }
    #endif
    #endif

assert(board->begin());

Serial.println("Initializing LVGL");
lvgl_port_init(board->getLCD(), board->getTouch());

Serial.println("Creating UI");
/* Lock the mutex due to the LVGL APIs are not thread-safe /
lvgl_port_lock(-1);
ui_init();
/
Release the mutex */
lvgl_port_unlock();

// PRIORITY 2: Connect to WiFi
connectWiFi();

// PRIORITY 3: First data fetch
if (WiFi.status() == WL_CONNECTED) {
fetchHAData();
}
}

void loop() {
// Handle display updates
lvgl_port_task_handler();

// Check WiFi connection
if (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi connection lost, reconnecting...");
connectWiFi();
}

// Check if it's time to update data from Home Assistant (every 10 minutes)
unsigned long currentTime = millis();
if (currentTime - lastUpdateTime >= updateInterval || lastUpdateTime == 0) {
if (WiFi.status() == WL_CONNECTED) {
fetchHAData();
lastUpdateTime = currentTime;
}
}

delay(10); // Small delay to prevent watchdog issues
}

// Connect to WiFi
void connectWiFi() {
Serial.println("Connecting to WiFi...");
WiFi.begin(ssid, password);

// Wait for connection with timeout
int timeout = 20; // 10 seconds timeout
while (WiFi.status() != WL_CONNECTED && timeout > 0) {
delay(500);
Serial.print(".");
timeout--;
}

if (WiFi.status() == WL_CONNECTED) {
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
} else {
Serial.println("");
Serial.println("WiFi connection failed");
}
}

// Fetch data from Home Assistant
void fetchHAData() {
Serial.println("Fetching data from Home Assistant...");

// Update UI with values from Home Assistant
lvgl_port_lock(-1);

// Get and set outdoor temperature
String outdoorTemp = getSensorValue(outdoor_temp_id);
if (outdoorTemp != "") {
lv_label_set_text(ui_outdoorTemp, outdoorTemp.c_str());
}

// Get and set outdoor humidity
String outdoorHumi = getSensorValue(outdoor_humidity_id);
if (outdoorHumi != "") {
lv_label_set_text(ui_outdoorHumi, outdoorHumi.c_str());
}

// Get and set indoor temperature
String indoorTemp = getSensorValue(indoor_temp_id);
if (indoorTemp != "") {
lv_label_set_text(ui_indoorTemp, indoorTemp.c_str());
}

// Get and set indoor humidity
String indoorHumi = getSensorValue(indoor_humidity_id);
if (indoorHumi != "") {
lv_label_set_text(ui_indoorHumi, indoorHumi.c_str());
}

// Get and set energy consumption
String energy = getSensorValue(energy_consumption_id);
if (energy != "") {
lv_label_set_text(ui_energyConsum, energy.c_str());
}

lvgl_port_unlock();

Serial.println("Home Assistant data updated");
}

// Helper function to get sensor value from Home Assistant
String getSensorValue(const char* sensorId) {
String value = "";
HTTPClient http;

// Construct the API URL
String url = String(ha_url) + "/api/states/" + String(sensorId);

// Begin HTTP request
http.begin(url);

// Add authorization header
http.addHeader("Authorization", "Bearer " + String(ha_token));
http.addHeader("Content-Type", "application/json");

// Send GET request
int httpCode = http.GET();

if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();

// Parse JSON response
DynamicJsonDocument doc(1024);
DeserializationError error = deserializeJson(doc, payload);

if (!error) {
  value = doc["state"].as<String>();
  
  // Include unit of measurement if available
  if (doc.containsKey("attributes") && doc["attributes"].containsKey("unit_of_measurement")) {
    value += " " + doc["attributes"]["unit_of_measurement"].as<String>();
  }
} else {
  Serial.print("JSON parsing failed: ");
  Serial.println(error.c_str());
}

} else {
Serial.print("HTTP GET failed, error: ");
Serial.println(httpCode);
}

http.end();
return value;
}`

@Lzw655
Copy link
Collaborator

Lzw655 commented Apr 30, 2025

Hi @razarahil,

Could you provide the complete error logs?

@alexhowarth
Copy link

alexhowarth commented May 9, 2025

@Lzw655 This happens for me as well with the squareline_port example.

It works until I add the following minimal code to the example:

#include "WiFi.h"

...

	/* Release the mutex */
	lvgl_port_unlock();

	// Set WiFi to station mode and disconnect from an AP if it was previously connected.
	WiFi.mode(WIFI_STA);
	WiFi.disconnect();
	delay(100);
}

lvgl v8.4.0
esp display panel: v1.0.2

Supported hardware Waveshare ESP32-S3-Touch-LCD-7 and configured in Arduino IDE as per the configured as per Recommended Configurations.

[I][Panel][esp_lcd_touch_gt911.c:0401](touch_gt911_read_cfg): TouchPad_ID:0x39,0x31,0x31
[I][Panel][esp_lcd_touch_gt911.c:0402](touch_gt911_read_cfg): TouchPad_Config_Version:88
[I][LvPort][esp_panel_board.cpp:0463](begin): Board begin success
Initializing LVGL
[I][LvPort][lvgl_v8_port.cpp:0761](lvgl_port_init): Initializing LVGL display driver
Creating UI
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x8 (TG1WDT_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x40379b50
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce2820,len:0x118c
load:0x403c8700,len:0x4
load:0x403c8704,len:0xc20
load:0x403cb700,len:0x30e0
entry 0x403c88b8
Initializing board
[I][LvPort][esp_panel_board.cpp:0066](init): Initializing board (Waveshare:ESP32_S3_TOUCH_LCD_7)
[I][LvPort][esp_panel_board.cpp:0235](init): Board initialize success
[I][LvPort][esp_panel_board.cpp:0253](begin): Beginning board (Waveshare:ESP32_S3_TOUCH_LCD_7)
[I][Expander][esp_io_expander_ch422g.c:0075](esp_io_expander_new_i2c_ch422g): version: 0.1.0
[I][Panel][esp_lcd_touch_gt911.c:0067](esp_lcd_touch_new_i2c_gt911): version: 1.1.1
[W][Panel][esp_lcd_touch_gt911.c:0144](esp_lcd_touch_new_i2c_gt911): Unable to initialize the I2C address
[I][Panel][esp_lcd_touch_gt911.c:0401](touch_gt911_read_cfg): TouchPad_ID:0x39,0x31,0x31
[I][Panel][esp_lcd_touch_gt911.c:0402](touch_gt911_read_cfg): TouchPad_Config_Version:88
[I][LvPort][esp_panel_board.cpp:0463](begin): Board begin success
Initializing LVGL
[I][LvPort][lvgl_v8_port.cpp:0761](lvgl_port_init): Initializing LVGL display driver
Creating UI
Guru Meditation Error: Core  1 panic'ed (Cache disabled but cached memory region accessed). 


Core  1 register dump:
PC      : 0x40056f64  PS      : 0x00060034  A0      : 0x803791a9  A1      : 0x3fc9ade0  
A2      : 0x3fcb0fac  A3      : 0x3c201560  A4      : 0x00003e80  A5      : 0x3fcb0fac  
A6      : 0xbad00bad  A7      : 0xbad00bad  A8      : 0x00000000  A9      : 0x3fca8a10  
A10     : 0x01ffffff  A11     : 0x3fcac63f  A12     : 0x3fcac630  A13     : 0x3fcac600  
A14     : 0x3fc99ac4  A15     : 0x3fcac63f  SAR     : 0x00000004  EXCCAUSE: 0x00000007  
EXCVADDR: 0x00000000  LBEG    : 0x40056f5c  LEND    : 0x40056f72  LCOUNT  : 0x000003e7  


Backtrace: 0x40056f61:0x3fc9ade0 0x403791a6:0x3fc9adf0 0x40379353:0x3fc9ae10 0x4037b746:0x3fc9ae30 0x403797e5:0x3fc9ae60 0x40383627:0x3fcac560 0x40385949:0x3fcac5a0 0x4038658b:0x3fcac5e0 0x403861e5:0x3fcac600 0x4038656e:0x3fcac630 0x4038602e:0x3fcac660 0x403760a4:0x3fcac6e0 0x42038825:0x3fcac730 0x4204577d:0x3fcac750 0x42045da9:0x3fcac770 0x420460b9:0x3fcac790 0x42044e46:0x3fcac810 0x4204532a:0x3fcac880 0x42045865:0x3fcac8c0 0x42043eff:0x3fcac900 0x42043f7b:0x3fcac930 0x420b00f2:0x3fcac950 0x420b0169:0x3fcac970 0x4209c8a6:0x3fcac990 0x4209cca4:0x3fcac9b0 0x42071488:0x3fcac9d0 0x42032e4b:0x3fcaca00 0x42032f30:0x3fcacb80 0x42003475:0x3fcacc70 0x42036717:0x3fcacca0 0x4037f386:0x3fcaccc0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants