Skip to content

Commit 25f113d

Browse files
committed
use IO_USERNAME to match adafruit.io UI
1 parent 405a7d7 commit 25f113d

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

.env.defaults

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Store common settings here.
22
# You can commit this file to source control, make sure there are no secrets.
33

4-
AIO_FEED="devicescript"
5-
AIO_USER="pelikhan"
4+
IO_FEED=devicescript
5+
IO_USERNAME=pelikhan

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The APIs will read a default username, feed and key from the [settings](https://
2020

2121
```.env
2222
# env.defaults
23-
IO_USER=user
23+
IO_USERNAME=user
2424
IO_FEED=feed
2525
```
2626

@@ -33,7 +33,7 @@ This extension uses the following settings:
3333

3434
- IO_KEY: (required) access key
3535
- IO_FEED: feed name
36-
- IO_USER: io.adafruit.com user name
36+
- IO_USERNAME: io.adafruit.com user name
3737
- IO_LAT: (optional) latitude (as a number)
3838
- IO_LON: (optional) longitude (as a number)
3939
- IO_ELE: (optional) elevation (as a number)

src/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { delay } from "@devicescript/core"
12
import { createData, publishData, startAdafruitIOMQTTClient } from "."
23

4+
console.log(`post data using http`)
35
await createData(123)
46

7+
console.log(`post data using mqtt in 5s`)
8+
await delay(5000)
59
const client = await startAdafruitIOMQTTClient()
6-
710
await publishData(client, 456)

src/options.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface UserOptions {
1010
/**
1111
* Merges the passed options and the options in the settings
1212
* - IO_KEY: (required) access key
13-
* - IO_USER: io.adafruit.com user name
13+
* - IO_USERNAME: io.adafruit.com user name
1414
* @param options
1515
* @returns a valid option object, including the key
1616
* @throws Error missing user or feed information
@@ -21,8 +21,11 @@ export async function loadUserOptions(
2121
const key = await readSetting("IO_KEY")
2222
if (!key) throw new Error("Adafruit.io: missing secret IO_KEY")
2323
let { user } = options || {}
24-
user = user || (await readSetting("IO_USER"))
25-
if (!user) throw new Error("Adafruit.io: missing setting IO_USER")
24+
user =
25+
user ||
26+
(await readSetting("IO_USERNAME")) ||
27+
(await readSetting("IO_USER"))
28+
if (!user) throw new Error("Adafruit.io: missing setting IO_USERNAME")
2629
return { user, key }
2730
}
2831

0 commit comments

Comments
 (0)