Go Down

Topic: SHIELD SIM900 and READSMS (Read 939 times) previous topic - next topic

skosso

hello

I have a problem with SIM900 GPRS SHIELD ..

I want you to read the incoming SMS shield. I want to read the sms text and put it into a variable.

I can not ...

have libraries to recommend?

here is a sample code, how can I make readsms?


Code: [Select]

#include <SoftwareSerial.h>
#include <String.h>
#include <leOS.h>
SoftwareSerial mySerial(7, 8);
int ledcontrollo = 13; //led di controllo stato sensore PIR

int sen = 10; //porta sensore PIR
int allarme = 0; //variabile di controllo attivazione/disattivazione allarme

void setup()
{
pinMode(9, OUTPUT);
digitalWrite(9,LOW);
delay(1000);
digitalWrite(9,HIGH);
delay(2000);
digitalWrite(9,LOW);
delay(3000);

mySerial.begin(19200); //inizializzazione shield gprs
pinMode(sen, INPUT); //pin di input sensore PIR
pinMode(ledcontrollo, OUTPUT);
delay(500);


}
void loop()
{
if (digitalRead(sen) == HIGH){
digitalWrite(ledcontrollo, HIGH);
DialVoiceCall(); }
else{
digitalWrite(ledcontrollo, LOW);}

}

void SendTextMessage()
{
mySerial.print("AT+CMGF=1\r"); //Because we want to send the SMS in text mode
delay(100);
mySerial.println("AT + CMGS = \"+86138000000\"");//send sms message, be careful need to add a country code before the cellphone number
delay(100);
mySerial.println("A test message!");//the content of the message
delay(100);
mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
mySerial.println();
}

void DialVoiceCall()
{
mySerial.println("ATD + +3930000000;");//dial the number
delay(100);
mySerial.println();
}

void controllo(){
if (digitalRead(sen) == HIGH){
digitalWrite(ledcontrollo, HIGH);}
else{
digitalWrite(ledcontrollo, LOW);}
}

PaulS

Quote
I want to read the sms text and put it into a variable.

I can not ...

Why can't you? That code does something. What does it do?

You want it to do something. What do you want it to do?

How do those two things differ?

fbriggs4

I am not an Arduino expert but I am pretty good with GSM modems. Before you do anything you need to make sure that the GSM has registered to the network with the AT+CREG? command. You need to see either a 5 (registered roaming) or a 1 ( registered home) before you try to transmit anything. I notice that you are trying to send an SMS but I don't see anything to read the SMS. To read the SMS you need to use the AT+CMGL command. I also don't think the SendTextMessage() code will work.

My suggested changes. Make sure you have the proper GSM registration before you send this though.

Code: [Select]

void SendTextMessage()
{
mySerial.println("AT+CMGF=1"); //removed the \r and did a println instead
delay(100);
mySerial.println("AT+CMGS=+86138000000");//I removed the spaces and extra characters
delay(100);
mySerial.print("A test message!");//you dont need the CR here.
delay(100);
mySerial.println((char)26);//PaulS might be better able to tell if this is correct. I am not sure..........
delay(100);
mySerial.println();
}



Go Up