npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

arduino-iot-js

v0.13.0

Published

JS module providing Arduino Create IoT Cloud Connection

Downloads

211

Readme

License: GPL v3 npm version

arduino-iot-js

Introduction

This library provides interaction with the Arduino IoT Cloud MQTT broker and It can be used both from the browser and Node.js

It allows to connect in two different modes:

The main features of this module are:

  • Connection/disconnection to Arduino IoT Cloud Broker using WebSocket
  • Behave as a device via MQTT
  • Send IoT Cloud property updates
  • Listen for IoT Cloud property updates made by other clients and/or devices

If you are looking for a way to create, read, update, delete resources (like Devices , Things, Properties, Data Timeseries, ecc...) please check the official Javascript Rest API client.

If you want to learn more about Arduino IoT Cloud architecture, check the official getting started documentation.

Installation

Via NPM

$ npm install arduino-iot-js

Via Yarn

$ yarn add arduino-iot-js

How to use

The MQTT connection relies on Username / Password authentication.

Under the hood, this module could uses your user ID (plus a timestamp) as Username and a valid JWT Token as Password when needs to connect to every properties (You can use either a valid JWT token or just your API Credentials) or some device credentials.

How to connect via User Credentials

  • via API Credentials
import { ArduinoIoTCloud } from 'arduino-iot-js';

(async () => {
  const client = await ArduinoIoTCloud.connect({
    clientId: 'YOUR_CLIENT_ID',
    clientSecret: 'YOUR_CLIENT_SECRET',
    onDisconnect: (message) => console.error(message),
  });

  // Send a value to a thing property
  const value = 'some value';
  client.sendProperty('YOUR_THING_ID', 'YOUR_VARIABLE_NAME', value);

  // Listen to a thing property's changes
  client.onPropertyValue('YOUR_THING_ID', 'ANOTHER_VARIABLE_NAME', (value) => console.log(value));
})();
  • via User JWT Token
import { ArduinoIoTCloud } from 'arduino-iot-js';

async function retrieveUserToken() {
  // Retrieve JWT Token here
}

(async () => {
  const token = await retrieveUserToken();

  const client = await ArduinoIoTCloud.connect({
    token,
    onDisconnect: (message) => console.error(message),
  });

  // Send a value to a thing property
  const value = 'some value';
  client.sendProperty('YOUR_THING_ID', 'YOUR_VARIABLE_NAME', value);

  // Listen to a thing property's changes
  client.onPropertyValue('YOUR_THING_ID', 'ANOTHER_VARIABLE_NAME', (value) => console.log(value));
})();

How to connect via Device Credentials

import { ArduinoIoTCloud } from 'arduino-iot-js';

(async () => {
  const client = await ArduinoIoTCloud.connect({
    deviceId: 'YOUR_DEVICE_ID',
    secretKey: 'YOUR_SECRET_KEY',
    onDisconnect: (message) => console.error(message),
  });

  // Send property's values as a device
  const value = 'some value';
  client.sendProperty('YOUR_VARIABLE_NAME', value);

  // Listen property's updates
  client.onPropertyValue('ANOTHER_VARIABLE_NAME', (value) => console.log(value));
})();