Node-RED tutorial: How to get GPS coordinates with a Maps Widget

GPS and GPRS TouchBerry Pi 10 & Node-RED Applications
May 19, 2021 by
Node-RED tutorial: How to get GPS coordinates with a Maps Widget
Boot & Work Corp. S.L., Fernandez Queralt Martinez

Introduction

Data control with TouchBerry Pi Panel PC 10.1"

Node-RED is a programming tool to wire together hardware devices, APIs and online services in new and interesting ways.

It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click.

As it is quite fascinating to use for open source projects, you are going to learn how to get GPS coordinates from your SIM7600E module and put them in a Google Maps Widget in Node-RED Dashboard.

Related links

How to

connect a Raspberry Pi PLC to Wi-Fi

Read 

Basics about

Raspberry Pi based PLC Analog outputs

Read 

How to

program the interrupt inputs of a Raspberry Pi PLC with Python

Read 

How to

find your perfect industrial PLC

See 

Raspberry Pi PLC

Family products

See 

Touchberry Pi

Family products

See 

Explanation

In this post, you will learn how to get GPS coordinates with a Map Widget from Node-RED. Let's continue the post below:

👉 How to get GPS location on Panel PC  Read >>
 

Installing and Upgrading Node-RED

In order to start your Node-RED application, you must check if you already have Node-RED installed in your Industrial Panel PC. If you do not have it already installed, run the following command to download and run the script to install Node.js, npm and Node-RED onto a Raspberry Pi.


sudo apt install build-essential git

 bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

The script above will:

  • Remove the pre-packaged version of Node-RED and Node.js if present.
  • Install the current Node.js LTS release using the NodeSource. If it detects Node.js is already installed from NodeSource, it will ensure it is at least Node 8, but otherwise it will leave it alone.
  • Install the latest version of Node-RED using npm.
  • Optionally, install a collection of useful Pi-specific nodes.
  • Setup Node-RED to run as a service and provide a set of commands to work with the service.


Autostart on boot

If you want Node-RED to run when the Pi is turned on, or re-booted, you can enable the service to autostart by running the command:

sudo systemctl enable nodered.service

To disable the service, run the command:

sudo systemctl disable nodered.service

To know more about Node-RED installation, check out the following link:  

👉 Running on Raspberry Pi   Read >>


GPSD

GPSD is a monitor daemon that collects information from GPS, differential-GPS radios, or AIS receivers attached to the host machine. Each GPS, DGPS radio, or AIS receiver is expected to be connected directly to the host via a USB or RS232 serial device. So, to link the data you get from your Serial Port (See how here >>) to Node-RED, just download some gpsd nodes: node-red-contrib-gpsd

Go to the Side Tab Menu > Click on Manage Palette > Install > Type "gpsd" > Install the node-red-contrib-gpsd package:

GPSD


Install Map nodes

Now, you are going to install some nodes for the Map Widget.

Go to the Side Tab Menu > Click on Manage Palette > Install > Type "web-worldmap" > Install the node-red-contrib-web-worldmap package:


Install Map nodes

                                 

Getting GPS Coordinates

Once installed, type: gpsd in the filter nodes search bar, and drag and drop the Adafruit Ultimate GPS node to your flow. Add a switch node and evaluate the property: msg.payload.class == (string) TPV and connect it to a debug node like this:

Getting GPS Coordinates

You will see that you will start receiving data immediately, every second. So, if you want to control that time, just add a Delay node between the Adafruit Ultimate GPS node and the switch node, with the configuration you want. For example, try receiving 1 msg every 5 seconds, and drop intermediate messages.


Add the WorldMap node

Once you get all the GPS data, you are going to add two world map nodes so that it displays in the Dashboard correctly:

Add the WorldMap node
Add the WorldMap node

If you take a look at the node help documentation, the minimum msg.payload from the worldmap nodes, must contain namelat and lon properties.


E.g. { "name": "John", "lat": 41.45, "lon": 1.53 }


So, as you already get the lat and lon properties from the GPS, you need the msg.payload.name.  So, let's add a change node, and set msg.payload.name to "Worldmap" (or any name):

Edit change node


Connect this to the world map node as shown below:

World map node

And go to your Dashboard to check your map with your location! Your flow should something be like this:

[{"id":"6e545ede.d4925","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"7a97b4c5.876cfc","type":"gpsd","z":"6e545ede.d4925","name":"Adafruit Ultimate GPS","hostname":"0.0.0.0","port":"2947","tpv":true,"sky":true,"info":false,"device":true,"gst":false,"att":false,"x":140,"y":200,"wires":[["6560f5f6.c0ed8c"]]},{"id":"6560f5f6.c0ed8c","type":"switch","z":"6e545ede.d4925","name":"","property":"payload.class","propertyType":"msg","rules":[{"t":"eq","v":"TPV","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":350,"y":200,"wires":[["4d22a0bd.63dda"]]},{"id":"2cf3ed7c.bd6ad2","type":"ui_worldmap","z":"6e545ede.d4925","group":"88f77589.0122d8","order":2,"width":"14","height":"14","name":"Worldmap ","lat":"","lon":"","zoom":"","layer":"OSM grey","cluster":"","maxage":"","usermenu":"show","layers":"show","panit":"true","panlock":"false","zoomlock":"true","hiderightclick":"false","coords":"deg","showgrid":"false","allowFileDrop":"false","path":"/mapui","x":710,"y":120,"wires":[]},{"id":"4d22a0bd.63dda","type":"change","z":"6e545ede.d4925","name":"","rules":[{"t":"set","p":"payload.name","pt":"msg","to":"Worldmap","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":200,"wires":[["23b5e03.345882"]]},{"id":"23b5e03.345882","type":"worldmap","z":"6e545ede.d4925","name":"","lat":"","lon":"","zoom":"","layer":"Esri Satellite","cluster":"","maxage":"","usermenu":"show","layers":"show","panit":"false","panlock":"false","zoomlock":"false","hiderightclick":"false","coords":"none","showgrid":"false","allowFileDrop":"false","path":"/mapui","x":730,"y":200,"wires":[]},{"id":"88f77589.0122d8","type":"ui_group","name":"","tab":"c4c17961.4519f8","order":1,"disp":true,"width":15,"collapse":false},{"id":"c4c17961.4519f8","type":"ui_tab","name":"Location","icon":"dashboard","disabled":false,"hidden":false}]



Check your map with your location


Want to create Open Source projects?

Click on the link top learn how to do it with Industrial Raspberry Pi PLC and Arduino based PLCs. See you there! :)

​Search in our Blog

Node-RED tutorial: How to get GPS coordinates with a Maps Widget
Boot & Work Corp. S.L., Fernandez Queralt Martinez May 19, 2021
Share this post

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>