Tutorial de Node-RED: Cómo obtener las coordenadas GPS con un widget de mapas

GPS y GPRS TouchBerry Pi 10 y aplicaciones Node-RED
19 de mayo de 2021 por
Tutorial de Node-RED: Cómo obtener las coordenadas GPS con un widget de mapas
Boot & Work Corp. S.L., Fernandez Queralt Martinez

Introduction

Odoo • Image and Text

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

Ofrece un editor basado en el navegador que facilita el cableado de los flujos utilizando la amplia gama de nodos de la paleta que pueden desplegarse en su tiempo de ejecución con un solo clic.

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

En este blog, aprenderás cómo obtener las coordenadas GPS con un Widget de Mapa de Node-RED. Continuemos con el post siguiente:

👉 Cómo obtener la localización GPS en el Panel PC  Read >>
 

Instalación y actualización de Node-RED

Para iniciar tu aplicación Node-RED, debes comprobar si ya tienes Node-RED instalado en tu Panel PC Industrial. Si no lo tienes ya instalado, ejecuta el siguiente comando para descargar y ejecutar el script para instalar Node.js, npm y Node-RED en una 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.
  • Instalará la versión actual de Node.js LTS utilizando el NodeSource. Si detecta que Node.js ya está instalado desde NodeSource, se asegurará de que sea al menos Node 8, pero en caso contrario lo dejará solo.
  • 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.


Autoinicio en el arranque

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   Leer >>


GPSD

GGPSD es un daemon de monitorización que recoge información de GPS, radios DGPS diferenciales o receptores AIS conectados a la máquina anfitriona. Se espera que cada GPS, radio DGPS o receptor AIS esté conectado directamente al host a través de un dispositivo serie USB o RS232. Por lo tanto, para vincular los datos que se obtienen del puerto serie (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








Instalar los nodos del Mapa

Ahora, vas a instalar algunos nodos para el Widget de Mapa.

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


Instalar los nodos del Mapa

                                 

Obtención de coordenadas GPS

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:

Obtención de coordenadas GPS

Verás que empezarás a recibir datos inmediatamente, cada segundo. Así que, si quieres controlar ese tiempo, solo tienes que añadir un nodo de retardo entre el nodo GPS del Adafruit Ultimate y el nodo del interruptor, con la configuración que quieras. Por ejemplo, intenta recibir 1 msg cada 5 segundos, y elimina los mensajes intermedios.


Añadir el nodo WorldMap

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


Añadir el nodo WorldMap
Añadir el nodo WorldMap

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):

Editar el nodo de cambio


Connect this to the world map node as shown below:

Nodo del mapa del mundo

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}]



Comprueba el mapa con tu ubicación







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! :)

Buscar en nuestro blog

Tutorial de Node-RED: Cómo obtener las coordenadas GPS con un widget de mapas
Boot & Work Corp. S.L., Fernandez Queralt Martinez 19 de mayo de 2021
Compartir

¿Estás buscando tu Controlador Lógico Programable ideal?

Echa un vistazo a esta comparativa de producto de varios controladores industriales basados en Arduino.

Comparamos entradas, salidas, comunicaciones y otras especificaciones con las de los equipos de otras marcas destacadas.


Industrial PLC comparison >>>