Wenn ich auf dem ESP8266 den Seriellen Monitor öffne kommt nur so ein wir war Text: ⸮⸮⸮⸮Qz9⸮⸮⸮{m⸮5⸮z⸮T⸮k⸮⸮⸮3{-5⸮⸮⸮͎⸮⸮⸮H. Woran kann das liegen ?
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
// Set up GPIO pin
const int pump_pin = 8;
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Set pump_pin as output
pinMode(pump_pin, OUTPUT);
}
// Define function to start or stop the pump
void control_pump(bool on) {
if (on) {
Serial.println("Startet die Bewässerung...");
digitalWrite(pump_pin, HIGH);
delay(420000); // in milliseconds
digitalWrite(pump_pin, LOW);
Serial.println("Bewässerung fertig");
}
else {
digitalWrite(pump_pin, LOW);
Serial.println("Pumpe gestoppt");
}
}
// Define function to continuously check weather and pump status
void auto_mode() {
// Define start times for pump operation
String start_times[] = {"06:00", "20:00"};
int num_start_times = sizeof(start_times)/sizeof(start_times[0]);
while (true) {
// Get current time
WiFiClient client;
HTTPClient http;
http.begin(client, "http://worldtimeapi.org/api/timezone/Europe/Berlin");
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
int time_index = payload.indexOf("datetime\":\"") + 12;
String current_time = payload.substring(time_index, time_index + 5); // Extract hour and minute
Serial.print("Aktuelle Zeit: ");
Serial.println(current_time);
// Check if it's time to start pump
for (int i = 0; i < num_start_times; i++) {
if (current_time == start_times[i]) {
// Make API request to get weather data
String api_key = ":)";
String city = ":)";
String postal_code = ":)";
String url = "http://api.weatherapi.com/v1/current.json?key=" + api_key + "&q=" + city + "&postal_code=" + postal_code;
http.begin(client, url);
httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
DynamicJsonDocument doc(1024);
DeserializationError error = deserializeJson(doc, payload);
if (error) {
Serial.print("Fehler beim Analysieren des Wetter-API-Antwort: ");
Serial.println(error.c_str());
return;
}
const char* weatherCondition = doc["current"]["condition"]["text"];
Serial.print("Wetterbedingungen: ");
Serial.println(weatherCondition);
// Check if it's raining
if (strstr(weatherCondition, "rain") != NULL) {
Serial.print("Es regnet, die Pumpe bleibt bis zur nächsten Uhrzeit aus.");
} else {
// Turn on pump for 7 minutes
control_pump(true);
delay(420000);
control_pump(false);
}
// End HTTP connection
http.end();
} else {
Serial.println("Fehler beim Verbinden mit dem Wetter-API-Server");
}
delay(60000); // Wait 1 minute before checking again
}
}
}
}
}
void loop() {
auto_mode();
}