Implementation of devices using MQTT as protocol

88bit16 days ago

Hi all, firstly I would like to express my utmost admiration for this project, it is next level. I'm only using Traccar for a week so please be kind. :-)
I have tried to find some information on the implementation of the MQTT protocol in Traccar, I did find some information but it is not clear to me how this is implemented. I would have expected that the Traccar server subscribes to one or multiple topics on an EMQX MQTT broker implemented in the server settings as an attribute. The EMQX to MySQL integration would insert the received decrypted message from the device in clear text in a JSON formatted string adhering to some format e.g. OsmAnd {deviceid=12345&lat=48.8566&lon=2.3522&timestamp=2021-01-01T00:00:00Z&speed=15&bearing=270&altitude=35&accuracy=10&hdop=0.8&batt=75}.
However, the information I found suggests that the incoming MQTT data from the device needs to be converted into an HTTP push to the server.
Anton Tananaev, mentioned in a post that MQTT is now implemented, it would be great if he could elaborate on this.
The background to this is that I'm building a LoRaWAN-based tracking solution for very remote locations where no other communication infrastructure is avalible.
Thank you all for making the world a better place, helping each other. Regards

Anton Tananaev16 days ago

Traccar does not subscribe to MQTT. It can receive data in MQTT format and/or it can push decoded data via MQTT.

88bit16 days ago

Thank you for your quick reply, when you say it can receive data in MQTT format what do you mean by that? MQTT does not format the data it is a data bus. In most IoT applications it would be value pairs. Are you saying that the HTML post method into the Traccar application will accept a typical value pair text string e.g.

{
  "deviceid" : 12345,
  "lat" : 48.8566,
  "lon" : "2.3522",
  "timestamp" : "2021-01-01T00:00:00",
  "altitude" : 987 
}

and this is inserted as a string with the HTTP Post method?
Regards

Anton Tananaev16 days ago

MQTT is a protocol, so it certainly has its format. Not sure how HTTP is related to this conversation.

88bit15 days ago

Hi Anton, yes in the greater sense we could call it a protocol, in the true sense of the word it is a network transport application. However, the payload can be just about anything. When you say you support MQTT then what do you mean by that? Somehow the received MQTT payload message has to get from the MQTT message ( example above) into the database. The API uses HTTP GET, PUT, and DELETE. I can certainly write a conversion extracting the MQTT message and insert it via the Traccar API. However, if there is an inbuild function I would rather use it.
In this specific use case, I use a Chirpstack server that receives my messages from a LoRaWan device, the Chirpstack server will decrypt the base 64 messages, which are then sent to the Influx DB via Telegraf and inserted into the DB.
I'm somehow missing a piece of the puzzle. Your help would be greatly appreciated.

88bit15 days ago

I should have mentioned that the decrypted LoRaWAN message is sent via MQTT.

Anton Tananaev15 days ago

Traccar supports more than 250 different protocols. Some of them are MQTT-based. But again, we don't subscribe to a broker. Instead a device pushes data to Traccar directly using MQTT. It obviously has some application level format as well. If you're interested in more details, I recommend checking relevant decoders in the source code.

88bit14 days ago

Thank you Anton for your answer, I now understand the concept.
For anyone coming from the OT world, this is a different concept, it loses many of the underlying benefits of the MQTT protocol, such as " last will" statements and so forth. I'm not saying that this is bad for this use case, in fact the opposite, I just struggled to understand the way it was used.
I will try to use the Chirpstack HTTP integration and report on my adventures.