content values of http request

Hi.

I'm struggling to read all the content values of the webpage "http://www.equipgest.net/" using http request in a arduino uno with a SIM800C keystudio shield. Wathever i do it only shows the folowing values: 1000,1,2000,1,3000,1,4000,1,5000,1

What shoud i do to see all the data in serial monitor? thanks in advance

#include <SoftwareSerial.h>

SoftwareSerial SIM900(7, 8); // configure software serial port




void setup() {

  SIM900.begin(19200);
  Serial.begin(19200);
  Serial.print("power up" );
  SubmitHttpRequest();

}



void loop()
{
}




void SubmitHttpRequest()
{


  SIM900.println("AT");
  delay(1000);
  ShowSerialData();

  
  SIM900.println("AT+CGATT=1"); //Attach or Detach from GPRS Support
  delay(100);
  ShowSerialData();

  
  SIM900.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
  delay(1000);
  ShowSerialData();


  SIM900.println("AT+SAPBR=3,1,\"APN\",\"myconnection\"");//setting the APN, Access point name string
  delay(4000);
  ShowSerialData();


  SIM900.println("AT+SAPBR=1,1");//setting the SAPBR
  delay(2000);
  ShowSerialData();


  SIM900.println("AT+HTTPINIT"); //init the HTTP request
  delay(2000);
  ShowSerialData();




  SIM900.println("AT+HTTPPARA=\"URL\",\"http://www.equipgest.net\"");// setting the httppara, the second parameter is the website you want to access
  delay(1000);

  ShowSerialData();

  SIM900.println("AT+HTTPACTION=0");//submit the request
  delay(10000);
  ShowSerialData();

  
  SIM900.println("AT+HTTPREAD");// read the data from the website you access
  delay(5000);
  SIM900.println("");
  delay(100);


  SIM900.println("AT+HTTPTERM");  /* Terminate HTTP service */
  delay(3000);
  ShowSerialData();
  delay(5000);
}


void ShowSerialData()
{
  while (SIM900.available() != 0)
    Serial.write(char (SIM900.read()));
}


void TurnOnSIM() {
  digitalWrite(9, HIGH);
  delay(2000);
  digitalWrite(9, LOW);
}

your problem is that your code to read what happened is expecting to find all the answer in the buffer

 void ShowSerialData ()
{
  while (SIM900.available ()! = 0)
  Serial.write (char (SIM900.read ()));
}

This while() loop runs quick and you are going to empty the communication buffer faster than data gets in and you do not know if there is still data coming in.

so in a nutshell, you try to second guess the necessary waiting time with delay () but for an asynchronous protocol, involving in addition here the time of access to the Internet, it is a little pointless ... you'll never get it right.

  • an intermediate solution would be to listen until a time out has arrived
  • a better solution would be to know what marks the end of the "response" communication and to wait for this mark (or a timeout to avoid getting stuck waiting)

I would suggest to study Serial Input Basics to get some ideas on how to handle this

Interesting
curl http://www.equipgest.net/ returns just this data no http header info
1000,1,2000,1,3000,1,4000,1,5000,1,6000,1

so this will collect all the data, in an Arduino String

String data;

bool CollectData () {
  while (SIM900.available() != 0)
      char c = SIM900.read();
      if (c == '\n') {
         return true;
      } // else
      data += c;
      return false;
}

void loop() {
   if (CollectData()) {
      Serial.println(data); 
      // parse your data here
      data = ""; // clear for next data line
   }
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.