GSM code for sending GPS data
this sister project "gps logger, reading , writing , sd" because connected, again separate , stand alone device. project, using had on hand, , be temporarily; arduino pro mini 168 chinese copy, fine, until 2 projects merge. using nano 328.
this code functional limited, , starting point. both pro mini 168 module , gsm a6 module, being powered usb ports, now, change when projects merge. virtual serial tx, rx connected pins (6,7) using<softwareserial.h>, change also.
the amount of characters i'm able send, on gsm, per text right 118. i'm hoping someone, further knowledge can increase amount per text. code have grab data gps module, send text message, every 5 minutes or so, automatically. ***this added after original posting*** able upload 5 character text (**.**) reflect sea level pressure correctly adjust altitude. ***end off added content***
i had piece code copy pasting half @ time. don't know why arduino ide not allow me copy paste @ once sketch should work fine.
this code functional limited, , starting point. both pro mini 168 module , gsm a6 module, being powered usb ports, now, change when projects merge. virtual serial tx, rx connected pins (6,7) using<softwareserial.h>, change also.
the amount of characters i'm able send, on gsm, per text right 118. i'm hoping someone, further knowledge can increase amount per text. code have grab data gps module, send text message, every 5 minutes or so, automatically. ***this added after original posting*** able upload 5 character text (**.**) reflect sea level pressure correctly adjust altitude. ***end off added content***
i had piece code copy pasting half @ time. don't know why arduino ide not allow me copy paste @ once sketch should work fine.
code: [select]
#include <softwareserial.h>
char messagein;
// if more 118 characters string, giberish in serial monitor
//...at+cmgs="+181386753giberish here ...notice final 2 cell phone numbers "gibberish" covered.
// used 120 characters achieve error
string coordinatesgps = "-82.41273,28.07181,4433.00-82.41273,28.07181,4433.00-82.41273,28.07181,4433.00-82.41273,28.07181,4433.00testtesttestte";
softwareserial myserial(6, 7);
void setup()
{
myserial.begin(9600); // setting baud rate of gsm module
serial.begin(9600); // setting baud rate of serial monitor (arduino)
delay(100);
//would not send text message unless sent these @ commands first
myserial.println("at");
delay(1000);
myserial.println("atd");
myserial.println("ath");
delay(100);
//send text
myserial.println("at+cmgf=1"); //sets gsm module in text mode
delay(1000); // delay of 1000 milli seconds or 1 second
myserial.println("at+cmgs=\"+18133477680\"\r"); // replace jenny jennies number mobile number
delay(1000);
myserial.println("zeppelin initialized");// sms text want send
delay(100);
myserial.println((char)26);// ascii code of ctrl+z
delay(1000);
}
void loop()
{
// myserial.println("s");
// delay(2000);
if (serial.available() > 0)
switch (serial.read())
{
case 's':
sendmessage();
break;
case 'r':
recievemessage();
break;
}
if (myserial.available() > 0)
serial.write(myserial.read());
}
void sendmessage()
{
myserial.println("at");
delay(1000);
myserial.println("atd");
myserial.println("ath");
delay(100);
myserial.println("at+cmgf=1"); //sets gsm module in text mode
delay(1000); // delay of 1000 milli seconds or 1 second
myserial.println("at+cmgs=\"+18138675309\"\r"); // replace jenny jennies cell number mobile number
delay(1000);
myserial.println(coordinatesgps);// sms text want send
delay(100);
myserial.println((char)26);// ascii code of ctrl+z
delay(1000);
}
void recievemessage()
{
myserial.println("at+cnmi=2,2,0,0,0"); // @ command receive live sms
delay(1000);
}
made few changes , upgrades sketch. replaced softwareserial library altsoftserial along tx/rx pins (8,9). buffer altsoftserial changed expand 118 (softwareserial) 159 bytes. seems limit tx buffer, or it? therefore second variable created send text message containing date/time , information, in sea level pressure variable, separately.
deleted code manually receive text messages; did nothing , text messages printed serial monitor, automatically. unfortunately text sent arduino, while arduino serial monitor isn't active, never received. still needed way save 5 character float, text message variable, in arduino.
deleted code manually receive text messages; did nothing , text messages printed serial monitor, automatically. unfortunately text sent arduino, while arduino serial monitor isn't active, never received. still needed way save 5 character float, text message variable, in arduino.
code: [select]
#include <altsoftserial.h>
#define rx_buffer_size 8 //90// default// receives messages if set 0
#define tx_buffer_size 90 //58// default //99 tops 159 characters
altsoftserial gpsport; // must on specific pins (8 & 9 uno)
// storage received 5 character text message, containing local sea level info.
char messagein;
// if more 159 characters loaded string , attempted sent,
//...none of message texted. empty spaces count character in string count.
string coordinatesgps = "-182.41271,-28.07181,10,000.00 -182.41271,-28.07181,10,000.00 -182.41271,-28.07181,10,000.00 -182.41271,-28.07181,10,000.00 -1821.4127,-28.07181,10,000.00";
// amount of characters possibly obtained gps , altimeter
// date time year gps , mercury @ sea level being stored in variable
string datetimesealevel = "2017-06-21 19:25:53 sl=22.22";
void setup()
{
gpsport.begin(9600); // setting baud rate of gsm module
serial.begin(9600); // setting baud rate of serial monitor (arduino)
delay(100);
//would not send text message unless sent these @ commands first
gpsport.println("at");
delay(1000);
gpsport.println("atd");
gpsport.println("ath");
delay(100);
//send text
gpsport.println("at+cmgf=1"); //sets gsm module in text mode
delay(1000); // delay of 1000 milli seconds or 1 second
gpsport.println("at+cmgs=\"+18133477680\"\r"); // replace jenny jennies number mobile number
delay(1000);
gpsport.println("zeppelin initialized");// sms text want send
delay(100);
gpsport.println((char)26);// ascii code of ctrl+z
delay(1000);
}
void loop()
{
if (serial.available() > 0)
switch (serial.read())
{
case 'l':
sendmessage();
break;
case 't':
sendmessage2();
break;
}
if (gpsport.available() > 0)
serial.write(gpsport.read());
}
void sendmessage()
{
gpsport.println("at");
delay(1000);
gpsport.println("atd");
gpsport.println("ath");
delay(100);
gpsport.println("at+cmgf=1"); //sets gsm module in text mode
delay(1000); // delay of 1000 milli seconds or 1 second
gpsport.println("at+cmgs=\"+18133477680\"\r"); // replace x mobile number
delay(1000);
gpsport.println(coordinatesgps);// sms text want send
delay(100);
gpsport.println((char)26);// ascii code of ctrl+z
delay(1000);
}
void sendmessage2()
{
// altsoftserial buffer has limit, send second text message,
// time date , whats in sealevel variable.
gpsport.println("at");
delay(1000);
gpsport.println("atd");
gpsport.println("ath");
delay(100);
gpsport.println("at+cmgf=1"); //sets gsm module in text mode
delay(1000); // delay of 1000 milli seconds or 1 second
gpsport.println("at+cmgs=\"+18133477680\"\r"); // replace x mobile number
delay(1000);
gpsport.println(datetimesealevel);// sms text want send
delay(100);
gpsport.println((char)26);// ascii code of ctrl+z
delay(1000);
}
Arduino Forum > Using Arduino > Project Guidance > GSM code for sending GPS data
arduino
Comments
Post a Comment