Long time ago I bought a Telit GSM module to learn how to use. Last month I want to use this module at a weekend project and then this project is born.
There are two leds connected to 13 and 53 pins (selected randomly, you can move to another pins by correcting pin define).
Sending 1ON or 1OFF text using SMS; controls Led 1.
Sending 2ON or 2OFF text using SMS controls Led 2. Any relay and other devices can be controlled by developing codes.
Sending Loc text, sends back sms to you including google maps location link.
Google maps link shows modules gps location.
SMS looks like this. "Konum: https://www.google.com.tr/maps/place/....."
You can click the link to track device's location.
Serial2 is used for debugging, Serial3 is used to communicate with Gsm module.
pins 6 and 7, s used for wake up gsm module and check whether module is on.
Telit GM862 is a too old module to buy.
You can use another telit gsm/gps module or other manifacurer's gsm/gps module by redesignin AT commands.
There is a structure in program.
With enum define commands headers are paired with numbers. Then define three field for one command. One is command number, one is command text and last one is for keeping delay time for command response timeout.
The last code defines array by using this structure for each command and fill text and timeout delay.
sendCmd(eAT);
sends AT to gsm module serial port, waits 10ms and checks whether there is any response for AT command. If there is a response takes data. If not, wait until timeout.
One command line makes lots of duty. You only send command and it looks for command response(CMGL, GPSACP etc)
You can use this structure for any command set by redefining it .
I hope it is useful for you. Codes are below that i described upper.
enum enumCmd
{
eAT,
eATFCLASS,
eATGPSACP,
eATE,
eATCOPS,
eATCNMI,
eATCMGF,
eATCMGD,
eATCMGS,
eATCMGL,
eATCCLK,
eATNITZ
};
//typedef
struct command{
int nr;
String text;
int sure;
};
command myCmd[20]
{
eAT,{"AT"},300,
eATFCLASS,{"AT+FCLASS=8"},300,
eATGPSACP,{"AT$GPSACP"},1000,
eATE,{"ATE0"},300,
eATCOPS,{"AT+COPS?"},300,
eATCNMI,{"AT+CNMI=2,1"},300,
eATCMGF,{"AT+CMGF=1"},300,
eATCMGD,{"AT+CMGD=1,4"},300,
eATCMGS,{"AT+CMGS="},1000,
eATCMGL,{"AT+CMGL=\"ALL\""},2000,
eATCCLK,{"AT+CCLK"},300,
eATNITZ,{"AT#NITZ=1,1"},300
} ;
void sendCmd(int cmd)
{
Serial2.print("cmd: ");
Serial2.println(myCmd[cmd].text);
Serial3.println(myCmd[cmd].text);
//delay(myCmd[cmd].sure);
delay(10);//minimal bir süre bekle
sure=myCmd[cmd].sure/10;
for (sayac=0;sayac<sure;sayac++)
{
if (Serial3.available()>0)
{
break;
}
else
{
delay(10);
}
}
Serial2.print("sayac:");
Serial2.println(sayac);
if (Serial3.available()>0)
{
ser3Data=Serial3.readString();
Serial2.print("Veri: ");
Serial2.println(ser3Data);
if(ser3Data.startsWith("\r\n+CMGL:"))
{
//String smsBody=ser3Data;
//smsBody.replace('\n','_');
//smsBody.replace('\r','_');
//Serial2.print("smsBody:");
//Serial2.println(smsBody);
telNum=ser3Data.substring(26,39);
Serial2.print("Tel Num:");
Serial2.println(telNum);
if (ser3Data.substring(42,45)=="1ON")
{
digitalWrite(led1,HIGH);
}
if (ser3Data.substring(42,46)=="1OFF")
{
digitalWrite(led1,LOW);
}
if (ser3Data.substring(42,45)=="2ON")
{
digitalWrite(led2,HIGH);
}
if (ser3Data.substring(42,46)=="2OFF")
{
digitalWrite(led2,LOW);
}
if (ser3Data.substring(42,45)=="Loc")
{
sendSms(telNum,smsBody);
}
}
if(ser3Data.startsWith("\r\n$GPSACP:") and ser3Data.length()>81)
{
enlemStr=ser3Data.substring(22,32);
Serial2.println("enlemRAW: ");
Serial2.println(enlemStr);
deg=enlemStr.substring(0,2);
mn=enlemStr.substring(2,4).toInt();
scnd=enlemStr.substring(5,9).toInt();
dirNS=enlemStr[9];
dec = (mn *100000 +scnd* 10)/6;
enlemStr=deg + "." + String(dec);
//Serial2.println("enlem: ");
//Serial2.print(enlemStr);
//Serial2.println(dirNS);
...
...
..
Comments