Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
Fix displaying device name in frontend
Browse files Browse the repository at this point in the history
The device name was always "RGB WiFi Lamp" for my devices. Because
the name is available to the frontend with the settings websocket
message, this commit adds a small JS function that updates the
page title and logo area with the device name.
  • Loading branch information
LarsMichelsen committed Dec 30, 2019
1 parent d909e75 commit eea3c50
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Super_Simple_RGB_WiFi_Lamp/Web_Page.ino
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const char websiteSource[] PROGMEM =
" // console.log(\"Found State Message\")\n"
" handleStateMessage(jsonMessage.State)\n"
" }\n"
" if (\"Name\" in jsonMessage) {\n"
" // console.log(\"Found Name Message\")\n"
" handleNameMessage(jsonMessage.Name)\n"
" }\n"
" if (\"Fade Time\" in jsonMessage) {\n"
" // console.log(\"Found Fade Time Message\")\n"
" handleFadeTimeMessage(jsonMessage[\"Fade Time\"])\n"
Expand Down Expand Up @@ -124,6 +128,13 @@ const char websiteSource[] PROGMEM =
" }\n"
" }\n"
"\n"
" function handleNameMessage(name) {\n"
" if (typeof name === \"string\") {\n"
" $(document).attr(\"title\", name);\n"
" $(\"#HomeButton\").text(name);\n"
" }\n"
" }\n"
"\n"
" function handleFadeTimeMessage(jsonMessage) {\n"
" if (typeof jsonMessage === \"number\") {\n"
" $(\"#fadeTime\").val(jsonMessage)\n"
Expand Down
13 changes: 12 additions & 1 deletion Website/Website.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
// console.log("Found State Message")
handleStateMessage(jsonMessage.State)
}
if ("Name" in jsonMessage) {
// console.log("Found Name Message")
handleNameMessage(jsonMessage.Name)
}
if ("Fade Time" in jsonMessage) {
// console.log("Found Fade Time Message")
handleFadeTimeMessage(jsonMessage["Fade Time"])
Expand Down Expand Up @@ -122,6 +126,13 @@
}
}

function handleNameMessage(name) {
if (typeof name === "string") {
$(document).attr("title", name);
$("#HomeButton").text(name);
}
}

function handleFadeTimeMessage(jsonMessage) {
if (typeof jsonMessage === "number") {
$("#fadeTime").val(jsonMessage)
Expand Down Expand Up @@ -1554,4 +1565,4 @@ <h2>Wifi Configuration</h2>
</div>
</body>

</html>
</html>

0 comments on commit eea3c50

Please sign in to comment.