hi everyone,
I'm new with the Arduino. I want to extract a JSON outof a response of a SQL server. I use EthernetClient.readString() to read the received data from the buffer. But it seems to lost the end part of the data. I also tried cleint.readString('\0') and set a larger timeout. It still doesn't work.
The fully response that should be contained in String c is:
HTTP/1.1 200 OK
Server: Apache
Vary: Accept-Encoding,User-Agent
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
(some debug information, like username and posted data are listed here)
??MYSQL??[{"varname":"n","dimRows":"1","dimCols":"1","unit":"1","data":"INT","value":"10"}]
0
disconnecting,
but instead it prints:
HTTP/1.1 200 OK
Server: Apache
Vary: Accept-Encoding,User-Agent
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
(some debug information, like username and posted data are listed here)
??MYSQL??[{"varname":"n","dimRows":"1","dimCols":"1","unit":"
disconnecting,
The end part is missing. I can only get the full response by using client.read() function. but it returns no String, and can't be parsed with the String member function.
I'm really appreciated if there's someone helps me out.
This is my code:
#include<SPI.h>
#include<Ethernet.h>
#include<ArduinoJson.h>
#define buffersize 2000
byte mac[]={ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[]=SSID;
IPAddress ip(xxx, xxx, x, xxx);
// DATA
String GetINT="user=user1&pass=123&variabletyp=int&variable2=2";
EthernetClient client;
bool post(String data)
{
if(client.connect(server,80))
{
Serial.println("connected");
client.println("POST /server.php HTTP/1.1");
client.println("Host: SSID");
client.println("User-Agent: Arduino/1.0");
client.println("Connection: colse");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.println(data); // Post login data
client.println();
delay(200);
}
else{Serial.println("connected failed");}
}
void setup()
{
Serial.begin(115200);
while(!Serial){}
if(Ethernet.begin(mac)==0)
{Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac,ip);}
delay(1000);
Serial.println("connecting...");
client.setTimeout(5000);
post(GetINT);
}
void loop()
{ String s;
if(client.available())
{ String c=client.readStringUntil('\0');
Serial.print(c);
s=c.indexOf("??**");
Serial.print(s);
}
if(!client.connected())
{
Serial.println();
Serial.println("disconnecting,");
client.stop();
while(true);
}
}