1.2.16. fejezet, SMS küldés, GPRS kommunikáció és GPS logger

Alkalmazott hardverek

Projekt forráskódok

Hasonló projektek

GPS koordináták fogadása

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
 
static const int RXPin = 6, TXPin = 7;
static const uint32_t GPSBaud = 9600;
 
TinyGPSPlus gps;
 
SoftwareSerial ss(RXPin, TXPin);
 
void setup()
{
  Serial.begin(115200);
  ss.begin(GPSBaud);
}
 
void loop()
{
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      displayInfo();
 
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
  }
}
 
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/Time: "));
  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.print(F(" "));
  if (gps.time.isValid())
  {
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    Serial.print(F(":"));
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    Serial.print(F(":"));
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
  }
  else
  {
    Serial.print(F("INVALID"));
  }
 
  Serial.println();
}

SMS küldés

/* use Leonardo or similar that have secondary serial */
void setup() {
  Serial1.begin(19200);
  // Give time to your GSM shield log on to network
  delay(20000);     
  sendSMS();
}
 
void loop() { 
 
}
 
void sendSMS() {
  Serial1.print("AT+CMGF=1\r"); 
  delay(100);
 
  Serial1.println("AT + CMGS = \"+36301234567\""); 
  delay(100);
 
  Serial1.println("Szia."); 
  delay(100);
 
  Serial1.println((char)26); 
  delay(100);
  Serial1.println();
  delay(5000); 
}