I'm using a SIMCOM 5320A module like this one to try to establish a TCP connection.

Adafruit's SIMCOM5320A instantiation.

I'm going through SIMCOM's application note on TCP/IP as a reference.

The AT commands I'm using may very well be working, but I'm not sure the best way to verify this. I later plan to build atop this TCP connection to add a MQTT protocol connection to Amazon's AWS servers for IoT. But I like to do smaller "unit-testing" and build my way up, so that when I get to the MQTT and it's not working, I know that my TCP foundation it's built on is not the issue.

I believe my preliminary steps to this are working fine (registering to GPRS, connecting via APN, establishing PDP context, open network connection, open TCP socket). At least, they seem to be giving me the expected AT command return values indicating they're OK. It's from that point on where I have my doubts.

Currently what I'm doing is ust connecting to a web server (happen to be using Adafruit's IP address) and I send a simple message, like:

AT+CIPSEND=0,5   // send 5 chars to link 0

When I send the command to see sent/received, it reports 5 chars were sent, 0 received. I don't think the Adafruit server is configured to do anything in response to my sent data, like I am not doing an HTTP GET request or anything, so it does nothing. So again, it might be working, but I don't know.

I thought the best way to test this might be an echo server. I poked around for quite some time trying to find free online echo servers I could try to connect to, who whould just send back my "HELLO" ever so politely. There is a whole UNIX protocol for this, but it looks like it's been obsoleted.

I then tried to set up a local echo server on my PC and connect into that. I think I set it up right, because when I ran both a server and also a client (on the same machine, connected to localhost IP address), I got echoes in both terminals. But when I tried to connect to it from my SIMCOM module, I couldn't establish any connection. I messed around with firewall settings forever, and probably opened up every port to hackers in the process, but no dice.

I'm a bit out of my expertise with this internets stuff (more of a circuits/embedded guy), so I'm hoping someone can help point me in the right direction.

Finally, there are two similar questions to this on Stack Exchange, but I'm having trouble reaching those guys to see how they had configured their testing.
Is it possible to send AT commands through TCP?
How do I send data over TCP from a SIM5320A?

Essentially, I just want to connect to a TCP socket in transparent mode (vs. data mode), send some data one way, and read some data back successfully, then close the connection. Any help greatly appreciated.

  • \$\begingroup\$ Has the receiver opened the port used in the channel? Is it routed? forwarded? \$\endgroup\$ Commented Nov 1, 2016 at 16:46
  • \$\begingroup\$ After establishing a TCP connection any message you send should have a returned answer, which should be "bad request" in your case. Have you added the "ctrl+z" (0x1A) character to the end of your message? You can do so by adding $1A to the end of your message. \$\endgroup\$ Commented Nov 1, 2016 at 17:35
  • \$\begingroup\$ @BatuYıldız See my comment below to tcrosley. Am sending $1A after each command in RealTerm using "Send Numbers" button. Is this correct? \$\endgroup\$ Commented Nov 1, 2016 at 22:30
  • \$\begingroup\$ @JoelWigton yes that was what i meant. Since you are already doing it (which may be redundant as said by people below -but i was using it) it seems to be dead-end. "OK" returns after your send process but according to datasheet, before OK you should get +CIPSEND:5,5 which is intriguing. Have you tried sending AT+CIPSEND=? and AT+CIPSEND? for possible IP/CME errors? \$\endgroup\$ Commented Nov 2, 2016 at 8:08
  • \$\begingroup\$ So Joel? Did you succeeded to implement MQTT on the sim5320? \$\endgroup\$
    – Chris
    Commented Jan 25, 2017 at 19:57

2 Answers 2


About the easiest way to get a response from a server is to do a HEAD request.

For example, open a socket to www.stackexchange.com port 80

Then send:

HEAD /about HTTP/1.1
Host: www.stackexchange.com
(blank line)

You should get a response back, but just the headers, not the whole page.

Something like:

HTTP/1.1 200 OK
Date: Tue, 31 Oct 2016 22:44:11 GMT
Server: Apache


I have used this just to get the current time off the network.

  • \$\begingroup\$ Trying that. Using RealTerm. I'm able to open a connection to stackexchange.com in transparent mode (it informs me: "CONNECT 4800"). My understanding is at this point anything sent is acting transparently and not like AT commands. I put each of those lines you wrote and "Send ASCII" (without EOL characters) and then in a separate send I enter $1A and hit "Send Numbers" which should send the CTRL+Z after each message. After a long time sitting, nothing happening in terminal. Wondering if this idea is right but being hindered by the way I'm doing it. \$\endgroup\$ Commented Nov 1, 2016 at 22:31
  • \$\begingroup\$ @JoelWigton You need to send a carriage return (0x0D) after each of the two lines, and then a third all by itself (for the blank line). \$\endgroup\$
    – tcrosley
    Commented Nov 1, 2016 at 22:31
  • \$\begingroup\$ Added +CR (0x0D) for the main three lines (HEAD, Host, blank). Then I send $1A for CTRL-Z. My datasheet says to end TCP send commands with CTRL-Z, but the examples of it doing such is in a AT+CIPSEND command, not transparent mode. It's not clear if I need the $1A at all in transparent mode. It also talks about <ETX><CTRL-Z>, which is $03 $1A. Tried both variations, no response from either until my TCP connection times out. \$\endgroup\$ Commented Nov 1, 2016 at 22:39
  • \$\begingroup\$ @JoelWigton You shouldn't need the Ctrl-Z, I recall only needing that for SMS. Been a couple years since I was working with this but it seemed straightforward, although I never tried it interactively, just from firmware. But that shouldn't make a difference. \$\endgroup\$
    – tcrosley
    Commented Nov 1, 2016 at 22:44
  • \$\begingroup\$ @JoelWigton Be sure you are going to port 80 \$\endgroup\$
    – tcrosley
    Commented Nov 1, 2016 at 22:59

I would recommend trying non-transparent mode first to see if everything's set. You can test with arduino.cc/asciilogo.txt.

  • First, connect using CIPOPEN to port 80 of arduino.cc using the IP address you get from ping on Windows. The module also has a command to resolve names to addresses.
  • To GET the contents of the txt file, the HTTP request should look like this:

    GET /asciilogo.txt HTTP/1.1\r\nHost: arduino.cc\r\n\r\n

    Total length is 49. So your next command should be: AT+CIPSEND=0,49.

  • The important part now is to actually send the data to the module. You have to make sure that it's this exact request that's sent; a character less or more, and you get nothing or Bad Request. Make the serial monitoring program work for you here. I don't have RealTerm, so cant say exactly how to do it there, though presumably it has some option to append CRLF to commands. If you have the Arduino IDE, with its serial monitor set to BOTH NL & CR, you can send the request piece-by-piece. It's basically: type GET /asciilogo.txt HTTP/1.1, Enter, type Host: arduino.cc, press Enter twice. No Ctrl+Z needed.

If it all went well, you should see this on your screen.

  • \$\begingroup\$ Thanks, this might work too, but since I really need transparent mode validated, tcrosley's solution worked for me. \$\endgroup\$ Commented Nov 2, 2016 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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