4G 16: GPS autonomous mode

This example shows how to use de GPS in autonomous mode

Required Materials

1 x Waspmote 1 x Battery 1 x 4G module 1 x 4G antenna 1 x SIM card

Notes

- If the required satellites visibility is not available, no GPS position is provided by the module - The battery has to be connected. - This example can be executed in Waspmote v15

Code

/*
    --------------- 4G_16 - GPS Autonomous mode  ---------------

    Explanation: This example shows how to use de GPS in autonomous mode

    Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
    http://www.libelium.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see .

    Version:           3.0
    Design:            David Gascón
    Implementation:    Alejandro Gállego
*/

#include "Wasp4G.h"

// define variables
uint8_t error;
uint8_t gps_status;
float gps_latitude;
float gps_longitude;
uint32_t previous;


void setup()
{
  USB.ON();
  USB.println("Start program");


  //////////////////////////////////////////////////
  // 1. Switch on the 4G module
  //////////////////////////////////////////////////
  error = _4G.ON();

  // check answer
  if (error == 0)
  {
    USB.println(F("1. 4G module ready..."));


    ////////////////////////////////////////////////
    // 2. Start GPS feature
    ////////////////////////////////////////////////
   
    // get current time
    previous = millis();

    // init GPS feature
    gps_status = _4G.gpsStart();

    // check answer
    if (gps_status == 0)
    {
      USB.print(F("2. GPS started in Autonomous (Standalone) mode. Time(secs) = "));
      USB.println((millis()-previous)/1000);
    }
    else
    {
      USB.print(F("2. Error calling the 'gpsStart' function. Code: "));
      USB.println(gps_status, DEC);
    }

  }
  else
  {
    // Problem with the communication with the 4G module
    USB.println(F("1. 4G module not started"));
    USB.print(F("Error code: "));
    USB.println(error, DEC);
    USB.println(F("The code stops here."));
    while (1);
  }
}



void loop()
{
  ////////////////////////////////////////////////
  // Wait for satellite signals and get values
  ////////////////////////////////////////////////
  if (gps_status == 0)
  {
    error = _4G.waitForSignal(20000);
    if (error == 0)
    {
      USB.print(F("3. GPS signal received. Time(secs) = "));
      USB.println((millis()-previous)/1000);
      
      USB.println(F("Acquired position:"));      
      USB.println(F("----------------------------"));
      USB.print(F("Latitude: "));
      USB.print(_4G._latitude);
      USB.print(F(","));
      USB.println(_4G._latitudeNS);
      USB.print(F("Longitude: "));
      USB.print(_4G._longitude);
      USB.print(F(","));
      USB.println(_4G._longitudeEW);
      USB.print(F("UTC_time: "));
      USB.println(_4G._time);
      USB.print(F("date: "));
      USB.println(_4G._date);
      USB.print(F("Number of satellites: "));
      USB.println(_4G._numSatellites, DEC);
      USB.print(F("HDOP: "));
      USB.println(_4G._hdop);
      USB.println(F("----------------------------"));

      // get degrees
      gps_latitude  = _4G.convert2Degrees(_4G._latitude, _4G._latitudeNS);
      gps_longitude = _4G.convert2Degrees(_4G._longitude, _4G._longitudeEW);
      
      USB.println("Conversion to degrees:");
      USB.print(F("Latitude: "));
      USB.println(gps_latitude);
      USB.print(F("Longitude: "));
      USB.println(gps_longitude);  
      USB.println();
      delay(10000);
    }
    else
    {
      USB.println("no satellites fixed");
    }
  }
  else
  {
    ////////////////////////////////////////////////
    // Restart GPS feature
    ////////////////////////////////////////////////
    
    USB.println(F("Restarting the GPS engine"));
   
    // stop GPS 
    _4G.gpsStop();
    delay(1000);

    // start GPS 
    gps_status = _4G.gpsStart();
  }

}

Output

H#
Start program
1. 4G module ready...
2. GPS started in Autonomous (Standalone) mode. Time(secs) = 1
no satellites fixed
no satellites fixed
3. GPS signal received. Time(secs) = 60
Acquired position:
----------------------------
Latitude: 4140.1246,N
Longitude: 00051.4291,W
UTC_time: 113250
date: 110816
Number of satellites: 4
HDOP: 4.5000000000
----------------------------
Conversion to degrees:
Latitude: 41.6687431335
Longitude: -0.8571516990
3. GPS signal received. Time(secs) = 70
Acquired position:
----------------------------
Latitude: 4140.1728,N
Longitude: 00051.4210,W
UTC_time: 113301
date: 110816
Number of satellites: 4
HDOP: 4.5000000000
----------------------------
Conversion to degrees:
Latitude: 41.6695480346
Longitude: -0.8570166587
3. GPS signal received. Time(secs) = 81
Acquired position:
----------------------------
Latitude: 4140.1713,N
Longitude: 00051.4196,W
UTC_time: 113312
date: 110816
Number of satellites: 4
HDOP: 4.4000000953
----------------------------
Conversion to degrees:
Latitude: 41.6695213317
Longitude: -0.8569932937

Last updated