v.0.2.3 ColorSerial, more usage
This commit is contained in:
@@ -452,3 +452,10 @@ void ColorSerial::weatherCondition(int code, const char *customLabel)
|
|||||||
Serial.print(RESET);
|
Serial.print(RESET);
|
||||||
Serial.println();
|
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_DOUBLE_VERT;
|
||||||
static const char *BOX_SINGLE_VERT;
|
static const char *BOX_SINGLE_VERT;
|
||||||
|
|
||||||
|
static void clearScreen();
|
||||||
|
|
||||||
// Main Logging Methods
|
// Main Logging Methods
|
||||||
static void success(const char *message, const char *details = "");
|
static void success(const char *message, const char *details = "");
|
||||||
static void error(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;
|
const u_int8_t font_height = 16;
|
||||||
#endif
|
#endif
|
||||||
const auto *fontData = fontData_.data();
|
const auto *fontData = fontData_.data();
|
||||||
Serial.print("<");
|
String msg = "<" + String(c) + ">";
|
||||||
Serial.print(c);
|
ColorSerial::debug(msg.c_str());
|
||||||
Serial.println(">");
|
|
||||||
|
|
||||||
String mtrx = "";
|
String mtrx = "";
|
||||||
for (int row = 0; row < font_height; row++)
|
for (int row = 0; row < font_height; row++)
|
||||||
@@ -107,9 +106,7 @@ void connect_wifi()
|
|||||||
delay(250);
|
delay(250);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
}
|
}
|
||||||
Serial.println("\nConnected to WiFi!");
|
ColorSerial::wifiStatus();
|
||||||
Serial.print("IP address: ");
|
|
||||||
Serial.println(WiFi.localIP());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void json_with_WiFiClient()
|
void json_with_WiFiClient()
|
||||||
@@ -121,7 +118,7 @@ void json_with_WiFiClient()
|
|||||||
|
|
||||||
if (client.connect("api.open-meteo.com", 80))
|
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("GET /v1/forecast?latitude=52.52&longitude=13.41¤t_weather=true HTTP/1.1");
|
||||||
client.println("Host: api.open-meteo.com");
|
client.println("Host: api.open-meteo.com");
|
||||||
@@ -208,12 +205,13 @@ void json_with_HTTPClient()
|
|||||||
|
|
||||||
if (httpCode != HTTP_CODE_OK)
|
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();
|
http.end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorSerial::info("connected to api.open-meteo.com :-)");
|
ColorSerial::info("connected to api.open-meteo.com");
|
||||||
ColorSerial::info("=== Full Response Complete ===");
|
ColorSerial::info("=== Full Response Complete ===");
|
||||||
|
|
||||||
String payload = http.getString();
|
String payload = http.getString();
|
||||||
@@ -233,18 +231,20 @@ void json_with_HTTPClient()
|
|||||||
float temperature = current["temperature"];
|
float temperature = current["temperature"];
|
||||||
String temp_unit = units["temperature"];
|
String temp_unit = units["temperature"];
|
||||||
|
|
||||||
|
uint8_t weathercode = current["weathercode"];
|
||||||
|
|
||||||
ColorSerial::temperature(temperature, temp_unit.c_str());
|
ColorSerial::temperature(temperature, temp_unit.c_str());
|
||||||
|
|
||||||
String temp_msg = "Temperature: " + String(temperature, 1) + temp_unit.c_str();
|
String temp_msg = "Temperature: " + String(temperature, 1) + temp_unit.c_str();
|
||||||
|
|
||||||
ColorSerial::info(temp_msg.c_str(), "Anzeige Temperatur Wert");
|
ColorSerial::info(temp_msg.c_str(), "Anzeige Temperatur Wert");
|
||||||
Serial.printf("Temperature: %.1f %s", temperature, temp_unit.c_str());
|
ColorSerial::weatherCondition(weathercode);
|
||||||
Serial.println();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("JSON parse failed");
|
String errCode = error.c_str();
|
||||||
Serial.println(error.c_str());
|
String errMsg = "JSON parse failed: " + errCode;
|
||||||
|
ColorSerial::error(errMsg.c_str());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -259,20 +259,17 @@ void setup()
|
|||||||
while (!Serial)
|
while (!Serial)
|
||||||
delay(10);
|
delay(10);
|
||||||
|
|
||||||
ColorSerial::header("PICO W WEATHER STATION");
|
ColorSerial::clearScreen();
|
||||||
ColorSerial::boxHeader("PICO W WEATHER STATION");
|
ColorSerial::boxHeader("PICO W WEATHER STATION");
|
||||||
ColorSerial::info("System starting up", "v1.0");
|
ColorSerial::info("System starting up", "v1.0");
|
||||||
|
|
||||||
connect_wifi();
|
connect_wifi();
|
||||||
|
|
||||||
if (WiFi.status() == WL_CONNECTED)
|
if (WiFi.status() == WL_CONNECTED)
|
||||||
{
|
{
|
||||||
// json_with_WiFiClient();
|
// json_with_WiFiClient();
|
||||||
json_with_HTTPClient();
|
json_with_HTTPClient();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
ColorSerial::warning("WiFi NOT connected.");
|
|
||||||
}
|
|
||||||
|
|
||||||
setupMatrix();
|
setupMatrix();
|
||||||
// printCharMatrixSimple('@');
|
// printCharMatrixSimple('@');
|
||||||
|
|||||||
Reference in New Issue
Block a user