State Machine based serial interface to SM5100b shield in Python

Ever since I got TCP data rx/tx working on the SparkFun SM5100b GSM/GPRS shield I have been prepping for the next step which is to get HTTP GET requests working. The problem I seem to be having here is that the HTTP server disconnects the TCP connection immediately after sending the response to the GET request, and I am not able to transfer the TCP data received using the AT command after the TCP connection has been disconnected.

Yesterday I finally got a state machine based serial interface written in Python working. The input to the Python script is a state machine description written in a YAML file.

Dummy Shimmy

Here is the script:

And here is a very simple YAML state machine file for the boot up sequence:

Coding up something equivalent for the Arduino will be a pain.


PySerial not available for ActiveState Python 64bit free edition on Windows

If you install the free 64bit edition of ActiveState Python you will not be able to use pypm to download the pyserial package, as also listed here:

It works fine with the 32bit edition though. It seems like the 64bit editions of some packages are only available to customers with business licenses.


Finally, transfers over TCP are working with the SM5100B!!

Thanks to some help from a blog post about GPRS with the SM5100B Arduino GSM Shield by Hadley Rich I was finally able to get the TCP connection working. I will add more details on this when I get time.

Here is a screen shot of the shield transmitting the byte character “B” followed by CR and LF to a Perl TCP server running on my PC, and then receiving one copy of the message “[9212]AsYouWish” in return for each byte.

Sparkfun GSM/GPRS SM5100b shield on a Diavolino

I have decided to return the SM5100B evaluation board since I am instead using the SM5100B cellular shield. This is because I was not really going to use any of the interface pins of the SM5100B module broken out on the eval board. One useful thing about the shield (that I wasn’t expecting) is that it is able to reset the cellular module using the on board reset button similar to the eval board.


The Diavolino board here is running without any AVR 328 mega chip plugged into it, and has the 2.5mm x 5.5mm power barrel socket for the 5V 3A regulated power supply from EvilMadScience.

Diavolino hosting a GSM/GPRS shield

Meanwhile although I can receive TCP data on the SM5100B modem over GPRS I still haven’t been able to successfully confirm transmission of data.

TCP connection over GPRS with SM5100B module

After having no success sending GET requests to HTTP servers I finally decided to set up my own tcp server by directing a port on my router to my PC and setting up a simple tcpserver listener in cygwin like this:

~ > tcpserver -t1000 -v -Bare_we_receiving 0 9876 bash -c "sleep 1000"
tcpserver: status: 0/40

Then I sent the following commands to the modem


For some reason the MY_ROUTER_ADDRESS had to be the text host name instead of the IP address, which was something like for me as per my router.

Immediately I saw a connection appear in the tcpserver log:

tcpserver: status: 1/40
tcpserver: pid 5232 from
tcpserver: ok 5232 :::ffff: :::ffff:
tcpserver: end 5232 status 256
tcpserver: status: 0/40

And then some data was received on the GPRS modem side:

> +STCPD:1

Which I read back promptly:

> +SOCKSTATUS: 1,1,0102,54,0,16
> OK
> +SSTR:1,are_we_receiving
> OK

And it exactly matched the banner text. So atleast I can establish TCP connections. The AT command interface though is a real pain.

Push growl notifications to Prowlapp with telnet

Assuming that you know what I am talking about, here is how it was done:

> cat ~/bin/
 if [ $# -ne 4 ]
 echo "Example: `basename $0` 80 / | telnet"
 exit 1
 echo "open $1 $2"
 sleep 2
 echo "GET $4 HTTP/1.0"
 echo "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070515 Firefox/"
 echo "Host: $3"
 sleep 2
 > ~/bin/ 80 '/publicapi/add?apikey=YOUR_PROWL_KEY_GOES_HERE&application=dah&event=doo' | telnet
 telnet> Trying
 Connected to
 Escape character is '^]'.
 HTTP/1.1 200 OK
 Date: Mon, 10 Sep 2012 23:40:33 GMT
 Server: Apache/2.2.3 (CentOS)
 X-Powered-By: PHP/5.1.6
 Vary: Accept-Encoding
 Content-Length: 118
 Connection: close
 Content-Type: text/xml
 <?xml version="1.0" encoding="UTF-8"?>
 <success code="200" remaining="999" resetdate="1347324034" />
 Connection closed by foreign host.

Thanks to this blog post for the script idea with telnet.

Basic testing the SM5100B

SM5100B GSM GPRS modem setup

The parts for the first phase have arrived and basic functionality of the GSM modem was tested and found to be operational. Here is a log of the modem receiving a phone call:

+SIND: 1
+SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1
+SIND: 11
+SIND: 3
+SIND: 4

Here is a list of what I’m using:

  1. From SparkFun
    1. SM5100B Evaluation Board
    2. GSM/GPRS Module – SM5100B
    3. Quad-band Cellular Antenna SMA
  2. From EvilMadScience
    1. 5V, 3A Regulated Power Supply
  3. From BG Micro
    1. 2.5mm Jack To 2.1mm Plug

I also tested receiving SMS text messages but it seems that, they aren’t pushed over the UART. Instead I had to poll to check if I had received any new SMS messages.

+CMGL: 1,0,"REC READ","1511","12/09/09,00:29:11+00"
Welcome to T-Mobile! Dial #BAL# to check your balances. Your T-Mobile number is 1***412****
+CMGL: 2,0,"REC READ","+1***721****","12/09/09,01:14:02+00"
Hello, world
+CMGL: 3,0,"REC READ","+1***721****","12/09/09,01:16:33+00"
Hello, world 2

I am currently using this with a T-Mobile pay-by-the-day plan which gives me unlimited voice, text, and 2G data for $2 per day.

Next I am going to spend some time thinking about how I want to proceed.