Wiki source code of Chirpstack is integrated into the Thingseye step via MQTT
Last modified by Hera Guo on 2024/11/26 12:12
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | **Table of Contents:** | ||
| 2 | |||
| 3 | {{toc/}} | ||
| 4 | |||
| 5 | = **How to connect chirpstack to Thingseye by way of MQTT** = | ||
| 6 | |||
| 7 | * **How to connect chirpstack to Thingseye by way of MQTT? The following tutorial will show you** | ||
| 8 | |||
| 9 | == **Step 1: Thingseye adds MQTT integration** == | ||
| 10 | |||
| 11 | Go to the Integrations page in the Integrations center section. Click the plus button to start adding a new integration. Select the type "MQTT" integration and click "Next"; | ||
| 12 | |||
| 13 | [[image:图片1.png||height="655" width="1320"]] | ||
| 14 | |||
| 15 | |||
| 16 | == **Step 2. Add an uplink and downlink data converter** == | ||
| 17 | |||
| 18 | In the function decoder field, specify the script to parse and transform the data. | ||
| 19 | |||
| 20 | [[image:图片2.png||height="653" width="1315"]] | ||
| 21 | |||
| 22 | * **Uplink——JavaScript:** | ||
| 23 | |||
| 24 | var data = decodeToJson(payload); | ||
| 25 | |||
| 26 | var deviceName = data.deviceInfo.deviceName; | ||
| 27 | |||
| 28 | var deviceType = data.applicationName; | ||
| 29 | |||
| 30 | var devEui = data.deviceInfo.devEui | ||
| 31 | |||
| 32 | var label = data.deviceInfo.devEui | ||
| 33 | |||
| 34 | var model = {}; | ||
| 35 | |||
| 36 | var data2 = data.object; | ||
| 37 | |||
| 38 | var flg = data.fPort | ||
| 39 | |||
| 40 | for (var key in data2) { | ||
| 41 | |||
| 42 | ~/~/ 将属性名存入新对象中 | ||
| 43 | |||
| 44 | model[key] = data2[key]; | ||
| 45 | |||
| 46 | } | ||
| 47 | |||
| 48 | ~/~/var obj = {"devid":deviceName} | ||
| 49 | |||
| 50 | |||
| 51 | var result = { | ||
| 52 | |||
| 53 | deviceName: deviceName, | ||
| 54 | |||
| 55 | deviceType: deviceType, | ||
| 56 | |||
| 57 | telemetry: model, | ||
| 58 | |||
| 59 | groupName: "Case Study", | ||
| 60 | |||
| 61 | ~/~/label:label, | ||
| 62 | |||
| 63 | attributes:{"devEui":devEui, | ||
| 64 | |||
| 65 | ~/~/"timevalue":"test", | ||
| 66 | |||
| 67 | "inactivityTimeout":1260000 | ||
| 68 | |||
| 69 | ~/~/ "High_humidity_alarm":"not set", | ||
| 70 | |||
| 71 | ~/~/ "High_temperature_alarm":"not set", | ||
| 72 | |||
| 73 | ~/~/ "Low_humidity_alarm":"not set", | ||
| 74 | |||
| 75 | ~/~/ "Low_temperature_alarm":"not set", | ||
| 76 | |||
| 77 | ~/~/ "Low_voltage_alarm":"not set" | ||
| 78 | |||
| 79 | ~/~/"customerName": "Civionic Engineering & Consulting (2014) Inc." | ||
| 80 | |||
| 81 | } | ||
| 82 | |||
| 83 | }; | ||
| 84 | |||
| 85 | function decodeToString(payload) { | ||
| 86 | |||
| 87 | return String.fromCharCode.apply(String, payload); | ||
| 88 | |||
| 89 | } | ||
| 90 | |||
| 91 | |||
| 92 | function decodeToJson(payload) { | ||
| 93 | |||
| 94 | var str = decodeToString(payload); | ||
| 95 | |||
| 96 | var data = JSON.parse(str); | ||
| 97 | |||
| 98 | return data; | ||
| 99 | |||
| 100 | } | ||
| 101 | |||
| 102 | |||
| 103 | return result; | ||
| 104 | |||
| 105 | [[image:图片3.png||height="657" width="1324"]] | ||
| 106 | |||
| 107 | * **Dowblink——JavaScript:** | ||
| 108 | |||
| 109 | ~/~/ Encode downlink data from incoming Rule Engine message | ||
| 110 | |||
| 111 | |||
| 112 | ~/~/ msg - JSON message payload downlink message json | ||
| 113 | |||
| 114 | ~/~/ msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc. | ||
| 115 | |||
| 116 | ~/~/ metadata - list of key-value pairs with additional data about the message | ||
| 117 | |||
| 118 | ~/~/ integrationMetadata - list of key-value pairs with additional data defined in Integration executing this converter | ||
| 119 | |||
| 120 | |||
| 121 | ~/~/ /~*~* Encoder ~*~*/ | ||
| 122 | |||
| 123 | |||
| 124 | ~/~/var data = {"value":99}; | ||
| 125 | |||
| 126 | |||
| 127 | ~/~/ ~/~/ Process data from incoming message and metadata | ||
| 128 | |||
| 129 | |||
| 130 | ~/~/ data.tempFreq = msg.temperatureUploadFrequency; | ||
| 131 | |||
| 132 | ~/~/ data.humFreq = msg.humidityUploadFrequency; | ||
| 133 | |||
| 134 | |||
| 135 | ~/~/ data.devSerialNumber = metadata['ss_serialNumber']; | ||
| 136 | |||
| 137 | |||
| 138 | ~/~/ ~/~/ Result object with encoded downlink payload | ||
| 139 | |||
| 140 | var result = { | ||
| 141 | |||
| 142 | |||
| 143 | ~/~/ downlink data content type: JSON, TEXT or BINARY (base64 format) | ||
| 144 | |||
| 145 | contentType: "TEXT", | ||
| 146 | |||
| 147 | |||
| 148 | ~/~/ downlink data | ||
| 149 | |||
| 150 | data: msg.shared_value ,~/~/JSON.stringify(data), | ||
| 151 | |||
| 152 | |||
| 153 | ~/~/ Optional metadata object presented in key/value format | ||
| 154 | |||
| 155 | metadata: { | ||
| 156 | |||
| 157 | topic: '/test/down/'+metadata.deviceName | ||
| 158 | |||
| 159 | } | ||
| 160 | |||
| 161 | |||
| 162 | }; | ||
| 163 | |||
| 164 | |||
| 165 | return result; | ||
| 166 | |||
| 167 | |||
| 168 | == **Step 3. Configure the connection** == | ||
| 169 | |||
| 170 | Generate MQTT certificate integrated on chirpstack | ||
| 171 | |||
| 172 | Chirpstack generates CA certificate, TLS certificate, and TLS key respectively | ||
| 173 | |||
| 174 | They correspond to the CA certificate file, Certificate file, and Private key file on thingseye | ||
| 175 | |||
| 176 | |||
| 177 | [[image:图片4.png||height="669" width="1348"]] | ||
| 178 | |||
| 179 | [[image:图片5.png||height="669" width="1348"]] | ||
| 180 | |||
| 181 | * Copy the contents of the certificates and paste them into the linked file below, a total of three certificates are required | ||
| 182 | |||
| 183 | **Integrated Certificate File demo Download Address:** | ||
| 184 | |||
| 185 | [[https:~~/~~/github.com/ThingsEye-io/te-platform/tree/main/chirpstack>>https://github.com/ThingsEye-io/te-platform/tree/main/chirpstack]] | ||
| 186 | |||
| 187 | Enter the server address Host: lns1.thingseye.io on the Connection configuration | ||
| 188 | |||
| 189 | Port: 8883 | ||
| 190 | |||
| 191 | Credentials type: PEM | ||
| 192 | |||
| 193 | Upload the certificate and key file | ||
| 194 | |||
| 195 | [[image:图片6.png||height="672" width="1353"]] | ||
| 196 | |||
| 197 | [[image:图片7.png||height="671" width="1352"]] | ||
| 198 | |||
| 199 | |||
| 200 | The default for Topic is: | ||
| 201 | |||
| 202 | application/**chirpstack application id**/device/+/event/up | ||
| 203 | |||
| 204 | [[image:图片8.png||height="673" width="1356"]] | ||
| 205 | |||
| 206 | [[image:1732500689044-955.png]] | ||
| 207 | |||
| 208 | == Step 4. Check the connection == | ||
| 209 | |||
| 210 | [[image:图片9.png||height="718" width="1446"]] | ||
| 211 | |||
| 212 | |||
| 213 | [[image:图片10.png||height="711" width="1432"]] |