MQTT Service

MQTT SERVICE

Introduction

This service offers the option to send data generated in a device to MQTT brokers.

Possible events are:

TAG_ADDED and TAG_REMOVED are only available in the AdvanTrack_Asset_Location read mode

Configuration

In order to enable and configure this service go to the system tab and in the Services drop-down select MQTT_SERVICE

Required fields are marked with *

Connection

The connection options are:

MQTT payload

Details on the required format can be seen in the JSON config chapter.

Send options

The send options are:

Inventory tag TTL is applied only on TAG_READ events.

It has no effect for other events: ADPY_PAYMENT, TAG_ALARM, etc.

To reduce the frequency of repeated events (other than TAG_READ), please change them in the ReadMode page settings (RF & Antenna options).

Advanced JSON conf

This setting allows to configure additional parameters:

An example of JSON is

{"debug":true,"debugTransport":true}

Other advanced config

These options require SSH access. Please request SSH access if required.

1. With the SSH credentials, lo into the system

2. Locate the active AdvanNet directory.

3. Download file $ADVANNET/META-INF/connectors.xml

4. Change the file connectors.xml

Possible changes are:

The configuration options must be defined at the beginning of the file. For example:

<?xml version='1.0' encoding='utf-8'?>

<aliases>

    <load-order-scope>default</load-order-scope>

    <load-order>20000</load-order>

    <CONFIGURATION>

        <com.keonn.MQTTService.MaxRetryTimeSecs>86400</com.keonn.MQTTService.MaxRetryTimeSecs>

        <com.keonn.device.IgnoreUserConfigMac>true</com.keonn.device.IgnoreUserConfigMac>

        <logger>net.ihg.util.log.DummyLogger</logger>

        <com.keonn.advannet.manager.refreshIdPeriod>2000</com.keonn.advannet.manager.refreshIdPeriod>

        <com.keonn.advannet.manager.refreshMonitorPeriod>400</com.keonn.advannet.manager.refreshMonitorPeriod>

        <com.keonn.rest.aliasfile.AdvanNetCSVS>/home/keonn/csvs/data.csv</com.keonn.rest.aliasfile.AdvanNetCSVS>

        <com.keonn.rest.aliasfile.AdvanNetCSVSDir>/home/keonn/csvs/</com.keonn.rest.aliasfile.AdvanNetCSVSDir>

        <com.keonn.rest.aliasfile.AdvanNetConfFiles>/home/keonn/kernel/module/app.AdvanNet/META-INF,/root/.advannet/</com.keonn.rest.aliasfile.AdvanNetConfFiles>

        <com.keonn.rest.aliasfile.AdvanNetLog>/var/log/AdvanNet-kernel.log</com.keonn.rest.aliasfile.AdvanNetLog>

        <com.keonn.rest.aliasfile.AdvanNetLog2>/run/log/AdvanNet-kernel.log</com.keonn.rest.aliasfile.AdvanNetLog2>

        <com.keonn.rest.aliasfile.AdvanNetLogDir>/home/keonn/logs/,/var/log/</com.keonn.rest.aliasfile.AdvanNetLogDir>

        <com.keonn.rest.aliasfile.AdvanNetLogDir2>/run/log/</com.keonn.rest.aliasfile.AdvanNetLogDir2>

    </CONFIGURATION>
...

5. Verify the modified version is a valid XML file

6. Upload modified version

Persist settings

Once the current settings seems to work as desired, please do not forget to persist system settings using the "Save current" button at the top.

JSON config

This is a JSON List of Maps, each Map with the following elements:

The javascript expression is evaluated with an injected context filled with real time data

Correct escaping of " and ' inside the body expression is the most difficult part.

Additional care is required when escaping characters.

Before entering the JSON config in the device it is recomendable to double check it's correctly formed by using a JSON validator like this one: https://jsonlint.com/

Possible examples of a JSON config entry are

Example 1:

[{

"event":"TAG_READ",

"topic":"'/to/my/topic'",

"body":"

var body='<read no=\"'+ctx_tagno+'\" id=\"'+ctx_devid+'\" ip=\"'+ctx_devip+'\" mac=\"'+ctx_devmac+'\">';

var i=0;

for(i=0;i<ctx_tagno;i++){

body+='<tag epc=\"'+ctx_tags[i].getEPC()+'\" port=\"'+ctx_tags[i].getAntenna()+'\" t=\"'+ctx_tags[i].getTimeFormatted()+'\" rssi=\"'+ctx_tags[i].getRSSI()+'\" />';

}

body+='</read>';

"

}

]

Example 2:

[{

"event":"TAG_READ",

"topic":"'/to/my/topic'",

"body":"

var body='{';

body+='\"devid\": \"'+ctx_devid+'\",';

body+='\"devip\": \"'+ctx_devip+'\",';

body+='\"devmac\": \"'+ctx_devmac+'\",';

body+='\"reads\": [';

for(i=0;i<ctx_tagno;i++)

{

body+='{';

body+='\"EPC\": \"'+ctx_tags[i].getEPC()+'\",';

body+='\"TID\": \"'+ctx_tags[i].getTID()+'\",';

body+='\"Antenna\": \"'+ctx_tags[i].getAntenna()+'\",';

body+='\"URI\": \"'+ctx_tags[i].getURI()+'\",';

body+='\"RSSI\": \"'+ctx_tags[i].getRSSI()+'\",';

body+='\"UTC time\": \"'+ctx_tags[i].getUTC()+'\",';

body+='\"Time stamp of the read with the local TimeZone offset\": \"'+ctx_tags[i].getTime()+'\",';

body+='\"Formatted UTC time\": \"'+ctx_tags[i].getUTCFormatted()+'\",';

body+='\"Formatted time of the read with the local TimeZone offset\": \"'+ctx_tags[i].getTimeFormatted()+'\"';

body+='}';

if(i< ctx_tagno - 1){

body+=',';

}

}

body+=']';

body+='}';

"

}]

Example 3:

[{

"event":"TAG_ALARM",

"topic":"'/topic/tag_alarm'",

"body":"

var body='{';

body+='\"type\": \"'+ctx_type+'\",';

body+='\"devid\": \"'+ctx_devid+'\",';

body+='\"devip\": \"'+ctx_devip+'\",';

body+='\"devmac\": \"'+ctx_devmac+'\",';

body+='\"epc\": \"'+ctx_epc+'\",';

body+='\"uri\": \"'+ctx_uri+'\"';

body+='}';

"

},

{

"event":"TAG_ADPY_PAYMENT",

"topic":"'/topic/tag_payment'",

"body":"

var body='{';

body+='\"type\": \"'+ctx_type+'\",';

body+='\"devid\": \"'+ctx_devid+'\",';

body+='\"devip\": \"'+ctx_devip+'\",';

body+='\"devmac\": \"'+ctx_devmac+'\",';

body+='\"epc\": \"'+ctx_epc+'\",';

body+='\"uri\": \"'+ctx_uri+'\"';

body+='}';

"

}]

Example 4:

[{

 "event":"GPI",

 "topic":"'name.of.my.topic'",

 "body":"var body=ctx_devid+','+ctx_devip+','+ctx_devmac+','+ctx_type+','+ctx_subtype;"

}]

Possible events

The available context injected into the body javascript expression depends on the EVENT TYPE

TAG_READ context

Available context variables are

ctx_tags.length must never be used! The internal buffer array is a fixed size array, the real valid entries are defined by ctx_tagno

Other events context

All other events share the same context variables

Examples

application/xml

Send inventory data in xml format.

The JSON string is as follows.

[{

"event":"TAG_READ",

"topic":"'/to/my/topic'",

"body":"

var body='<read no=\"'+ctx_tagno+'\" id=\"'+ctx_devid+'\" ip=\"'+ctx_devip+'\" mac=\"'+ctx_devmac+'\">';

var i=0;

for(i=0;i<ctx_tagno;i++){

body+='<tag epc=\"'+ctx_tags[i].getEPC()+'\" port=\"'+ctx_tags[i].getAntenna()+'\" t=\"'+ctx_tags[i].getTimeFormatted()+'\" rssi=\"'+ctx_tags[i].getRSSI()+'\" />';

}

body+='</read>';

"

}

]