none consistent results for the same incoming GET call

Hello,

When running the SIM808 as a GSM server I’m encountering none consistent results for the same incoming GET call with the same data sent, for testing I use the Request Maker online tool:

|500x389

This is server code that prints the output:

        if (inet.connectedClient()) {
            //Read and print the last message received.
            char msg[200];
            gsm.read(msg, 200);
            Serial.println(msg);
            memset(msg, 0, sizeof(msg));
            inet.disconnectTCP();
            inet.connectTCPServer(80);
        }

The following is the output for the same GET call as shown in the screenshot above:

STATE: SERVER LISTENING

Starting read.. Waiting for Data.................................................................................. REMOTE IP: 72.47.248.155 GET / HTTP/1.1 Host: simple.ram.sh Accept: / Content-Length: 17 Content-Type: application/x-www-form-urlencoded

key1=100&key2=200 Done..

REMOTE IP: 72.47.248.155 GET / HTTP/1.1 Host: simple.ram.sh Accept: / Content-Length: 17 Content-Type: application/x-www-form-urlencoded

key1=100&key2=200 ATT: CONNECT OK RIC: CLOSE OK

ERROR

OK

STATE: SERVER LISTENING

Starting read.. Waiting for Data.................................... REMOTE IP: 72.47.248.155

Done..

REMOTE IP: 72.47.248.155

ATT: CONNECT OK RIC: T*$)TLLC??t:si???????5 Accept: / Content-Length: 17 Content OK

STATE: SERVER LISTENING Waiting for Data... REMOTE IP: 72.47.248.155

Done..

REMOTE IP: 72.47.248.155

ATT: CONNECT OK RIC: CLOSE OK

ERROR

OK

STATE: SERVER LISTENING

Starting read.. Waiting for Data... REMOTE IP: 72.47.248.155

Done..

REMOTE IP: 72.47.248.155

ATT: CONNECT OK RIC: QH????? ost: simple.ram.sh Accept: / Content-Length: 17 {got the correct string length but did not print it at all} C OK

STATE: SERVER LISTENING

Starting read.. Waiting for Data.................................

What is it I'm missing here? Thank you in advance! Best, Ram

What is it I'm missing here?

Links to the libraries. Code. Realistic expectations.

I, for one, would not expect gsm.read() to block, waiting for a complete message. I would expect it to be you responsibility to accumulate the data until a complete response was received. I am prepared to be pleasantly surprised though, when you post the complete code and library links (as links, not just text).

@PaulS

Thank you for your reply.

Realistic expectations.

Have you been speaking with my wife?? :slight_smile:

here is my code:

#include <inetGSM.h>
#include <SoftwareSerial.h>
#include <SIM900.h>
#include <LOG.h>

InetGSM inet;

int i = 0;
boolean started = false;
long lasttime = millis();

void setup()
{
//Serial connection.
Serial.begin(9600);
Serial.println(“GSM Server testing.”);
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower

if (gsm.begin(4800))
{
Serial.println("\nstatus=READY");
started = true;
}
else
{
Serial.println("\nstatus=IDLE");
}

if (started) {
//GPRS attach, put in order APN, username and password.
//If no needed auth let them blank.
if (inet.attachGPRS(“internetg”, “”, “”))
Serial.println(“status=ATTACHED”);
else Serial.println(“status=ERROR”);

// enable PING ECHO
gsm.SimpleWriteln(“AT+CIPCTL=1”);
delay(1000);
i = 0;
while (i<50) {
gsm.SimpleRead();
i++;
}

//TCP Server. Start the socket connection
//as server on the assigned port.
if (inet.connectTCPServer(80))
Serial.println(“status=TCPSERVERWAIT”);
else Serial.println(“ERROR in Server”);
lasttime = millis();
}
};

void loop()
{
if (started) {
//Check if there is an active connection.
if (inet.connectedClient()) {
//Read and print the last message received.
char msg[200];
gsm.read(msg, 200);
Serial.println(msg);
memset(msg, 0, sizeof(msg));
inet.disconnectTCP();
inet.connectTCPServer(80);
}
}
}

All libraries were downloaded from here

I appreciate your willing to help!!

Please use code tags when posting code - makes life easier for those trying to help.

That SIM900 library is crap. The read() method reads whatever serial data is available, and then puts a NULL at the end of the array, NOT after the last bit of data written to the array.

It does NOT know anything about the type of response to be expected (and it probably shouldn't), so it does not know what constitutes a packet. In it's way, a packet is whatever data has arrived.

That would mean that this is consi

dered a packet, because I

typed all the lett

ers in some given time frame.

Obviously, that is nonsense. As is the way that it "null-terminates the array" in the wrong place.

OK, that makes sense, what library would you recommend to use instead of the SIM900 then?

I do not know that there is a better library. It is not difficult to fix the way the library misplaces the NULL, which MIGHT deal with the issue you are seeing.

It is unfortunate that when devices were first made that accepted AT commands, there was no commonly agreed upon symbol used to mean "I'm done sending my reply". That makes creating a really robust process for reading and parsing the reply difficult.

Itisliketryingtocommunicatewithoutusingspacesbetweenwordsoranypunctuation