From dce7117267b96e30ef666d308fdbe9c8f31f567d Mon Sep 17 00:00:00 2001 From: tiijay Date: Sun, 9 Nov 2025 19:57:01 +0100 Subject: [PATCH] v.0.2.3 ColorSerial, more usage --- lib/Utils/src/ColorSerial.cpp | 9 ++++++++- lib/Utils/src/ColorSerial.h | 2 ++ src/main.cpp | 33 +++++++++++++++------------------ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/Utils/src/ColorSerial.cpp b/lib/Utils/src/ColorSerial.cpp index fa79209..bf67592 100644 --- a/lib/Utils/src/ColorSerial.cpp +++ b/lib/Utils/src/ColorSerial.cpp @@ -451,4 +451,11 @@ void ColorSerial::weatherCondition(int code, const char *customLabel) Serial.print(condition); Serial.print(RESET); Serial.println(); -} \ No newline at end of file +} + +// Terminal Control Methods +void ColorSerial::clearScreen() +{ + Serial.print("\033[2J"); // Clear entire screen + Serial.print("\033[H"); // Move cursor to home position (0,0) +} diff --git a/lib/Utils/src/ColorSerial.h b/lib/Utils/src/ColorSerial.h index 2dbce54..9ed5308 100644 --- a/lib/Utils/src/ColorSerial.h +++ b/lib/Utils/src/ColorSerial.h @@ -44,6 +44,8 @@ public: static const char *BOX_DOUBLE_VERT; static const char *BOX_SINGLE_VERT; + static void clearScreen(); + // Main Logging Methods static void success(const char *message, const char *details = ""); static void error(const char *message, const char *details = ""); diff --git a/src/main.cpp b/src/main.cpp index 77aa70b..892be63 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,9 +34,8 @@ void printCharMatrixSimple(char c) const u_int8_t font_height = 16; #endif const auto *fontData = fontData_.data(); - Serial.print("<"); - Serial.print(c); - Serial.println(">"); + String msg = "<" + String(c) + ">"; + ColorSerial::debug(msg.c_str()); String mtrx = ""; for (int row = 0; row < font_height; row++) @@ -107,9 +106,7 @@ void connect_wifi() delay(250); Serial.print("."); } - Serial.println("\nConnected to WiFi!"); - Serial.print("IP address: "); - Serial.println(WiFi.localIP()); + ColorSerial::wifiStatus(); } void json_with_WiFiClient() @@ -121,7 +118,7 @@ void json_with_WiFiClient() if (client.connect("api.open-meteo.com", 80)) { - Serial.println("connected to api.open-meteo.com :-)"); + Serial.println("connected to api.open-meteo.com"); client.println("GET /v1/forecast?latitude=52.52&longitude=13.41¤t_weather=true HTTP/1.1"); client.println("Host: api.open-meteo.com"); @@ -208,12 +205,13 @@ void json_with_HTTPClient() if (httpCode != HTTP_CODE_OK) { - Serial.printf("HTTP error: %d\n", httpCode); + String errMsg = "HTTP error: GET request failed (httpCode:" + String(httpCode + ")"); + ColorSerial::error(errMsg.c_str()); http.end(); return; } - ColorSerial::info("connected to api.open-meteo.com :-)"); + ColorSerial::info("connected to api.open-meteo.com"); ColorSerial::info("=== Full Response Complete ==="); String payload = http.getString(); @@ -233,18 +231,20 @@ void json_with_HTTPClient() float temperature = current["temperature"]; String temp_unit = units["temperature"]; + uint8_t weathercode = current["weathercode"]; + ColorSerial::temperature(temperature, temp_unit.c_str()); String temp_msg = "Temperature: " + String(temperature, 1) + temp_unit.c_str(); ColorSerial::info(temp_msg.c_str(), "Anzeige Temperatur Wert"); - Serial.printf("Temperature: %.1f %s", temperature, temp_unit.c_str()); - Serial.println(); + ColorSerial::weatherCondition(weathercode); } else { - Serial.println("JSON parse failed"); - Serial.println(error.c_str()); + String errCode = error.c_str(); + String errMsg = "JSON parse failed: " + errCode; + ColorSerial::error(errMsg.c_str()); return; } @@ -259,20 +259,17 @@ void setup() while (!Serial) delay(10); - ColorSerial::header("PICO W WEATHER STATION"); + ColorSerial::clearScreen(); ColorSerial::boxHeader("PICO W WEATHER STATION"); ColorSerial::info("System starting up", "v1.0"); connect_wifi(); + if (WiFi.status() == WL_CONNECTED) { // json_with_WiFiClient(); json_with_HTTPClient(); } - else - { - ColorSerial::warning("WiFi NOT connected."); - } setupMatrix(); // printCharMatrixSimple('@');