Wiki source code of How to connect -NB and -CB series devices data by MQTT with Thingseye
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | **Table of Contents:** | ||
| 2 | |||
| 3 | {{toc/}} | ||
| 4 | |||
| 5 | = 1. Introduction = | ||
| 6 | |||
| 7 | This document guides you on integrating Dragino **-NB** and **-CB** series devices data with Thingseye. | ||
| 8 | |||
| 9 | The **NB series** devices end with the suffix **-NB**, and the **CB series** devices end with the suffix **-CB**. For example, **S31B-NB** is an **NB device**, and **S31-CB** is a **CB device**. | ||
| 10 | |||
| 11 | = 2. Prerequisites = | ||
| 12 | |||
| 13 | To complete this tutorial, you need to have certificate files. [[lns1.thingseye.io>>url:http://lns1.thingseye.io/]] is the Dragino's MQTT broker, which requires a CA certificate file, Certificate file, and the Private key file to use. | ||
| 14 | |||
| 15 | If customers need to use this MQTT connection with Thingseye, they need to contact TE team to obtain three license files or click this [[link>>url:https://www.dropbox.com/scl/fo/d5s1wf36f4syv30a8laup/AK8FjVpNXYXCWodRnnQ1Hig?rlkey=jrz1ip0f0xwwq5z2m2gu1tuij&e=1&st=kl4caub0&dl=0]] to download the certificates.. | ||
| 16 | |||
| 17 | [[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/ins1.png?width=500&height=310&rev=1.1||alt="ins1.png" height="310" width="500"]] | ||
| 18 | |||
| 19 | |||
| 20 | = 3.General MQTT Connection = | ||
| 21 | |||
| 22 | The NB-IoT Sensor can send packet to server use MQTT protocol. | ||
| 23 | |||
| 24 | Below are the commands. | ||
| 25 | |||
| 26 | **AT Commands:** | ||
| 27 | |||
| 28 | {{code language="none"}} | ||
| 29 | AT+PRO=3,0 // Set to use MQTT protocol to uplink, Payload Type select Hex payload. | ||
| 30 | AT+SERVADDR=120.24.4.116,1883 // Set MQTT server address and port | ||
| 31 | AT+CLIENT=CLIENT // Set up the CLIENT of MQTT | ||
| 32 | AT+UNAME=UNAME // Set the username of MQTT | ||
| 33 | AT+PWD=PWD // Set the password of MQTT | ||
| 34 | AT+PUBTOPIC=NSE01_PUB // Set the sending topic of MQTT | ||
| 35 | AT+SUBTOPIC=NSE01_SUB // Set the subscription topic of MQTT | ||
| 36 | {{/code}} | ||
| 37 | |||
| 38 | [[image:https://wiki.dragino.com/xwiki/bin/download/Main/General%20Configure%20to%20Connect%20to%20IoT%20server%20for%20-NB%20%26%20-NS%20NB-IoT%20models/WebHome/image-20230802112413-4.png?rev=1.1||alt="image-20230802112413-4.png"]] | ||
| 39 | |||
| 40 | [[image:https://wiki.dragino.com/xwiki/bin/download/Main/General%20Configure%20to%20Connect%20to%20IoT%20server%20for%20-NB%20%26%20-NS%20NB-IoT%20models/WebHome/image-20230802112413-5.png?width=987&height=530&rev=1.1||alt="image-20230802112413-5.png" height="530" width="987"]] | ||
| 41 | |||
| 42 | (% class="mark small text-uppercase" %)##**Notice: MQTT protocol has a much higher power consumption compare with UDP/CoAP protocol. Please check the power analyze document and adjust the uplink**## | ||
| 43 | |||
| 44 | (% class="mark small text-uppercase" %)##**period to a suitable interval.**## | ||
| 45 | |||
| 46 | = 4. Data Converters = | ||
| 47 | |||
| 48 | In **Thingseye**, **Data Converters** are components used to transform incoming or outgoing data between different formats, typically to convert raw telemetry data from devices into a structured format that Thingseye can understand, or vice versa. | ||
| 49 | |||
| 50 | == 4.1 Uplink == | ||
| 51 | |||
| 52 | In the left navigation, click **Integrations center**, and then click **Data converters**. | ||
| 53 | |||
| 54 | On the **Data converters** page, click on the ‘**+**’ button, and then click on the **Create new converter** from the dropdown menu. | ||
| 55 | |||
| 56 | [[image:1743578461281-635.png]] | ||
| 57 | |||
| 58 | |||
| 59 | Once you modify the decoder function, click on the **Add** button. | ||
| 60 | |||
| 61 | [[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/ul-data-converter-device-a.png?width=500&height=524&rev=1.1||alt="ul-data-converter-device-a.png"]] | ||
| 62 | |||
| 63 | You should see that the newly added **MQTT Uplink converter **NB/CB is listed on the **Data Converters** page. | ||
| 64 | |||
| 65 | [[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/ul-data-converter-added.png?height=257&rev=1.1||alt="ul-data-converter-added.png"]] | ||
| 66 | |||
| 67 | = 5. Add Integration = | ||
| 68 | |||
| 69 | == 5.1. Creat new MQTT integration == | ||
| 70 | |||
| 71 | In the left navigation, click **Integrations center**, and then click **Integrations**. | ||
| 72 | |||
| 73 | On the **Integrations** page, click on the '**+**' button. | ||
| 74 | |||
| 75 | [[image:1743578691561-822.png]] | ||
| 76 | |||
| 77 | |||
| 78 | The **Add integration** window appears. | ||
| 79 | |||
| 80 | In the **Add integration** window, configure the following settings: | ||
| 81 | |||
| 82 | **Basic settings:** | ||
| 83 | |||
| 84 | * **Integration type**: MQTT | ||
| 85 | * **Name**: MQTT integration | ||
| 86 | * **Enable integration**: YES | ||
| 87 | * **Debug mode**:YES | ||
| 88 | * **Allows create devices or assets**: YES | ||
| 89 | |||
| 90 | Click **Next** button. | ||
| 91 | |||
| 92 | [[image:1743578960106-916.png||height="549" width="547"]] | ||
| 93 | |||
| 94 | |||
| 95 | **Uplink/downlink data converter:** | ||
| 96 | |||
| 97 | * ((( | ||
| 98 | Next, directly select to create a new Uplink data converter . | ||
| 99 | ))) | ||
| 100 | |||
| 101 | Click **Next** button. | ||
| 102 | |||
| 103 | [[image:1743581191958-140.png||height="547" width="543"]] | ||
| 104 | |||
| 105 | |||
| 106 | |||
| 107 | **Downlink data converter:** | ||
| 108 | |||
| 109 | * Next, directly select to create a new Uplink data converter . | ||
| 110 | |||
| 111 | Click **Skip** button. | ||
| 112 | |||
| 113 | [[image:1743581287837-189.png||height="547" width="542"]] | ||
| 114 | |||
| 115 | |||
| 116 | **Connection:** | ||
| 117 | |||
| 118 | * **Host**: [[lns1.thingseye.io>>url:http://lns1.thingseye.io/]] | ||
| 119 | * **Port**: 8883 | ||
| 120 | * **Credentials **: PEM(Paste 3 certificates to boxs below)Click this [[link>>url:https://www.dropbox.com/scl/fo/d5s1wf36f4syv30a8laup/AK8FjVpNXYXCWodRnnQ1Hig?rlkey=jrz1ip0f0xwwq5z2m2gu1tuij&e=1&st=kl4caub0&dl=0]] to download the certificates. | ||
| 121 | * **Password:** Password or nothng | ||
| 122 | * **Enable SSL**: YES | ||
| 123 | * **Topic: ** **It needs to align with the device's topic.** | ||
| 124 | * **QoS:** 0-At most once or an MQTT QoS level | ||
| 125 | |||
| 126 | Click **Skip** button. | ||
| 127 | |||
| 128 | [[image:1743579352961-586.png||height="507" width="502"]] | ||
| 129 | |||
| 130 | [[image:1743580606618-281.png||height="495" width="504"]] | ||
| 131 | |||
| 132 | |||
| 133 | Click on the **Add** button. | ||
| 134 | |||
| 135 | You should see that the newly added integration is listed on the **Integrations** page. | ||
| 136 | |||
| 137 | Since we haven't received data from a device yet, the integration **Status** is shown as **Pending, Active instead if it have.** | ||
| 138 | |||
| 139 | |||
| 140 | |||
| 141 | |||
| 142 | |||
| 143 | == 5.2. Setup uplink and downlink converters == | ||
| 144 | |||
| 145 | First, you need to download the [[**MQTT uplink/downlink JS** **code**>>url:https://www.dropbox.com/scl/fo/d5s1wf36f4syv30a8laup/AK8FjVpNXYXCWodRnnQ1Hig?rlkey=jrz1ip0f0xwwq5z2m2gu1tuij&e=1&st=kl4caub0&dl=0]]. | ||
| 146 | |||
| 147 | * **Uplink Converter** | ||
| 148 | |||
| 149 | The purpose of the decoder function is to parse the incoming data and metadata to a format that ThingsBoard can consume. | ||
| 150 | |||
| 151 | Go to the **Integrations center** -> **Data converters** page, and find that MQTT uplink converter that was newly created when the integration was created. | ||
| 152 | |||
| 153 | [[image:1743581830822-223.png]] | ||
| 154 | |||
| 155 | |||
| 156 | Enter edit mode and apply **MQTT uplink JS code** to this uplink converter. | ||
| 157 | |||
| 158 | [[image:1743581965585-763.png]] | ||
| 159 | |||
| 160 | |||
| 161 | * **Downlink Converter** | ||
| 162 | |||
| 163 | Go to the **Integrations center** -> **Data converters** page, and find that MQTT downlink converter that was newly created when the integration was created. | ||
| 164 | |||
| 165 | |||
| 166 | Enter edit mode and apply **MQTT downlink JS code** to this downlink converter. | ||
| 167 | |||
| 168 | [[image:1743582084494-111.png]] | ||
| 169 | |||
| 170 | |||
| 171 | = 6. Configure Physical NB-IoT Sensor = | ||
| 172 | |||
| 173 | Now, let's experiment with sending data to Thingseye using a real NB-IoT device. For example, we will use the **TS01-NB**. | ||
| 174 | |||
| 175 | First, configure the NB-IoT device with the necessary MQTT settings using AT commands. Below is a list of AT commands you can use. | ||
| 176 | |||
| 177 | **AT Commands** | ||
| 178 | |||
| 179 | * **AT+PRO=3,3 **~/~/ Use MQTT to connect to Thingseye. Payload Type set to 3. | ||
| 180 | * **AT+SUBTOPIC=<MQTT subscribe topic> Eg: TS01-NB** | ||
| 181 | * **AT+PUBTOPIC=<MQTT publish topic> Eg: TS01-NB** | ||
| 182 | * **AT+CLIENT=null** | ||
| 183 | * **AT+UNAME=<MQTT Username>** | ||
| 184 | * **AT+PWD=<MQTT Password>** | ||
| 185 | * **AT+SERVADDR=<Broker address, Port>** | ||
| 186 | |||
| 187 | Test your uplink by pressing the ACT button for 1 second. | ||
| 188 | |||
| 189 | |||
| 190 | The following image shows the uplink payload of a real Dragino device. The publish topic is '**TS01-NB' that contains fields in the payload, IMEI, IMSI, Model, temperature, etc**. Note that we have created a device named **TS01-NB** in the **Devices** section in advance. | ||
| 191 | |||
| 192 | [[image:https://wiki.dragino.com/xwiki/bin/download/Main/ThingsBoard/image-4.png?rev=1.2||alt="image-4.png"]] |