How to track gps coordinates in Grafana with The Things Network LoRa

Some time ago I bought a Dragino lgt-92 GPS Tracker and connected it to The Things Network. The Things Network uses a console to output the payload wich is received from the end-nodes. It’s functional but not user friendly. I was looking for a way to plot the wearabouts of the gps tracker on a live map. You can read here how I managed to make this.

The Things Network uses the community to deliver a free LoRaWAN network. You can connect your own gateway to let people connect with the network and ofcourse you can use your own nodes. However it is not nessecary to have your own gateway. The Things network has a growing number of gateways so the coverage is growing fast.


DSMR P1 – Slimme meter via WiFi adapter met display


Adding the Dragino GPS Tracker to TTN

Adding the Dragino GPS Tracker to the things network was easy.

First you have to make an account with TTN. After you logged in you can add a application. Go to this url and click on APPLICATIONS

Click on Add Application and give it a id. I used “gpsapp”. You can select the nearest handler.

Now you have to enter some information from the label wich was inside the box of the Dragino Tracker.

There is an auto-generated Application EUI. You first have to remove this and enter the one from the label.

Go to the devices menu and enter a descriptive Device ID. Fill in the Device EUI from the label and one of the tree App Keys. Klick on Register to finish the registration.

The last thing you have to do is to disable the Frame Counter Checks. This is a security mechanism that does not work well with this kind of devices. Go to the device settings and disable it.

Now turn on the Dragino DPS Tracker and wait for it to connect to TTN. This can take a while to join and activate. You can follow this process in the Application data tab.

I was getting some information in the console. The information wich is displayed is the raw payload wich the tracker transmits. You can use a conversion to make it readable to us humans. To do this you have to make a custom payload format and put it in the console. Go to your application and click on Payload Formats. Enter the following code under Custom and click Save Changes.

function Decoder(bytes, port) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.
var alarm=(bytes[6] & 0x40)?true:false;//Alarm status
value=((bytes[6] & 0x3f) <<8) | bytes[7];
var batV=value/1000;//Battery,units:Volts
value=bytes[8]<<8 | bytes[9];
if(bytes[8] & 0x80)
value |=0xFFFF0000;
var roll=value/100;//roll,units: Β°
value=bytes[10]<<8 | bytes[11];
if(bytes[10] & 0x80)
value |=0xFFFF0000;
var pitch=value/100; //pitch,units: Β°
var json={
var value=bytes[0]<<16 | bytes[1]<<8 | bytes[2];
if(bytes[0] & 0x80)
value |=0xFFFFFF000000;
var value2=bytes[3]<<16 | bytes[4]<<8 | bytes[5];
if(bytes[3] & 0x80)
value2 |=0xFFFFFF000000;
if (value == 0x0FFFFF && value2 == 0x0FFFFF)
//gps disabled (low battery)
} else if (value === 0 && value2 === 0) {
//gps no position yet
} else {
json.latitude=value/10000;//gps latitude,units: Β°
json.longitude=value2/10000;//gps longitude,units: Β°
return json;

When this is done you can check the payload again. The Battery Status, GPS Coordinates Pitch and Roll and Alarm data is visible now

Install Node-RED on your system and install the “node-red-contrib-ttn” pallette via the hamburger menu on the right.

Restart Node-RED and log in again. You will now see some ttn boxes on the left. Drag the ttn-event box to the flow and double click it.

Enter the Device ID wich you entered in the TTN console. You can give it the same name.

Now click on the pencil next to the App. Enter the App ID from the TTN Console and copy the Access Key. The discovery address is filled in automatically.

Click on Update to go back to the properties of the uplink node. Click on Done.

Now drag the green debug box from the output menu on the left to the flow. Connect the gray dots from the blue box to the debug box. Double click on the debug box and select “complete msg object”. To get the full payload. Now click Done.

If all is right you can click Deploy in the upper right corner. The gray dot on the dragino-gps-tracker box has to be green to show it’s connected to TTN. You can see the new payloads coming in Node-RED in the debug window on the right. Select “Debug messages” from the hamburger menu.

Connecting Node-RED to InfluxDB

Install InfluxDB on your system and create a new database. There are many manuals online you can follow. Now let’s connect Node-RED to InfluxDB. Click on the hamburger menu / Palette. Search for the node-red-contrib-influxdb palette and install it. Click Close and restart Node-RED.

You will now see some influxdb boxes under the storage menu on the left. Drag the brown influxdb out node to the flow on the right.

Double click it and click on the pencil next to Server to create a new database connection. Fill in the ip address of the Host, the port and the previously created database. Enter the user credentials and Click Update.

You are now back in the influxdb out node properties, select the just created server. Enter “location” in the Measurement field to fill the location table with the output of the payload from the GPS Tracker. Give it a name and click on Done.


You have now successfully created the database connection. Click on Deploy to apply the changes. The debug window gives you some messages for troubleshooting connection issues.

Connect Grafana to InfluxDB

First you have to install the InfluxDB data source and connect to the just created InfluxDB database. Click on Configuration / Data Sources and search for the InfluxDB data source. Give it a name, fill in the ip address and port number. Under Auth, select “With Credentials” and fill in the Database name, username and password to connect to InfluxDB.

Click on Save & Test to apply the changes.

Installing the Grafana TrackMap plugin

You are now ready to install the Grafana TrackMap plugin. This plugin uses the location information from the database to display it on a map. You can even make a graph of the battery voltage and configure an alarm when you have to recharge the battery.

You can install the TrackMap plugin the cli. Just install it by entering:

sudo grafana-cli plugins install pr0ps-trackmap-panel

You are now able to add a new visualisation when you add a new dashboard. Just fill in the next fields and the locations from the tracker will be displayed on the map.

You can paste this into grafana to make it more easy:

SELECT median("latitude"), median("longitude") FROM "location" WHERE $timeFilter GROUP BY time($__interval) fill(none)

Adding the battery graph

Did you see the battery graph in the previous screenshot? You can enable this by creating a new graph. Just enter the following fields:

You can paste the following code to make it easy for yourselve:

SELECT mean("value") FROM "measurement" WHERE $timeFilter GROUP BY time($__interval) fill(null)

Change the following settings:

  • Visualisation / Draw Modes / Points: enabled
  • Visualisation / Stacking & Null Value: Connected
  • Axes / Left Y / Y-Min 0
  • Axes / Left Y / Y-Max 5.5
  • Axes / Left Y / Units / Energy / Volt
  • Legend / Options / To the right: enable
  • Legend / Options / Values / Current: enable
  • Thresholds & Time Regions / T1 gt : 2,8 – Color Critical – Line: enabled

That’s it, you’re done!

16 thoughts on “Plot GPS Tracks with The Things Network in Gafana”
  1. Hi Roel,
    this is a very good explanation for the lgt-92 I have myself. I will try this today. The frame counter sucks, but I never was that smart to disable ist, good idea.. When the lgt-92 is powered Up again, the frame counter needs to reset too, what is really stupid. Thanks for your Tutorial, you should link this in the ttn Forum.

    1. Hi Peter.

      The frame counter has to be disabled for devices wich use ABS. I don’t think the dragino can use otaa. When there is a way to set up otaa on this device the frame counters can be enabled again. Disabling only weakens security a bit but is faster with joining the ttn network.

      Good idea of linking it to the ttn forum. I will do that when I am home again.

  2. Is there a way to link the lgt-92 data to grafana without node-red?
    This user-unfriendly prog does not work the right way.
    The node-red-contrib palette installation is not possible at my system….sucks.

    1. Hi peter. I only looked at node red because of the manual i found on another site. Maybe there are other brokers i don’t know yet.

      I had the same problem. Reinstalling node red on another system solved the pallette problem for me. Many people have this problem. The internet is full of people complaining of problems with the palette.

  3. I stopped my activities to copy this workflow because I would prefer to have an online-version of lgt-92-data on a online map, like every 30$ gps-gsm-tracker does provide.
    I donΒ΄t want to install this amount of tools on every system where I want to see the gnss-data, that is not efficient. It should be online, to have it on my mobile devices, pc, and so on.
    Any ideas? Thanks for your support.

    1. Hi Peter.

      This was the way I made it work. I agree there are many steps involved. I also configurerd my 3 ttgo t-beams this way. I guess it is the best way of visualizing the ttn data at this moment. If you found a more easy way to do this, please let me know.

      Greetz, Roel

  4. Hi Roel,

    excellent summary, helped me a lot!

    As I did the first part earlier already, I started from Node Red onwards, and succeeded with some minor adaptations.

    I bought my LGT92 Mid January.
    I failed with some other tutorials until I realized I got one with newer 1.5.0 firmware, which is different in various aspects.
    From your Custom decoder, I can see that this is the one for the older 1.4 firmware, it does not work for the 1.5 FW.

    (BTW, I always had frame counter check enabled without any issues.)

    I just have one open issue:
    When my LGT92 does not get the GPS fix, it sends 0 (a zero) for latitude and longitude, which really makes the tracking look ugly in the trackmap.

    So I’m wondering how to solve that. Two ideas:
    1) A function in Node Red to not send such payload to InfluxDB at all
    2) Ignoring such Coordinates for the trackmap in Grafana

    The first idea has the disadvantage that even the battery state gets lost.

    However, my skills are not enough for both.

    Would be great if you have any idea or even solution to this.

    Best regards, Dirk

    1. Hi Dirk,

      I don’t use the LGT92 anymore so I am not aware of recent updates. I use the TTGO T-BEAM instead wich you can program with arduino yourself. You can configure grafana not to show zero values with the following setting. Grafana - Ingnore zero values

      Best regards,

  5. Hi Roel,

    Very nice job on the casing, I saw you made the design available. As I dont have a 3D printer and as I want to use 3 TTGO T-Beam ESP32 for demo purposes I was wondering if I can order 3 printed casings from you?

    Kind regards,


  6. Hi Roel,

    On what operating system did you install influx and grafana?

    I will try to reproduce this procedure.


  7. Hello Roel,

    I continue with the replica of the tutorial, but I am not sure how to add the new visualization from a query.

    How do I get to that point?


  8. Hello Roel,
    Nice writeup :thumbsup:
    I’m searching for a way to show multiple sheep trackers in the same map, and I also need to be able to look up the map from mobilephone while out in the mountains. Would this be possible with grafana?

    I’m also curious about the power consumption of the ttgo t-beam. Would it be possible to have maybe four positions pr day for about 120 days?

    Kind regards

    1. Hi Kjetil,

      It is certainly possible to plot multiple positions on the same map, grafana is such a nice tool! The t-beam is very power hungry so I don’t know if it could survive for 120 days with 4 transmissions per day. Maybe if you disable the screen it is doable. You can also put it in deep sleep and wake it up 4 times a day.

Leave a Reply

Your email address will not be published. Required fields are marked *