Skip to content

pelikhan/devicescript-adafruit-io

Repository files navigation

Adafruit.IO DeviceScript Client

This project is a DeviceScript library that uses Adafruit.io REST APIs to upload data.

Requires a microcontroller with network connectivity such as the Adafruit QT Py C3.

Setup

Install this project to your DeviceScript project

npm install --save pelikhan/devicescript-adafruit-io#v...

where v... is the current release

Settings

The APIs will read a default username, feed and key from the settings.

# env.defaults
IO_USERNAME=user
IO_FEED=feed
# env.local
IO_KEY=...

This extension uses the following settings:

  • IO_KEY: (required) access key
  • IO_FEED: feed name
  • IO_USERNAME: io.adafruit.com user name
  • IO_LAT: (optional) latitude (as a number)
  • IO_LON: (optional) longitude (as a number)
  • IO_ELE: (optional) elevation (as a number)

REST

The createData function will upload a value to the Adafruit.io feed using the REST APIs and return the HTTP status code.

import { createData } from "devicescript-adafruit-io"
const value = await temperature.reading.read()
const status = await createData(value)
console.log({ status })

MQTT

This API connects to the MQTT broker and let's you publish sensor data through the feed topics.

import {
    publishData,
    startAdafruitIOMQTTClient,
} from "devicescript-adafruit-io"

const client = await startAdafruitIOMQTTClient()

await publishData(client, 456)