Étape 6: Code
Le code est:-
#include
#include
gpsSentenceInfoStruct info ; buff de char [256] ; url de char [120] ; fix int = 0 ;
const int noofDest = 2 ; const char * numéros [] = {"0123456789", "0123456789"} ; amendements qui recevront le sms chaque fois que char incoming_num [21] = « 0123456789 » ; Cette no.will ne recevoir sms lorsque nous envoyer de sms pour cela aucune. message de char [256] ;
int ButtonPin = 2 ;
public static unsigned char getComma (unsigned char num, const char * str) {unsigned char i, j = 0; int len=strlen(str) ; pour (j’ai = 0; j’ai < len ; j’ai ++) {si (str [i] == «, ») j ++; if(j == num) retourner i + 1;} return 0;}
public static double getDoubleNumber (const char * s) {char buf [10]; unsigned char j’ai ; double rev ; j’ai = getComma (1 s); j’ai = i - 1; strncpy (buf, s, i); buf [i] = 0; rev=atof(buf) ; retour rev;}
public static double getIntNumber (const char * s) {char buf [10]; unsigned char j’ai ; double rev ; j’ai = getComma (1 s); j’ai = i - 1; strncpy (buf, s, i); buf [i] = 0; rev=atoi(buf) ; retour rev;}
flotteur toWGS84(float nmeaCoord) {float degWhole = float(int(nmeaCoord/100)) ; float degDec = (nmeaCoord - degWhole * 100) / 60 ; return degWhole + degDec;}
void parseGPGGA (const char * GPGGAstr) {/ * Référence : http://www.gpsinformation.org/dale/nmea.htm#GGA * / double latitude ; double longitude ; int tmp, heure, minute, seconde, num ; si (GPGGAstr [0] == '$') {tmp //latitude = getComma (2, GPGGAstr); latitude = getDoubleNumber (& GPGGAstr[tmp]) ; tmp = getComma (3, GPGGAstr); / / N ou S float latWGS84 = toWGS84(latitude) ; if (de ' == GPGGAstr[tmp]) {latWGS84 = - latWGS84; / / réduire à néant si la coordonnée de l’hémisphère Sud} //longitude tmp = getComma (4, GPGGAstr); longitude = getDoubleNumber (& GPGGAstr[tmp]) ; tmp = getComma (5 GPGGAstr) ; E ou o flotteur lonWGS84 = toWGS84(longitude) ; Si (« W » == GPGGAstr[tmp]) {lonWGS84 = - lonWGS84; / / réduire à néant si l’Ouest coordonner} sprintf (url, « http://maps.google.com/?q=%f, %f », latWGS84, lonWGS84) ;
emplacement fix tmp = getComma (6, GPGGAstr) ; Difficulté = getIntNumber (& GPGGAstr[tmp]) ; } else {Serial.println ("données de GPS non");}}
void send_sms (numéro de char, char * message) {LSMS.beginSMS(number) ; pour (int i = 0; j’ai < strlen(message); i ++) {LSMS.write(message[i]);} LSMS.endSMS() ; }
void setup() {pinMode (ButtonPin, INPUT_PULLUP) ; Serial.Begin(115200) ; LGPS.powerOn() ; Serial.println ("LGPS sous tension, l’attente...") ; Delay(3000) ; }
void loop() {LGPS.getData (& info) ; Serial.Print ((char*) info. GPGGA) ; parseGPGGA ((const char*) info. GPGGA) ;
if(digitalRead(ButtonPin) == faible) {si (Difficulté! = 0) {sprintf (message, "s’il vous plaît aidez-moi!. Emplacement actuel: %s ", url) ; } else {sprintf (message, "Aidez-moi. Dernière localisation: %s ", url) ; } Serial.println(message) ; pour (int i = 0; i < noofDest; i ++) {char num [20]; sprintf (num, numbers[i]), send_sms (num, message);} delay(5000) ; } / / Réponse SMS entrants en retournant la position if(LSMS.available()) {LSMS.remoteNumber (incoming_num, 20); if (Difficulté! = 0) {sprintf (message, "emplacement actuel: %s", url);} else {sprintf (message, "dernier emplacement: %s", url);} Serial.println(message) ; SEND_SMS (incoming_num, message) ; LSMS.flush() ; } }
Et il est également attaché au fond.