OpenRemote GPS Tracker Setup Integration Help

Hello OpenRemote Support Team, May I have please wiki setup guide to integrate GPS tracker with openremote map for assert location monitoring application or anybody has successfully integrate with the same? Thanks.

Hi @kpin404
I’m not sure if I understood correctly what you need, but if you are trying to send GPS position to OpenRemote, I’m actually doing something like this:

let nmeaData = msg.payload;

// Extract the line containing the GPS information
let lines = nmeaData.split("\n");
let gpsInfoLine = lines.find(line => line.startsWith("+CGPSINFO:"));

if (gpsInfoLine) {
    // Parse CGPSINFO and extract latitude and longitude
    let match = gpsInfoLine.match(/(\d{2})(\d+\.\d+),(N|S),(\d{3})(\d+\.\d+),(E|W)/);
    if (match) {
        let latitudeDegrees = Number(match[1]);
        let latitudeMinutes = Number(match[2]);
        let longitudeDegrees = Number(match[4]);
        let longitudeMinutes = Number(match[5]);

        // Calculate decimal latitude and longitude
        let latitude = latitudeDegrees + (latitudeMinutes / 60);
        let longitude = longitudeDegrees + (longitudeMinutes / 60);

        // Adjusting latitude and longitude based on hemisphere (N/S, E/W)
        if (match[3] === 'S') {
            latitude = -latitude;
        }
        if (match[6] === 'W') {
            longitude = -longitude;
        }

        // Constructing the final payload in the desired format
        msg.payload = {
            type: "Point",
            coordinates: [longitude.toFixed(6), latitude.toFixed(6)]
        };
    } else {
        // Handling the case when the NMEA data doesn't match the expected pattern
        msg.payload = "Invalid NMEA data";
    }
} else {
    // Handling the case when the GPS information line is not found
    msg.payload = "GPS information not found";
}

return msg;

I have some Raspberrys that move around, a Python script that calls the serial port every few sec to read GPS informations and pass them to this node in Node-Red. Be careful with the format of the coordinates you send, they need to be like this

        // Constructing the final payload in the desired format
        msg.payload = {
            type: "Point",
            coordinates: [longitude.toFixed(6), latitude.toFixed(6)]

To send the location data of a device to OpenRemote, you can simply create a new asset, and use MQTT, HTTP, or any other protocol within our wiki page to send over the JSON-serialized GeoJSON point to the OpenRemote server. By doing that, the asset’s location will automatically update in real time. Other than that, I cannot understand exactly what you would like to achieve.

I have written a small test script for testing certain functionalities. Specifically, it tests that an asset moves in real time on the map page. You can use it to see how it is done (comment/uncomment respectively whether you have SSL or not). The script is using Python, along with Paho for its MQTT communication. You can absolutely alter it to fit your own use-case (For example, with a Raspberry Pi, you could use it to write a program that automatically sends the current location every second).

import paho.mqtt.client as mqtt
import time
import ssl
import logging
from geojson import Point
import json

import random

realm = "master"
username = 'master:mqtttest'
secret = ''
host = 'localhost'
port = 1883
clientID = 'pythonScriptForMockData'
assetID = ''

# locations = [((5.554028, 51.425707)),
# ((5.287170, 51.712115)),
# ((5.841980, 51.842566)),
# ((5.946350, 52.205924)),
# ((4.920666, 52.376000)),
# ((4.636230, 52.383982)),
# ((4.269826, 52.069086)),
# ((4.400024, 52.008555)),
# ((4.576609, 51.834784)),
# ((4.671936, 51.798824)),
# ((5.248718, 51.681071)),
# ((5.430775, 51.457919))]

locations = [
((4.435696166798136, 51.940636417954586)),
((4.375382174432978, 51.95330994830479)),
((4.327670248217883, 51.960418691438214)),
((4.291615746483567, 51.95494527458846)),
((4.2556074561153325, 51.92940838114288)),
((4.361289477915206, 51.914107637823356))
]

points = [Point(location) for location in locations]

def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))
    logging.info("Connected with result code "+str(rc))


def on_publish(client, userdata, msg):
    print(msg.topic+" "+str(msg.payload))
    logging.info(msg.topic+" "+str(msg.payload))


def on_disconnect(client, userdata, rc):
    if rc != 0:
        print("Unexpected disconnection.")
        logging.info(f"Unexpected disconnection. Reason: {mqtt.connack_string(rc)}")


def on_log(client, userdata, level, buf):
    print("log: ", buf)
    logging.info("log: ", buf)


mqtt_client = mqtt.Client(clientID)
mqtt_client.username_pw_set(username, password=secret)
# context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
# mqtt_client.tls_set_context(context)
mqtt_client.on_connect = on_connect
mqtt_client.on_disconnect = on_disconnect
mqtt_client.on_log = on_log
mqtt_client.connect(host, port=port, keepalive=930)
mqtt_client.loop_start()

# Continuously read and send temperature values
while True:

    for point in points:

        print("{"+json.dumps(random.randint(0, 9))+"}")

        value = mqtt_client.publish(f"{realm}/{clientID}/writeattributevalue/location/{assetID}", json.dumps(point), 2)
        # print(str(point))
        time.sleep(0.5)
    


# Disconnect MQTT client
mqtt_client.disconnect()
mqtt_client.loop_stop()

Best of luck, let me know if there are any questions!

1 Like