node-red-contrib-relink 0.1.1

Node-RED nodes for Relink IoT virtual pins over encrypted UDP and direct mesh

npm install node-red-contrib-relink

Relink for Node-RED

Connect Node-RED to the same virtual pins as an ESP32, Python script or C++ program on Relink. One shared connection gives encrypted UDP, relay fallback, direct device mesh and numeric history summaries. No runtime npm dependencies.

Needs Node.js 18+ and Node-RED 3+.

Available nodes

Node Purpose
Relink connection Shared server settings and device credentials; one encrypted UDP endpoint
relink in Receive one pin or all pins from the dashboard and other endpoints
relink out Write a fixed pin or choose a pin from each incoming message
ESP32 / Python / C++ ← binary UDP mesh → Relink connection
                                              │
                                        relink in → Debug
                                        relink out ← Inject / Function

The relay supplies peer addresses and handles fallback. Once peers establish a direct path, their pin data can travel directly between endpoints.

Install

In Node-RED: Menu → Manage palette → Install, search for node-red-contrib-relink, then Install.

Or from your Node-RED user directory (normally ~/.node-red), then restart Node-RED:

cd ~/.node-red
npm install node-red-contrib-relink

The palette's Network category then shows relink in and relink out.

1. Settings

Create a test device in Relink and add V0 Float, V1 Integer, and optionally V2 ByteArray. Copy its token and encryption key. Programs sharing both join one device; avoid writing to an actuator unless that is intended.

Drag relink in onto a flow. Open it, add a Relink connection, and enter:

Field Value
Server Your relay hostname or IPv4 address, such as relink-iot.com
UDP port 7445, unless configured otherwise
API URL Your API origin, such as https://relink-iot.com; do not append /api
Device token From the device page
Encryption key The device's 64-character hexadecimal key
Direct mesh Enabled to attempt direct UDP links to the other endpoints

The token and key use Node-RED's credential system, rather than ordinary flow properties. They are omitted from exported example flows. Configure Node-RED's own credential encryption for your installation. A missing or malformed key is rejected; plaintext fallback is not supported.

2. Connect

Deploy. The status changes from connecting to connected after the relay's authenticated session handshake. All in/out nodes using one connection share one UDP endpoint. Different connection configurations create separate endpoints.

Signed HTTP requests fetch declared pins every 30 seconds. If the API is unavailable at startup, the relay continues to enforce the pin list and direct mesh waits for authorization. After a successful fetch, an API outage retains the previous list. The UDP connection re-registers after relay outages without blocking other flows.

Mesh uses Relink's existing binary UDP protocol: a sealed N peer list supplies public and LAN candidates, encrypted H hellos open the direct path, and D batches carry pin values. A short-TTL priming phase precedes public-address punching, matching the host SDK approach. The relay receives L link reports to avoid duplicate forwarding. Direct peers use the unsalted device envelope; relay uplink uses its session salt. Existing direct links continue carrying data when the relay session expires. Actual NAT reachability depends on both networks; relay fallback remains available.

Pin values, including ByteArray Buffers, are binary on UDP rather than JSON or base64. JSON is used for API metadata and Node-RED flow import/export only. If a dashboard is connected through an ESP32 WebRTC gateway, the gateway can carry this endpoint's mesh values to that browser.

3. Handlers: receive values

Connect relink in → Debug. Leave Pin empty to receive all pins, or enter V1 to filter.

{
    topic: "V1",
    pin: 1,
    payload: 42,
    dtype: "int32",
    transport: "relay",
    checksum: 123456789
}

transport is relay or p2p. payload is a number, string, or Buffer. No token or encryption key is added to messages. Own writes do not produce a local echo.

msg.dtype reports the actual wire type of that update. It does not prove the value matched the type selected on the Relink datastream page.

4. Loop: write values

Connect Inject → relink out. Set Inject's numeric payload to 23.5, select pin V0 in relink out, and choose Float. Click Inject; a dashboard widget or another SDK endpoint on the same device should receive it. For periodic readings, set Inject's repeat interval.

Leave the output node's Pin blank for dynamic routing: msg.pin takes priority over msg.topic. A topic such as V2 selects pin 2.

Payload / selected type Wire value
Whole number, Automatic Int16 when it fits; otherwise Int32
Fractional number, Automatic Float32
Boolean, Automatic Int16 0 or 1
String UTF-8 text, up to 255 bytes
Buffer ByteArray, up to 255 bytes

Choose the type explicitly when required by your datastream: for example, a whole-number reading for a Float datastream should use Float. Objects, non-finite numbers, out-of-range integers, and oversized values are rejected through Node-RED's Catch mechanism. Values are never silently truncated.

Integer and binary examples

For V1 Integer, configure relink out with Pin V1 and Data type Int32, then inject the number 1. Explicit integer selections reject a fractional payload such as 32.5.

Explicit selection Equivalent Bytes Range / encoding
Int16 int16_t, wire dtype 0 2 −32,768 to 32,767, little-endian
Int32 int32_t, wire dtype 1 4 −2,147,483,648 to 2,147,483,647, little-endian
Float Float32, wire dtype 2 4 Finite IEEE 754 single-precision, little-endian
String Wire dtype 3 Up to 255 UTF-8 bytes
ByteArray Wire dtype 4 Up to 255 Raw Buffer bytes

The dashboard's generic Integer declaration does not currently choose or enforce Int16 versus Int32. In Automatic mode, whole numbers use Int16 when they fit, otherwise Int32; numbers outside Int32 range are rejected. Fractional numbers use Float, regardless of the dashboard declaration.

For V2 ByteArray, use a Function node connected to relink out with Pin V2 and Data type ByteArray:

msg.payload = Buffer.from([0x00, 0xff, 0x80, 0x01]);
return msg;

The receiving endpoint gets those exact four bytes. Do not JSON-stringify the Buffer or encode it as base64 before sending it to relink out.

Writes are coalesced to the latest value per pin, including during an outage. Pending values are in memory only and cleared on redeploy. Completion means queued, not acknowledged by the destination. High-rate intermediate values may be coalesced. Numeric history uses minute summaries, matching the host SDK protocol.

Import Menu → Import → Examples → node-red-contrib-relink → basic, or import examples/basic.json. It contains no credentials and sends only when Inject is clicked; configure the connection first.

The bytes example uses a binary Inject payload and V2 ByteArray. Its bytes stay a Buffer throughout the flow and are sent as binary UDP data.

Known limitations

  • Declared datastream types are not enforced end to end. The signed API supplies allowed pin numbers, without type metadata. Node-RED Automatic mode infers the type from the payload, and relink in decodes the sender's actual wire type. An Integer datastream can therefore receive 32.5 sent by another endpoint as Float. A dashboard slider can display rounded 33 while transmitting 32.50. Explicit Int16/Int32 on relink out protects that node's own writes, but does not validate other senders. The fix must cover every datastream type across UI, SDKs, relay, and direct P2P. Binary stress-test success does not close this bug.
  • Intermediate writes can be coalesced. The latest-value queue makes this a state-update client, rather than a lossless stream of every submitted value. Two writers on the same device/pin also share the relay's rate cap.
  • Transport status describes the relay connection. Input messages report their actual path in msg.transport. A previously established direct path can continue while the relay reconnects.
  • Camera frames, browser WebRTC, and firmware flashing are not implemented by this package. Browser dashboards can still communicate with this endpoint through an ESP32 gateway or the relay. No server wire-format change is required by this package.
  • Separate-network NAT and ESP32 hardware remain unverified for this package. Direct UDP and relay interoperability were tested on one machine; network conditions can prevent hole punching.

Troubleshooting

Symptom Check
Relink nodes are missing from the palette Install in the user directory used by the running Node-RED, then restart it and search for relink
Connection stays at connecting Device token/key, relay hostname, outbound UDP access, and server port
Relay works but direct mesh does not Enable mesh; verify the API origin and signed pin-list fetch; allow time for peer discovery; some NATs require relay fallback
No pin values arrive Declare the pin as a datastream, check the input filter, and send from another endpoint; own writes have no local echo
Integer pin receives a fraction Inspect msg.dtype and the sender; see the declared-type enforcement limitation above
A write fails Connect a Catch node; check pin, payload type, integer range, and the 255-byte text/Buffer limit
Values skip during high-rate traffic Compare offered and transmitted values; latest values replace intermediate writes, and relay limits apply per device/pin

License

MIT

Node Info

Version: 0.1.1
Updated 2 days ago
License: MIT
Rating: not yet rated

Categories

Actions

Rate:

Downloads

0 in the last week

Nodes

  • relink-connection
  • relink in
  • relink out

Keywords

  • node-red
  • relink
  • iot
  • esp32
  • virtual-pins

Maintainers