Hallo,
ich würde gerne mit kleinstmöglichem Aufwand einen Staubsauger durch den S20 Tasmota einschalten wenn ein analoger Pin HIGH am ESP detektiert wird. Dazu müsste ich jetzt erstmal den Code der vom S20 zurückkommt parsen. Im Browser ist das ganz einfach und funktioniert wunderbar mit
Zurück kommt ein "{"POWER":"ON"}". Perfekt soweit.
Ich habe dazu Code geschrieben/verändert. Der loggt sich erstmal sauber ins WLAN. Ich kann auch mit entsprechender URL die Steckdose ein und ausschalten...nur halt leider nicht den Status lesen...
Code
#include <ESP8266WiFi.h>
const char* ssid = "*****";
const char* password = "*****";
const char* host = "192.168.0.102";
void setup() {
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
}
void loop() {
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url = "/cm?cmnd=Power";
Serial.println("-------------------------------------------------------");
Serial.print("Requesting URL: ");
Serial.print(host);
Serial.println(url);
// This will send the request to the server
Serial.println("Send request");
client.print(String("Get: ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
// start waiting for the response
unsigned long lasttime = millis();
while (!client.available() && millis() - lasttime < 3000) {
delay(1); // wait max 1s for data
}
// Read all the lines of the reply from server and print them to Serial
while (client.available()) {
char readchar = client.read();
Serial.print(readchar);
}
Serial.println("closing connection");
delay(5000);
}
Alles anzeigen
Die Meldung die ich dann zurückbekomme ist
HTTP
-------------------------------------------------------
Requesting URL: 192.168.0.102/cm?cmnd=Power
Send request
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: -1
Accept-Ranges: none
Transfer-Encoding: chunked
Connection: close
******Hier sollte eigentlich der Status stehen...****
closing connection
Alles anzeigen
Hat hier jemand eine Idee? Bin mir nicht sicher ob dass das richtige Forum ist...bei Arduino wäre ich sicherlich auch nur halb richtig...