v.0.2.3 ColorSerial, more usage
This commit is contained in:
@@ -451,4 +451,11 @@ void ColorSerial::weatherCondition(int code, const char *customLabel)
|
||||
Serial.print(condition);
|
||||
Serial.print(RESET);
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
// Terminal Control Methods
|
||||
void ColorSerial::clearScreen()
|
||||
{
|
||||
Serial.print("\033[2J"); // Clear entire screen
|
||||
Serial.print("\033[H"); // Move cursor to home position (0,0)
|
||||
}
|
||||
|
||||
@@ -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 = "");
|
||||
|
||||
33
src/main.cpp
33
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('@');
|
||||
|
||||
Reference in New Issue
Block a user