зеркало из
1
0
Форкнуть 0
azure-iot-sdk-node/device/transport/mqtt
Vishnu Reddy a85e280350
release(2023-07-24): bump package versions (#1197)
Co-authored-by: Azure IoT Client Build <aziotclb@microsoft.com>
2023-07-24 07:48:17 -04:00
..
devdoc chore: rename digital-twin-model-id to model-id in mqtt (#829) 2020-07-02 11:32:42 -07:00
src fix(azure-iot-device-mqtt): add naive D2C message size checking (#1181) 2023-04-05 16:54:53 -04:00
test fix(azure-iot-device-mqtt): add naive D2C message size checking (#1181) 2023-04-05 16:54:53 -04:00
.eslintignore (chore) update to eslint in device, fix bad exports 2022-11-29 08:28:49 -08:00
.npmignore refactor(multiple): update to typescript 3.7.5 move to dist instead of lib parameter checking and suppression (#824) 2020-06-26 17:00:25 -07:00
index.d.ts refactor(multiple): update to typescript 3.7.5 move to dist instead of lib parameter checking and suppression (#824) 2020-06-26 17:00:25 -07:00
index.js (chore) update to eslint in device, fix bad exports 2022-11-29 08:28:49 -08:00
package.json release(2023-07-24): bump package versions (#1197) 2023-07-24 07:48:17 -04:00
readme.md Update node transport readmes 2016-03-11 08:33:01 +00:00
tsconfig.json (chore) update to eslint in device, fix bad exports 2022-11-29 08:28:49 -08:00

readme.md

#azure-iot-device-mqtt Communicate with Azure IoT Hub from any device over MQTT.

npm version

Install

npm install -g azure-iot-device-mqtt@latest to get the latest (pre-release) version.

Getting Started

Create a device client:

var clientFromConnectionString = require('azure-iot-device-mqtt').clientFromConnectionString;
var Message = require('azure-iot-device').Message;

var connectionString = '[IoT Hub device connection string]';

var client = clientFromConnectionString(connectionString);

Create a callback that sends a message and receives messages. When it receives a message it sends an acknowledgement receipt to the server:

var connectCallback = function (err) {
  if (err) {
    console.error('Could not connect: ' + err);
  } else {
    console.log('Client connected');
    var message = new Message('some data from my device');
    client.sendEvent(message, function (err) {
      if (err) console.log(err.toString());
    });

    client.on('message', function (msg) { 
      console.log(msg); 
      client.complete(msg, function () {
        console.log('completed');
      });
    }); 
  }
};

Open the connection and invoke the callback:

client.open(connectCallback);