So here's my code:
#include <String.h>
void setup()
{
Serial1.begin(9600); // the GPRS baud rate
Serial.begin(9600); // the GPRS baud rate
delay(500);
}
void loop()
{
//after start up the program, you can using terminal to connect the serial of gprs shield,
//if you input 't' in the terminal, the program will execute SendTextMessage(), it will show how to send a sms message,
//if input 'd' in the terminal, it will execute DialVoiceCall(), etc.
if (Serial.available())
switch(Serial.read())
{
case 't':
SendTextMessage();
break;
case 's':
Send2Pachube();
break;
}
if (Serial1.available())
Serial.write(Serial1.read());
}
///SendTextMessage()
///this function is to send a sms message
void SendTextMessage()
{
Serial1.print("AT+CMGF=1\r"); //Because we want to send the SMS in text mode
delay(100);
Serial1.println("AT + CMGS = \"+919003109999 \"");//send sms message, be careful need to add a country code before the cellphone number
delay(100);
Serial1.println("A test message!");//the content of the message
delay(100);
Serial1.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
Serial1.println();
}
///send2Pachube()///
///this function is to send the sensor data to the pachube, you can see the new value in the pachube after execute this function///
void Send2Pachube()
{
Serial1.println("AT+CGATT?");
delay(1000);
ShowSerialData();
Serial1.println("AT+CSTT:\"airtelgprs.com\"");//start task and setting the APN,
delay(1000);
ShowSerialData();
Serial1.println("AT+CIICR");//bring up wireless connection
delay(3000);
ShowSerialData();
Serial1.println("AT+CIFSR");//get local IP adress
delay(2000);
ShowSerialData();
Serial1.println("AT+CIPSPRT=0");
delay(3000);
ShowSerialData();
Serial1.println("AT+CIPSTART=\"tcp\",\"api.xively.com\",\"8081\"");//start up the connection
delay(2000);
ShowSerialData();
Serial1.println("AT+CIPSEND");//begin send data to remote server
delay(4000);
ShowSerialData();
String humidity = "1031";//these 4 line code are imitate the real sensor data, because the demo did't add other sensor, so using 4 string variable to replace.
String moisture = "1242";//you can replace these four variable to the real sensor data in your project
String temperature = "30";//
String barometer = "60.56";//
Serial1.print("{\"method\": \"put\",\"resource\": \"/feeds/FEED_ID/\",\"params\"");//here is the feed you apply from pachube
delay(500);
ShowSerialData();
Serial1.print(": {},\"headers\": {\"X-ApiKey\":");//in here, you should replace your pachubeapikey
delay(500);
ShowSerialData();
Serial1.print("\"API_KEY""},\"body\":");
delay(500);
ShowSerialData();
Serial1.print(" {\"version\": \"1.0.0\",\"datastreams\": ");
delay(500);
ShowSerialData();
Serial1.println("[{\"id\": \"01\",\"current_value\": \"" + barometer + "\"},");
delay(500);
ShowSerialData();
Serial1.println("{\"id\": \"02\",\"current_value\": \"" + humidity + "\"},");
delay(500);
ShowSerialData();
Serial1.println("{\"id\": \"03\",\"current_value\": \"" + moisture + "\"},");
delay(500);
ShowSerialData();
Serial1.println("{\"id\": \"04\",\"current_value\": \"" + temperature + "\"}]}}");
delay(500);
ShowSerialData();
Serial1.println((char)26);//sending
delay(5000);//waitting for reply, important! the time is base on the condition of internet
Serial1.println();
ShowSerialData();
Serial1.println("AT+CIPCLOSE");//close the connection
delay(100);
ShowSerialData();
}
void ShowSerialData()
{
while(Serial1.available()!=0)
Serial.write(Serial1.read());
}
And this is my output, on running the send function
"status":400,"body":"Syntax Error: lexical error
I also get an error message for AT+CSTT:"airtelgprs.com" but i get a response from the server.
The code is from here:
http://www.seeedstudio.com/wiki/GPRS_Shield_V1.0