Socket
Socket
Sign inDemoInstall

azure-iot-device-mqtt

Package Overview
Dependencies
Maintainers
6
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

azure-iot-device-mqtt

MQTT transport for Azure IoT device SDK


Version published
Weekly downloads
3.3K
increased by9.28%
Maintainers
6
Weekly downloads
 
Created
Source

#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);

FAQs

Package last updated on 24 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc