Dear users,
I am new in this board and also new on coding using arduino.
I have a problem with reading out some data via http.
#include <WiFi.h>
#include <Arduino.h>
#include <WiFiClient.h>
#include <ESPmDNS.h>
#include <stdio.h>
#include <string.h>
#include <HTTPClient.h>
#define USE_SERIAL Serial
const char* ssid = "SSID";
const char* password = "WLAN-PW";
const char* ip_readout = "data.sparkfun.com";
void setup()
{
Serial.begin(115200);
delay(10);
//my_sensor.begin();
// 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());
}
int value = 0;
void loop()
{
char* pos;
char* httpcode[1024];
char delimiter[] = "/n";
char *ptr;
char array[32];
if (WiFi.status() != WL_CONNECTED) ESP.restart();
HTTPClient http;
USE_SERIAL.print("[HTTP] begin...\n");
http.begin("http://192.168.10.85/files/esp32_readout.html");
USE_SERIAL.print("[HTTP] GET...\n");
int httpCode = http.GET();
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
payload.toCharArray(array, sizeof(array));
USE_SERIAL.print("Begin:");
//USE_SERIAL.println(array);
USE_SERIAL.print("Testausgabe\n");
USE_SERIAL.print(payload);
USE_SERIAL.print("Testausgabe\n");
}
http.end();
}
delay(2000); //allow the cpu to switch to other tasks
}
The output of the serial monitor gives:
17:23:52.267 -> [HTTP] begin...
17:23:52.267 -> [HTTP] GET...
17:23:52.267 -> [HTTP] GET... code: 200
17:23:52.267 -> Begin:Testausgabe
17:23:52.267 -> <!doctype html>
17:23:52.267 -> <html>
17:23:52.267 -> <body>
17:23:52.267 -> <p>HKV EG 01 0</p>
17:23:52.267 -> <p>HKV EG 02 0</p>
17:23:52.267 -> <p>HKV EG 03 0</p>
17:23:52.267 -> <p>HKV EG 04 0</p>
17:23:52.267 -> <p>HKV EG 05 0</p>
17:23:52.267 -> <p>HKV EG 06 0</p>
17:23:52.267 -> <p>HKV OG 01 0</p>
17:23:52.267 -> <p>HKV OG 02 0</p>
17:23:52.267 -> <p>HKV OG 03 0</p>
17:23:52.267 -> <p>HKV OG 04 0</p>
17:23:52.267 -> <p>HKV OG 05 0</p>
17:23:52.267 -> <p>HKV OG 06 0</p>
17:23:52.313 -> <p>HKV OG 07 0</p>
17:23:52.313 -> <p>HKV OG 08 0</p>
17:23:52.313 -> <p>HKV UG 01 0</p>
17:23:52.313 -> <p>HKV UG 02 0</p>
17:23:52.313 -> <p>HKV UG 03 0</p>
17:23:52.313 -> <p>HKV UG 04 0</p>
17:23:52.313 -> <p>HKV UG 05 0</p>
17:23:52.313 -> </body>
17:23:52.313 -> </html>
17:23:52.313 -> Testausgabe
Now i would like to cut oout the state of the different lines. The last 0 says if the relay is closed or opened. Can anyone give me an example how to cut this out?
Thank you very much for your help!
Greetings
Peter