MQTT

MQTT is a lightweight messaging protocol based on agent publishing / subscribing for low bandwidth and intermittent communication. MQTT Server provides MQTT client-side with 3.1 compatible MQTT API interface service that support QoS 0, QoS 1 messaging service quality.

Log into IoT cloud platform, visit developer page, in basic settings section, you will receive the AppID (application identifier - MQTT username/clientId), AppSecret(message password signature - MQTT password). In “MQTT settings”, you can configure message transmission quality (note that during beta phase, server side default quality is QoS 0). In message push settings, if you set message transmission to safe mode, MQTT will apply the same encryption method for data transmission.

MQTT BROKER IP Interface Encryption: Yes/No
iot.sensoro.com 1883 Encryption under safe mode

1. Client-Side Settings

To connect to our MQTT server, you need to configure username, password, clientId and other setting of your MQTT client by the way described below:

  • Use AppID as MQTT username

  • Use AppSecret as MQTT password

  • MQTT clientID need any string match the regexp ^#AppID#(\/[-_0-9a-zA-Z]{0,36})?$ (e.g. suppose your AppID is foobar, clientid need to match ^foobar(\/[-_0-9a-zA-Z]{0,36})?$. both foobar, foobar/ and foobar/abc are valid client id).

Note:

  • If there're multiple MQTT clients configured with same AppID, make sure that they're configured with different clientId.

  • If connection was established but closed immediately with message [Error: Connection refused: Not authorized],please make sure you have provided the correct username, password and clientid.

NodeJS Sample code as below:

var mqtt = require('mqtt'); var clientOption = { username: $YOUR_APPID, password: $YOUR_APPSECRET, clientId: $YOUR_APPID + '/' + $UUID, reconnectPeriod: '10000', clean: true }; var client = mqtt.connect('mqtt://iot.sensoro.com:1883', clientOption); client.on('connect', function () { console.log('SUBSCRIBE users/' + clientOption.username + '/devices'); client.subscribe('users/' + clientOption.username + '/devices', { qos: 1 }); }); client.on('message', function (topic, message) { // message is Buffer console.log(message.toString()); });

2. Sensor Data Push and Receive (/users/:APPID/devices)

MQTT Client-side leverages /users/:APPID/devices topic to receive data push from sensors, and this data format is consistent with the format of Webhook(custom callback URL) data push.

Copyright © 2021 SENSORO Co.,Ltd.保留所有权利。iBeacon 是苹果公司的注册商标。京ICP备18013471号-1 版权所有:北京升哲科技有限公司 all right reserved,powered by Gitbook 2021-12-07 17:28:41