Neuron Powered Motorization
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

azure-iot-device-http

1.13.3 • Public • Published

azure-iot-device-http

Communicate with Azure IoT Hub from any device over HTTP 1.1.

npm version

Install

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

Getting Started

Create a device client:

var clientFromConnectionString = require('azure-iot-device-http').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);

Keywords

none

Install

npm i azure-iot-device-http

DownloadsWeekly Downloads

1,164

Version

1.13.3

License

MIT

Unpacked Size

66.8 kB

Total Files

9

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar