SIM900 gprs web with arduino - arduino

I have a problem with this simple code.
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8); // configure software serial port
void setup() {
pinMode(9, OUTPUT);
digitalWrite(9, HIGH);
SIM900.begin(19200);
Serial.begin(19200);
Serial.println("power up" );
delay(15000);
}
void loop()
{
Serial.println("SubmitHttpRequest - started" );
SubmitHttpRequest();
//callSomeone();
Serial.println("SubmitHttpRequest - finished" );
delay(10000);
}
void SubmitHttpRequest()
{
SIM900.println("AT+CSQ"); // Signal quality check
delay(100);
ShowSerialData();
SIM900.println("AT+CSQ"); // Signal quality check
delay(100);
ShowSerialData();
SIM900.println("AT+CGATT?"); //Attach or Detach from GPRS Support
delay(100);
ShowSerialData();
SIM900.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
delay(1000);
ShowSerialData();
SIM900.println("AT+SAPBR=3,1,\"APN\",\"gprs-service.com\"");
delay(1000);
ShowSerialData();
SIM900.println("AT+SAPBR=1,1");
delay(1000);
ShowSerialData();
SIM900.println("AT+HTTPINIT"); //init the HTTP request
delay(1000);
ShowSerialData();
SIM900.print("AT+HTTPPARA=\"URL\",\"http://xxxxxx.com/master.php");
SIM900.println("\"");
delay(1000);
ShowSerialData();
SIM900.println("AT+HTTPACTION=0");//submit the request
delay(10000);
ShowSerialData();
SIM900.println("AT+HTTPREAD");// read the data from the website you access
delay(500);
ShowSerialData();
SIM900.println("");
delay(100);
SIM900.println("AT+HTTPTERM");// read the data from the website you access
delay(300);
ShowSerialData();
}
void getContent()
{
String content = "";
while(SIM900.available() != 0)
{
content = content + String(char(SIM900.read()));
Serial.write(char(SIM900.read()));
delay(500);
Serial.flush();
}
}
void ShowSerialData()
{
while(SIM900.available()!=0)
Serial.write(char (SIM900.read()));
}
Receipt few characters, the output is this:
power up
SubmitHttpRequest - started
AT+CSQ
+CSQ: 25,0
OK
AT+CSQ
+CSQ: 25,0
OK
AT+CGATT?
+CGATT: 1
OK
AT+SAPBR=3,1,"CONTYPE","GPRS"
OK
AT+SAPBR=3,1,"APN","gprs-service.com"
OK
AT+SAPBR=1,1
OK
AT+HTTPINIT
OK
AT+HTTPPARA="URL","http://xxxxxx.com/master.php"
OK
AT+HTTPACTION=0
OK
+HTTPACTION:0,200,66
AT+HTTPREAD
+HTTPREAD:66
Numero de accesos: 77 | Identifica
AT+HTTPTERM
OK
SubmitHttpRequest - finished
==> "Numero de accesos: 77 | Identifica"
But, realy, the output should be:
Numero de accesos: 77 | Identificador: 4l02pnl828o3kctg4strc87ed1
Exactly like: HTTPREAD missing characters with Arduino and SIM900
Any ideas or help?
Thanks!

Numero de accesos: 77 | Identifica is 34 charcters. This means that sim900 gives back 66 characters which is the correct length.
Try to increase the delay before ShowSerialData or wait until you have 66 bytes in serial buffer.

Related

Arduino + SIM800A messages get cut-off

I am working with Arduino and SIM800A. My goal is to save the sms message received by SIM800A to a string variable to be used later. Yet to my surprise, the message always get cut off and I have no clue why.
I send to SIM:
This is a test message
The Serial Monitor only shows:
+CMT: "+XXXXXXXXXX","","21/02/20,01:52:40+28"
This is a tes
Below is the code
#include <SoftwareSerial.h>
// Configure software serial port
SoftwareSerial Sim(2, 3);
// Variable to store text message
char incomingMessage;
String textMessage;
void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
// Initializing serial commmunication
Serial.begin(9600);
Sim.begin(9600);
delay(100);
while (!Sim.available()) {
Sim.println("AT");
delay(200);
Serial.println("Connecting...");
}
Serial.println("Connected!");
Sim.println("AT+CMGF=1"); //Set SMS to Text Mode
delay(200);
// Sim.println("AT+CMGL=\"ALL\"");
// delay(500);
Sim.println("AT+CNMI=1,2,0,0,0"); //Procedure to handle newly arrived messages(command name in text: new message indications to TE)
delay(1000);
Sim.read();
//Sim.println("AT+CMGL=\"REC UNREAD\""); // Read Unread Messages
}
void loop() {
if (Sim.available()>0) {
delay(200);
// Serial Buffer
while (Sim.available()>0) {
incomingMessage = Sim.read();
textMessage += incomingMessage;
}
delay(500);
Serial.println(textMessage);
textMessage = "";
}
}

Arduino UNO & Modem Sim800L Can't write setup commands to send data to server

I am using arduino UNO board, with modem sim800l. I want use it to send data to server, but the problem is that I can't write the setup commands.
What am I doing wrong? Are not this the right commands to use for sim800l?
I've tried with different commands and the output is the same.
#include <SoftwareSerial.h>
//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
//Begin serial communication with Arduino and SIM800L
mySerial.begin(9600);
Serial.println("Initializing...");
delay(100);
delay(1000);
mySerial.println("AT+CMEE=2"); // Error mode
delay(100);
updateSerial();
mySerial.println("AT"); //Once the handshake test is successful, i t will back to OK
delay(100);
updateSerial();
mySerial.println("AT+CFUN=1"); //Level "full functionality"
delay(100);
updateSerial();
mySerial.println("AT+CGATT?"); //attach or detach from GPRS service
delay(100);
updateSerial();
mySerial.println("AT+CSTT=\"net\",\"\",\"\""); //AT+CSTT AT command sets up the apn, user name and password for the PDP context.
delay(2000);
updateSerial();
mySerial.println("AT+CSTT?"); //AT+CSTT show apn
delay(2000);
updateSerial();
mySerial.println("AT+CIICR"); // Brings up wireless connection
delay(2000);
updateSerial();
mySerial.println("AT+CIFSR"); // Get local IP address if connected
delay(2000);
updateSerial();
}
Here is the output from the console of Arduino IDE:
Initializing...
AT+CHEE=2
OK
AT
OK
AT+CFUN=1
OK
AT+CGAIT?
+CGATT: 1
OK
AT+CSTT="net","",""
+CME ERROR: operation not allowed
AT+CSTT?
+CSTT: "CMNET","",""
OK
AT+CIICR
+CME ERROR: operation not allowed
AT+CIFSR
+CME ERROR: operation not allowed
You have my sympathies, it took me weeks to get my Arduino talking to the net. I think your problem is happening on the line containing "CSTT", which I don't think SIM800L recognises.
Try the below setup instead, with "SAPBR" in its place:
SoftwareSerial gprsSerial(7, 8); // working here with Arduino ports 7 and 8
void setup() {
gprsSerial.begin(19200);
Serial.begin(19200);
Serial.println("connect to GPRS");
gprsSerial.println("AT");
toSerial();
gprsSerial.println("AT+CREG?");
toSerial();
gprsSerial.println("AT+CGATT?");
toSerial();
gprsSerial.println("AT+CSQ ");
toSerial();
gprsSerial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
delay(2000);
toSerial();
gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"" + String(APN) + "\"");
delay(300);
gprsSerial.println("AT+SAPBR=3,1,\"USER\",\"" + String(USER) + "\"");
delay(300);
gprsSerial.println("AT+SAPBR=3,1,\"PWD\",\"" + String(PWD) + "\"");
delay(1000);
toSerial();
gprsSerial.println("AT+SAPBR=1,1");
delay(2000);
toSerial();
gprsSerial.println("AT+SAPBR=2,1");
delay(2000);
toSerial();
}
Your run loop:
void loop(){
// Do your stuff
}
And your toSerial function:
void toSerial()
{
delay(200);
if(gprsSerial.available()>0){
textMessage = gprsSerial.readString();
delay(100);
Serial.print(textMessage);
}
}
Your call server function should be like this:
void callServer() {
Serial.println("Calling server");
gprsSerial.println("AT+CCLK?");
toSerial();
gprsSerial.println("AT+HTTPINIT");
toSerial();
gprsSerial.println("AT+HTTPPARA=\"CID\",1");
toSerial();
gprsSerial.println("AT+HTTPPARA=\"URL\",\"http:[YOURURL]") // NOTE: NOT HTTPS!
delay(1000);
toSerial();
gprsSerial.println("AT+HTTPACTION=0");
delay(3000);
toSerial();
gprsSerial.println("AT+HTTPREAD");
delay(3000);
toSerial();
}
The sequence of send commands to set up TCP/IP connection:
//Check the registration status
AT+CREG?
//Check attach status
AT+CGACT?
//Attach to the network
AT+CGATT=1
//Wait for Attach
WAIT=7
//Start task ans set the APN. Check your carrier APN
AT+CSTT="bluevia.movistar.es" // Here you havve net which I guess is not a NetworkAPN you have to use the APN from your provider (= sim card)
//Bring up the wireless connection
AT+CIICR
//Wait for bringup
WAIT=6
//Get the local IP address
AT+CIFSR
//Start a TCP connection to remote address. Port 80 is TCP.
AT+CIPSTART="TCP","74.124.194.252","80"
//Set prompt of '>' when module sends data
AT+CIPSPRT=1
//Send the TCP data
AT+CIPSEND
If you want to test quickly a stable setup use this 7 days free to use tool for SIM800, SIM900 and then copy the succesfull process into code.

POST request to firebase functions with sim900 arduino

Im trying to send POST request with sim900 connected to arduino uno.
I send it to firebase functions but I dont get it in the function.
I will be happy to get solution for my problem,
or alternative way that i can store data from sensors to firebase with sim900 or any other celular network solution).
arduino code:
#include<SoftwareSerial.h>
SoftwareSerial client(7,8);
String reading="{ \"testID\" : 1, }";
void setup()
{
Serial.begin(9600);
client.begin(9600);
delay(500);
if(client.available())
{
Serial.println("Connected");
}
else
{
Serial.println("NotConnected");
}
//initSIM();
connectGPRS();
connectHTTP();
}
void loop()
{
}
void connectGPRS()
{
client.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
delay(1000);
ShowSerialData();
client.println("AT+SAPBR=3,1,\"APN\",\"www\"");//APN
delay(1000);
ShowSerialData();
client.println("AT+SAPBR=1,1");
delay(1000);
ShowSerialData();
client.println("AT+SAPBR=2,1");
delay(1000);
ShowSerialData();
}
void connectHTTP()
{
client.println("AT+HTTPINIT");
delay(1000);
ShowSerialData();
client.println("AT+HTTPPARA=\"CID\",1");
delay(1000);
ShowSerialData();
client.println("AT+HTTPPARA=\"URL\",\"www.us-central1-**************.cloudfunctions.net/helloWorld\"");//Public server IP address
delay(1000);
ShowSerialData();
client.println("AT+HTTPPARA=\"CONTENT\",\"application/json\"");
delay(1000);
ShowSerialData();
client.println("AT+HTTPDATA=" + String(reading.length()) + ",100000");
delay(1000);
ShowSerialData();
client.println(reading);
delay(1000);
ShowSerialData;
client.println("AT+HTTPACTION=1");
delay(1000);
ShowSerialData();
client.println("AT+HTTPREAD");
delay(1000);
ShowSerialData();
client.println("AT+HTTPTERM");
delay(1000);
ShowSerialData;
}
void ShowSerialData()
{
while(client.available()!=0)
{
Serial.write(client.read());
delay(100);
}
}
firebase function:
const functions = require('firebase-functions');
// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
// Check for POST request
if (request.method !== "POST") {
console.log('Please send a POST request');
}
if (request.method !== "GET") {
console.log('Please send a GET request');
}
let data = request.body;
console.log(`Hello from Firebase! ${JSON.stringify(data)}`);
// console.log('testing: ' + data[0]);
// console.log('testing: ' + data.longitude);
// console.log('testing: ' + data['longitude']);
});
Thank you all!
This is by no means a definitive solution but should work on most SIM modules but make sure you have up to date firmware for SSL connection.
This is only a snip of code from my project, you can only POST, GET and DELETE using these SIM modules built in HTTP functions, there's no PUT and PATCH so a bit limited for Firebase.
This is very basic code so you may have to tweak some timing here and there. It will work a lot faster if you put code to check the responses, most delays are not necessary.
Try this command first:
AT+HTTPSSL=1
If you get an error you MUST update the module's firmware before using Firebase.
Firebase will only work with HTTPS connection.
// Firebase HTTPS connection, POST example
#define MODEM_TX 16
#define MODEM_RX 17
// Set serial for debug console (to Serial Monitor, default speed 115200)
#define SerialMon Serial
// Set serial for AT commands (to SIM808 module)
#define client Serial1
void setup()
{
SerialMon.begin(115200);
// Set GSM module baud rate and UART pins
client.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
delay(1000);
float tempIn = 21.5;
float humidity = 54.6;
float pressure = 1010.64;
char fbtimebuff[32] = "1:30 20/2/21";
char dataTEST[256];
char FirebaseUrl[300]; // dimension to suit required character space
const char FirebaseID[100] = "https://my-project-details.firebaseio.com"; // project ID
const char FirebaseAuth[100] = "YPXm66X-My-Big-Secrete-J9xsZsL"; // secret
strcpy(FirebaseUrl, FirebaseID); // Firebase account ID
strcat(FirebaseUrl, "/GPRS-Test/.json?auth="); // Parenet/child path + .json and auth
strcat(FirebaseUrl, FirebaseAuth);
sprintf(dataTEST, "{\"TempIn\" : \"%3.2f\",\"Humidity\" : \"%2.2f\",\"Pressure\" : \"%4.2f\",\"Time\" : \"%s\"}", tempIn, humidity, pressure, fbtimebuff);
// connect to GPRS network
SerialMon.printf("\n\nConnect to GPRS\n");
client.println("AT+CIPSHUT");
ShowSerialData();
delay(500);
client.println("AT+CGATT=1");
ShowSerialData();
delay(1000);
client.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
ShowSerialData();
delay(1000);
client.println("AT+SAPBR=1,1");
ShowSerialData();
delay(1000);
client.println("AT+SAPBR=2,1");
ShowSerialData();
delay(1000);
// post to Firebase
SerialMon.printf("post function to Firebase\n");
client.println("AT+HTTPINIT");
ShowSerialData();
delay(1000);
client.println("AT+HTTPSSL=1"); // set SSL for HTTPS
ShowSerialData();
delay(1000);
client.println("AT+HTTPPARA=\"CID\",1");
ShowSerialData();
delay(1000);
client.println("AT+HTTPPARA=\"URL\"," + String(FirebaseUrl));
ShowSerialData();
delay(1000); client.println("AT+HTTPPARA=\"CONTENT\",\"application/json\"");
ShowSerialData();
delay(1000);
int stlen = strlen(dataTEST);
SerialMon.printf("length: %d\n", stlen);
client.println("AT+HTTPDATA=" + String(stlen) + ",100000");
ShowSerialData();
delay(1000);
SerialMon.printf("set data\n");
client.println(dataTEST);
ShowSerialData();
delay(1000);
SerialMon.printf("POST data to Firebase\n");
client.println("AT+HTTPACTION=1");
ShowSerialData();
delay(6000);
client.println("AT+HTTPREAD");
ShowSerialData();
delay(1000);
SerialMon.printf("Dissconect\n");
client.println("AT+HTTPTERM");
ShowSerialData();
delay(1000);
// now disconnect from GPRS network
client.println("AT+CIPSHUT");
ShowSerialData();
delay(1000);
client.println("AT+SAPBR=0,1");
ShowSerialData();
delay(1000);
client.println("AT+CGATT=0");
ShowSerialData();
delay(1000);
}
void loop()
{
}

uploading sensor data to internet by arduino and sim900

I am using arduino mega 2650, sim 900 GSM/GPRS module and 2 xbee (version 2) modules. Temperature sensor sends data between the 2 xbees wireless, then upload this data to a web page using the sim900 but for a reason I cannot get the code working correctly.
#include <SoftwareSerial.h>
SoftwareSerial gprsSerial(7, 8);
int temp;
void setup(){
gprsSerial.begin(19200);
Serial.begin(9600);
Serial1.begin(19200);
Serial1.println("Config SIM900...");
delay(2000);
Serial1.println("Done!...");
gprsSerial.flush();
Serial1.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\",\"Umniah Internet\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=1,1");
delay(2000);
toSerial();
};
void loop(){
if (Serial.available() >= 21) {
if (Serial.read() == 0x7E) {
for (int i = 1; i < 19; i++) {
byte discardByte = Serial.read();
}
int analogMSB = Serial.read();
int analogLSB = Serial.read();
int analogReading = analogLSB + (analogMSB * 256);
temp = analogReading / 1023.0 * 1.23;
temp = temp - 0.5;
temp = temp / 0.01;
Serial.print(temp);
Serial.println(" degrees c");
// initialize http service
gprsSerial.println("AT+HTTPINIT");
delay(2000);
toSerial();
// set http param value
gprsSerial.println("AT+HTTPPARA= \"URL\" ,\"http://ar.ahu.edu.jo/sensor.aspx?Sens1=10&Sens2=0&Sens3=0\"");
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)
{
Serial1.write(gprsSerial.read());
}
}
Your code block below is supposed to read whatever received from GPRS modem .
void toSerial()
{
while(gprsSerial.available()!=0)
{
Serial1.write(gprsSerial.read());
}
}
Can you show us what you see on your serial monitor?
I am very new, but probably the mistake is on the ports election. Ports 7 and 8 are only available for Arduino UNO.
In this case you should work with ports 10 and 11:
SoftwareSerial gprsSerial(10, 11);

How to read an SMS from Arduino and get LED to switch on or off

#include <SoftwareSerial.h>
char inchar; //Will hold the incoming character from the serial port.
SoftwareSerial cell(2,3); //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.
int led1 = A2;
void setup()
{
// Prepare the digital output pins
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
//Initialize GSM module serial port for communication.
cell.begin(19200);
delay(30000); // Give time for GSM module to register on network, etc.
cell.println("AT+CMGF=1"); // Set SMS mode to text
delay(200);
cell.println("AT+CNMI=3,3,0,0"); // Set module to send SMS data to serial out upon receipt
delay(200);
}
void loop()
{
//If a character comes in from the cellular module...
if(cell.available() >0)
{
delay(10);
inchar=cell.read();
if (inchar=='a')
{
delay(10);
inchar=cell.read();
if (inchar=='0')
{
digitalWrite(led1, LOW);
}
else if (inchar=='1')
{
digitalWrite(led1, HIGH);
}
delay(10);
delay(10);
}
cell.println("AT+CMGD=1,4"); // Delete all SMS
}
}
This is the code for receiving SMSes from the cellular network. I am using the Arduino Gboard with SIM900. There is no error in the code, but the LED on the board doesn't switch on or off in response to an SMS.
Why?
Here's a fully functional code for sending a command thru SMS using Arduino and GSM, it will also reply the state of the light.
#include <SoftwareSerial.h>
SoftwareSerial GPRS(10, 11);
String textMessage;
String lampState;
const int relay = 12; //If you're using a relay to switch, if not reverse all HIGH and LOW on the code
void setup() {
pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH); // The current state of the light is ON
Serial.begin(9600);
GPRS.begin(9600);
delay(5000);
Serial.print("GPRS ready...\r\n");
GPRS.print("AT+CMGF=1\r\n");
delay(1000);
GPRS.print("AT+CNMI=2,2,0,0,0\r\n");
delay(1000);
}
void loop(){
if(GPRS.available()>0){
textMessage = GPRS.readString();
Serial.print(textMessage);
delay(10);
}
if(textMessage.indexOf("ON")>=0){ //If you sent "ON" the lights will turn on
// Turn on relay and save current state
digitalWrite(relay, HIGH);
lampState = "ON";
Serial.println("Lamp set to ON\r\n");
textMessage = "";
GPRS.println("AT+CMGS=\"+631234567890\""); // RECEIVER: change the phone number here with international code
delay(500);
GPRS.print("Lamp was finally switched ON.\r");
GPRS.write( 0x1a );
delay(1000);
}
if(textMessage.indexOf("OFF")>=0){
// Turn off relay and save current state
digitalWrite(relay, LOW);
lampState = "OFF";
Serial.println("Lamp set to OFF\r\n");
textMessage = "";
GPRS.println("AT+CMGS=\"+631234567890\""); /// RECEIVER: change the phone number here with international code
delay(500);
GPRS.print("Lamp was finally switched OFF.\r");
GPRS.write( 0x1a );
delay(1000);
}
if(textMessage.indexOf("STATUS")>=0){
String message = "Lamp is " + lampState;
GPRS.print("AT+CMGF=1");
delay(1000);
Serial.println("Lamp state resquest");
textMessage = "";
GPRS.println("AT+CMGS=\"+631234567890\""); // RECEIVER: change the phone number here with international code
delay(500);
GPRS.print("Lamp is currently ");
GPRS.println(lampState ? "ON" : "OFF"); // This is to show if the light is currently switched on or off
GPRS.write( 0x1a );
delay(1000);
}
}
Change
AT+CNMI=3,3,0,0
to:
AT+CNMI=2,2,0,0,0
The simplest way is the best way.
// if You use SoftwareSerial lib, declare object for GSM
SoftwareSerial gsm(8,9); // TX, RX
void setup(){
// initialise UART and GSM communication between Arduino and modem
Serial.begin(115200);
gsm.begin(115200);
// wait 5-10sec. for modem whitch must connect to the network
delay(5000);
// configure modem - remember! modem didn't remeber Your's configuration!
gsm.print("at+cmgf=1\r"); // use full functionality (calls, sms, gprs) - see app note
gsm.print("at+clip=1\r"); // enable presentation number
gsm.print("at+cscs=\"GSM\"\r"); // configure sms as standard text messages
gsm.print("at+cnmi=1,2,0,0,0\r"); // show received sms and store in sim (probobly, I don't compre this settings with app note but it's working :)
}
void loop(){
String response = gsmAnswer();
if(response.indexOf("+CMT:") > 0 ) { // SMS arrived
// Now You can parse Your Message, if You wont controll only LED, just write
if(response.indexOf("LED ON") > 0) {
digitalWrite(LED_PIN, HIGH); // enable it
}else if(response.indexOf("LED OFF") > 0) {
digitalWrite(LED_PIN, LOW); // turn off
}
delay(1000);
}
}
String gsmAnswer(){
String answer;
while(!gsm.available());
while(gsm.available()){
delay(5);
if(Serial.available() > 0){
char s = (char)gsm.read();
answer += s;
}
}
return answer;
}
One think more, incomming sms has the following format:
+CMT: "+48xxxxxxxxx","","17/07/07,21:57:04+08"
Test of arrived messages
You should first know exactly what the response is before attempting to parse it.
Try something simple like the following code (note: untested!) to get a feeling of what you should look for:
void loop() {
if(cell.available() > 0) {
char ch = cell.read();
Serial.print(ch);
}
}
My guess is you'll see more than just a '0' or a '1' :)
void loop() {
while(cell.available() > 0) {inchar = cell.read(); readString+=c;delay(1);} ///can be a delay up to (10) so you can get a clear reading
Serial.print(readString); /// Declare a string " String readString; "
for (i=0; i<200; i++){ /// Serch for the txt you sent up to (200) times it depends how long your ""readString" is
if(readString.substring(i,i+4)=="RING"){ //// I am looking for the word RING sent from my phone
digitalWrite(13,HIGH);
break;
}
}
}
this will help you find the specific word ir your reading (text message)

Resources