void toSerial(int delay_ms)
{
delay(delay_ms);
while(mySerial.available())
{
Serial.write(mySerial.read());
}
}
Serial.begin(9600);
mySerial.begin(9600);
mySerial.println("AT+HTTPINIT");
toSerial(500);
mySerial.println("AT+HTTPPARA=\"CID\", 1");
toSerial(500);
mySerial.println("AT+HTTPPARA=\"URL\", \"www.example.test\"");
toSerial(500);
mySerial.println("AT+HTTPPARA=\"CONTENT\", \"application/json\"");
toSerial(500);
mySerial.println("AT+HTTPACTION=0");
toSerial(4000);
mySerial.println("AT+HTTPREAD");
delay(3000);
while(mySerial.available())
{
Serial.write(mySerial.read());
}
Serial.println("");
mySerial.println("AT+HTTPTERM");
toSerial(500);
Result:
AT+HTTPREAD
+HTTPREAD:39
{"pinRed":0,"pinGreen":1,"pinYello
I expect messages:
{"pinRed":0,"pinGreen":1,"pinYellow":0}
-
1Simple, reading serial data is way faster than it comes in. So you read everything out of the buffer and cleared it so that available returned zero before everything got there. You can check that available gives you a large enough number so that you know the whole message is there before you start reading or you can parse your message to see if it is all there before you move on. Had you come back later and read some more on the next loop you would have seen ":0} before the next message. It just got there after you stopped reading.Delta_G– Delta_G2020年05月05日 00:09:05 +00:00Commented May 5, 2020 at 0:09
-
hey how did you finally make it? could you post the final code? I've been despairing of the detail for days. I would be very grateful! Greetings from GermanySeverin Baumgartner– Severin Baumgartner2021年09月14日 17:28:04 +00:00Commented Sep 14, 2021 at 17:28
1 Answer 1
Okay, I've found a solution. To start with, you need to download the server response length and loop according to the response length.