OpenRemote GPS Tracker Setup Integration Help

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