Has anyone tried sending GPS coords to TTN?

(Nidaros) #15

Here is what I used for my decorder. This was like 4 months ago so please don’t ask me questions :joy:

function Decoder (bytes) {
  var _lat = ((bytes[0] << 16) + (bytes[1] << 8) + bytes[2]) / 16777215.0 * 180.0 - 90;
  var _lng = ((bytes[3] << 16) + (bytes[4] << 8) + bytes[5]) / 16777215.0 * 360.0 - 180;
  var _alt = (bytes[6] << 8) + bytes[7];
  var _acc = bytes[8] / 10.0;
  var _VCC = bytes[9] / 50;
  var _tempCPU = bytes[10] -100;
  var _time_to_fix_bin = bytes[11];
  var _time_to_fix;
  if (_time_to_fix_bin>=218) { _time_to_fix = 60*60+(_time_to_fix_bin-218)*600 }
  else if (_time_to_fix_bin>=168) { _time_to_fix = 10*60+(_time_to_fix_bin-168)*60 }
  else if (_time_to_fix_bin>=60) {  _time_to_fix = 60+(_time_to_fix_bin-60)*5 }
  else  {_time_to_fix = _time_to_fix_bin }
          // 0..60 sec  at 1 sec interval <==> values 0 .. 60 
          // 1..10 min at 5 sec interval  <==> values 60 ..  168
          // 10..60 min at 1 min interval <==> values 168 .. 218
          // 1..7 hour at 10 min interval <==> values 218 ..254; 255 means "more than 7 hours"

      return {
        gps_lat: _lat,
        gps_lng: _lng,
        gps_alt: _alt,
        gps_prec: _acc,
        arduino_VCC: _VCC,
        arduino_temp: _tempCPU,
        time_to_fix: _time_to_fix,

(Adrewetx) #16

Thanks for the update :slight_smile:

(Kazi93) #17

@Nidaros @Epyon @Gig @casper

For mapping or range test. I am building Arudino mega + lora shield + adafruit ultimate gps v3 … Please correct me if I am wrong. Many thanks
GPS >> arduino Shield pin mapping…
vin >>vin
Gnd >> gnd
Tx >> rx (0)
Rx >> tx (1)

Config with ABP :
#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#include <TinyGPS.h>

TinyGPS gps;

GPS got fixed in 30 second to 1 min… however, only 0000000000 delivered as a payload.

Compiling the code has no error.arduino-gps


isn’t the GPS 3v3 logic level ? ( and the mega uart 5v)

(Kazi93) #19

Thanks for prompt reply. I powered mega by USB 5v. and GPS breakout board by mega VIN. Like this UNO examplw wiring @https://learn.adafruit.com/adafruit-ultimate-gps/arduino-wiring. Please tell me how should I wire since mega use hw serial as discussed in previous posts.

(Brady Aiello) #20

I’m doing it with a Seeeduino LoRaWAN w/ GPS



(Kazi93) #21

Thanks for sharing. However, I do not have those hw/resource and the frequency is EU.



// what’s the name of the hardware serial port?
#define GPSSerial Serial1

(Kazi93) #23

I have added #define GPSSerial Serial1

Serial output : However, not receiving any packet in the console.

Packet queued

Packet queued
Packet queued




pls read this when you are placing lots of code

did you see the edited picture … youre wiring is wrong for the mega

(Kazi93) #25

Thank you. I have changed the Pinout : GPS >> Mega

VIN >> 5V
Tx >> RX1 (19)
Rx >> TX1 (18)

Is it correct? The GPS got a fix but no data in the console


If I was you I disconnect the lora board from the mega and first try to get communication between the mega and the GPS module.
also I think that the signallevel from the GPS is to low for the mega but I’m not sure @ this moment

(Duineuk) #27

I’m trying to get a TTN Mapper node working with Pro Mini, RFM95W, Neo6 GPS, and a small OLED display with the position information. I want it to be able to happily run in the background unless I press a button to turn on the display.

All working fine, except it takes longer than normal to lock, and doesn’t take read all the position data in one go - it will update long, say, then a few iterations later HDOP, Alt etc. All this makes me suspect it’s not reading the serial feed properly.

I clearly don’t understand the scheduling of lmic and/or how to handle the softserial port. I’ve got the GPS feeding into ss(9, 8). I’ve got the serial GPS reading in do_send (see below) which just doesn’t feel like the right place for it. Would it make more sense (and be cleaner) to do the reading and OLED update in an interrupt service routine?

*Forgot to say - I’m using the sample ttn-abp code as a base, and TinyGPS++.


void do_send(osjob_t* j) {
  // Check if there is not a current TX/RX job running
  if (LMIC.opmode & OP_TXRXPEND) {
    Serial.println(F("OP_TXRXPEND, not sending"));
  } else {

    while (ss.available())

    if (GPS.location.lat() == 0.0) {
      oled.println("NO FIX :(");
    else {
      oled.println("FIX LOCKED!");
      oled.print("Lat: "); oled.println(GPS.location.lat(), 6);
      oled.print("Lon: "); oled.println(GPS.location.lng(), 6);
      oled.print("Alt: "); oled.print(GPS.altitude.meters(), 1); oled.print(" ");
      oled.print("HDOP: "); oled.print(GPS.hdop.hdop(), 1);

    lpp.reset(); // clear the buffer
    lpp.addGPS(1, GPS.location.lat(), GPS.location.lng(), GPS.altitude.meters());                 
    LMIC_setTxData2(1, lpp.getBuffer(),  lpp.getSize(), 0);
    Serial.println(F("Packet queued"));



Not exactly the same, but a sort of similar question passed by in another topic. Maybe this example may be useful for you too.

(Duineuk) #29

Thank, I’ll have a look tomorrow. Brain fried :slight_smile:

(Duineuk) #30

Yup, that works just nicely. Thanks for the link!


@ duineuk

You say you use a pro-mini, rfm95, neo6 and a small OLED

I use exact these parts and my GPS-tracker works fine except that I cannot use the 128*64 Oled, I could not find a library small enough to fit in the sketch.
I do not use any sensor and modified the LMIC library a bit so it is 4k smaller (explained in document of ttn_nodeworkshop). There is almost 8kB memory left so maybe a oled can be used.

Which Oled-library are you using with the code on the pro-mini ?

(Duineuk) #32

I’m away from home right now so can’t check my source. But it was this or one like it:

Basically you want a text only 1306 driver. It’s the bitmapped screen buffering that takes up the memory - limiting to text drastically reduces the footprint.


Thanks .

I found the library in the library manager of the arduino IDE.
It works cool.


Have you also tried U8x8 (part of U8g2)?