1
  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}
2
  • 1
    Simple, 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
    May 5 '20 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 Germany Sep 14 at 17:28
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.