Skip to content

Commit

Permalink
Replace HTTP calls by UDP
Browse files Browse the repository at this point in the history
ndex.htm / css
- theme: add starbase/starleds (wip)

SysModWeb
- add serializeState and serializeInfo (WLED compatibility) - wip

UserModInstances:
- replace httpclient by udp - wip
- add macAddress in InstanceInfo - wip
- split instance type in WLED, StarBase, StarLeds and StarFork
- init dash vars: chMod StarBase json udp write
- handleNotifications: check for StarBase json udp read
- sendSysInfoUDP: header type depending on esp32 board type
- updateInstance: set macAddress (WIP)
  • Loading branch information
ewoudwijma committed May 1, 2024
1 parent 61a0a60 commit 3f8e67b
Show file tree
Hide file tree
Showing 8 changed files with 1,586 additions and 1,551 deletions.
161 changes: 80 additions & 81 deletions data/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -7,90 +7,89 @@
@Copyright © 2024 Github StarBase Commit Authors
@license GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
@license For non GPL-v3 usage, commercial licenses must be purchased. Contact [email protected]
*/
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta name="author" content="MoonModules ☾ and it's contributors">
<link rel="icon" href="https://ewowi.github.io/StarDocs/assets/images/ui/StarBase/favicon-16x16.png">
<!-- <link rel="icon" type="image/x-icon" href="favicon-16x16.png"> currently only works in chrome -->
<!-- <link rel="mask-icon" type="image/x-icon" href="favicon-16x16.png"> for safari tabs? -->
<!-- <link rel="shortcut icon" type="image/x-icon" href="favicon-16x16.png"> found in wled... -->
<link rel="stylesheet" href="index.css">
<script src="app.js"></script>
<script src="index.js"></script>
<title>StarBase💫 by MoonModules 🌔</title>

<!-- favicon in safari not working. see: -->
<!-- https://stackoverflow.com/questions/68885882/favicon-not-displaying-on-safari -->
<!-- test: rm /Users/ewoudwijma/Library/Safari/Favicon\ Cache also from trash bin -->

<!-- tbd: add max-age=86400 to imports -->

<!-- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules -->
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/[email protected]/build/three.module.js",
"three/addons/": "https://unpkg.com/[email protected]/examples/jsm/"
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta name="author" content="MoonModules and it's contributors">
<link rel="icon" href="https://ewowi.github.io/StarDocs/assets/images/ui/starbase/favicon-16x16.png">
<!-- <link rel="icon" type="image/x-icon" href="favicon-16x16.png"> currently only works in chrome -->
<!-- <link rel="mask-icon" type="image/x-icon" href="favicon-16x16.png"> for safari tabs? -->
<!-- <link rel="shortcut icon" type="image/x-icon" href="favicon-16x16.png"> found in wled... -->
<title>StarBase💫 by MoonModules 🌔</title>
<link rel="stylesheet" href="index.css">
<script src="app.js"></script>
<script src="index.js"></script>

<!-- favicon in safari not working. see: -->
<!-- https://stackoverflow.com/questions/68885882/favicon-not-displaying-on-safari -->
<!-- test: rm /Users/ewoudwijma/Library/Safari/Favicon\ Cache also from trash bin -->

<!-- tbd: add max-age=86400 to imports -->

<!-- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules -->
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/[email protected]/build/three.module.js",
"three/addons/": "https://unpkg.com/[email protected]/examples/jsm/"
}
}
}
</script>
</head>
<body onload="onLoad()">
<div class="module">
<hgroup>
<h1 style="float: left;">StarBase💫 by MoonModules 🌔</h1>
<a href="https://ewowi.github.io/StarDocs" style="float: right;"></a>
</hgroup>
<br>
<h2><div id="serverName"></div></h2>
<input type="button" value="App" id="vApp" onclick="setView(this)">
<input type="button" value="DashBoard" id="vDash" onclick="setView(this)">
<input type="button" value="User" id="vUser" onclick="setView(this)">
<input type="button" value="System" id="vSys" onclick="setView(this)">
<input type="button" value="All" id="vAll" onclick="setView(this)">
<input type="button" value="Setup" id="vSetup" onclick="setView(this)">
<span> | </span>
<input type="button" value="Save" id="bSave" onclick="saveModel(this)">
<span> | </span>
<label>Theme</label> <select name="theme-select" id="theme-select" onchange="setTheme(this)">
<option value="starbase">StarBase</option>
<option value="wled">WLED</option>
<option value="grayeen">Grayeen</option>
<option value="dev">Dev</option>
<option value="light">Light</option>
<option value="dark">DeathStar</option>
<option value="blue">Blue</option>
<option value="pink">Pink</option>
<option value="space">Space</option>
<option value="nyan">Nyan</option>
</select>
<!-- <div id="instPH"></div> -->
</div>
<div id="mdlContainer">
<div id="mdlColumn0" class = "mdlColumn">
</div>
<div id="mdlColumn1" class = "mdlColumn">
</script>
</head>
<body onload="onLoad()">
<div class="module">
<hgroup>
<h1 style="float: left;">StarBase💫 by MoonModules 🌔</h1>
<a href="https://ewowi.github.io/StarDocs" style="float: right;"></a>
</hgroup>
<br>
<h2><div id="serverName"></div></h2>
<input type="button" value="App" id="vApp" onclick="setView(this)">
<input type="button" value="DashBoard" id="vDash" onclick="setView(this)">
<input type="button" value="User" id="vUser" onclick="setView(this)">
<input type="button" value="System" id="vSys" onclick="setView(this)">
<input type="button" value="All" id="vAll" onclick="setView(this)">
<input type="button" value="Setup" id="vSetup" onclick="setView(this)">
<span> | </span>
<input type="button" value="Save" id="bSave" onclick="saveModel(this)">
<span> | </span>
<label>Theme</label> <select name="theme-select" id="theme-select" onchange="setTheme(this)">
<option value="starbase">StarBase</option>
<option value="wled">WLED</option>
<option value="grayeen">Grayeen</option>
<option value="dev">Dev</option>
<option value="light">Light</option>
<option value="dark">DeathStar</option>
<option value="blue">Blue</option>
<option value="pink">Pink</option>
<option value="space">Space</option>
<option value="nyan">Nyan</option>
</select>
<!-- <div id="instPH"></div> -->
</div>
<div id="mdlColumn2" class = "mdlColumn">
<div id="mdlContainer">
<div id="mdlColumn0" class = "mdlColumn">
</div>
<div id="mdlColumn1" class = "mdlColumn">
</div>
<div id="mdlColumn2" class = "mdlColumn">
</div>
<div id="mdlColumn3" class = "mdlColumn">
</div>
</div>
<div id="mdlColumn3" class = "mdlColumn">
<div id="connind">&#9790;</div>
<div id="modalView" class="modal"></div>
<p style="color:grey;"> © 2024 MoonModules ☾ - Licensed under GPL-v3</p>
<div id="canvasMenu" style="position:absolute;display:none"> <!--;background-color:#b60f62-->
<p><button id="canvasButton1"></button></p>
<p><button id="canvasButton2"></button></p>
<p><button id="canvasButton3"></button></p>
<span id="canvasData" hidden="true"></span>
</div>
</div>
<div id="connind">&#9790;</div>
<div id="modalView" class="modal"></div>
<p style="color:grey;"> © 2024 MoonModules ☾ - Licensed under GPL-v3</p>
<div id="canvasMenu" style="position:absolute;display:none"> <!--;background-color:#b60f62-->
<p><button id="canvasButton1"></button></p>
<p><button id="canvasButton2"></button></p>
<p><button id="canvasButton3"></button></p>
<span id="canvasData" hidden="true"></span>
</div>
</body>
</html>
</body>
</html>
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ build_flags =
${STARBASE_USERMOD_E131.build_flags}
; ${STARBASE_USERMOD_HA.build_flags}
-DAPP=StarBase
-DVERSION=24042614 ; Date and time (GMT!)
-DVERSION=24050109 ; Date and time (GMT!)
-DPIOENV=$PIOENV
lib_deps =
${StarBase.lib_deps}
Expand Down
1 change: 1 addition & 0 deletions src/Sys/SysModPins.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class SysModPins:public SysModule {
#elif defined(ESP32)
if (pinNr > 5 && pinNr < 12) pinType = pinTypeReserved; else
#else //???
prf("dev unknown board\n");
pinType = pinTypeInvalid; return pinType;
#endif

Expand Down
6 changes: 4 additions & 2 deletions src/Sys/SysModUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,10 @@ class SysModUI: public SysModule {
// if (!var["value"].isNull() &&
if (funType != f_ValueFun) {
ppf("%sFun %s", funType==f_ValueFun?"val":funType==f_UIFun?"ui":funType==f_ChangeFun?"ch":funType==f_AddRow?"add":funType==f_DelRow?"del":"other", mdl->varID(var));
if (rowNr != UINT8_MAX) ppf("[%d]", rowNr);
ppf(" (%s)\n", var["value"].as<String>().c_str());
if (rowNr != UINT8_MAX)
ppf("[%d] (%s)\n", rowNr, var["value"][rowNr].as<String>().c_str());
else
ppf(" (%s)\n", var["value"].as<String>().c_str());
}
}
}
Expand Down
64 changes: 43 additions & 21 deletions src/Sys/SysModWeb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,39 @@ void SysModWeb::sendResponseObject(WebClient * client) {
}
}

void SysModWeb::serializeState(JsonObject root) {
const char* jsonState;// = "{\"transition\":7,\"ps\":9,\"pl\":-1,\"nl\":{\"on\":false,\"dur\":60,\"mode\":1,\"tbri\":0,\"rem\":-1},\"udpn\":{\"send\":false,\"recv\":true},\"lor\":0,\"mainseg\":0,\"seg\":[{\"id\":0,\"start\":0,\"stop\":144,\"len\":144,\"grp\":1,\"spc\":0,\"of\":0,\"on\":true,\"frz\":false,\"bri\":255,\"cct\":127,\"col\":[[182,15,98,0],[0,0,0,0],[255,224,160,0]],\"fx\":0,\"sx\":128,\"ix\":128,\"pal\":11,\"c1\":8,\"c2\":20,\"c3\":31,\"sel\":true,\"rev\":false,\"mi\":false,\"o1\":false,\"o2\":false,\"o3\":false,\"ssim\":0,\"mp12\":1}]}";
jsonState = "{\"on\":true,\"bri\":60,\"transition\":7,\"ps\":1,\"pl\":-1,\"AudioReactive\":{\"on\":true},\"nl\":{\"on\":false,\"dur\":60,\"mode\":1,\"tbri\":0,\"rem\":-1},\"udpn\":{\"send\":false,\"recv\":true,\"sgrp\":1,\"rgrp\":1},\"lor\":0,\"mainseg\":0,\"seg\":[{\"id\":0,\"start\":0,\"stop\":16,\"startY\":0,\"stopY\":16,\"len\":16,\"grp\":1,\"spc\":0,\"of\":0,\"on\":true,\"frz\":false,\"bri\":255,\"cct\":127,\"set\":0,\"col\":[[255,160,0],[0,0,0],[0,255,200]],\"fx\":139,\"sx\":240,\"ix\":236,\"pal\":11,\"c1\":255,\"c2\":64,\"c3\":16,\"sel\":true,\"rev\":false,\"mi\":false,\"rY\":false,\"mY\":false,\"tp\":false,\"o1\":false,\"o2\":true,\"o3\":false,\"si\":0,\"m12\":0}],\"ledmap\":0}";
JsonDocument docState;
deserializeJson(root, jsonState);

//tbd: //StarBase has no idea about leds so this should be led independent
root["bri"] = mdl->getValue("bri");
root["on"] = mdl->getValue("on").as<bool>();

}
void SysModWeb::serializeInfo(JsonObject root) {
const char * jsonInfo = "{\"ver\":\"0.14.1-b30.36\",\"rel\":\"abc_wled_controller_v43_M\",\"vid\":2402252,\"leds\":{\"count\":1024,\"countP\":1024,\"pwr\":1124,\"fps\":32,\"maxpwr\":9500,\"maxseg\":32,\"matrix\":{\"w\":32,\"h\":32},\"seglc\":[1],\"lc\":1,\"rgbw\":false,\"wv\":0,\"cct\":0},\"str\":false,\"name\":\"WLED-Wladi\",\"udpport\":21324,\"live\":false,\"liveseg\":-1,\"lm\":\"\",\"lip\":\"\",\"ws\":2,\"fxcount\":195,\"palcount\":75,\"cpalcount\":0,\"maps\":[{\"id\":0}],\"outputs\":[1024],\"wifi\":{\"bssid\":\"\",\"rssi\":0,\"signal\":100,\"channel\":1},\"fs\":{\"u\":20,\"t\":983,\"pmt\":0},\"ndc\":16,\"arch\":\"esp32\",\"core\":\"v3.3.6-16-gcc5440f6a2\",\"lwip\":0,\"totalheap\":294784,\"getflash\":4194304,\"freeheap\":115988,\"freestack\":6668,\"minfreeheap\":99404,\"e32core0code\":12,\"e32core0text\":\"SW restart\",\"e32core1code\":12,\"e32core1text\":\"SW restart\",\"e32code\":4,\"e32text\":\"SW error (panic or exception)\",\"e32model\":\"ESP32-D0WDQ5 rev.3\",\"e32cores\":2,\"e32speed\":240,\"e32flash\":4,\"e32flashspeed\":80,\"e32flashmode\":2,\"e32flashtext\":\" (DIO)\",\"uptime\":167796,\"opt\":79,\"brand\":\"WLED\",\"product\":\"MoonModules\",\"mac\":\"08b61f6fa800\",\"ip\":\"192.168.8.171\"}";
JsonDocument docInfo;

deserializeJson(root, jsonInfo);

root["name"] = mdl->getValue("instanceName");
// docInfo["arch"] = "esp32"; //platformName

// docInfo["rel"] = _INIT(TOSTRING(APP));
// docInfo["ver"] = "0.0.1";
// docInfo["vid"] = 2025121212; //WLED-native needs int otherwise status offline!!!
// docInfo["leds"]["count"] = 999; //StarBase has no idea about leds
// docInfo["leds"]["countP"] = 998; //StarBase has no idea about leds
// docInfo["leds"]["fps"] = mdl->getValue("fps"); //tbd: should be realFps but is ro var
// docInfo["wifi"]["rssi"] = WiFi.RSSI();// mdl->getValue("rssi"); (ro)

root["mac"] = JsonString(mdns->escapedMac.c_str(), JsonString::Copied);
root["ip"] = JsonString(WiFi.localIP().toString().c_str(), JsonString::Copied);
// print->printJson("serveJson", root);
}

void SysModWeb::serveJson(WebRequest *request) {

AsyncJsonResponse * response;
Expand All @@ -675,28 +708,17 @@ void SysModWeb::serveJson(WebRequest *request) {
JsonObject root = response->getRoot();

//temporary set all WLED variables (as otherwise WLED-native does not show the instance): tbd: clean up (state still needed, info not)
const char* jsonState = "{\"transition\":7,\"ps\":9,\"pl\":-1,\"nl\":{\"on\":false,\"dur\":60,\"mode\":1,\"tbri\":0,\"rem\":-1},\"udpn\":{\"send\":false,\"recv\":true},\"lor\":0,\"mainseg\":0,\"seg\":[{\"id\":0,\"start\":0,\"stop\":144,\"len\":144,\"grp\":1,\"spc\":0,\"of\":0,\"on\":true,\"frz\":false,\"bri\":255,\"cct\":127,\"col\":[[182,15,98,0],[0,0,0,0],[255,224,160,0]],\"fx\":0,\"sx\":128,\"ix\":128,\"pal\":11,\"c1\":8,\"c2\":20,\"c3\":31,\"sel\":true,\"rev\":false,\"mi\":false,\"o1\":false,\"o2\":false,\"o3\":false,\"ssim\":0,\"mp12\":1}]}";
JsonDocument docState;
deserializeJson(docState, jsonState);
root["state"] = docState;

//tbd: //StarBase has no idea about leds so this should be led independent
root["state"]["bri"] = mdl->getValue("bri");
root["state"]["on"] = mdl->getValue("on").as<bool>();
root["info"]["name"] = mdl->getValue("instanceName");
root["info"]["arch"] = "esp32"; //platformName

root["info"]["rel"] = _INIT(TOSTRING(APP));
root["info"]["ver"] = _INIT(TOSTRING(VERSION));
root["info"]["vid"] = VERSION; //WLED-native needs int otherwise status offline!!!
root["info"]["leds"]["count"] = 999; //StarBase has no idea about leds
root["info"]["leds"]["countP"] = 998; //StarBase has no idea about leds
root["info"]["leds"]["fps"] = mdl->getValue("fps"); //tbd: should be realFps but is ro var
root["info"]["wifi"]["rssi"] = WiFi.RSSI();// mdl->getValue("rssi"); (ro)

root["info"]["mac"] = JsonString(mdns->escapedMac.c_str(), JsonString::Copied);
root["info"]["ip"] = JsonString(WiFi.localIP().toString().c_str(), JsonString::Copied);
// print->printJson("serveJson", root);
if (request->url().indexOf("state") > 0) {
serializeState(root);
}
else if (request->url().indexOf("info") > 0) {
serializeInfo(root);
}
else {
serializeState(root["state"].to<JsonObject>());
serializeInfo(root["info"].to<JsonObject>());
}
}

response->setLength();
Expand Down
2 changes: 2 additions & 0 deletions src/Sys/SysModWeb.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class SysModWeb:public SysModule {
//add an url to the webserver to listen to
void serveIndex(WebRequest *request);
//mdl and WLED style state and info
void serializeState(JsonObject root);
void serializeInfo(JsonObject root);
void serveJson(WebRequest *request);


Expand Down
Loading

0 comments on commit 3f8e67b

Please sign in to comment.