Reference
Use MQTT.fx to access Yanfei Gewu DMP platform
New product
Use MQTT.fx to access Yanfei Gewu DMP platform
MQTT.fx is an MQTT client tool written in Java language based on Eclipse Paho, which supports subscribing and publishing messages through Topic. The following takes MQTT.fx as an example to introduce the use of third-party software to access the Yanfei Gewu DMP platform through the MQTT protocol.
Prerequisites: Products and devices have been created on the Yanfei Gewu DMP platform, and device authentication information (ProductKey, DeviceKey, DeviceSerect, etc.) has been obtained. For details on how to create products and devices, please refer to the documentation for creating products, creating devices individually, or creating devices in batches.
Take the MQTT directly connected device using the one-machine-one-secret authentication method to authenticate the access platform as an example. For other access authentication methods, see the device online instruction document.
Connection information
deviceId can be customized, it only needs to be globally unique;
Use the hmac_sha256 algorithm http://www.jsons.cn/allencrypt online signature to get the password
Data reporting
Reference document: https://help-dmp.cuiot.cn/?6WSscvjNEnkN=1678755274556#/onlineDocument/display?articleId=69 &articleTypeId=0
Single attribute reporting
$sys/cu10pusjit6gfi1n/yangchen1/property/pub // content {<!-- --> "messageId": "1234", "params": {<!-- --> "key": "windSpeed", "value": 13, "ts": "1678759768157" } }
Multi-attribute batch reporting
$sys/cu10pusxxx/yangchen1/property/batch // content {<!-- --> "messageId": 54691, "params": {<!-- --> "data": [{<!-- --> "key": "tsp", "value": 10 }, {<!-- --> "key": "pm25", "value": 9.93 }, {<!-- --> "key": "pm10", "value": 12.93 }, {<!-- --> "key": "windSpeed", "value": 5 }, {<!-- --> "key": "powerSavingMode", "value": 1 }, {<!-- --> "key": "geoLocation", "value": {<!-- --> "longitude": 118.763334, "latitude": 32.0175, "altitude": 3.93, "coordinateSystem":1 } } ], "ts": 1600695731000 } }
Display Data
Device Shadow
Platform release update
Device monitor shadow theme
After the platform sends out the command, the device listens to the command, then performs local settings, and then responds to $sys/{productKey}/{deviceKey}/deviceShadow/command_reply
# $sys/cu10pusjit6gfi1n/yangchen1/deviceShadow/command {<!-- --> "messageId": "2", "params": {<!-- --> "state": {<!-- --> "desired": {<!-- --> "tsp": 12, "pm25": 2, "pm10": 23, "windSpeed": 23.0 }, "reported": {<!-- -->} }, "metadata": {<!-- --> "desired": {<!-- --> "tsp": {<!-- --> "ts": "1678766756862" }, "pm25": {<!-- --> "ts": "1678766756862" }, "pm10": {<!-- --> "ts": "1678766756862" }, "windSpeed": {<!-- --> "ts": "1678766756862" } }, "reported": {<!-- -->} }, "ts": "1678766756862", "version": 3 } }
Use http to access the smoke sensor
Get token
{<!-- --> "productKey":"cu1twobqbsa4bftp", "deviceKey":"yangan1", "operator":"0", "secretKey":"264F1FFA2F89FC0BA3078CFF8D0303", "deviceId":"yanganjiance1", "timestamp":"{<!-- -->{timestamp}}", "signMethod":"hmacsha256", "sign":"{<!-- -->{sign}}" }
Pre-request Script
// Get the current timestamp var timestamp = new Date().getTime(); var body = pm.request.body; console.log("body:",body); var raw = body.raw; console.log("raw:",raw); var data = JSON. parse(raw); console.log("data:",data); var productKey = data. productKey; var deviceKey = data.deviceKey; var deviceId = data.deviceId; var deviceSecret = data. secretKey; var signMethod = data. signMethod; var operator = data. operator; console.log("productKey:",productKey); console.log("deviceKey:",deviceKey); console.log("deviceId:",deviceId); console.log("deviceSecret:",deviceSecret); var reqContent = deviceId + deviceKey + productKey + signMethod + operator + timestamp; console.log("reqContent:",reqContent); var reqSign=(CryptoJS.HmacSHA256(reqContent,deviceSecret)).toString() // encrypt and convert to string var sign = reqSign.toString(CryptoJS.enc.Hex) // Convert to hexadecimal console.log("sign:",sign); pm.environment.set("timestamp", timestamp); pm.environment.set("sign", sign);
Property reporting
{<!-- --> "messageId": 54691, "params": {<!-- --> "data": [ {<!-- --> "key": "batteryPower", "value": 10 }, {<!-- --> "key": "signalStrength", "value": 9.93 }, {<!-- --> "key": "smokeScope", "value": 12.93 }, {<!-- --> "key": "dirtyPercent", "value": 5 }, {<!-- --> "key": "signalSNR", "value": 1 }, {<!-- --> "key": "geoLocation", "value": {<!-- --> "longitude": 118.763334, "latitude": 32.0175, "altitude": 3.93, "coordinateSystem": 1 } } ], "ts": {<!-- -->{<!-- -->timestamp}} } }
Event reporting
{<!-- --> "messageId": 54691, "params": {<!-- --> "data": [ {<!-- --> "key": "fireAlarm_event", "value": 10 }, {<!-- --> "key": "power_event", "value": 9.93 }, {<!-- --> "key": "communication_event", "value": 12.93 }, {<!-- --> "key": "dirtyPercent", "value": 5 }, {<!-- --> "key": "signalSNR", "value": 1 }, {<!-- --> "key": "geoLocation", "value": {<!-- --> "longitude": 118.763334, "latitude": 32.0175, "altitude": 3.93, "coordinateSystem": 1 } } ], "ts": {<!-- -->{<!-- -->timestamp}} } }