HomeNews

Nostriot News

← Back to News

Nostr IoT PR notes

Published October 18, 2024

First and foremost, a significant acknowledgment goes to Riccardo (@rblb0) for his discussions and contributions so far. The details outlined below largely derive from our discussions and his documented insights here.

The IoT specifications for Nostr will likely be articulated through more than one NIP, aiming to extend beyond data capture. However, the cornerstone of IoT in Nostr involves capturing data from and managing devices - therefore, an initial proposal, a PR, to NIP 90 is essential. Future IoT-specific NIPs may address additional functionalities such as remote configuration and group encryption.

NIP 90 (Data Vending Machine) Overview

NIP 90 (DVMs) allows for both data capture and remote device control. For example, a device, hereafter referred to as a 'Thing', might react to a DVM job request or autonomously publish job results.

We will propose a change to NIP 90 to add job responses as addressable kinds with the kind 36107.

A 'Thing' could represent a single device or a collective of devices associated with a Nostr npub. It's possible for a device to have a single npub with multiple functionalities such as controlling a motor or monitoring temperature and pressure.

An IoT job request requires a single i input tag containing a stringified json array representing a sequence of methods to run that should be executed in order.

Job Request

{
    "content": "",
    "kind": 5107,
    "tags": [
        ["i", "<stringified-json-array>", "text"],
        ["output", "text/plain"]
    ]
}

Example of a stringified JSON array in the 'i' tag

[
    {
        "method": "setTimezone",
        "params": ["Europe/London"]
    },
    {
        "method": "setLanguage",
        "params": ["en-GB"]
    },
    {
        "method": "getTime",
        "params": []
    },
    {
        "method": "setTemperature",
        "params": ["value", "20", "unit", "celcius"]
    }
]

These methods, defined as text, enable a wide range of devices to operate under this NIP.

Standard Job Response

  • Kind: 6107 (follows NIP90 specifications)
{
  "pubkey": "<service-provider pubkey>",
  "content": "<stringified-json-array>",
  "kind": 6107,
  "tags": [
    ["request", "<job-request>"],
    ["e", "<job-request-id>", "<relay-hint>"],
    ["i", "<input-data>"],
    ["p", "<customer's-pubkey>"],
    ["amount", "requested-payment-amount", "<optional-bolt11>"]
  ],
  // additional fields as necessary...
}

Addressable Job Response

A new addressable event kind, 36107, is proposed for NIP 90.

Addressable events (aka parameterised replaceable events) are events for which a relay MUST only store the most recent event identified by a "combination of kind, pubkey and the d tag value" addressable events will allow the use of public relays for IoT data whilst being "kind" to the network.

{
  "pubkey": "<service-provider pubkey>",
  "content": "<stringified-json-array>",
  "kind": 36107,
  "tags": [
    ["i", "<input-stringified-json-array>"],
    ["d", "<unique-string>"]
  ],
}

In the example above, the d tag can have any value, but using a human readable string such as "iot-device-123-event-8333" can improve usability.