Description


This article describes the steps to add Milesight IoT end devices on Loriot, with a LoRaWAN® gateway that uses same regional parameters already added. For the steps about the gateway, refer to How to connect Milesight Gateway to Loriot.


Requirement


  • Loriot account
  • A Milesight LoRaWAN® gateway connected to Loriot
  • Milesight LoRaWAN® end devices whose frequency plan matches the gateway’s


Configuration


1. Go to Dashboard page to click Create New Application or go to Applications page to click +New Application.

2. Click the application you create, go to +Enroll Device to reach the page to type device information and create device:

  • LoRaWAN Version: 1.0.x
  • Enrollment Process: ABP or OTAA. All Milesight end devices use OTAA by default.
  • Following information from device’s user guide or ToolBox:
    • For OTAA devices: DevEUI, AppKey, AppEUI(Join EUI)
    • For ABP devices: DevEUI, DevAddr, NwkSkey, AppSkey

The default AppKey is 5572404C696E6B4C6F52613230313823.

Note: Make sure that the frequency plan and frequency settings of gateway and node are matched.

3. Go to Applications > Devices > LoRaWAN Parameters page to click Configure Parameters to adjust the parameters.

Usually you can keep all settings by default. If your device class type is Class C, please adjust the class value.

 

4. Wait for a while and refresh the Device page, on Last data (10 latest records)* section you’ll see the uplinks from device.


5. Go to Dashboard > Applications > Devices > Send downlink, you can control the devices via downlink command.

Example: reboot the device.

  • Port: application port of end device, all Milesight end devices use 85 by default
  • Payload: refer to user guide of devices


6. If you need to check the decoded data, go to Applications > Websocket Applications page, click the WebSocket sample link.


Click Decode Data From Device to add decoder to add the decoder.


Find the Milesight device decoder from github and modify the decoders of below points:

  • 1) Delete function header function Decoder(bytes, port){ and return decoded;
  • 2) Modify all variables bytes to v;
  • 3) Add JSON.stringify(decoded, null, 2) in the end.

 

AM103 example decoder for Loriot:

    var decoded = {};

    for (var i = 0; i < v.length;) {
        var channel_id = v[i++];
        var channel_type = v[i++];
        // BATTERY
        if (channel_id === 0x01 && channel_type === 0x75) {
            decoded.battery = v[i];
            i += 1;
        }
        // TEMPERATURE
        else if (channel_id === 0x03 && channel_type === 0x67) {
            // ℃
            decoded.temperature = readInt16LE(v.slice(i, i + 2)) / 10;
            i += 2;

            // ℉
            // decoded.temperature = readInt16LE(v.slice(i, i + 2)) / 10 * 1.8 + 32;
            // i +=2;
        }
        // HUMIDITY
        else if (channel_id === 0x04 && channel_type === 0x68) {
            decoded.humidity = v[i] / 2;
            i += 1;
        }
        // CO2
        else if (channel_id === 0x07 && channel_type === 0x7D) {
            decoded.co2 = readUInt16LE(v.slice(i, i + 2));
            i += 2;
        } else {
            break;
        }
    }



/* ******************************************
 * v to number
 ********************************************/
function readUInt16LE(v) {
    var value = (v[1] << 8) + v[0];
    return value & 0xffff;
}

function readInt16LE(v) {
    var ref = readUInt16LE(v);
    return ref > 0x7fff ? ref - 0x10000 : ref;
}

JSON.stringify(decoded, null, 2)

7. The decoded data will be shown on the page.


                                                                                         ----END- --