Remote Monitoring & Control

Enter Your Electronics & Design Project for a chance to win up to a $200 Shopping Cart of Product!

Back to The Project14 homepage

Project14 Home
Monthly Themes
Monthly Theme Poll

 

Making some progress - I got the GPS hooked up to the MKR 1300 and transmitting data to The Things Network.

 

GPS Module

The GPS that I am using is a Neo-6M board with a ceramic antenna.

The module communicates with the MKR 1300 via a UART so the connections are just 4 wires: 3.3V, Gnd, Tx and Rx.

 

Test Setup

Here is my test setup.  The breadboard is just used to physically anchor the MKR 1300 so it doesn't get pulled around by the USB cable.

GPS Test Setup

 

Software

The good news is that there is a good collection of open source software available on GitHub for Arduino with GPS.  I found a program for the MKR 1300 by Gonzalo Casas that uses the TinyGPS++ library and also formats data for use by the TTN Mapper: https://github.com/gonzalocasas/arduino-mkr-wan-1300/tree/master/mkrwan_03_gps_tracker .  This program is known to work with the Neo-6M.  So, the programming is straightforward - download and include the TinyGPS++ zip library written by Mikal Hart: https://github.com/mikalhart/TinyGPSPlus/releases and put in the correct appEui and appKey obtained from the application in the TTN console.

 

Initially nothing seemed to be working.  The MKR 1300 would not connect to the TTN network.  I finally figured out that I had to reset the MKR 1300 twice and then let the LoRa modem try multiple times to get a reliable connection to the gateway.  I'm not sure about resetting twice, but it appears that multiple connect tries are required because of the frequency (channel) hopping of the Things gateway.  I think it is a synchronization problem because when it does not connect it registers a very low signal strength (less than -110dBm).  I can get a good signal strength on the same channel on a later pass (about -45dBm for my current test setup).

 

With some software tweaks (and a double reset), I can consistently connect to TTN.

 

However, I was not getting any GPS data.  I waited for an hour with no success, moving the device location periodically.  I gave up for the night and the next morning I was happily surprised with location data spewing forth.  It turns out that TinyGPS library requires acquiring 4 satellites before sending GPS data (this requirement is needed to determine altitude).

 

And the data arrives successfully in the TTN console:

 

TTN Mapper

JP Meijers has written a TTN Mapper integration and a payload decoder to format the received data.  Integrations are programs that tie your TTN device to other applications or even external platforms like AWS, Azure, or Watson.  Here is a sample of available integrations.  I'll be using TTN Mapper to plot my GPS data, but I can already think of uses for IFTTT.

 

 

You just need to add the integration to your application.  In this instance my application is ttn_ry_gps and the process id for my device is mkr_wan_gps.

 

 

The other thing needed is the payload decoder which is added to your console application:

// Author:
// Copyright (c) 2016 JP Meijers
// Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0
// https://github.com/jpmeijers/RN2483-Arduino-Library
function Decoder(bytes, port) {
  // Decode an uplink message from a buffer
  // (array) of bytes to an object of fields.
  var decoded = {};
  // if (port === 1) decoded.led = bytes[0];
  decoded.lat = ((bytes[0]<<16)>>>0) + ((bytes[1]<<8)>>>0) + bytes[2];
  decoded.lat = (decoded.lat / 16777215.0 * 180) - 90;
  decoded.lon = ((bytes[3]<<16)>>>0) + ((bytes[4]<<8)>>>0) + bytes[5];
  decoded.lon = (decoded.lon / 16777215.0 * 360) - 180;
  var altValue = ((bytes[6]<<8)>>>0) + bytes[7];
  var sign = bytes[6] & (1 << 7);
  if(sign)
  {
    decoded.alt = 0xFFFF0000 | altValue;
  }
  else
  {
    decoded.alt = altValue;
  }
  decoded.hdop = bytes[8] / 10.0;
  return decoded;
}

 

 

Device on TTN Map:

 

Zoomed in:

 

 

The one bothersome thing about this data is that while the average location is correct, the outliers in the data are 40-60 meters out.  I'll need to investigate what's going on.  I suspect I may be losing satellites periodically.  Hopefully the GPS performance will be substantially better outdoors.