SIM 800C GPRS communication with server

Hello,
Below is the sequence of commands that i have implemented in software for GSM 800C module acting as client.
I am trying communicate between server and GSM.(the data im receiving is plain text)
AT+CFUN=1
OK
AT+CSTT=“airtelgprs”
OK
AT+CIICR
OK
AT+CIFSR
Local IP
AT+CIPSTART=“TCP”,“IP”,PORTNUMBER
OK
CONNECT OK
AT+CIPSEND

after that i am checking uart interrupt for incoming data from server.

I am using hercules as a means to send data to GSM. I am receiving message sent through hercules in the terminal.

the issue is i am able to send or recieve data only for short period of time. after that it is going to hang state and does not respond to any commands or received messages.

is there anything wrong in command sequence or did i miss any commands?

how to have stable communcication between server and GSM for longer periods.

Thanks in advance

I am using hercules to listen to the port and send data.

Hello and welcome!

What is this hercules you speak of? Is it a software, hardware…?

Usually the connection is ended by the server, as the usual use case tends to dispatch every client as soon as possible in order to attend other clients. Server configuration is a hole topic onto itself, so I recommend you to check in some other more specialized forum.

But consider the following: usually it is preferable to keep the connections as short as possible, because you are using a lot more power when you have an open connection, and you need to implement a “re-connection” logic to your firmware anyways, as connections aren’t guaranteed to be 100% stable. Furthermore, it will help you with the scalability of the server side, as there are more and cheaper options that handle a limited amount of simultaneous connections.

As a final recomendation, if your messages can be easily sent as some HTTP GET or POST requests, the SIM800 has a whole different interface for that which is much simpler and stable to use. Check the commands on the AT Commnad Manual starting at page 256, section “11 AT Commands for HTTP Application”

2 Likes

Hello Viedana,

Thanks you for the response and your time.

I am using HTTP commands as you suggested. Below is the sequence in which i am sending commands.

at
OK
at+sapbr=3,1,“Contype”,“GPRS”

OK
at+sapbr=3,1,“APN”,“airtelgprs.com

OK
at+sapbr=1,1

OK
at+sapbr=2,1

+SAPBR: 1,1,“100.89.145.234”

OK
at+httpinit

OK
at+httppara=“PROIP”,“202.56.231.117”

OK
at+httppara=“PROPORT”,“8080”

OK
at+httppara=“CID”,1

OK
at+httppara=“URL”,“http://www.m2msupport.net/m2msupport/test.php

OK
at+httpaction=0

OK

+HTTPACTION: 0,601,0

I was getting a dns error so with some searching, i found out in an arduino forum to add the proxy IP and port to get rid of DNS resolution error. It worked.

But I am getting 601(Network error) which im not able to fix.
Kindly let me know what could be done.

Thanks

Have just checked here with a SIM800l module, following what you typed here (but without the proxy settings) I get a 200 response from the server and receive the “test” string without problems. Things to check:

  • Have you save or change some configuration on your SIM800? I’m just using default factory configuration.
  • Is your LED light from the module blinking rapidly after you receive the OK from the AT+SAPBR=1,1 command?
  • Do you have a 2A power supply feeding the module? How are you powering it?

Hi viedana

  • I have not changed any configurations to sim800c.
  • The module does not have any LED’s to check blinking after sapbr=1,1.
  • The module is connected to a controller board and is drawing power from the board

i am able to get message responses correctly using at commands so i doubt it to be a power issue. The signal strength is between 10 to 15.
i have attached an image of the module.

I am currently using Airtel sim.

Should I establish any specifc PDP context before using HTTP commands?

Not that I’m aware of. But if you can try with different providers, It wouldn’t hurt. Also, what kind of plan do your sim has? What usually works best is to use the ones only configured for data transmission and no voice/sms functionality (if that works for your project). Otherwise, you might need to configure things depending on your provider. If you put that sim on a cellphone, do you need to do something extra besides turning on your data in order to use the internet?

In regards to the power issue, that board has a worrisome lack of beefy capacitors around the SIM800, maybe it has some on the backside? If you check most SIM800 “modules” or prefabbed PCBs, they have at least one big tantalum (yellow/orange or sometimes black) capacitor right next to the chip. And the controller board and its corresponding power supply are unknown, so there is no way of knowing how well do they deal with the power needs of the chip. It’s probably ok, but it would be nice to discard any problems and be sure.

It does have 2 big capacitors on the back of the PCB. the controller is a freescale kinetis processor. and the whole thing is powered by a 7.4V battery.

For now I will check with other network providers and see if there is any luck. will update then.

thanks for the reply.

Ok! power seems quite good. It might be something to do with the sim card then, as everything on the software side also seems very clearly ok.

In order to help you discard problems with the sim card, you can try calling the number and see if you get a Unsolicited Response on your serial terminal informing you of this; or even trying to read a SMS message (which is a little more involved).

hi @viedana, i got it to work. thank you for the support.
strangely, I had to add the content type field using HTTPPARA for it to work which i have not seen anywhere in the command sequence.
below is the sequence for anyone facing the same issue.

at+sapbr=3,1,“Contype”,“GPRS”
OK

at+sapbr=3,1,“APN”,“airtelgprs”
OK

at+sapbr=1,1
OK

at+sapbr=2,1
+SAPBR: 1,1,“100.124.79.222” OK

at+httpinit
OK

at+httppara=“CONTENT”,“text/plain; charset=UTF-8”
OK

at+httppara=“CID”,1
OK

at+httppara=“URL”,“http://ptsv2.com/t/6msqn-1576062108/post
OK

at+httpaction=0
OK
+HTTPACTION: 0,200,20

at+httpread
+HTTPREAD: 20
have a wonderful day
OK

I have one more question: Even with HTTP, few minutes after which the module does not respond to at commands. Is this an issue with SIM800C? because my requirement is to print data received from the server continuosly.

Thanks.

Congrats! Hmmm, that you had to specify the Content-type is probably a requirement of the server, for what is worth.

When you say that the module does not respond to AT commands, what behavior are you seeing? I have a hundred modules working autonomously for months receiving and sending data with the HTTP interface without problems, so it’s definitively not an issue with the SIM800 in general.

Things to check:

  • Is your network connection still working? A sudden connection might brake the logic of your software if not handled properly.
  • Have you maybe received too long of a response from the server? This might overflow the receive buffer of the SIM800, which is shared with the send buffer; so overflows make the SIM800 send wrong responses, but usually it still reads AT commands ok.
  • Are you waiting proper times after each command? The AT manual has estimations, but you’ll usually need to adjust the times a bit in some cases to improve stability.

hi @viedana,
I am waiting 1 second for all the commands, 5 seconds for httpaction and 5 seconds for httpread for which, upon keeping breakpoints, I am getting success responses for all commands and able to get data into the Rx buffer.

As per my experience, I am not able to read twice using at+httpread(Module stops responding to AT commands).

My understanding is that once data is read, the session should be closed using at+httpterm and begin with httpinit command.

Is this the right way to receive data from server? Or have I got something wrong here.?

The issue I have is, once the data is read succesfuly, module is not responding to at+httpterm command(or any other commands after that).

When you say “upon keeping breakpoints” do you mean that you wait for the SIM800 response, and then you wait an extra 1 or 5 seconds?

Yes, that is correct. But remember that once you send AT+HTTTERM, the SIM800 looses all the configuration from the HTTP interface (all headers setted by AT+HTTPPARA for example).

How long is the last server response you manage to get?

I am using timer to wait for sim 800 response and checking received buffer for OK or ERROR response. according to the received response, if OK string is received im moving on to the next command.
By breakpoints I meant just to check response after each command execution in the code.

yes, after terminating i am setting all the parameters once again.

I am currently resorting to using SAPBR=0,1 to cut off GPRS connection and then using HTTPTERM which worked via direct commands. currently implemeting it in software.

it is 20 bytes. I am waiting 5 seconds to receive data

Ok, if disconnecting from the network resolves your issue, maybe you are getting a unsolicited response from your network provider that’s interfering with the functionality of the SIM800. Some questions regarding your serial communication implementation:

  • How are you implementing the “waiting for response” logic?
  • Do you keep the serial open for a certain amount of time (if so, what do you do if no message arrives)? Or just wait for that amount of time and then you open your port?
  • Are you using interrupts attached to the serial port?
  • Are you only listening for messages from the SIM800 after you send a command or all the time?
  1. After sending the command via uart, I am starting a timer for 1 sec or 5 sec depending on the command being sent.
    In UART ISR, I have a flag that gets set when I receive data. depending upon the string receivd i am checking for succss or error response.

If data is not received, I have another flag in timer ISR that sets. if the uart rx flag isn't set before the timer flag does, I am treating it as failure and returning from the function.

  1. Yes, I am using interrupts. In my case, the SIM800C module’s UART pins are connected to controller UART pins. Uart ISR is configured to store data in a buffer whenever module receives the data.
  1. I have the serial port enabled all the time. I have no trouble receiving normal text messages as I directly get uart interrupts when there is an incoming message.

However, I am having trouble figuring out how i can get notified when there is new data in server side so that I can display it on LCD as and when new data gets uploaded to server.

On GSM network I think you would only be able to poll the server periodically, there is no way to push a notification/message from the server to the SIM800, as far as I know. Consider the GSM network as one giant “local area network” to which you have no control of what the router does, or when it does it.

I’m not sure if I understand this… If the module stops responding to AT commands, how are you sending the SAPBR=0,1 command?

I meant to say that the GSM module stops responding if I send at+httpterm after at+httpread.

Instead I am sending at+sapbr=0,1, after httpread for which i am getting OK response.

After this, i am able to get OK response for at+httpterm.

Its like this:

sequence that’s not working
.
.
at+httpaction=0
success rsponse
at+httpread
success
at+httpterm
(stops responding)

sequence that works
.
.
at+httpaction=0
success
at+httpread
success
at+sapbr=0,1
success
at+httpterm
success

thanks for the input. I alco couldn’t find any methods. Only way we can avoid polling for new data is to make GSM as a server and push data to it which can not be done directly. we need to get a private IP and APN to the sim which is not feasible.

Oh,ok, I understand now. That’s really estrange behavior. I would definitively try with another module to discard any software issue, but to me it sounds like a faulty unit or something. Maybe you can try changing the firmware of the GSM module and see if that fixes anything, but that’s a whole other can of worms.