Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

aws-iot-device-sdk

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-iot-device-sdk

AWS IoT Node.js SDK for Embedded Devices


Version published
Weekly downloads
113K
decreased by-17.34%
Maintainers
19
Weekly downloads
 
Created

What is aws-iot-device-sdk?

The aws-iot-device-sdk is an npm package that provides a set of tools to connect, authenticate, and interact with AWS IoT services. It allows devices to communicate with AWS IoT Core, enabling functionalities such as publishing and subscribing to MQTT topics, managing device shadows, and handling device lifecycle events.

What are aws-iot-device-sdk's main functionalities?

Connecting to AWS IoT

This feature allows you to establish a secure connection to AWS IoT Core using your device's credentials. The code sample demonstrates how to configure and connect a device to AWS IoT.

const awsIot = require('aws-iot-device-sdk');

const device = awsIot.device({
  keyPath: 'path/to/private.pem.key',
  certPath: 'path/to/certificate.pem.crt',
  caPath: 'path/to/root-CA.crt',
  clientId: 'myClientId',
  host: 'your-iot-endpoint.amazonaws.com'
});

device.on('connect', function() {
  console.log('Connected to AWS IoT');
});

Publishing to an MQTT Topic

This feature enables devices to publish messages to a specified MQTT topic. The code sample shows how to publish a JSON message to the 'my/topic' topic.

device.publish('my/topic', JSON.stringify({ key: 'value' }));

Subscribing to an MQTT Topic

This feature allows devices to subscribe to MQTT topics and receive messages. The code sample demonstrates how to subscribe to 'my/topic' and handle incoming messages.

device.subscribe('my/topic');

device.on('message', function(topic, payload) {
  console.log('Message received on topic', topic, ':', payload.toString());
});

Managing Device Shadows

This feature provides the ability to manage device shadows, which are virtual representations of devices. The code sample shows how to register a device shadow and handle status updates.

const thingShadow = awsIot.thingShadow({
  keyPath: 'path/to/private.pem.key',
  certPath: 'path/to/certificate.pem.crt',
  caPath: 'path/to/root-CA.crt',
  clientId: 'myClientId',
  host: 'your-iot-endpoint.amazonaws.com'
});

thingShadow.on('connect', function() {
  thingShadow.register('myThingName');
});

thingShadow.on('status', function(thingName, stat, clientToken, stateObject) {
  console.log('received status', stat, 'on', thingName, ':', JSON.stringify(stateObject));
});

Other packages similar to aws-iot-device-sdk

FAQs

Package last updated on 03 Jul 2024

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