Stand with Ukraine flag
Try it now Pricing
Community Edition
Register of a mokosmart LoRaWAN device and Gateway in ThingsBoard
Getting Started Documentation Devices Library Guides Installation Architecture API FAQ
On this page

Register of a mokosmart LoRaWAN device and Gateway in ThingsBoard

The purpose of this guide is to outline how to register mokosmart LoRaWAN end devices and gateway in ThingsBoard. This document is applicable to all the end point LoRaWan product of mokosmart.

Add Gateway

Add Gateway on TTN

Step 1: Power on gateway, and connect to gateway WIFI, access to the Web GUI, get the gateway ID on the “FUNCTAION-Server Access” page of Web GUI.

image

Step 2: Login in TTN account, choose the corresponding cluster, Here select US915 frequency plan as example, so the cluster will be North America 1.

image

Step 3: Go to gateway console on the home page.

image

Step 4: Register new gateway:

image


  • Fill in the gateway ID got in step 1:

image


  • Customize your gateway ID in TTN;
  • Choose the frequency plan United States 902-928 MHz as your plan;
  • Click the “Register gateway” to finish gateway register.

image

Step 5: Configure gateway’s parameter on the “FUNCTION-Server Access” page of Web GUI.

  • Get the gateway server address in gateway General setting page.

image

  • Fill in the server address in MKGW2 Web GUI page, the port will be 1700.

image

  • Select the Frequency as your plan, here choose 915, and channel must be same as the configuration in TTN, we choose FSB2 in Step 4, so here we select channel US915_CH08-15.

Step 6: Check the gateway status:

  • Check the status in gateway Web GUI, if it’s green, it means the gateway connect to server successfully, if it’s red, it means the gateway doesn’t connect to the server.

image


  • Check the status on TTN platform.

image


Doc info icon

Note: When registering the gateway, please choose the gateway frequency band carefully and make sure the frequency band of the device and the gateway are the same.

Create Application on TTN

Step 1: Open your console and click on the “Create an application”.

image


Step 2: Fill in the required fields about the application. Then click “Create application” button.

image


Step 3: Go to the “Integrations” -> open the “MQTT” page in the left menu. Then, click on the “Generate new API key” button.

image


Step 4: Copy and save the password (API key) (after leaving the page it won’t be displayed).

image


Create Integration in ThingsBoard

  • Go to the “Integrations” page of the “Integrations center” section. Click “plus” icon in the upper right corner to add new integration. Select “The Things Stack Community” as the integration type. Then, click “Next”.

image

  • Paste the following script to the Decoder function section. Click “Next”.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var data = decodeToJson(payload);

var deviceName = data.end_device_ids.device_id;
var deviceType = data.end_device_ids.application_ids.application_id;

// If you want to parse incoming data somehow, you can add your code to this function.
// input: bytes
// expected output:
//  {
//    "attributes": {"attributeKey": "attributeValue"},
//    "telemetry": {"telemetryKey": "telemetryValue"}
//  }
// default functionality - convert bytes to HEX string with telemetry key "HEX_bytes"

function decodeFrmPayload(input) {
    var output = { attributes:{}, telemetry: {} };
    // --- Decoding code --- //

    output.telemetry.HEX_bytes = bytesToHex(input);

    // --- Decoding code --- //
    return output;
}

// --- attributes and telemetry objects ---
var telemetry = {};
var attributes = {};
// --- attributes and telemetry objects ---

// --- Timestamp parsing
var incomingDateString = data.uplink_message.received_at;
var dateString = incomingDateString.substring(0, incomingDateString.lastIndexOf(".")+3) + "Z";
var timestamp = new Date(dateString).getTime();
// --- Timestamp parsing

// You can add some keys manually to attributes or telemetry
attributes.f_port = data.uplink_message.f_port;
attributes.settings = data.uplink_message.settings;
// We want to save correlation ids as single object, so we are excluding them from attributes parse and add manually
attributes.correlation_ids = data.correlation_ids;

// You can exclude some keys from the result
var excludeFromAttributesList = ["device_id", "application_id", "uplink_message", "correlation_ids"];
var excludeFromTelemetryList = ["uplink_token", "gateway_id", "settings"];

// Message parsing
// To avoid paths in the decoded objects we passing false value to function as "pathInKey" argument.
// Warning: pathInKey can cause already found fields to be overwritten with the last value found, e.g. receive_at from uplink_message will be written receive_at in the root.
var telemetryData = toFlatMap(data.uplink_message, excludeFromTelemetryList, false);
var attributesData = toFlatMap(data, excludeFromAttributesList, false);

// Passing incoming bytes to decodeFrmPayload function, to get custom decoding
var customDecoding = {};
if (data.uplink_message.get("frm_payload") != null) {
    customDecoding = decodeFrmPayload(base64ToBytes(data.uplink_message.frm_payload));
}

// Collecting data to result
if (customDecoding.?telemetry.size() > 0) {
    telemetry.putAll(customDecoding.telemetry);
}

if (customDecoding.?attributes.size() > 0) {
    attributes.putAll(customDecoding.attributes);
}

telemetry.putAll(telemetryData);
attributes.putAll(attributesData);

var result = {
    deviceName: deviceName,
    deviceType: deviceType,
    telemetry: {
        ts: timestamp,
        values: telemetry
    },
    attributes: attributes
};

return result;

image

  • Leave the “Downlink data converter” field empty. Click on “Skip” button.

image

  • Next, fill in the fields with your parameters. After, press “Add” button.

image

Add Device

Step 1:

  • Go to the application console - “End devices” page;
  • Click “Register end device”.

image


Step 2:

  • Choose enter end device specifies manually;
  • Select frequency plan (the frequency plan should be totally same as your gateway frequency plan);
  • Select LoRaWan version as v1.0.3.

image


Step 3: Enter the JoinEUI, MOKO device default JoinEUI is 70 B3 D5 7E D0 02 6B 87

Step 4: After JoinEUI is confirmed, enter the DevEUI and AppKEY, for MOKO device, you can get the DevEUI on the package label, and the AppKEY for device is 2B 7E 15 16 28 AE D2 A6 AB F7 15 88 09 CF 4F 3C by default. Or you can connect to the device via “MKLora” APP and read the DevEUI and AppKEY from the APP.

image


Step 5: Click Register end device to finish.

Step 6: Check the status of device on TTN.

image


And you can also check the live data, if there is payload uploaded means the device already connect to the server.

image


Step 7: Navigate to Payload formatters, get the decoder from the moko github_link, copy the related decoder and paste it. And then save it.

image


Step 8: Navigate to the “Devices” page of the “Entities” section, here you can see that:

  • Devices registered in TTN were registered in ThingsBoard in the “Latest telemetry” section you will the update data from the device.

image

Add Dashboard

A dashboard in ThingsBoard allows users to visualize and monitor data collected from IoT devices. Let’s create a dashboard and add two widgets to it:

  • The first widget will show the device’s battery level.
  • The second widget will display the device’s location on a map.

Add Dashboard

  • Navigate to the “Dashboards” page through the main menu on the left of the screen. Click the “+” sign in the upper right corner of the screen, and select “Create new dashboard” from the drop-down menu. In the opened dialog, it is necessary to enter a dashboard title, description is optional. Click “Add”;

Add Battery level widget

  • Click the “+ Add widget” button at the top of the screen or click the large “Add new widget” icon in the center of the screen (if this is your first widget on this dashboard);

  • Find the “Status indicators” widget bundle and click on it;

  • Select the “Battery level” widget;

  • The “Add widget” window will appear. Specify the “lw006test” device as the datasource and “batt_level” data ket as the variable that you want to monitor. Click “Add”;

  • You have added a widget that displays the battery level.

Add Map widget

  • Click the “+ Add widget” button at the top of the screen to add another one widget;

  • Find the “Maps” widget bundle and click on it;

  • Select the “Google map” widget;

  • The “Add widget” window will appear. Select “Device” as the datasource type. Specify the “lw006test” device as the datasource. Add “latitude” and “longitude” as time series data keys. Click “Add”;

  • To save the dashboard, click “Save” button in the upper right corner;

  • You have added a widget that displays the device's location on a map.

Next steps