Skip to content

Commit 6eacf8e

Browse files
authored
Merge pull request wled#1683 from blazoncek/autodiscovery
Auto node discovery.
2 parents 9b3e627 + 20bebe9 commit 6eacf8e

File tree

11 files changed

+2368
-2063
lines changed

11 files changed

+2368
-2063
lines changed

wled00/NodeStruct.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef WLED_NODESTRUCT_H
2+
#define WLED_NODESTRUCT_H
3+
4+
/*********************************************************************************************\
5+
* NodeStruct from the ESP Easy project (https://github.com/letscontrolit/ESPEasy)
6+
\*********************************************************************************************/
7+
8+
#include <map>
9+
#include <IPAddress.h>
10+
11+
#define NODE_TYPE_ID_UNDEFINED 0
12+
#define NODE_TYPE_ID_ESP8266 82
13+
#define NODE_TYPE_ID_ESP32 32
14+
15+
/*********************************************************************************************\
16+
* NodeStruct
17+
\*********************************************************************************************/
18+
struct NodeStruct
19+
{
20+
String nodeName;
21+
IPAddress ip;
22+
uint8_t unit;
23+
uint8_t age;
24+
uint8_t nodeType;
25+
uint32_t build;
26+
27+
NodeStruct() : age(0), nodeType(0), build(0)
28+
{
29+
for (uint8_t i = 0; i < 4; ++i) { ip[i] = 0; }
30+
}
31+
};
32+
typedef std::map<uint8_t, NodeStruct> NodesMap;
33+
34+
#endif // WLED_NODESTRUCT_H

wled00/const.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@
231231
#define JSON_BUFFER_SIZE 16384
232232
#endif
233233

234+
// Maximum size of node map (list of other WLED instances)
235+
#ifdef ESP8266
236+
#define WLED_MAX_NODES 15
237+
#else
238+
#define WLED_MAX_NODES 150
239+
#endif
240+
234241
//this is merely a default now and can be changed at runtime
235242
#ifndef LEDPIN
236243
#define LEDPIN 2

wled00/data/index.css

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ button {
9090

9191
#namelabel {
9292
position: fixed;
93-
bottom: calc(var(--bh) + 5px);
93+
bottom: calc(var(--bh) + 6px);
9494
right: 4px;
9595
color: var(--c-6);
96+
cursor: pointer;
9697
writing-mode: vertical-rl;
9798
}
9899

@@ -366,10 +367,18 @@ button {
366367
z-index: 3;
367368
}
368369

369-
#rover {
370+
#rover, #nodes {
370371
z-index: 2;
371372
}
372373

374+
#ndlt {
375+
margin: 12px 0;
376+
}
377+
378+
.valtd i {
379+
font-size: 14px;
380+
}
381+
373382
#roverstar {
374383
position: fixed;
375384
top: calc(var(--th) + 5px);
@@ -394,11 +403,15 @@ button {
394403
display: inline-block;
395404
}
396405

397-
#kv {
406+
#kv, #kn {
398407
max-width: 490px;
399408
display: inline-block;
400409
}
401410

411+
#kn td {
412+
padding-bottom: 12px;
413+
}
414+
402415
#lv {
403416
max-width: 600px;
404417
display: inline-block;
@@ -930,6 +943,12 @@ input[type=number]::-webkit-outer-spin-button {
930943
}
931944
}
932945

946+
@media all and (max-width: 770px) {
947+
#buttonNodes {
948+
display: none;
949+
}
950+
}
951+
933952
@media all and (max-width: 1249px) {
934953
#buttonPcm {
935954
display: none;

wled00/data/index.htm

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
<button id="buttonNl" onclick="toggleNl()"><i class="icons">&#xe2a2;</i><p class="tab-label">Timer</p></button>
2424
<button id="buttonSync" onclick="toggleSync()"><i class="icons">&#xe116;</i><p class="tab-label">Sync</p></button>
2525
<button id="buttonSr" onclick="toggleLiveview()"><i class="icons">&#xe410;</i><p class="tab-label">Peek</p></button>
26-
<button id="buttonI" onclick="toggleInfo()"><i class="icons">&#xe34b;</i><p class="tab-label">Info</p></button>
26+
<button id="buttonI" onclick="toggleInfo()"><i class="icons">&#xe34b;</i><p class="tab-label">Info</p></button>
27+
<button id="buttonNodes" onclick="toggleNodes()"><i class="icons">&#xe22d;</i><p class="tab-label">Nodes</p></button></div>
2728
<button onclick="window.location.href = '/settings';"><i class="icons">&#xe0a2;</i><p class="tab-label">Config</p></button>
28-
<button id="buttonPcm" onclick="togglePcMode(true)"><i class="icons">&#xe23d;</i><p class="tab-label">PC Mode</p></button>
29+
<button id="buttonPcm" onclick="togglePcMode(true)"><i class="icons">&#xe23d;</i><p class="tab-label">PC Mode</p></button>
2930
</div>
3031
<div id="briwrap">
3132
<p class="hd">Brightness</p>
@@ -66,17 +67,17 @@
6667
</div>
6768
</div>
6869
<div id="qcs-w">
69-
<div class="qcs" onclick="pC('#ff0000');" style="background-color:#ff0000;"></div>
70-
<div class="qcs" onclick="pC('#ffa000');" style="background-color:#ffa000;"></div>
71-
<div class="qcs" onclick="pC('#ffc800');" style="background-color:#ffc800;"></div>
72-
<div class="qcs" onclick="pC('#ffe0a0');" style="background-color:#ffe0a0;"></div>
73-
<div class="qcs" onclick="pC('#ffffff');" style="background-color:#ffffff;"></div>
74-
<div class="qcs qcsb" onclick="pC('#000000');" style="background-color:#000000;"></div><br>
75-
<div class="qcs" onclick="pC('#ff00ff');" style="background-color:#ff00ff;"></div>
76-
<div class="qcs" onclick="pC('#0000ff');" style="background-color:#0000ff;"></div>
77-
<div class="qcs" onclick="pC('#00ffc8');" style="background-color:#00ffc8;"></div>
78-
<div class="qcs" onclick="pC('#08ff00');" style="background-color:#08ff00;"></div>
79-
<div class="qcs" onclick="pC('rnd');" style="background-color:var(--c-3); padding: 4px 8px; transform: translateY(-10px);">R</div>
70+
<div class="qcs" onclick="pC('#ff0000');" title="Red" style="background-color:#ff0000;"></div>
71+
<div class="qcs" onclick="pC('#ffa000');" title="Orange" style="background-color:#ffa000;"></div>
72+
<div class="qcs" onclick="pC('#ffc800');" title="Yellow" style="background-color:#ffc800;"></div>
73+
<div class="qcs" onclick="pC('#ffe0a0');" title="Warm White" style="background-color:#ffe0a0;"></div>
74+
<div class="qcs" onclick="pC('#ffffff');" title="White" style="background-color:#ffffff;"></div>
75+
<div class="qcs qcsb" onclick="pC('#000000');" title="Black" style="background-color:#000000;"></div><br>
76+
<div class="qcs" onclick="pC('#ff00ff');" title="Pink" style="background-color:#ff00ff;"></div>
77+
<div class="qcs" onclick="pC('#0000ff');" title="Blue" style="background-color:#0000ff;"></div>
78+
<div class="qcs" onclick="pC('#00ffc8');" title="Cyan" style="background-color:#00ffc8;"></div>
79+
<div class="qcs" onclick="pC('#08ff00');" title="Green" style="background-color:#08ff00;"></div>
80+
<div class="qcs" onclick="pC('rnd');" title="Random" style="background-color:var(--c-3); padding: 4px 8px; transform: translateY(-10px);">R</div>
8081
</div>
8182
<div id="csl">
8283
<button class="xxs cl btn" onclick="selectSlot(0);">1</button>
@@ -169,19 +170,26 @@
169170

170171
<div id="connind"></div>
171172
<div id="toast"></div>
172-
<div id="namelabel"></div>
173+
<div id="namelabel" onclick="toggleNodes()"></div>
173174
<div id="info" class="modal">
174175
<div id="imgw">
175176
<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAggAAACMCAYAAAAZQlGEAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAKLSURBVHhe7dgxjtwwEADBpf//5zUDwklnpzFAnKoSTigNFTT0AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGDcOieX+G5nvNLaznil6f1Nv+/tz3c7+3tmen/Tpu/jbe877c85AQD+EQgAQAgEACAEAgAQAgEACIEAAIRAAABCIAAAIRAAgBAIAEAIBAAgBAIAEAIBAAiBAACEQAAAQiAAACEQAIAQCABACAQAINY5+aHvdsYRazvjK9jfM7fvz/0+Y3+/2+336w8CABACAQAIgQAAhEAAAEIgAAAhEACAEAgAQAgEACAEAgAQAgEACIEAAIRAAABCIAAAIRAAgBAIAEAIBAAgBAIAEAIBAAiBAADEOudrfLczXmltZ3yF6fuwv2em9+d+n5ne3zT3cZfp+/AHAQAIgQAAhEAAAEIgAAAhEACAEAgAQAgEACAEAgAQAgEACIEAAIRAAABCIAAAIRAAgBAIAEAIBAAgBAIAEAIBAAiBAACEQAAAYp3zNb7bGUes7Yz8wO334fmeuf35bmd/z9y+v9ufzx8EACAEAgAQAgEACIEAAIRAAABCIAAAIRAAgBAIAEAIBAAgBAIAEAIBAAiBAACEQAAAQiAAACEQAIAQCABACAQAIAQCABACAQCIdc4x3+2MV1rbGfmFpr+/6e/l9ue73fT+pt1+H2/bn+/lGX8QAIAQCABACAQAIAQCABACAQAIgQAAhEAAAEIgAAAhEACAEAgAQAgEACAEAgAQAgEACIEAAIRAAABCIAAAIRAAgBAIAEAIBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgP/u8/kLYCqAxINTyZkAAAAASUVORK5CYII=">
176177
</div><br>
177178
<div id="kv">Loading...</div><br>
178179
<button class="btn infobtn" onclick="requestJson(null)">Refresh</button>
179180
<button class="btn infobtn" onclick="toggleInfo()">Close Info</button><br>
180-
<button class="btn infobtn" onclick="openGH()">WLED Wiki</button>
181+
<button class="btn infobtn" onclick="toggleNodes()">Instance List</button>
181182
<button class="btn infobtn" id="resetbtn" onclick="cnfReset()">Reboot WLED</button><br>
182183
<span class="h">Made with <span id="heart">&#10084;&#xFE0E;</span> by Aircoookie and the WLED community</span>
183184
</div>
184185

186+
<div id="nodes" class="modal">
187+
<div id="ndlt">WLED instances</div>
188+
<div id="kn">Loading...</div><br>
189+
<button class="btn infobtn" onclick="loadNodes()">Refresh</button>
190+
<button class="btn infobtn" onclick="toggleNodes()">Close list</button><br>
191+
</div>
192+
185193
<div id="rover" class="modal">
186194
<i class="icons huge">&#xe410;</i><br>
187195
<div id="lv">?</div><br><br>
@@ -191,6 +199,7 @@
191199
<button class="btn" onclick="setLor(2)">Override until reboot</button><br>
192200
<span class="h">For best performance, it is recommended to turn off the streaming source when not in use.</span>
193201
</div>
202+
194203
<i id="roverstar" class="icons huge" onclick="setLor(0)">&#xe410;</i><br>
195204
<script src="iro.js"></script>
196205
<script src="rangetouch.js"></script>

wled00/data/index.js

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//page js
22
var loc = false, locip;
33
var noNewSegs = false;
4-
var isOn = false, nlA = false, isLv = false, isInfo = false, syncSend = false, syncTglRecv = true, isRgbw = false;
4+
var isOn = false, nlA = false, isLv = false, isInfo = false, isNodes = false, syncSend = false, syncTglRecv = true, isRgbw = false;
55
var whites = [0,0,0];
66
var expanded = [false];
77
var powered = [true];
@@ -463,6 +463,7 @@ function populateInfo(i)
463463
}
464464
}
465465
}
466+
466467
var vcn = "Kuuhaku";
467468
if (i.ver.startsWith("0.12.")) vcn = "Hikari";
468469
if (i.cn) vcn = i.cn;
@@ -566,6 +567,68 @@ function populateSegments(s)
566567
d.getElementById('rsbtn').style.display = (segCount > 1) ? "inline":"none";
567568
}
568569

570+
function btype(b){
571+
switch (b) {
572+
case 32: return "ESP32";
573+
case 82: return "ESP8266";
574+
}
575+
return "?";
576+
}
577+
function bname(o){
578+
if (o.name=="WLED") return o.ip;
579+
return o.name;
580+
}
581+
582+
function populateNodes(i,n)
583+
{
584+
var cn="";
585+
var urows="";
586+
var nnodes = 0;
587+
if (n.nodes) {
588+
n.nodes.sort((a,b) => (a.name).localeCompare(b.name));
589+
for (var x=0;x<n.nodes.length;x++) {
590+
var o = n.nodes[x];
591+
if (o.name) {
592+
var url = `<button class="btn btna-icon tab" onclick="location.assign('http://${o.ip}');">${bname(o)}</button>`;
593+
urows += inforow(url,`${btype(o.type)}<br><i>${o.vid==0?"N/A":o.vid}</i>`);
594+
nnodes++;
595+
}
596+
}
597+
}
598+
if (nnodes == 0) cn += `No other instances found.`;
599+
cn += `<table class="infot">
600+
${urows}
601+
${inforow("Current instance:",i.name)}
602+
</table>`;
603+
d.getElementById('kn').innerHTML = cn;
604+
}
605+
606+
function loadNodes()
607+
{
608+
var url = '/json/nodes';
609+
if (loc) {
610+
url = `http://${locip}/json/nodes`;
611+
}
612+
613+
fetch
614+
(url, {
615+
method: 'get'
616+
})
617+
.then(res => {
618+
if (!res.ok) {
619+
showToast('Could not load Node list!', true);
620+
}
621+
return res.json();
622+
})
623+
.then(json => {
624+
populateNodes(lastinfo, json);
625+
})
626+
.catch(function (error) {
627+
showToast(error, true);
628+
console.log(error);
629+
});
630+
}
631+
569632
function updateTrail(e, slidercol)
570633
{
571634
if (e==null) return;
@@ -869,12 +932,21 @@ function toggleLiveview() {
869932
}
870933

871934
function toggleInfo() {
935+
if (isNodes) toggleNodes();
872936
isInfo = !isInfo;
873937
if (isInfo) populateInfo(lastinfo);
874938
d.getElementById('info').style.transform = (isInfo) ? "translateY(0px)":"translateY(100%)";
875939
d.getElementById('buttonI').className = (isInfo) ? "active":"";
876940
}
877941

942+
function toggleNodes() {
943+
if (isInfo) toggleInfo();
944+
isNodes = !isNodes;
945+
d.getElementById('nodes').style.transform = (isNodes) ? "translateY(0px)":"translateY(100%)";
946+
d.getElementById('buttonNodes').className = (isNodes) ? "active":"";
947+
if (isNodes) loadNodes();
948+
}
949+
878950
function makeSeg() {
879951
var ns = 0;
880952
if (lowestUnused > 0) {

wled00/fcn_declare.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ void notify(byte callMode, bool followUp=false);
170170
void realtimeLock(uint32_t timeoutMs, byte md = REALTIME_MODE_GENERIC);
171171
void handleNotifications();
172172
void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w);
173+
void refreshNodeList();
174+
void sendSysInfoUDP();
173175

174176
//um_manager.cpp
175177
class Usermod {

0 commit comments

Comments
 (0)