You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 38 Next »

Introduction

Many RouterOS devices have GPS support. It allows RouterOS to determine the precise location of its GPS receiver. GPS coordinates will indicate the latitude and the longitude values (among other parameters) of the current position.

Let's say, you have LTAP (or any other RouterOS device with GPS support) and you wish to track its location. You want the router to send this data to a server, where the data will be stored and integrated into a map, as it is more convenient to monitor. In this guide, we will showcase how you can do that. This scenario will utilize MQTT protocol communication with a platform called ThingsBoard.

Please check our MQTT and ThingsBoard guide as it will have additional useful information. ThingsBoard has a cloud solution and different local installation options (on different OS).

Since we've added a container feature, it became possible to also run the platform within the RouterOS. Meaning, you can build this scenario, solely on RouterOS units → devices with GPS support that you wish to track (for example, cars equipped with LTAPs → RouterOS devices that act as MQTT publishers), and a ThingsBoard server run within a more powerful RouterOS device (for example, a CHR machine or CCR2004-16G-2S+ → RouterOS device that acts as an MQTT broker).

If you want to choose this route (container route), make sure to pick the devices that you plan on using as a "server" carefully, because this implementation can be heavy on RAM usage (it is suggested to have a device that has at least 2 GB RAM and is either ARM64 or AMD64 architecture).

Configuration

In this guide, we will demonstrate how to configure a GPS receiver (MQTT publisher) and how to create a map under the ThingsBoard. To configure the server device (container MQTT broker), check the guide over here.

Before proceeding, make sure that the ThingsBoard is up and running and that you are able to access its WEB portal. Make sure that you can send static MQTT messages to the server (to confirm that the MQTT port is open or/and NATed properly when using the container feature). For example, from RouterOS, you can send an MQTT message like this:

/iot/mqtt/publish broker="tb" topic="v1/devices/me/telemetry" message="{\"test\":\"123\"}"

Container-ThingsBoard guide and MQTT-ThingsBoard guide have examples showing how to verify the results. After confirming that MQTT publish is successful and the data is displayed, you can set up your GPS receiver.

Package requirement: gps, iot

GPS receiver

Set up the MQTT broker:

/iot/mqtt/brokers/add name=tb address=x.x.x.x port=1883 username=YOUR_TOKEN

, where address=x.x.x.x is your ThingsBoard public IP address or a domain name. In case, it is a container ThingsBoard instance within another RouterOS device, it is that device's public IP address (used in the DNAT rule for the MQTT port).


###Configuration###
#Enter pre-configured broker's name within "":
:local broker "pc"
#Enter the topic name within "", per the broker's configuration:
:local topic "v1/devices/me/telemetry"

###Variables####
:global lat
:global lon

###GPS####
:put ("[*] Capturing GPS coordinates...")
/system gps monitor once do={
:set $lat $("latitude");
:set $lon $("longitude");}

:local message \
"{\"latitude\":$lat,\
\"longitude\":$lon}"

###MQTT###
:if ($lat != "none") do={\
:put ("[*] Sending message to MQTT broker...");
/iot mqtt publish broker=$broker topic=$topic message=$message} else={:put ("[*] Lattitude=none, not posting anything!");:log info "Latitude=none, not posting anything!"}

  • No labels