GPRS/GSM Quadband (SIM900) shield for Raspberry Pi Tutorial
Tutorial Index
- Introduction
- Step 1: The GPRS/GSM shield (hardware)
- Step 2: Using GSM/GPRS module with AT commands
- Step 3: Powering the board
- Step 4: Using the shield in standalone mode - Calls
- Step 5: Using the shield in standalone mode - Sending and receiving SMS
- Step 6: Using the shield in standalone mode - FTP
- Step 7: Using the shield in standalone mode - TCP and UDP
- Step 8: Using the shield in standalone mode - HTTP
- Links and Documentation
Introduction
Ingredients:
- 1 x Raspberry Pi
- 1 x GPRS SIM900 shield for Raspberry Pi
- 1 x GPRS antenna
- 1 x SIM card
NOTE: If you don't have a Raspberry Pi you can get one buying a Raspberry Pi Starter Kit.
Difficulty: Medium - 
Preparation Time: 45 minutes

NOTE: All the code examples in this tutorial use the arduPi library. You can see the documentation and download the library here.
NOTE: If you are looking for a complete solution to use 3G, GPRS and A-GPS, you can use our 3G/GPRS shield for Arduino/Raspberry Pi (3G + GPRS) or our Kit with Audio/Video
Step 1: The shield (hardware)
The board (shield) we are going to use in this tutorial is the GPRS/GSM Quadband Module (SIM900) for Arduino/Raspberry Pi from Cooking hacks.
The GPRS shield is fully compatible with old Arduino USB versions, Duemilanove and Mega.
GPRS Shield diagram version 2:
NOTE: The Arduino/Raspberry Pi jumper MUST be in Raspberry Pi position. The Raspberry Pi position should be used only if the shield is connected to a Raspberry Pi.
A wrong position of this jumper can damage the GPRS shield.
GPRS Shield diagram version 1:
Step 2: Using GSM/GPRS module with AT commands
Important issues:
- Use capital letters for AT commands.
- Send CR (Carriage return) and LF (Line feed) after the AT command.
- Place the serial communication jumpers in the right position.
- Use an external power supply and place the power jumpers in the right position. If the shield is powered from the Raspberry Pi, the power jumper must be in Arduino 5V position. It the shield is powered from the Vin input (in the shield), the power jumper must be in Vext position.
The first thing we are going to do with the module is to check the basic AT commands. In this case, serial communication jumpers have to be set on USB gateway position.
Basic configuration:
Connect the GPRS/GSM shield to the Raspberry Pi to Arduino shield.
Then introduce the SIM card in the GPRS/GSM shield.
Finally open on the Raspberry a serial port terminal to communicate with the GPRS/GSM shield (just run cutecom in a terminal). This step can be done directly on ther Raspberry with a keyboard, mouse and screen plugged, or via ssh exporting X (e.g: ssh -X pi@<ip adress of raspberry>)
Be sure that you are sending CR (Carriage return) and LF (Line Feed).
Set the baudrate to 115200 bps and open the serial port, then press the ON button for two seconds. Then if you type AT you'll get OK, this means that the communication with the module is working fine. Now, with the module working you can check some AT commands to control the module, the basic commands are:
Important type commands in capital letters and with CR (carriage return) and LF (line feed)!!!
| Command | Response | Description |
| AT | OK | If you get OK, the communication with the module is working |
| AT+CPIN="****" | OK | If the SIM card is locked with PIN (**** is the pin number) |
| AT+COPS? | Operator information |
Note
Factory baudrate setting is auto-bauding by default. Baudrate can be fixed using the command AT+IPR=baudrate . Allowed baudrates: 0 (Auto-bauding) , 1200 , 2400 , 4800 , 9600 , 19200 , 38400 , 57600 and 115200 ;
All the AT commands here
Step 3: Powering the board:
Probably the Raspberry Pi is not able to give all the current the module needs to work, if your module goes down when it tries to connect to the network, you can use an external power supply (12V - 2A) on the shield.
Remember set the power switch of the Raspberry to arduino shield to EXT (switch closer to Raspberry Pi logo).
How to set the power jumper in the GPRS/GSM shield?.
If you want that the shield takes power from Raspberry => Set the jumper to Arduino 5V possition
If you want the GPRS/GSM shield takes power from an external supply => Set the jumper to V ext. possition
For powering the shield from external supply, you have to use V in ext. connector (Vin + GND).
If you use a power supply with output smaller than 2 A, you should add an extra capacitor for the power.
For example, a 220 uF electrolytic capacitor between 3.3V and GND.
Step 4: Using the shield in standalone mode - Calls
Originating and receiving voice calls
The code example and the connection diagram shown below are used to originate a voice call and, pushing a button, end that voice call. The button is connected between digital pin 7 an ground. A 10kΩ pull-up resistor is needed at this pin.
/*
* Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Version 0.1
* Author: Alejandro Gállego
*/
//Include ArduPi library
#include "arduPi.h"
void switchModule(); //Declaration of an aditonal function apart from setup() and loop();
int led = 9;
int button = 8;
int onModulePin = 2; // the pin to switch on the module (without press on button)
int timesToSend = 1; // Numbers of calls to make
int count=0;
char phone_number[]="*********"; // ********* is the number to call
void switchModule(){
digitalWrite(onModulePin,HIGH);
delay(2000);
digitalWrite(onModulePin,LOW);
}
void setup(){
Serial.begin(115200); // UART baud rate
delay(2000);
pinMode(button, INPUT);
pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);
for (int i=0;i < 5;i++){
delay(1000);
}
}
void loop(){
while (count < timesToSend){
Serial.print("ATD");
Serial.print(phone_number);
Serial.println(";");
while(digitalRead(button)==1);
Serial.println("ATH"); // disconnects the existing call
delay(5000);
count++;
}
}
int main (){
setup();
while(1){
loop();
}
return (0);
}
To make a lost call next code is used.
/*
* Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Version 0.1
* Author: Alejandro Gállego
*/
//Include ArduPi library
#include "arduPi.h"
void switchModule(); //Declaration of an aditonal function apart from setup() and loop();
int led = 9;
int onModulePin = 2; // the pin to switch on the module (without press on button)
int timesToSend = 1; // Numbers of calls to make
int count = 0;
int tones = 5; //Each tone has a duration of 6 seconds aprox.
char phone_number[]="*********"; // ********* is the number to call
void switchModule(){
digitalWrite(onModulePin,HIGH);
delay(2000);
digitalWrite(onModulePin,LOW);
}
void setup(){
Serial.begin(115200); // UART baud rate
delay(2000);
pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);
switchModule(); // switches the module ON
for (int i=0;i < 5;i++){
delay(5000);
}
}
void loop(){
while (count < timesToSend){
Serial.print("ATD");
Serial.print(phone_number);
Serial.println(";");
delay(6000*tones);
Serial.println("ATH"); // cancel the call
delay(5000);
count++;
}
}
int main (){
setup();
while(1){
loop();
}
return (0);
}
To receive calls the used code are this and the connection diagram is the same that the used to originate calls. Don't forget the pull-up resistor on pin 12.
Command summary
| Command | Response | Description |
|---|---|---|
| ATD*********; | ********* is the number to call. | |
| ATA | OK | Answer an incoming call. |
| ATH | OK | Cancel voice calls. |
Step 5: Using the shield in standalone mode - Sending and receiving SMS
The first code is used to send a SMS, the second one reads the first SMS into the memory.
/*
* Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Version 0.1
* Author: Alejandro Gállego
*/
//Include ArduPi library
#include "arduPi.h"
void switchModule();
int led = 9;
int onModulePin = 2; // the pin to switch on the module (without press on button)
int timesToSend = 1; // Numbers of SMS to send
int count = 0;
char phone_number[]="*********"; // ********* is the number to call
void switchModule(){
digitalWrite(onModulePin,HIGH);
delay(2000);
digitalWrite(onModulePin,LOW);
}
void setup(){
Serial.begin(115200); // UART baud rate
delay(2000);
pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);
switchModule(); // switches the module ON
for (int i=0;i < 5;i++){
delay(5000);
}
Serial.println("AT+CMGF=1"); // sets the SMS mode to text
delay(100);
}
void loop(){
while (count < timesToSend){
delay(1500);
Serial.print("AT+CMGS=\""); // send the SMS number
Serial.print(phone_number);
Serial.println("\"");
while(Serial.read()!='>');
Serial.print("Hola caracola..."); // the SMS body
delay(500);
Serial.write(0x1A); //sends ++
Serial.write(0x0D);
Serial.write(0x0A);
delay(5000);
count++;
}
}
int main (){
setup();
while(1){
loop();
}
return (0);
}
/*
* Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Version 0.1
* Author: Alejandro Gállego
*/
//Include ArduPi library
#include "arduPi.h"
void switchModule();
int led = 9;
int onModulePin = 2; // the pin to switch on the module (without press on button)
int timesToSend = 1; // Numbers of SMS to send
int count = 0;
int n_sms,x,sms_start;
char data[256];
void switchModule(){
digitalWrite(onModulePin,HIGH);
delay(2000);
digitalWrite(onModulePin,LOW);
}
void setup(){
Serial.begin(115200); // UART baud rate
delay(2000);
pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);
switchModule(); // switches the module ON
for (int i=0;i < 5;i++){
delay(5000);
}
Serial.println("AT+CMGF=1"); // sets the SMS mode to text
delay(1000);
}
void loop(){
Serial.println("AT+CMGR=1"); //Reads the first SMS
Serial.flush();
for (x=0;x < 255;x++){
data[x]='\0';
}
x=0;
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
if(data[x-1]==0x0D&&data[x-2]=='"'){
x=0;
}
}while(!(data[x-1]=='K'&&data[x-2]=='O'));
data[x-3]='\0'; //finish the string before the OK
Serial.println(data); //shows the message
delay(5000);
}
int main (){
setup();
while(1){
loop();
}
return (0);
}
Command summary
| Command | Response | Description |
|---|---|---|
| AT+CMGF= | OK | Specifies the input and output format of the short messages. 0 for PDU mode and 1 for text mode. |
| AT+CMGS | Sends a message. | |
| AT+CMGR=* | Reads a message. * is the number of the message. |
Step 6: Using the shield in standalone mode - FTP
Creating a file into the FTP server, writing it and reading it.
/*
* Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Version 0.1
* Author: Alejandro Gállego
*/
//Include ArduPi library
#include "arduPi.h"
void switchModule();
int led = 9;
int onModulePin = 2; // the pin to switch on the module (without press on button)
char data[1024];
int x=0;
int data_size;
char aux;
void switchModule(){
digitalWrite(onModulePin,HIGH);
delay(2000);
digitalWrite(onModulePin,LOW);
}
void setup(){
Serial.begin(115200); // UART baud rate
delay(2000);
pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);
switchModule(); // switches the module ON
for (int i=0;i < 4;i++){
delay(5000);
}
Serial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\""); //Configures GPRS connection
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+SAPBR=3,1,\"APN\",\"myAPN\"");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+SAPBR=1,1");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+FTPCID=1"); //Selects profile 1 for FTP operations
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+FTPSERV=\"FTP_IP_dir\""); //Configures FTP parameters
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+FTPPORT=port_number");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+FTPUN=\"username\"");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+FTPPW=\"password\"");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
}
void loop(){
Serial.println("AT+FTPPUTNAME=\"filename.extension\""); //Sets destiny file name
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+FTPPUTPATH=\"/\""); //Sets destiny file path
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+FTPPUT=1"); //Starts session
do{
while(Serial.available()==0);
}while(Serial.read()!=',');
do{
while(Serial.available()==0);
}while(Serial.read()!=',');
delay(100);
data_size=0;
while(Serial.available()==0);
aux=Serial.read();
do{
data_size*=10;
data_size+=(aux-0x30);
while(Serial.available()==0);
aux=Serial.read();
}while(aux!=13);
Serial.println("AT+FTPPUT=2,100"); //Sends data
do{
while(Serial.available()==0);
}while(Serial.read()!='+');
do{
while(Serial.available()==0);
}while(Serial.read()!='\r');
delay(100);
Serial.print("0000000011111111222222223333333344444444555555556666666677777777000000001111111122222222333333334444");
do{
while(Serial.available()==0);
}while(Serial.read()!='+');
do{
while(Serial.available()==0);
}while(Serial.read()!='\r');
delay(100);
Serial.println("AT+FTPPUT=2,0"); //Closes the file and the session
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
do{
while(Serial.available()==0);
}while(Serial.read()!='+');
delay(100);
Serial.println("AT+FTPGETNAME=\"filename.extension\""); //Sets file name to download
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+FTPGETPATH=\"/\""); //Sets file path to download
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+FTPGET=1"); //Starts session
do{
while(Serial.available()==0);
}while(Serial.read()!=',');
delay(100);
Serial.println("AT+FTPGET=2,512"); //Request data
do{
while(Serial.available()==0);
}while(Serial.read()!=',');
do{
while(Serial.available()==0);
}while(Serial.read()!=',');
delay(100);
data_size=0;
while(Serial.available()==0);
aux=Serial.read(); //Gets data length
do{
data_size*=10;
data_size+=(aux-0x30);
while(Serial.available()==0);
aux=Serial.read();
}while(aux!=13);
for(x=0;x<=data_size;x++){ //Gets data string
while(Serial.available()==0);
data[x]=Serial.read();
}
do{
while(Serial.available()==0);
}while(Serial.read()!=':');
delay(100);
Serial.print(data);
while(1);
}
int main (){
setup();
while(1){
loop();
}
return (0);
}
Command summary
| AT command | Response | Description |
|---|---|---|
| AT+SAPBR | OK | Configures GPRS profile. |
| AT+FTPCID=1 | OK | Selects profile 1 for FTP. |
| AT+FTPSERV=”****” | OK | Sets FTP server domain name or IP address. **** is the domain name or the IP. |
| AT+FTPPORT=*** | OK | Sets FTP server port. *** is the port. |
| AT+FTPUN=”***” | OK | Sets user name for FTP server access. *** is the user name. |
| AT+FTPPW=”***” | OK | Sets password for FTP server access. *** is the password. |
| AT+FTPPUTNAME="****" | OK | Sets destiny name for the file.*** is the name of the file. |
| AT+FTPPUTPATH="****" | OK | Sets destiny file path. *** is the path of the file. |
| AT+FTPPUT | OK | Use to put a file into the FTP server. |
| AT+FTPGETNAME="****" | OK | Sets origin name for the file.*** is the name of the file. |
| AT+FTPGETPATH="****" | OK | Sets origin file path. *** is the path of the file. |
| AT+FTPGET | Use to get a file into the FTP server. |
Step 7: Using the shield in standalone mode - TCP and UDP
Single client
Sending data to a TCP server first, and then it sends to a UDP server.
/*
* Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Version 0.1
* Author: Alejandro Gállego
*/
//Include ArduPi library
#include "arduPi.h"
void switchModule();
int led = 9;
int onModulePin = 2; // the pin to switch on the module (without press on button)
char data[1024];
int x = 0;
char name[20];
char server[ ]="";
char port[ ]="";
void switchModule(){
digitalWrite(onModulePin,HIGH);
delay(2000);
digitalWrite(onModulePin,LOW);
}
void setup(){
Serial.begin(115200); // UART baud rate
delay(2000);
pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);
switchModule(); // switches the module ON
for (int i=0;i < 4;i++){
delay(5000);
}
Serial.println("AT+CIPMUX=0"); //single connection
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+CSTT=\"myAP\"");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+CIICR");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+CIFSR");
do{
while(Serial.available()==0);
}while(Serial.read()!='.');
do{
while(Serial.available()==0);
}while(Serial.read()!='\n');
delay(100);
Serial.println("AT+CIPSTART=\"TCP\",\"IP_dir\",\"port\"");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
do{ //waits for connection
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+CIPSEND"); //sending data
do{
while(Serial.available()==0);
}while(Serial.read()!='>');
delay(100);
Serial.print("Data test!");
Serial.write(0x1A); //EOL character
Serial.write(0x0D);
Serial.write(0x0A);
delay(100);
Serial.println("AT+CIPCLOSE");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+CIPSTART=\"UDP\",\"IP_dir\",\"port\"");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
do{ //waits for connection
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+CIPSEND"); //sending data
do{
while(Serial.available()==0);
}while(Serial.read()!='>');
delay(100);
Serial.print("Data test!");
Serial.write(0x1A); //EOL character
Serial.write(0x0D);
Serial.write(0x0A);
delay(100);
Serial.println("AT+CIPCLOSE");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
}
void loop()
{
delay(500);
digitalWrite(led,HIGH);
delay(500);
digitalWrite(led,LOW);
}
int main (){
setup();
while(1){
loop();
}
return (0);
}
Multiple client
SIM900 allows to use 8 connections simultaneously. Here is the example code with a UDP and TCP connections.
/*
* Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Version 0.1
* Author: Alejandro Gállego
*/
//Include ArduPi library
#include "arduPi.h"
void switchModule();
int led = 9;
int onModulePin = 2; // the pin to switch on the module (without press on button)
char data[1024];
int x = 0;
char name[20];
char server[ ]="";
char port[ ]="";
void switchModule(){
digitalWrite(onModulePin,HIGH);
delay(2000);
digitalWrite(onModulePin,LOW);
}
void setup(){
Serial.begin(115200); // UART baud rate
delay(2000);
pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);
switchModule(); // switches the module ON
for (int i=0;i < 4;i++){
delay(5000);
}
Serial.println("AT+CIPMUX=1"); //multiple connection
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+CSTT=\"myAPN\"");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+CIICR");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+CIFSR");
do{
while(Serial.available()==0);
}while(Serial.read()!='.');
do{
while(Serial.available()==0);
}while(Serial.read()!='\n');
delay(100);
Serial.println("AT+CIPSTART=0,\"TCP\",\"IP_dir\",\"port\""); //TCP connection in id 0
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
do{ //waits for connection
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+CIPSTART=1,\"UDP\",\"IP_dir\",\"port\""); //UDP connection in id 1
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
do{ //waits for connection
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+CIPSEND=0"); //sending data
do{
while(Serial.available()==0);
}while(Serial.read()!='>');
delay(100);
Serial.print("Data test!");
Serial.write(0x1A); //EOL character
Serial.write(0x0D);
Serial.write(0x0A);
delay(100);
Serial.println("AT+CIPSEND=1"); //sending data
do{
while(Serial.available()==0);
}while(Serial.read()!='>');
delay(100);
Serial.print("Data test!");
Serial.write(0x1A); //EOL character
Serial.write(0x0D);
Serial.write(0x0A);
delay(100);
Serial.println("AT+CIPCLOSE=0");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+CIPCLOSE=1");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
}
void loop()
{
delay(500);
digitalWrite(led,HIGH);
delay(500);
digitalWrite(led,LOW);
}
int main (){
setup();
while(1){
loop();
}
return (0);
}
Command summary
| AT command | Response | Description |
|---|---|---|
| AT+CIPMUX= | OK | Selects single connection (0) or multiple connection (1) |
| AT+CSTT="myAPN" | OK | Sets APN |
| AT+CIICR | Brings up wireless connection | |
| AT+CIFSR | Get local IP address | |
| AT+CIPSTART | Establishes a connection with a server. | |
| AT+CIPSEND | Sends data when the a connection is established. | |
| AT+CIPCLOSE | Closes the connection |
Step 8: Using the shield in standalone mode - HTTP
SIM900 can launch a HTTP operation like GET or POST. Here is an example with GET operation:
/*
* Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Version 0.1
* Author: Alejandro Gállego
*/
//Include ArduPi library
#include "arduPi.h"
void switchModule();
int led = 9;
int onModulePin = 2; // the pin to switch on the module (without press on button)
char data[1024];
int data_size;
char aux;
int x = 0;
void switchModule(){
digitalWrite(onModulePin,HIGH);
delay(2000);
digitalWrite(onModulePin,LOW);
}
void setup(){
Serial.begin(115200); // UART baud rate
delay(2000);
pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);
digitalWrite(led,LOW);
switchModule(); // switches the module ON
for (int i=0;i < 5;i++){
delay(5000);
}
Serial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\""); //Sets GPRS parameters
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+SAPBR=3,1,\"APN\",\"myAPN\"");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+SAPBR=1,1");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+HTTPINIT");
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+HTTPPARA=\"CID\",1"); //Sets GPRS profile to use with HTTP
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
}
void loop()
{
Serial.println("AT+HTTPPARA=\"URL\",\"www.libelium.com\""); //Sets URL direction
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
Serial.println("AT+HTTPACTION=0"); //Connects with the HTTP server, this action can need to wait a several time
x=0;
do{
while(Serial.available()==0);
}while(Serial.read()!=',');
do{
while(Serial.available()==0);
}while(Serial.read()!='\r');
delay(100);
Serial.println("AT+HTTPREAD=0,200"); //Reads 200 bytes from byte 0
do{
while(Serial.available()==0);
}while(Serial.read()!=':');
data_size=0;
while(Serial.available()==0);
aux=Serial.read();
do{
data_size*=10;
data_size+=(aux-0x30);
while(Serial.available()==0);
aux=Serial.read();
}while(aux!='\r');
do{
while(Serial.available()==0);
}while(Serial.read()!='\n');
for(x=0;x<=data_size;x++){
while(Serial.available()==0);
data[x]=Serial.read();
}
Serial.println("AT+HTTPTERM"); //Closes the opened HTTP session
do{
while(Serial.available()==0);
}while(Serial.read()!='K');
delay(100);
printf("%s",data); //Shows data
}
int main (){
setup();
loop(); //Run the loop only 1 time
return (0);
}
Command summary
| AT command | Response | Description |
|---|---|---|
| AT+SAPBR | OK | Configures GPRS profile |
| AT+HTTPINIT | OK | Initializes HTTP service |
| AT+HTTPPARA | OK | Configures HTTP parameters |
| AT+HTTPACTION=0 | OK | Sets HTTP Method Action , GET in this chase. |
| AT+HTTPREAD | Reads HTTP data | |
| AT+HTTPTERM | OK | Closes the opened HTTP session. |
Links and Documentation
NOTE: If you are looking for a complete solution to use 3G, GPRS and A-GPS, you can use our 3G/GPRS shield for Arduino (3G + GPRS) or our Kit with Audio/Video





