EMQX Configuration

EMQX Configuration

Following are the components being used in EMQX stack.

  • MQTT-SN Gateway
  • Rule Engine
  • Rule Engine Action

If you used Docker (the recommended way) of installing the FindMyCat cloud software, you can skip to this step here.

After EMQX is correctly setup the following pipline will be created:



LightImage

Enable MQTT-SN Gateway

  1. Navigate to the EMQX Dashboard (port 18083). Under /plugins find emqx_sn plugin and enable it.
LightImage
  1. MQTT-SN listens over UDP protocol; make sure the port 1885 is listening.
LightImage

Choose MQTT topic string

Since FindMyCat uses MQTT-SN for device to server communication, and MQTT-SN does not yet support authentication, we must choose the topic name to which the device will publish to, be a random string that isn't easily guess-able eg. [}xRDvRP:kN*:8.

I will refer to this as /your-chosen-topic-string for this page.

For additional security measures, you can change what port the MQTT-SN is configured at in etc/emqx/plugins/emqx_sn.conf

mqtt.sn.port = <new-port>

Create Webhook Resource

  1. Create a webhook resource for Traccar port 5055. Use the following config:
LightImage

Configure Rule Engine

Create Rule

Paste the following SQL query in the Rule Condition SQL

SELECT
  nth(1, split(payload.msg, ',')) as latitude,
  nth(2, split(payload.msg, ',')) as longitude,
  nth(3, split(payload.msg, ',')) as satellites,
  nth(4, split(payload.msg, ',')) as accuracy,
  nth(5, split(payload.msg, ',')) as batt_lvl,
  clientid
FROM
  "/your-chosen-topic-string"

This tells the Rule engine to listen on mqtt topic /your-chosen-topic-string for any messages and extract the latitude, longitude, satellites, accuracy and battery_level to be passed over to the webhook that makes the POST request.

Add Rule Action

Click on Create Action, and Select Data to Web Server option. For the Resource, select the webhook you created in the above step.

Paste this for the body of the POST request:

id=${clientid}&lat=${latitude}&lon=${longitude}&accuracy=${accuracy}&sat=${satellites}&batt=${batt_lvl}
LightImage
LightImage

Done 👍 MQTT-SN -> Traccar pipeline should now work.