MQTT

MQTT

Inside Wialon (Also check documentation: https://docs.wialon.com/)

Before receiving data inside wialon - select: Messages(1.) → Select your module (2.) → select Unit properties (3.)

 

Make sure that Server address, Unique ID and Device type matches in FMSET:

 

Inside FMSET

While creating or editing user settings template go to: Connectivity → Telemetry server → MQTT broker adress settings. Domain name and Port should mach the ones inside Wialon:

Sending data via MQTT

Publish data any sensor from list of sensors:

Link to Sensor list

Publishing data
#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> main() { while(get_val(Sensor_SignalPDPActive) == 0) { Delay(100); //wait until device connects to network } while(1) { MQTT_PublishSensor(Sensor_GPS_coordinates); //publish Sensor_GPS_coordinates to server MQTT_PublishSensor(Sensor_GPS_speed); //publish Sensor_GPS_speed to server MQTT_PublishSensor(Sensor_SignalIN2); //publish Sensor_SignalIN2 to server MQTT_PublishSensor(Sensor_SignalMotion); //publish Sensor_SignalMotion to server MQTT_PublishSensor(Sensor_GSM_PWR); //publish Sensor_GSM_PWR to server Delay(10000); } }

 

Our published data inside wialon is going to look like this:

 

Sensor and then number indicates which sensor is being published, to understand which sensor is being published - look at sensor list decimal value and then compare it to published one:



Sending string/array of data under custom sensor name

It is possible to publish array with custom sensor name. Sensor ID's should be between 0xE000 and 0xEFFF:

Publishing array
#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> new dataPayload[15]; main(){ for(new i = 0; i<14; i++){ //creating data array dataPayload[i] = i+1; } while(get_val(Sensor_SignalPDPActive) == 0) { Delay(100); //wait until device connects to network } while(1) { MQTT_PublishArray(0xE001, dataPayload, sizeof(dataPayload)); Delay(10000); } }


Resulting data will look like so:

Publishing into string sensor

There are also sensors named "Sensor_STRINGX". To write data and publish it you must do it like so:

Publishing Sensor_STRINGX
#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> main(){ write_buf(Sensor_STRING1,11, "Test String"); write_buf(Sensor_STRING2,12, "Test String2"); write_buf(Sensor_STRING3,12, "Test String3"); while(get_val(Sensor_SignalPDPActive) == 0) { Delay(100); //wait until device connects to network } while(1){ MQTT_PublishSensor(Sensor_STRING1); // Publish string to server via MQTT MQTT_PublishSensor(Sensor_STRING2); // Publish string to server via MQTT MQTT_PublishSensor(Sensor_STRING3); // Publish string to server via MQTT Delay(10000); } }

 

Resulting data will look like so:

Publishing data to MQTT broker with user defined topic

You can also publish data under new topic, to which, later on, you should subscribe to see incoming data.

Publishing with new topic
#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> new array1[10]="35 degrees"; main(){ MQTT_PublishQoS0("865209039408092/temperature", array1, strlen(array1)); while(1){ Delay(100); } }

 

Result data will look like so:

Receiving data over MQTT via script

To receive data from wialon, you need to initialize Remote_Command and add callback to store it to your variable:

Receive data over MQTT
new buffer[100] public callback(event) { switch(event) { case Remote_Command: { len = buf_len(Remote_Command); //reading transmitted message length if(len != 0) //if length is not 0, then do the following { read_buf(Remote_Command, len, buffer); //reading and storing data into your predefined array } } } return 0; } main() { Init(Remote_Command) for(;;) { Delay(1000); } }

 

To send data over MQTT from custom server, first you need to set your MQTT broker address via settings template:

Once you've done that, now you need to send certain payload with certain topic. In the near future, there's going to be a possibility to change module subscription topic. At the moment it's only possible to send data to module only using 'imei/OUTC' topic, where 'imei' is your device imei number. For example, topic name: '865209039408092/OUTC'.

In order to send data to this topic, you need to form a payload which looks like so: