How to send data to Cosm with GPRS Shield

Lots people get their GPRS Shield and confuse how to use GPRS Shield to send data via internet, the introduction on its wiki page is so simple that just a Send2Pathube function hard to comprehend for those who are not familiar with SIM900 AT Command. Actually, it is not complexity, here it is an example, hope will help you. If we need to monitor real-time temperature and humidity in a place without wired network and power source, we can use GPRS Shield with an Arduino to achieve this functionality by collecting temperature and humidity data and sending data to Cosm. Certainly, it is just a method to access TCP server of Cosm , different server has its API. But it is the same way to access TCP server, for connecting to other server, you just need to change your API interface based on this example code.

What we need, all from SeeedStudio:
Seeeduino V3
GPRS Shiled
Solar Charger Shiled
Solar Panel
Lithium Battery
SIM Card can search internet

Hardware connection:
It is eay to combine all the electronics, see the following picture. If you don’t know functionality of these module, please refer to their documentations first on SeeedStduino website. Note that the jumper on GPRS Shield should connect GPRS_RX to D8 and GPRS_TX to D7, besides, since we are using Seeeduino V3, it has GROVE interface on board, so we can directly plug temperature&humidity sensor into it.

Interface to Seeeduino:
GPRS_RX -> D8
GRPS_TX -> D7
Temperature%Humidity SIG -> A5

Get Started with Cosm
For sending data to Cosm, we need to get a feed and its key from Cosm. Log on cosm.com/ , sign up a Cosm account and log in. Click on adding to add a Arduino feed, do remember your feed ID. After a new feed created, there will be a corresponding key created, we can access Keys menus to get it. So now, what we have is a feed ID and its corresponding key.

Programming:
Refer to SIM900 AT Command to get familiar with At Command first, there datasheet you could download
on the link : garden.seeedstudio.com/images/a/ … _V1.03.pdf

Step1 : Bring up wireless connection with GPRS.

GPRS.println("AT+CGATT=1"); // Attach from GPRS serivce delay(2000); GPRS.println("AT+CSTT=\"CMNET\""); // Start task and set APN delay(1000); GPRS.println("AT+CIICR"); // Bring up wireless connection with GPRS delay(1000); GPRS.println("AT+CIFSR"); // Get local IP address
Step2 : Staring up TCP connection with command AT+CIPSTART,refer to documentation of Socket Server(cosm.com/docs/beta/socket_server/), the Request Syntax is as following:

[code]
“method” : “put”,
“resource” : “/feeds/504”,
“params” : {},
“headers” : {“X-ApiKey”:“abcdef123456”},
“body” :
{
“version” : “1.0.0”,
“datastreams” : [
{
“id” : “0”,
“current_value” : “980”
},
{
“id” : “1”,
“current_value” : “-261”
}
]
},
“token” : “0x12345”
}

// Response:
{
“token” : “0x12345”,
“status” : 200,
“resource” : “/feeds/504”
}[/code]
We know TCP Socket “api.cosm.com”, Sever Port “8081” and Request Syntax to access Cosm TCP server, starting send data to Cosm.

GPRS.println("AT+CIPSTART=\"TCP\",\"api.cosm.com\",\"8081\""); //Start up TCP connection delay(2000); Response(); GPRS.println("AT+CIPSEND"); // Begin send data to Pachube through TCP connection Response(); // Request Syntax for TCP Socket Connection Type GPRS.print("{"); GPRS.print("\"method\" : \"put\","); GPRS.print("\"resource\" : \"/feeds/"); GPRS.print(FEEDID); GPRS.print("\","); GPRS.print("\"params\" : {},"); GPRS.print("\"headers\" : {\"X-ApiKey\":\""); GPRS.print(APIKEY); GPRS.print("\"},"); GPRS.print("\"body\" : "); GPRS.print("{\"version\" : \"1.0.0\","); GPRS.print("\"datastreams\" : ["); GPRS.print("{\"id\" : \"Temperature\","); GPRS.print("\"current_value\" : \""); GPRS.print(temperature,1); GPRS.print("\"},"); GPRS.print("{\"id\" : \"Humidity\","); GPRS.print("\"current_value\" : \""); GPRS.print(humidity,1); GPRS.println("\"}]},"); GPRS.print("\"token\" : \"123\"}"); // End of Request Syntax GPRS.println((char)26); // After sending AT+CIPSEND ,tap CTRL+Z to send data delay(3000); Response(); GPRS.println("AT+CIPCLOSE"); // Close TCP connection Response();

Graph showing change of temperature and humidity :

GprsTest.zip (5.23 KB)

it’s cool~

Hello,

i have problems with this script,
My APN is rigt but an error encour.
But the upload is running, but not ervery run.

If the APN is ok, the upload had errors.

Best regards

AP