Use Arduino GSM/GPRS shield to send data to my web service
Asked Answered
K

2

8

I know how to make calls and send SMSes using a GSM/GPRS shield for Arduino Uno. But I have a web service at the location http://mydomain.com/rest/receiveSensorData, and I want to send sensor data to this URL using a GSM/GPRS shield because I can not count on Wi-Fi being present at the operating locations. This is the shield I have, and I also have a 3G SIM card and am running on an Arduino Uno.

How do I do this?

Kisser answered 14/12, 2011 at 7:13 Comment(0)
B
10

You probably already got this working but just in case:

In my setup I'm using the Seeed Quad Band GPRS Shield that uses the Sim900 module. I believe this code will work with yours as well after looking at the specs for yours.

    #include <SoftwareSerial.h>
SoftwareSerial gprsSerial(7, 8);

void setup()
{
  gprsSerial.begin(19200);
  Serial.begin(19200);

  Serial.println("Config SIM900...");
  delay(2000);
  Serial.println("Done!...");
  gprsSerial.flush();
  Serial.flush();

  // attach or detach from GPRS service 
  gprsSerial.println("AT+CGATT?");
  delay(100);
  toSerial();


  // bearer settings
  gprsSerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(2000);
  toSerial();

  // bearer settings
  gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"epc.tmobile.com\"");
  delay(2000);
  toSerial();

  // bearer settings
  gprsSerial.println("AT+SAPBR=1,1");
  delay(2000);
  toSerial();
}


void loop()
{
   // initialize http service
   gprsSerial.println("AT+HTTPINIT");
   delay(2000); 
   toSerial();

   // set http param value
   gprsSerial.println("AT+HTTPPARA=\"URL\",\"http://YOUR.DOMAIN.COM/rest/receiveSensorData?sensorval1=blah&sensorval2=blah\"");
   delay(2000);
   toSerial();

   // set http action type 0 = GET, 1 = POST, 2 = HEAD
   gprsSerial.println("AT+HTTPACTION=0");
   delay(6000);
   toSerial();

   // read server response
   gprsSerial.println("AT+HTTPREAD"); 
   delay(1000);
   toSerial();

   gprsSerial.println("");
   gprsSerial.println("AT+HTTPTERM");
   toSerial();
   delay(300);

   gprsSerial.println("");
   delay(10000);
}

void toSerial()
{
  while(gprsSerial.available()!=0)
  {
    Serial.write(gprsSerial.read());
  }
}

Just change "epc.tmobile.com" to the apn for your carrier and "YOUR.DOMAIN.COM" to your server info and change the "sensorval1=blah" to your variable and sensor data.

Let me know if you get this working or not. I can help you figure it out it's not too hard.

Good Luck.

Barometer answered 23/2, 2013 at 13:31 Comment(2)
I get a error in all combinations of AT+SAPBR. I am using a sim300 based board,Jerlenejermain
Would you know how the subsequent Server side code? I am running on Meteor so it is all javascript with a mongodb database.Maxiemaxilla
L
0

It might actually be easier to keep sending SMS if the data is small and you add the ability to receive SMS info to your web application.

See the answers to the following question in particular the first one which suggests: http://www.twilio.com/sms/:

Receive SMS messages in a web application in the US on a hosted server

One advantage of using SMS is that it will save the shield having to set up a GPRS connection which will generally take longer and may use more power. One disadvantage, to be aware of is that SMS is not a guaranteed messaging system, although you could build some sort of acknowledgment on top of SMS if you wanted.

As an aside, having a 3G SIM will not enable you to use 3G on a GPRS modem unless the modem also supports 3G.

Lamontlamontagne answered 11/1, 2012 at 23:17 Comment(3)
He was not asking how to send sms to te server he was asking how to create a connection to the web service which is actually easier than setting up sms to server.Barometer
He was asking how to send sensor data to a web service, This can be done using SMS and a service on the server side which allows a web server receive SMS which is what the answer above shows. There are advantages to using SMS in certain cases and this is also pointed out.Lamontlamontagne
I think this would be a costly choice.Hallvard

© 2022 - 2024 — McMap. All rights reserved.