node-red-contrib-tdn-wifi 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +61 -0
- package/examples/Basic.json +28 -0
- package/package.json +19 -0
- package/tdn-wifi.html +89 -0
- package/tdn-wifi.js +505 -0
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# node-red-contrib-tdn-wifi
|
|
2
|
+
|
|
3
|
+
A Node-RED node that serves a WiFi scan/connect page at `/wifi-config`, for Raspberry Pi boards running
|
|
4
|
+
**systemd-networkd + wpa_supplicant** (not NetworkManager, not dhcpcd). No dependencies beyond Node's
|
|
5
|
+
own built-ins — nothing else to `npm install`.
|
|
6
|
+
|
|
7
|
+
## Quick start
|
|
8
|
+
|
|
9
|
+
1. Drag a **WiFi Config** node onto any flow (it needs no wiring — 0 inputs) and deploy.
|
|
10
|
+
2. Open `/wifi-config` (same host/port as Node-RED, or click **Open WiFi Config page** on the node).
|
|
11
|
+
3. Click **Scan Networks**, pick one, enter its password, **Connect**.
|
|
12
|
+
4. On success the page shows the assigned IP, gateway, DNS servers, and a live reachability check
|
|
13
|
+
against the node's **Check URL** (blank = `https://1.1.1.1`).
|
|
14
|
+
|
|
15
|
+
**⚠️ Security note: `/wifi-config` is unauthenticated by default (matching this Pi's other TDN pages)
|
|
16
|
+
and can change the Pi's WiFi network and store a new password on the device. Only run this on a
|
|
17
|
+
trusted LAN. If this Pi is ever reachable from an untrusted network, put it behind a reverse proxy or
|
|
18
|
+
VPN, or add your own auth in front of it.**
|
|
19
|
+
|
|
20
|
+
## Requirements on the Pi
|
|
21
|
+
|
|
22
|
+
- `wpa_cli` (part of `wpasupplicant`) reachable for the WiFi interface's control socket — Node-RED runs
|
|
23
|
+
as root on the Pi, so this works without extra permission setup.
|
|
24
|
+
- `ip` (iproute2) — used to read the interface's IP address and default route.
|
|
25
|
+
- `resolvectl` (systemd-resolved) for DNS servers, with a fallback to reading `/etc/resolv.conf` if it's
|
|
26
|
+
not present.
|
|
27
|
+
|
|
28
|
+
Only home-style WPA2/WPA3-Personal networks are supported (SSID + password, 8-63 characters) — no
|
|
29
|
+
WPA-Enterprise/802.1x.
|
|
30
|
+
|
|
31
|
+
## Install / update
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Install (from the Pi, same pattern as the TDN MWA packages)
|
|
35
|
+
cd /root/.node-red
|
|
36
|
+
npm install /path/to/node-red-contrib-tdn-wifi
|
|
37
|
+
|
|
38
|
+
# Update after a new version is published
|
|
39
|
+
npm install node-red-contrib-tdn-wifi@latest
|
|
40
|
+
|
|
41
|
+
sudo systemctl restart nodered
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Output
|
|
45
|
+
|
|
46
|
+
The node emits `{ payload: { event: 'connected' | 'disconnected', ssid? } }` whenever the WiFi state
|
|
47
|
+
changes, polled every 30 seconds independent of the page — wire it to a
|
|
48
|
+
MWA send node (`node-red-contrib-tdn-mwa` or `node-red-contrib-tdn-mwa-web`) to get an alert when
|
|
49
|
+
this Pi's WiFi drops or reconnects.
|
|
50
|
+
|
|
51
|
+
## Example
|
|
52
|
+
|
|
53
|
+
**Import → Examples → node-red-contrib-tdn-wifi → Basic**: the WiFi Config node with a debug node on its
|
|
54
|
+
output.
|
|
55
|
+
|
|
56
|
+
## Why no NetworkManager (`nmcli`)?
|
|
57
|
+
|
|
58
|
+
This Pi's networking is configured with systemd-networkd + wpa_supplicant directly, so the node drives
|
|
59
|
+
`wpa_cli` for scanning/associating and `ip`/`resolvectl` for reading the resulting IP configuration,
|
|
60
|
+
rather than `nmcli`. If you're deploying this on a Pi OS image that uses NetworkManager instead, this
|
|
61
|
+
package will not work as-is.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "wifb000000000001",
|
|
4
|
+
"type": "tdn-wifi-config",
|
|
5
|
+
"name": "",
|
|
6
|
+
"iface": "",
|
|
7
|
+
"checkUrl": "",
|
|
8
|
+
"x": 170,
|
|
9
|
+
"y": 80,
|
|
10
|
+
"wires": [
|
|
11
|
+
[
|
|
12
|
+
"wifb000000000002"
|
|
13
|
+
]
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "wifb000000000002",
|
|
18
|
+
"type": "debug",
|
|
19
|
+
"name": "wifi state",
|
|
20
|
+
"active": true,
|
|
21
|
+
"tosidebar": true,
|
|
22
|
+
"console": false,
|
|
23
|
+
"complete": "payload",
|
|
24
|
+
"x": 380,
|
|
25
|
+
"y": 80,
|
|
26
|
+
"wires": []
|
|
27
|
+
}
|
|
28
|
+
]
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-red-contrib-tdn-wifi",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "WiFi scan/connect config page for Node-RED (systemd-networkd + wpa_supplicant)",
|
|
5
|
+
"license": "AGPL-3.0-or-later",
|
|
6
|
+
"author": "letis009",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"node-red",
|
|
9
|
+
"wifi",
|
|
10
|
+
"wpa_supplicant",
|
|
11
|
+
"networkd",
|
|
12
|
+
"raspberry-pi"
|
|
13
|
+
],
|
|
14
|
+
"node-red": {
|
|
15
|
+
"nodes": {
|
|
16
|
+
"tdn-wifi": "tdn-wifi.js"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
package/tdn-wifi.html
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<!-- ═══════════════════════════════════════════════════════════════════════ -->
|
|
2
|
+
<!-- WIFI CONFIG NODE — tdn-wifi-config -->
|
|
3
|
+
<!-- ═══════════════════════════════════════════════════════════════════════ -->
|
|
4
|
+
<script type="text/javascript">
|
|
5
|
+
RED.nodes.registerType('tdn-wifi-config', {
|
|
6
|
+
category: 'TDN',
|
|
7
|
+
color: '#2196f3',
|
|
8
|
+
defaults: {
|
|
9
|
+
name: { value: '' },
|
|
10
|
+
iface: { value: '' },
|
|
11
|
+
checkUrl: { value: '' }
|
|
12
|
+
},
|
|
13
|
+
inputs: 0,
|
|
14
|
+
outputs: 1,
|
|
15
|
+
icon: 'font-awesome/fa-wifi',
|
|
16
|
+
paletteLabel: 'WiFi Config',
|
|
17
|
+
label: function () { return this.name || 'WiFi Config'; },
|
|
18
|
+
outputLabels: ['connect / disconnect event'],
|
|
19
|
+
oneditprepare: function () {
|
|
20
|
+
var adminRoot = (RED.settings.httpNodeRoot || '/').replace(/\/$/, '');
|
|
21
|
+
$('#wifi-config-link').attr('href', adminRoot + '/wifi-config');
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<script type="text/html" data-template-name="tdn-wifi-config">
|
|
27
|
+
<div class="form-row">
|
|
28
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
29
|
+
<input type="text" id="node-input-name" placeholder="WiFi Config">
|
|
30
|
+
</div>
|
|
31
|
+
<div class="form-row">
|
|
32
|
+
<label for="node-input-iface"><i class="fa fa-cog"></i> Interface</label>
|
|
33
|
+
<input type="text" id="node-input-iface" placeholder="Leave blank to auto-detect (e.g. wlan0)">
|
|
34
|
+
</div>
|
|
35
|
+
<div class="form-row">
|
|
36
|
+
<label for="node-input-checkUrl"><i class="fa fa-globe"></i> Check URL</label>
|
|
37
|
+
<input type="text" id="node-input-checkUrl" placeholder="https://1.1.1.1">
|
|
38
|
+
</div>
|
|
39
|
+
<div class="form-row" style="margin-top:16px">
|
|
40
|
+
<a id="wifi-config-link" href="/wifi-config" target="_blank" class="btn btn-default btn-sm">
|
|
41
|
+
<i class="fa fa-wifi"></i> Open WiFi Config page
|
|
42
|
+
</a>
|
|
43
|
+
</div>
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<script type="text/html" data-help-name="tdn-wifi-config">
|
|
47
|
+
<p>
|
|
48
|
+
Drag this node onto a flow and deploy — it doesn't need wiring to anything. It serves a
|
|
49
|
+
WiFi scan/connect page at <a href="/wifi-config" target="_blank">/wifi-config</a> for Raspberry
|
|
50
|
+
Pi boards running <b>systemd-networkd + wpa_supplicant</b> (not NetworkManager, not dhcpcd).
|
|
51
|
+
</p>
|
|
52
|
+
<p>
|
|
53
|
+
<b>⚠️ Security note: <code>/wifi-config</code> has no login by default (matching this Pi's other
|
|
54
|
+
TDN pages) and can change the Pi's WiFi network and store a new WiFi password on the device.
|
|
55
|
+
Only run this on a trusted LAN. If this Pi is ever reachable from an untrusted network, put it
|
|
56
|
+
behind a reverse proxy or VPN, or add your own auth in front of it.</b>
|
|
57
|
+
</p>
|
|
58
|
+
<h3>Interface</h3>
|
|
59
|
+
<p>
|
|
60
|
+
Leave blank to auto-detect the first WiFi-capable interface (checks
|
|
61
|
+
<code>/sys/class/net/*/wireless</code>), falling back to <code>wlan0</code>. Only set this if
|
|
62
|
+
auto-detection picks the wrong adapter.
|
|
63
|
+
</p>
|
|
64
|
+
<h3>What the page does</h3>
|
|
65
|
+
<ol>
|
|
66
|
+
<li><b>Scan Networks</b> — runs <code>wpa_cli scan</code> / <code>scan_results</code>, lists
|
|
67
|
+
SSIDs by signal strength.</li>
|
|
68
|
+
<li>Click a network, enter its password (8-63 characters — WPA2/WPA3-Personal only, no
|
|
69
|
+
enterprise/802.1x), click <b>Connect</b>.</li>
|
|
70
|
+
<li>On success, shows the assigned <b>IP address, gateway, and DNS servers</b>, plus a live
|
|
71
|
+
HTTPS reachability check against the <b>Check URL</b> (blank = <code>https://1.1.1.1</code>; set it to the host your alerts depend on).</li>
|
|
72
|
+
<li>On failure (wrong password, timeout), the half-added network profile is automatically
|
|
73
|
+
removed — nothing is left behind to retry manually.</li>
|
|
74
|
+
</ol>
|
|
75
|
+
<p>
|
|
76
|
+
<b>Test Connectivity</b> re-runs the IP/gateway/DNS + reachability check for whatever
|
|
77
|
+
network is currently connected, without reconnecting.
|
|
78
|
+
</p>
|
|
79
|
+
<h3>Output</h3>
|
|
80
|
+
<dl class="message-properties">
|
|
81
|
+
<dt>payload.event <span class="property-type">string</span></dt>
|
|
82
|
+
<dd><code>connected</code> or <code>disconnected</code> — fires whenever the WiFi state changes,
|
|
83
|
+
even if nobody has the page open (checked every 30s). Wire this to an MWA send node (from
|
|
84
|
+
<code>node-red-contrib-tdn-mwa</code> or <code>node-red-contrib-tdn-mwa-web</code>) to get an alert when the Pi's WiFi drops or comes
|
|
85
|
+
back.</dd>
|
|
86
|
+
<dt class="optional">payload.ssid <span class="property-type">string</span></dt>
|
|
87
|
+
<dd>Present when <code>event</code> is <code>connected</code>.</dd>
|
|
88
|
+
</dl>
|
|
89
|
+
</script>
|