diff --git a/firmware/esp32-s3-dashboard/esp32-s3-dashboard.ino b/firmware/esp32-s3-dashboard/esp32-s3-dashboard.ino index 319d81e..503ff43 100644 --- a/firmware/esp32-s3-dashboard/esp32-s3-dashboard.ino +++ b/firmware/esp32-s3-dashboard/esp32-s3-dashboard.ino @@ -134,12 +134,22 @@ static void parse_status_json(const String &body) if (error) { status_model.api_ok = false; status_model.http_code = 200; - status_model.temps_text = "JSON parse failed"; - status_model.outputs_text = error.c_str(); - update_overview_widgets(); + + String parse_error; + parse_error += "JSON parse failed\n"; + parse_error += error.c_str(); + + Serial.println(parse_error); + + set_label_text_if_changed(battery_label, last_battery_text, "Battery\nJSON parse failed"); + set_label_text_if_changed(temps_label, last_temps_text, parse_error); + set_label_text_if_changed(outputs_label, last_outputs_text, "Outputs\nNo parsed data"); + set_label_text_if_changed(system_label, last_system_text, parse_error); return; } + Serial.println("JSON parse OK"); + status_model.api_ok = true; status_model.http_code = 200; @@ -308,6 +318,7 @@ static void update_wifi_label() static void poll_status_api() { if (WiFi.status() != WL_CONNECTED) { + set_label_text_if_changed(system_label, last_system_text, "API: waiting for WiFi"); return; } @@ -317,18 +328,38 @@ static void poll_status_api() last_status_poll_ms = millis(); + String requesting; + requesting += "API: requesting\n"; + requesting += "/api/v1/status\n"; + requesting += "Dashboard IP:\n"; + requesting += WiFi.localIP().toString(); + set_label_text_if_changed(system_label, last_system_text, requesting); + Serial.print("GET "); Serial.println(CARGO_API_STATUS_URL); HTTPClient http; + http.setTimeout(5000); http.begin(CARGO_API_STATUS_URL); int code = http.GET(); status_model.http_code = code; + Serial.print("HTTP code: "); + Serial.println(code); + if (code == 200) { String body = http.getString(); - Serial.println("HTTP 200"); + + Serial.print("Body length: "); + Serial.println(body.length()); + Serial.println(body); + + String received; + received += "API: received\nHTTP: 200\nBytes: "; + received += String(body.length()); + set_label_text_if_changed(system_label, last_system_text, received); + parse_status_json(body); } else { status_model.api_ok = false; @@ -341,6 +372,7 @@ static void poll_status_api() system += http.errorToString(code); } + Serial.println(system); set_label_text_if_changed(system_label, last_system_text, system); } @@ -405,6 +437,10 @@ static void create_overland_status_screen() temps_label = create_body_label(temps_card); outputs_label = create_body_label(outputs_card); + lv_label_set_text(battery_label, "Waiting for battery data..."); + lv_label_set_text(temps_label, "Waiting for temp data..."); + lv_label_set_text(outputs_label, "Waiting for output data..."); + wifi_label = create_body_label(system_card); system_label = lv_label_create(system_card);