2023-10-10 17:27:08 -04:00
NIP-107
======
Nostr Internet of Things
-----------------------------------
2023-10-24 08:43:50 -04:00
`draft` `optional` `author:benarc` `author:blackcoffeebtc` `author:motorina0`
2023-10-10 17:27:08 -04:00
2023-10-19 05:55:59 -04:00
## Rationale
2023-10-10 17:27:08 -04:00
2023-10-24 08:33:47 -04:00
The terms/conditions of IoT software/hardware is horrible. A user should be able to message a light or heating system and ask it to turn on/off. Nostr gives the simple, permissionless development environment IoT needs.
2023-10-10 17:27:08 -04:00
## Terms
2023-10-19 06:00:51 -04:00
- `user` - user operating IoT devices with NOSTR key-pair and a client made specifically for IoT
2023-10-10 17:27:08 -04:00
- `device` - device to operate over Nostr with NOSTR key-pair, using a microcontroller client like < a href = "https://github.com/lnbits/arduino-nostr" > nostr-arduino</ a >
## Nostr IoT Clients
### User
Where the `user` registers 'device'(s) and its keys, then updates the `device` (s).
### Device
2023-10-19 06:27:29 -04:00
The `device` uses a client like < a href = "https://github.com/lnbits/arduino-nostr" > nostr-arduino</ a > to receive commands from the `user` or another `device` .
2023-10-19 05:53:43 -04:00
The `device` can also push data such as sensor readings and updates.
2023-10-10 17:27:08 -04:00
2023-10-19 06:27:29 -04:00
## Events
2023-10-10 17:27:08 -04:00
2023-10-24 08:33:47 -04:00
A `device` can publish any of the events described in [NIP-91 Event Kinds ](https://github.com/nostr-protocol/nips/blob/iot/91.md#event-kinds ).
A `user` can publish these event kinds:
| Kind | | Description | NIP |
|--------|----------|-------------------------------|-----------------------------------------------------------------------------------------|
| `8000` | `intent` | Trigger an action on a device | [NIP-91 Event Kinds ](https://github.com/nostr-protocol/nips/blob/iot/91.md#event-kinds ) |
2023-10-24 08:43:50 -04:00
The content of events can be transmitted in clear text (for public data) or as [NIP-59 Gift Wrap ](https://github.com/staab/nips/blob/NIP-59/59.md ).
2023-10-10 17:27:08 -04:00
2023-10-24 08:43:50 -04:00
### Intent Events
Intent Events represent different actions that can be performed on a device. The content of the event is a JSON.
2023-10-19 06:27:29 -04:00
Each `JSON` message `MUST` have a `type` field indicating the what the JSON represents. Possible types:
2023-10-10 17:27:08 -04:00
2023-10-19 06:27:29 -04:00
| Message Type | Sent By | Description |
|--------------|----------------|------------------|
| 0 | User | Configure Device |
### Event: Configure `device`
2023-10-24 02:29:59 -04:00
This message is sent by a `user` to a `device` . The `device` saves the config locally and uses it.
2023-10-10 17:27:08 -04:00
**Event Content**:
```json
{
2023-10-24 02:29:59 -04:00
"type": 0,
"admin_pubkeys": [ [< String ( optional ) , admin user public-key > ]],
"name": < String ( optional ) , set a name for the device > ,
2023-10-10 17:27:08 -04:00
"description": < String ( optional ) , device description > ,
"categories":[ < String ( optional ) , device category , such as ' boiler ' > ],
2023-10-24 02:29:59 -04:00
"send_to_pubkeys":[ [< String ( optional ) , user public-key > ]],
"commands_from_pubkeys":[ [< String ( optional ) , user public-key > ]],
2023-10-10 17:27:08 -04:00
}
```
Note:
2023-10-24 02:29:59 -04:00
- `admin_pubkeys` :
- list of public keys that are allowed to configure this device. A fresh/blank device will not have this value, so the first received `"type: 0"` should set it.
2023-10-10 17:27:08 -04:00
- `users` :
2023-10-24 02:29:59 -04:00
- a list that can restrict access to public-keys, `device` (s) also has keys and can be a `user` .
2023-10-10 17:27:08 -04:00
### Event: Update a `device`
**Event Content**:
```json
{
2023-10-19 05:54:38 -04:00
"id": < String , UUID generated by the user . Sequential IDs (` 0 `, `1` , `2` ...) are discouraged > ,
2023-10-10 17:27:08 -04:00
"device_id": < String , UUID of the stall to which this device belong to > ,
"settings":[ [< String ( optional ) , user public-key > ]]
}
```
Note:
- `settings` :
2023-10-19 06:00:51 -04:00
- Standard `settings` include:
2023-10-10 17:27:08 -04:00
- eg: `[["on", <bool>], ["range", <int, 0-1000>], ["timer_on", <int unix timestamp>], ["timer_off", <int unix timestamp>]]`