https://github.com/pelikhan/devicescript-adafruit-io
A DeviceScript library to use Adafruit IO
https://github.com/pelikhan/devicescript-adafruit-io
devicescript
Last synced: over 1 year ago
JSON representation
A DeviceScript library to use Adafruit IO
- Host: GitHub
- URL: https://github.com/pelikhan/devicescript-adafruit-io
- Owner: pelikhan
- Created: 2023-06-07T21:08:25.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-27T15:15:29.000Z (almost 3 years ago)
- Last Synced: 2025-01-12T00:26:31.672Z (over 1 year ago)
- Topics: devicescript
- Language: TypeScript
- Homepage:
- Size: 93.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
# Adafruit.IO DeviceScript Client
This project is a [DeviceScript](https://microsoft.github.io/devicescript/) library that uses [Adafruit.io REST APIs](https://io.adafruit.com/api/docs/#create-data) to upload data.
> Requires a microcontroller with network connectivity such as the [Adafruit QT Py C3](https://microsoft.github.io/devicescript/devices/esp32/adafruit-qt-py-c3).
## Setup
Install this project to your DeviceScript project
```bash
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](https://microsoft.github.io/devicescript/developer/settings).
```.env
# env.defaults
IO_USERNAME=user
IO_FEED=feed
```
```.env
# 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](https://io.adafruit.com/api/docs/#create-data) and return the HTTP status code.
```ts
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](https://io.adafruit.com/api/docs/mqtt.html#adafruit-io-mqtt-api)
broker and let's you publish sensor data through the feed topics.
```ts
import {
publishData,
startAdafruitIOMQTTClient,
} from "devicescript-adafruit-io"
const client = await startAdafruitIOMQTTClient()
await publishData(client, 456)
```