GSM module with GPRS

Hi

I have a webpage that receives data from a GET request like this:

http://mysite.com/probe.php?value=xxx

I have a Fez Hydra with a GSM module and i would like to send remote data to the webpage. I managed to start the GPRS module, connect to the APN network and get IP, but cannot send any kind of data. I tried different methods with no success:

#method 1 - AT HTTPPARA commands

cellularRadio.SendATCommand(“AT + HTTPINIT”);
cellularRadio.SendATCommand(“AT+HTTPPARA="CID",1”);
cellularRadio.SendATCommand(“AT+HTTPPARA="URL","http://mysite.com/probe.php?value=xxx\”");
cellularRadio.SendATCommand(“AT+HTTPACTION=0”);
cellularRadio.SendATCommand(“AT+HTTPREAD”);
Thread.Sleep(6000);
cellularRadio.SendATCommand(“AT+HTTPTERM”);

debug window shows no error but the page is never reached

#method 2 - AT HTTTDATA commands

cellularRadio.SendATCommand(“AT + HTTPINIT”);
Thread.Sleep(1000);
cellularRadio.SendATCommand(“AT+HTTPPARA="CID",1”);
cellularRadio.SendATCommand(“AT+HTTPPARA="URL","http://mysite.com"”);
string requestString = “GET /probe.php?value=xxx HTTP/1.1\r\n”;
requestString += “Host: mysite.com\r\n”;
requestString += “Connection: Keep-Alive\r\n”;
requestString += “Accept-Encoding: gzip\r\n”;
requestString += “Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7\r\n”;
requestString += “Cache-Control: no-cache\r\n”;
requestString += “\r\n”;
cellularRadio.SendATCommand(“AT+HTTPDATA=” + requestString.Length + “,3000”);
cellularRadio.SendATCommand(requestString);
cellularRadio.SendATCommand(“AT+HTTPACTION=0”);
cellularRadio.SendATCommand(“AT+HTTPREAD”);
cellularRadio.SendATCommand(“AT+HTTPTERM”);

debug window shows ERROR in AT+HTTPREAD

#method 3 - .net commands

tried sendTCPdata() with no success, it seems this function is using SendATCommand but with some bugs…

Any help?

Hi Geologic,

Are you using the GHI API or the API here:
https://tcpcellularradio.codeplex.com/?
~Shane

Hi @ shanekirkbride

Thanks for your help.
I’m using GHI API, i tried the API from codeplex but didn’t understand how to use it. Do i need a reference to CelluarRadioManager? Is there a sample code to test? I tried to run “CellularRadioTest” example but the code is for SMS sending only, not TCP.

Regards

Hi Geo,
Sorry for my delay (I forgot to check the box to watch this topic)
Are you going to use SMS or TCP for the cellulaRadio Manager? For SMS I think the GHI API is better for TCP the 3rd party app is better.

I’ve gotten them both to work on a functional level but i’m trying to improve their stability currently :slight_smile:
~Shane

hello,
thanks to help.

I wanted to use the two. how to use TCP to run the page?

I Shane

You mentioned that you have a working example, it is possible to share it?

I’m stucked with this TCP thing…

Regards

Hi Geo,
No problem. I will share this info when I get home this afternoon (MST).
~Shane

Few notes to start. I’m using a FEZCerbuinoBee. I’ve attached images of my design environment; this took me a while to get set up… I’ll put more details on this on my blog in a few days. (http://meca-labs.blogspot.com/)

I found the most ambiguity in the PIN for the SIM Card a (which I promptly disabled using an ATcommand) and the log on information for the GPRS network. One quick note about the GPRS is that the SIM900 Card is limited to 2G networks so what ever provider you have will need a backwards compatible network.

So for the SMS texting version I set up my FEZCebrino under a new project on VS2012. Added the CellularRadio module and literally copied and pasted the code here: https://www.ghielectronics.com/community/forum/topic?id=12072 and texted the guy who posted it with my SIM900…then I put in my cell phone number and text-ed my self
:wink:

For testing the TCP funcionality I have not found a good source. The site with the driver works but it is not really updated (?) or at least the solution prevented doesn’t show the full power of the driver: https://tcpcellularradio.codeplex.com/documentation

Here is what I came up with:


using System;
using System.Collections;
using System.Threading;
using System.Text;

// using Makina.HummingBird.DataModel; //you won't have this but you don't need it

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using GHIElectronics.Gadgeteer;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

using Gadgeteer.Modules.GHIElectronics;
using Gadgeteer.Modules.DLSys;
using Gadgeteer.Modules.Mekalogic;
using GHI.OSHW.Hardware;

using System.IO.Ports; //for series 2

namespace GadgeteerApp13
{
    
    public partial class Program
    {

        private CellularRadioManager m_radioManager;
        private GTM.Mekalogic.CellularRadio cellularRadio;
        bool state = false;
        const string serialPortName = "COM1";
        private ArrayList _nodes;
        
        string crlf = "" + (char)13 + (char)10;
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

            try //both usbSerial.Configure and usbSerial.Open()have different exceptions but it is rare that they will triggered in this specific code
            {
                //configure the usbSerial port
                usbSerial.Configure(9600, GT.Interfaces.Serial.SerialParity.None, GT.Interfaces.Serial.SerialStopBits.One, 8);
                //if the port is not open then open it
                if (!usbSerial.SerialLine.IsOpen)
                {
                    usbSerial.SerialLine.Open();
                    Debug.Print("opened the serial port");
                }
            }
            catch (Exception e) //Catch any exceptions
            {
                Debug.Print(e.ToString()); //print the error to the debug ouput 
            }

            usbSerial.SerialLine.DataReceived += new
            GT.Interfaces.Serial.DataReceivedEventHandler(SerialLine_DataReceived);

            m_radioManager = new CellularRadioManager(2) //SIM Card provider specific. I am using AT&T...ma bell's *still* got some ill communication
            {
                AccessPointName = "wap.cingular", 
                AccessPointUser = "wap@ cingulargprs.com",
                AccessPointPassword = "cingular1",
                DebugPrintEnabled = true,
                IsHttpModeEnabled = true
            }; //this takes about 2 mins to complete


            // initialize the loop timer
            GT.Timer timer = new GT.Timer(2000);

            //set the interrupt
            timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
            timer.Start();
        }

        
        void timer_Tick(GT.Timer timer) 
        {
           try
            {

                if (m_radioManager.RadioState == RadioState.Ready)
                {
                    Debug.Print("The radio is ready");
                    usbSerial.SerialLine.Write("The radio is ready \r\n");
                    Thread powerOnThread = new Thread(new ThreadStart(PowerOnSequenceThread));
                    powerOnThread.Start();
                }
                else
                {
                    Debug.Print("Cellular Radio not ready yet...");
                   return;
                }
            
            }
            catch (Exception e) //Catch any exceptions
            {
                Debug.Print(e.ToString()); //print the error to the debug ouput 

            }
         }

        bool isConnected = false;
        private void PowerOnSequenceThread() //the radio should be ready to connect and send/recieve data here
        {
            SystemTime sysTime = new SystemTime();
            string ipHostAddress = "192.168.0.1";  //need to put your ip here

//This is just a slick way to communicate with the server...
            Makina.HummingBird.Models.Device dev = new Makina.HummingBird.Models.Device();
            dev.Name = "shane";
            dev.ID = Guid.NewGuid().ToString();
            string post = HTTPRequestManager.GetRequestString(dev);

            if (!isConnected)
            {
                isConnected = m_radioManager.Connect(ipHostAddress);
            }

            if (isConnected)
            {
 
                try
                {
                    m_radioManager.SendData(post);
                    var response = "";
                    m_radioManager.ReceiveData(5000, out response);
                    Debug.Print(response);
                    usbSerial.SerialLine.Write(response);
                }
                catch (Exception e) //Catch any exceptions
                {
                    Debug.Print(e.ToString()); //print the error to the debug ouput 
                }
            }
            else
            {
                return;
            }
        }

        public void SerialLine_DataReceived(GT.Interfaces.Serial sender, System.IO.Ports.SerialData data)
        {
            int NumberOfBytesToRead = usbSerial.SerialLine.BytesToRead;
            byte[] readInputBuffer = new byte[NumberOfBytesToRead];
            usbSerial.SerialLine.Read(readInputBuffer, 0, NumberOfBytesToRead);
            usbSerial.SerialLine.Write(readInputBuffer);
            usbSerial.SerialLine.Flush();
        }
      }
    }
  


I hope this helps…
~Shane

1 Like