I using this code:
#include <ESP8266WiFi.h>
const char* ssid = "Signalizacija";
const char* password = "20170214";
const char* host = "ortex.lt";
String line;
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println(" connected");
}
void loop()
{
WiFiClient client;
Serial.printf("\n[Connecting to %s ... ", host);
if (client.connect(host, 80))
{
Serial.println("connected]");
Serial.println("[Sending a request]");
String url = "/testas.php";
client.print(String("GET /") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n" +
"\r\n"
);
Serial.println("[Response:]");
while (client.connected())
{
line = client.readStringUntil('\r');
Serial.print(line);
}
client.stop();
Serial.println("\n[Disconnected]");
}
else
{
Serial.println("connection failed!]");
client.stop();
}
delay(5000);
}
I got this information (attached picture), but I want to read only word which I underline red color "saule". How need separate this word from total html code? Could somebody give to my advice how to do it?
system
June 26, 2018, 12:51pm
2
attached picture
Why the f**k would you post a picture of TEXT? Post the damned text, so that it can be read!
It appears that you want the text between the and tags.
One of the Strings that you read contains "" (or some part of it). One of the Strings you read contains "" (or some part of it).
You should create ONE String containing ALL that you read, and then find the indexOf() the "" tag and the indexOf() the "" tag, and create a substring() of the part between the tags.
Juraj
June 26, 2018, 12:58pm
3
use client.find(""), client.readBytesUntil("", buff, sizeof(buff)) and take the content of buff from sizeof("") position.
this are functions of class Stream from which WiFiClient is derived
Juraj:
use client.find(""), client.readBytesUntil("", buff, sizeof(buff)) and take the content of buff from sizeof("") position.
this are functions of class Stream from which WiFiClient is derived
You have in mind this code
char* buff[8];
while (client.connected())
{
client.find("");
client.readBytesUntil("", buff, sizeof(buff));
}
Serial.println(buff);
Juraj
June 26, 2018, 1:53pm
6
yes, but I am not sure on the stream position after find or readUntil, if it will add or to buff. I hope not.
system
June 26, 2018, 2:00pm
7
Juraj:
yes
I hope not. An array of 8 pointers to char is NOT what client.readBytesUntil() is expecting.
Juraj
June 26, 2018, 2:01pm
8
PaulS:
I hope not. An array of 8 pointers to char is NOT what client.readBytesUntil() is expecting.
ups, I overlooked the *, thank you
@pcwortex , char buff[8], the function takes a pointer to char but C array type is pointer
Juraj:
ups, I overlooked the *
@pcwortex , char buff[8], the function takes a pointer to char but C array type is pointer
I got error and don't know how solve it
C:\Users\sarunas\Documents\Arduino\readserver\readserver.ino: In function 'void loop()':
readserver:50: error: no matching function for call to 'WiFiClient::readBytesUntil(const char [8], char* [8], unsigned int)'
client.readBytesUntil("", buff, sizeof(buff));
Juraj
June 26, 2018, 2:14pm
10
pcwortex:
I got error and don't know how solve it
C:\Users\sarunas\Documents\Arduino\readserver\readserver.ino: In function 'void loop()':
readserver:50: error: no matching function for call to 'WiFiClient::readBytesUntil(const char [8], char* [8], unsigned int)'
client.readBytesUntil("", buff, sizeof(buff));
change char * buff[8] to char buff[8]
Juraj:
change char * buff[8] to char buff[8]
I change, but have same problem before it
exit status 1
invalid conversion from 'const char*' to 'char' [-fpermissive]
I don't know what is wrong. Somebody can to give me suggest how solve this problem?
Juraj
June 27, 2018, 1:07pm
12
I am sorry. The readBytesUntil can find only one character. Use readBytesUntil('<', buff, sizeof(buff));