Skip to content

MQTT Plugin

Overview

This plugin provides access to an MQTT broker for organisations to publish-subscribe to their Krucial connect device data.

Setup

The following guide presumes that the user is utilising the Krucial CONNECT application. The same configuration can be carried out using the Krucial CONNECT CLI or API. The user has to complete the following steps to successfully set up their deployment to publish device data:

  1. Add a new MQTT Plugin on Krucial CONNECT
  2. Add a new deployment on Krucial CONNECT
  3. Create valid codecs for you device(s).
  4. Create device profiles for devices on Krucial CONNECT.
  5. Add devices to your deployment.

1. Add a new MQTT Plugin

To create a new MQTT Plugin:

  • Login to your Krucial CONNECT account
  • Select Plugins from the navigation menu to browse to the plugins section.
  • Click the "Add Plugin" button.
  • Give the plugin a name to identify different MQTT accounts or use cases.
  • From the dropdown list, select MQTT for the type
  • Enter a username and password
  • Click the "Save" button.

2. Add MQTT plugin to deployment

To create a new Deployment for your MQTT plugin:

  • Select Deployments from the navigation menu to browse to the deployments section.
  • Click the "Add Deployment" button.
  • Give the deployment a name to identify different deployments or use cases.
  • From the dropdown list, select your K-Cell
  • From the next dropdown list, select your MQTT plugin
  • Click the "Save" button.

3. Create valid codecs for your device(s)

Payload codecs can be used to decode your devices data as it passes through the Krucial CONNECT system. All codecs must conform to the standard outlined by the LoRA Alliance. Documentation for this can be found here LoRa Alliance Payload Codec API Docs.

Codecs must be written in JavaScript. An example codec is defined below:

function decodeData(bytes, recvTime) {
    let data = {
        decodedData: bytes,
        recvTime: recvTime
    }

    return {data: data, errors: [], warning: []};    
}

function decodeUplink(input) {
    decodeData(input.bytes, input.recvTime)
}

4. Create and sync device profiles for your devices

To create a device profile for your device:

  • Select Device Profiles from the navigation menu to browse to the device profiles section.
  • Click the "Add Device Profile" button
  • If using a JSON file to upload a device profile. Select "file upload" otherwise select "manual entry" (Example JSON files can be found here: GitHub)
  • Give the device profile a name and enter the configuration values. The "Krucial OTAA Default" values can be used or updated as required.
  • Copy the codec previously written to associate the device profile with your codec.
  • Click "Save" button
  • Once returned to the table click the "sync" button located in the Operations section of the table.

Repeat as necessary for your given devices

5. Add devices to your deployment

To add a device to your deployment:

  • Select Deployments from the navigation menu to browse to the deployments section.
  • Click on your deployment
  • Click "Manage Devices" button
  • Click "Add device to deployment" button
  • Give you device a name and enter the DevEui (this can be found on the device)
  • Enter the devices Lat/Lng coordinates (if necessary)
  • From the dropdown menu select the required profile for the device
  • Enter the AppKey for the device
  • Click "Save" button

Repeat as necessary for your devices.

Getting your MQTT Topic details

Once all of the above has been done, your deployment is ready to start publishing device data to the MQTT broker. Once the K-Cell has started to send data your MQTT Topic Name will be updated in the deployment plugin config section.

This is the topic that you can use to subscribe to in your own application to receive the device data.