Wiki source code of Chirpstack is integrated into the Thingseye step via MQTT
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | |||
| 2 | **Table of Contents:** | ||
| 3 | |||
| 4 | {{toc/}} | ||
| 5 | |||
| 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:1732499643153-403.png]] | ||
| 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:1732499643155-612.png]] | ||
| 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:1732499643158-822.png]] | ||
| 106 | |||
| 107 | * **Dowblink——JavaScript:** | ||
| 108 | |||
| 109 | |||
| 110 | ~/~/ Encode downlink data from incoming Rule Engine message | ||
| 111 | |||
| 112 | |||
| 113 | ~/~/ msg - JSON message payload downlink message json | ||
| 114 | |||
| 115 | ~/~/ msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc. | ||
| 116 | |||
| 117 | ~/~/ metadata - list of key-value pairs with additional data about the message | ||
| 118 | |||
| 119 | ~/~/ integrationMetadata - list of key-value pairs with additional data defined in Integration executing this converter | ||
| 120 | |||
| 121 | |||
| 122 | ~/~/ /~*~* Encoder ~*~*/ | ||
| 123 | |||
| 124 | |||
| 125 | ~/~/var data = {"value":99}; | ||
| 126 | |||
| 127 | |||
| 128 | ~/~/ ~/~/ Process data from incoming message and metadata | ||
| 129 | |||
| 130 | |||
| 131 | ~/~/ data.tempFreq = msg.temperatureUploadFrequency; | ||
| 132 | |||
| 133 | ~/~/ data.humFreq = msg.humidityUploadFrequency; | ||
| 134 | |||
| 135 | |||
| 136 | ~/~/ data.devSerialNumber = metadata['ss_serialNumber']; | ||
| 137 | |||
| 138 | |||
| 139 | ~/~/ ~/~/ Result object with encoded downlink payload | ||
| 140 | |||
| 141 | var result = { | ||
| 142 | |||
| 143 | |||
| 144 | ~/~/ downlink data content type: JSON, TEXT or BINARY (base64 format) | ||
| 145 | |||
| 146 | contentType: "TEXT", | ||
| 147 | |||
| 148 | |||
| 149 | ~/~/ downlink data | ||
| 150 | |||
| 151 | data: msg.shared_value ,~/~/JSON.stringify(data), | ||
| 152 | |||
| 153 | |||
| 154 | ~/~/ Optional metadata object presented in key/value format | ||
| 155 | |||
| 156 | metadata: { | ||
| 157 | |||
| 158 | topic: '/test/down/'+metadata.deviceName | ||
| 159 | |||
| 160 | } | ||
| 161 | |||
| 162 | |||
| 163 | }; | ||
| 164 | |||
| 165 | |||
| 166 | return result; | ||
| 167 | |||
| 168 | |||
| 169 | = **Step 3. Configure the connection** = | ||
| 170 | |||
| 171 | Generate MQTT certificate integrated on chirpstack | ||
| 172 | |||
| 173 | Chirpstack generates CA certificate, TLS certificate, and TLS key respectively | ||
| 174 | |||
| 175 | They correspond to the CA certificate file, Certificate file, and Private key file on thingseye | ||
| 176 | |||
| 177 | |||
| 178 | [[image:1732499643160-256.png]] | ||
| 179 | |||
| 180 | [[image:1732499643161-734.png||height="632" width="1273"]] | ||
| 181 | |||
| 182 | **Integrated Certificate Download Address:** | ||
| 183 | |||
| 184 | [[te-platform/ChirpStack_Integration Certificates at main · ThingsEye-io/te-platform · GitHub>>url:https://github.com/ThingsEye-io/te-platform/tree/main/ChirpStack_Integration Certificates]] | ||
| 185 | |||
| 186 | Enter the server address Host: lns1.thingseye.io on the Connection configuration | ||
| 187 | |||
| 188 | Port: 8883 | ||
| 189 | |||
| 190 | Credentials type: PEM | ||
| 191 | |||
| 192 | Upload the certificate and key file | ||
| 193 | |||
| 194 | [[image:1732499643163-473.png]] | ||
| 195 | |||
| 196 | [[image:1732499643164-724.png]] | ||
| 197 | |||
| 198 | |||
| 199 | The default for Topic is: | ||
| 200 | |||
| 201 | application/**chirpstack application id**/device/+/event/up | ||
| 202 | |||
| 203 | [[image:1732499643166-130.png]] | ||
| 204 | |||
| 205 | [[image:1732499912997-301.png]] | ||
| 206 | |||
| 207 | = Step 4. Check the connection = | ||
| 208 | |||
| 209 | [[image:1732499643167-363.png]] | ||
| 210 | |||
| 211 | [[image:1732499643169-383.png]] |