#include <SoftwareSerial.h>
#include <TinyGPSPlus.h>
SoftwareSerial sim(2, 3); // Broches RX et TX pour le module GSM
SoftwareSerial NEO6M(7, 6); // Broches RX et TX pour le module GPS
int _timeout;
String _buffer;
String number = "+6289668072234";
ss
TinyGPSPlus gps;
void setup() {
delay(7000);
Serial.begin(9600);
_buffer.reserve(50);
Serial.println("System Started...");
sim.begin(9600);
delay(1000);
NEO6M.begin(9600);
}
void loop() {
// Acquérir les données GPS
while (NEO6M.available() > 0) {
if (gps.encode(NEO6M.read()))
displayInfo();
}
if (millis() > 5000 && gps.charsProcessed() < 10) {
Serial.println(F("No GPS detected: check wiring."));
while (true);
}
// Envoi du SMS avec la position GPS
SendMessage();
delay(10000); // Délai pour éviter d'envoyer des messages fréquemment
}
void SendMessage() {
sim.println("AT+CMGF=1");
delay(1000);
sim.println("AT+CMGS=\"" + number + "\"\r");
delay(1000);
String SMS = "Personne a tombe! Position GPS: http://maps.google.com/maps?q=loc:";
SMS += String(gps.location.lat(), 6);
SMS += ",";
SMS += String(gps.location.lng(), 6);
sim.println(SMS);
delay(100);
sim.println((char)26);
delay(1000);
_buffer = _readSerial();
}
String _readSerial() {
_timeout = 0;
while (!sim.available() && _timeout < 12000) {
delay(13);
_timeout++;
}
if (sim.available()) {
return sim.readString();
}
}
void displayInfo() {
Serial.print(F("Location: "));
if (gps.location.isValid()) {
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
} else {
Serial.print(F("INVALID"));
}
Serial.print(F(" Date "));
if (gps.date.isValid()) {
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
} else {
Serial.print(F("INVALID"));
}
Serial.println();
}