Development v12

Warning - Product Update

All the resources present on this section belong to Waspmote v12, Waspmote Plug & Sense! v12 and Meshlium v3.8.

If you have a Waspmote v15, Waspmote Plug & Sense! v15 or Meshlium v4.0 please go to the new Development Section.

Check what is your version and what are the differences between the old and the new one in this document.

» 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;

char node_ID[] = "Node_01";


void setup()
{
  USB.ON();
  USB.println(F("Frame Utility Example for GPS"));

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

void loop()
{
  ///////////////////////////////////////////
  // 1. Turn on board and wait for GPS signal
  ///////////////////////////////////////////
  GPS.ON(); 
  status = GPS.waitForSignal(TIMEOUT);
  delay(100);


  ///////////////////////////////////////////
  // 2. Read data if GPS is connected
  ///////////////////////////////////////////  
  if( status == true )
  {
    // getPosition function gets all basic data 
    status = GPS.getPosition();   
  }
  else
  {
    USB.println("Could not connect GPS");
  }

  ///////////////////////////////////////////
  // 3. Create ASCII frame
  /////////////////////////////////////////// 

  // Create new frame (ASCII)
  frame.createFrame(ASCII);
  if( status == true )
  {
    //Add global position [degrees]
    frame.addSensor(SENSOR_GPS, 
                    GPS.convert2Degrees(GPS.latitude, GPS.NS_indicator),
                    GPS.convert2Degrees(GPS.longitude, GPS.EW_indicator) );
	
    //Add altitude [m]
    frame.addSensor(SENSOR_ALTITUDE,GPS.altitude);
    
    //Add speed [km/h]
    frame.addSensor(SENSOR_SPEED,GPS.speed);
    
    //Add course [degrees]
    frame.addSensor(SENSOR_COURSE,GPS.course);    
    
    //Add time
    frame.addSensor(SENSOR_TIME,GPS.timeGPS);
    
    //Add date
    frame.addSensor(SENSOR_DATE,GPS.dateGPS);
  
  }
  



  // Show the frame
  frame.showFrame();


  
  ///////////////////////////////////////////
  // 4. Turn off the board
  /////////////////////////////////////////// 
  GPS.OFF();
  
  //wait 2 seconds
  delay(2000);
}

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: