Main Site Documentation

Cellular radio and webserver


#1

Hello
I have a fez hydra (or raptor) mainboard and I want to simply send a data from SD-card to a HTTP webserver.
I could not find any documentation to how to implement GPRS of cellular radio.
How can I do that?
thanks


#2

I have GHI Cellular radio as is shown on your link :
https://www.ghielectronics.com/docs/63/cellular-radio-module
but there was no documentation!
I have also seen this link :


but I did not understand what it was? is it a driver which should be installed or a source code?
I’m new with “AT” commands, how can I use them?


#3

@ andre.m -
Any Kind of SIM card is supported for this module?


#4

I have managed to do this very thing with a SIM900 modem using AT commands.

It’s not a clean cut as the documents make out as you need to do a lot of checking in between each command.

I’ll try and get some time this week to post a snippet. It won’t be fully working code as you’ll need to handle the serial stuff but the AT commands to do this and how I managed to get a stable system will help you along.


#5

@ andre.m -
thanks…


#6

Ok… I was successful to see logs of “RING” when calling sim card. but I could not enter in event of cellularRadio.IncomingCall . Actually none of events works… :frowning:


 void ProgramStarted()
        {
        cellularRadio.DebugPrintEnabled = true;
            cellularRadio.PowerOn(50);
             timer = new GT.Timer(60000);
              timer.Tick += timer_Tick;        
            timer.Start();
        }
void timer_Tick(GT.Timer timer)
        {
             timer.Stop();
           cellularRadio.IncomingCall += cellularRadio_IncomingCall;
        }
        void cellularRadio_IncomingCall(CellularRadio sender, string caller)
        {
           debug.print ("calling ...")
        }

What is wrong there?
these are my logs…


#7

for a start, you probably should put this in your programstarted()

cellularRadio.IncomingCall += cellularRadio_IncomingCall;


#8

@ Brett -
No, it doesn’t work…


#9

I’m really confused about how to send and receive data using Cellular module. I tried to act as was existed in :


but I have some essential questions :

  1. What should I use for AccessPointName, AccessPointUser and AccessPointPassword in :

cellularRadio.AttachGPRS(AccessPointName, AccessPointUser, AccessPointPassword);

  1. can I use this? :

 var tcpState = cellularRadio.ConnectTCP("http://www.google.com", 80);

and, I was wondering if you could tell me how i can implement sending and receiving data.
Can I use any HttpWebRequest or Response? for example:


byte[] passData = System.Text.Encoding.UTF8.GetBytes(ID);
                        WebRequest request = WebRequest.Create("172.16.40.28");
                         request.Method = "POST";
                        request.ContentType = "application/x-www-form-urlencoded";
                        request.ContentLength = passData.Length;

                        #region Add Headers
                        request.Headers.Add("RFID", ID);
                            #endregion
                        Stream dataStream = request.GetRequestStream();
                        dataStream.Write(passData, 0, passData.Length);
                        dataStream.Close();
                        WebResponse response = request.GetResponse();
                        string userName = ((HttpWebResponse)response).Headers["UserName"];
                        response.Close();

If no, How can I use these methods?


cellularRadio.TcpDataReceived += TcpDataReceived;
 var result = cellularRadio.SendRawTcpData(data);

Thanks


#10

These are provided by your telecoms provider. The first one, is better known as APN and is something like “internet” or whatever the operator uses.

Username and password depend on the network operator’s GPRS settings.

If you are still unsure, post back what network SIM you are using and we can look it up for you?


#11

@ Dave McLaughlin -
Thanks, I found my APN , username and password…
now my basic question is how to connect to my webserver using http rquest and response…
I’m trying to use AT commands. Is it just a way to sending and receiving data using AT commands or there is other simple ways?
can I use HttpRequest and HttpResponse in AT commands?


#12

Ok, it is my codes using at commands :


       cellularRadio.RetrievePinState();
            Thread.Sleep(3000);
            cellularRadio.SendATCommand("AT+CREG?") ;
             cellularRadio.SendATCommand("AT+CGREG?") ;
            Thread.Sleep(3000);
           cellularRadio.SendATCommand("AT+CGATT?") ;
            Thread.Sleep(3000);
            cellularRadio.SendATCommand("AT+CIPSHUT");
           Thread.Sleep(3000);
            cellularRadio.SendATCommand("AT+CIPSTATUS") ;
            Thread.Sleep(3000);
             cellularRadio.SendATCommand("AT+CIPMUX=0");
            Thread.Sleep(3000);
             cellularRadio.SendATCommand("AT+CSTT= \"mcinet\",\"\" ,\"\" ");
            Thread.Sleep(3000);
             cellularRadio.SendATCommand("AT+CIICR") ;
            Thread.Sleep(3000);
             cellularRadio.SendATCommand("AT+CIFSR");
            Thread.Sleep(3000);
            cellularRadio.SendATCommand("AT+CIPSTART= \"TCP\" , \"www.google.com\", \"80\" ") ;
            Thread.Sleep(5000);
             cellularRadio.SendATCommand("AT+CGDCONT=1,\"IP\",\"mcinet\" ") ;
            Thread.Sleep(5000);
            cellularRadio.SendATCommand("AT+CGDCONT?") ;
            Thread.Sleep(3000);
             cellularRadio.SendATCommand("AT+CGACT=1,1") ;
            Thread.Sleep(3000);
            cellularRadio.SendATCommand("AT+CEER") ;
            Thread.Sleep(3000);

            cellularRadio.SendATCommand("AT+HTTPINIT");
           Thread.Sleep(3000);
            cellularRadio.SendATCommand("AT+HTTPPARA=\"URL\",\"www.google.com\"");
             cellularRadio.SendATCommand("AT+HTTPPARA=\"CID\",1");
            Thread.Sleep(3000);
            cellularRadio.SendATCommand("AT+HTTPACTION=0");
            Thread.Sleep(3000);
            cellularRadio.SendATCommand("AT+HTTPREAD");
            Thread.Sleep(3000);
            cellularRadio.SendATCommand("AT+HTTPTERM");
            Thread.Sleep(3000);

As you see HttpAction returns 601 …
where is the problem?


#13

@ andre.m -
I’ve followed SIM900 manual to make connection and HttpRequest. HTTPACTION should return : 200.
But it returns 601 error which means network error…
everybody has any idea?


#14

Did you also read the application note on TCP, there might be a newer version on the simcom site but here is the one I am thinking might help: http://www.propox.com/download/docs/SIM900_Application_Note.pdf


#15

This is the current test code I have for sending HTTP to a Mango SCADA server. It’s not cleaned up as I am still working on the code but this works. It’s not based on your GSM driver, but you can use the AT sequence shown to make the connection and send HTTP requests etc. I keep the connection open as I send data every 30 seconds.


        public bool ConnectHttp(String apn, String user, String pass)
        {
            String reply = "";
            bool Status = false;

            Debug.Print("GPRS Connection In Progress");

            string cmd = "AT+CGDCONT=1,\"IP\",\"" + apn + "\"";
            Status = ExecuteCommand(cmd, out reply, 2000);

            Status = ExecuteCommand("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"", out reply, 2000);
            Thread.Sleep(50);

            Status = ExecuteCommand("AT+CIPSHUT", out reply, 2000);
            Thread.Sleep(50);

            Status = ExecuteCommand("AT+CIPMUX=1", out reply, 2000);
            Thread.Sleep(50);

            Status = ExecuteCommand("AT+CIPSTATUS", out reply, 2000);
            Thread.Sleep(50);

            Status = ExecuteCommand("AT+CSTT=\"" + apn + "\",\"" + user + "\",\"" + pass + "\"", out reply, 2000);
            Thread.Sleep(50);

            Status = ExecuteCommand("AT+CIPSTATUS", out reply, 2000);
            Thread.Sleep(50);

            Status = ExecuteCommand("AT+CIICR", out reply, 60000);
            Thread.Sleep(50);

            ExecuteCommand("AT+CIFSR", out reply, 2000);
            Thread.Sleep(50);

            if (Status)
            {
                bool Done = false;
                while (!Done)
                {
                    ExecuteCommand("AT+CIPSTATUS", out reply, 2000);

                    if (reply.IndexOf("IP STATUS") >= 0)
                        Done = true;
                    else
                        Done = false;

                    Thread.Sleep(200);
                }
            }
            if (Status)
            {
                Debug.Print("GPRS Connected");

                gprsState = 6;      // Connected
            }
            else
            {
                Debug.Print("GPRS Failed To Connect");
            }
            return (Status);
        }

        public bool SendHTTP(String device, String msg, String host, int port)
        {
            bool Status = false;
            String reply;
            String command = "POST /httpds?__device=" +
                             device + 
                             " HTTP/1.1\r\nContent-Length: " +
                             msg.Length.ToString() +
                             "\r\nContent-Type: application/x-www-form-urlencoded\r\nHost: " +
                             host + ":" + port.ToString() + "\r\nConnection: Keep-Alive\r\nUser-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)\r\n\r\n" +
                             msg;
            //
            // See if the server is already connected?
            //
            ExecuteCommand("AT+CIPSTATUS", out reply, 2000);

            if (reply.IndexOf("CONNECTED") < 0)
            {
                ServerConnected = false;
                SendTries = 0;

                ServerLinkState = SERVER_CONNECTING;
                Debug.Print("TCP Connecting to server");
                String cmd = "AT+CIPSTART=0,\"TCP\",\"" + host + "\",\"8080\"";

                Status = ExecuteCommand(cmd, out reply, 2000);

                if (Status)
                {
                    ExecuteCommand("AT+CIPSTATUS", out reply, 2000);
                    //
                    // Wait until connected or we have a timeout
                    //
                    long msTimeOut = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) + 15000; // Allow max 15 seconds to connect

                    while ((reply.IndexOf("CONNECTED") < 0) && ((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) < msTimeOut))
                    {
                        Thread.Sleep(500);

                        ExecuteCommand("AT+CIPSTATUS", out reply, 2000);
                    }
                    if (reply.IndexOf("CONNECTED") >= 0)
                    {
                        ServerConnected = true;
                    }
                    else
                    {
                        Debug.Print("TCP failed to connect");

                        Status = false;
                    }
                }
            }
            if(ServerConnected)
            {
                Status = ExecuteCommand("AT+CIPSEND=0", out reply, 2000);

                if (Status || isSmsInitialized)
                {
                    ServerLinkState = SERVER_SENDING;
                    Debug.Print("TCP Sending to server");
                    ExecuteCommand(command, out reply, 10000, '\x1A');

                    if (reply.IndexOf("SEND OK") >= 0)
                    {
                        Debug.Print("TCP sent");
                    }
                    Status = true;
                }
                else
                {
                    ServerLinkState = SERVER_CONNECTING;

                    Debug.Print("TCP failed to send");

                    if (++SendTries > 3)
                    {
                        SendTries = 0;

                        ExecuteCommand("AT+CIPCLOSE=0,0", out reply, 6000);
                        Debug.Print("TCP Connection Closed");
                        ServerLinkState = SERVER_DISCONNECTED;

                        ServerConnected = false;
                    }
                }
            }
            return Status;
        }

        public bool CloseHttp()
        {
            bool Status;
            String reply;

            Status = ExecuteCommand("AT+CIPSHUT", out reply, 2000);

            gprsState = 5;

            return (Status);
        }


#16

@ Dave McLaughlin -
what is method :



Is it related to driver of  https://tcpcellularradio.codeplex.com/  ?
Or It is in libraries of GHI cellular module or somthing else?
Thanks... I have also handled an unstable  HTTP connection by using mentioned  driver

#17

It’s in my own code. It takes the command, sends it to the modem and waits for a reply or timeout. The returned value indicates status and reply contains the text received from the modem.

I don’t use Gadgeteer but plain NETMF and custom modem hardware so to get my code working requires a little effort I am afraid so that’s why I did not include the complete driver for now.

What I wanted to do was show you the AT commands and what checking you need to use to get a simple HTTP or any TCP connection working.

Simply sending the commands as per the SIM900 manual does not work as you need to do checks to see if the connection is completed or not. My code checks these things.