Development

» GPS 08: Frame Class Utility

This is the basic code to create a frame with some GPS location information

Required Materials

1 x Waspmote
1 x Battery
1 x GPS module
1 x GPS antenna

Notes

- Keep in mind that external antennas are not valid for indoor locations.
- This example can be executed in Waspmote v12 and Waspmote v15
- The battery has to be connected.

Code

/*
    ------------  [GPS_08] - Frame Class Utility  --------------

    Explanation: This is the basic code to create a frame with
    the GPS information.

    Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.

    Version:		        3.0
    Design:             David Gascón
    Implementation:     Eduardo Hernando
*/

#include <WaspGPS.h>
#include <WaspFrame.h>

// define GPS timeout when connecting to satellites
// this time is defined in seconds (240sec = 4minutes)
#define TIMEOUT 240

// define status variable for GPS connection
bool status;

long time=0;
char node_ID[] = "Node_01";


void setup()
{

  // open USB port
  USB.ON();
  // setup the GPS module
  USB.println(F("GPS_08 example"));

  // set GPS on
  GPS.ON();

  // Gets Power Mode
  USB.print(F("Power Mode: "));
  switch( GPS.getMode() )
  {
  case GPS_ON:
    USB.println(F("GPS_ON"));
    break;
  case GPS_OFF:
    USB.println(F("GPS_OFF"));
    break;
  }

  // Set the Waspmote ID
  frame.setID(node_ID);

  USB.println(F("--------------------------------"));


}

void loop()
{

  // set GPS on
  GPS.ON();

  ///////////////////////////////////////////////////
  // 1. wait for GPS signal for specific time
  ///////////////////////////////////////////////////
  status = GPS.waitForSignal(TIMEOUT);

  if( status == true )
  {
    USB.println(F("\n----------------------"));
    USB.println(F("Connected"));
    USB.println(F("----------------------"));
  }
  else
  {
    USB.println(F("\n----------------------"));
    USB.println(F("GPS TIMEOUT. NOT connected"));
    USB.println(F("----------------------"));
  }

  ///////////////////////////////////////////////////
  // 2. get parameters from GPS module (parameter-dedicated functions)
  ///////////////////////////////////////////////////
  if( status == true)
  {
    // Getting Time
    GPS.getTime();
    USB.print(F("Time [hhmmss.sss]: "));
    USB.println(GPS.timeGPS);

    // Getting Date
    GPS.getDate();
    USB.print(F("Date [ddmmyy]: "));
    USB.println(GPS.dateGPS);

    // Getting Latitude
    GPS.getLatitude();
    USB.print(F("Latitude [ddmm.mmmm]: "));
    USB.println(GPS.latitude);
    USB.print(F("North/South indicator: "));
    USB.println(GPS.NS_indicator);
    USB.print("Latitude (degrees):");
    USB.println(GPS.convert2Degrees(GPS.latitude, GPS.NS_indicator));

    // Getting Longitude
    GPS.getLongitude();
    USB.print(F("Longitude [dddmm.mmmm]: "));
    USB.println(GPS.longitude);
    USB.print(F("East/West indicator: "));
    USB.println(GPS.EW_indicator);
    USB.print("Longitude (degrees):");
    USB.println(GPS.convert2Degrees(GPS.longitude, GPS.EW_indicator));

    // Getting Altitude
    GPS.getAltitude();
    USB.print(F("Altitude [m]: "));
    USB.println(GPS.altitude);

    // Getting Speed
    GPS.getSpeed();
    USB.print(F("Speed [km/h]: "));
    USB.println(GPS.speed);

    // Getting Course
    GPS.getCourse();
    USB.print(F("Course [degrees]: "));
    USB.println(GPS.course);
    USB.println(F("--------------------------------"));
  }

  ///////////////////////////////////////////
  // 3. Create ASCII frame
  ///////////////////////////////////////////
  // Create new frame (ASCII)
  frame.createFrame(ASCII, node_ID);
  if (status == true)
  {
    // add frame fields
    frame.addSensor(SENSOR_GPS,
    GPS.convert2Degrees(GPS.latitude, GPS.NS_indicator),
    GPS.convert2Degrees(GPS.longitude, GPS.EW_indicator) );
    frame.addSensor(SENSOR_BAT, (uint8_t) PWR.getBatteryLevel());
  }
  else
  {
    // add frame fields
    frame.addSensor(SENSOR_STR,"GPS not connected");
  }

  // Show the frame
  frame.showFrame();

  //wait 5 seconds
  delay(5000);
}

Output

H#
GPS_07 example
Power Mode: GPS_ON
--------------------------------

----------------------
Connected
----------------------
Time [hhmmss.sss]: 124434.549
Date [ddmmyy]: 220517
Latitude [ddmm.mmmm]: 4140.1414
North/South indicator: N
Latitude (degrees):41.6690216064
Longitude [dddmm.mmmm]: 00051.4204
East/West indicator: W
Longitude (degrees):-0.8570066452
Altitude [m]: 199.2
Speed [km/h]: 0.48
Course [degrees]: 0.00
--------------------------------
===============================
Current ASCII Frame:
Length: 64
Frame Type: 134
frame (HEX): 3C3D3E86022331463243373836334439333734323543234E6F64655F30312330234750533A34312E3636393032323B2D302E383537303037234241543A393023
frame (STR): <=>�#1F2C7863D937425C#Node_01#0#GPS:41.669022;-0.857007#BAT:90#
===============================

Quick Publish: