Allows my home wiz lights to be timed on and off according to a schedule.

Dependents:   heating

Committer:
andrewboyson
Date:
Thu May 13 19:09:24 2021 +0000
Revision:
2:d3fe00659967
Parent:
1:a6b120e4031a
Child:
3:d33dda272a7f
Tidied the web display

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 0:9af80a39adcc 1 #include <stdio.h>
andrewboyson 0:9af80a39adcc 2
andrewboyson 0:9af80a39adcc 3 #include "http.h"
andrewboyson 0:9af80a39adcc 4 #include "web-nav-this.h"
andrewboyson 0:9af80a39adcc 5 #include "web-add.h"
andrewboyson 0:9af80a39adcc 6
andrewboyson 1:a6b120e4031a 7 static void addButton(char* name, int index, char* value, char* label)
andrewboyson 1:a6b120e4031a 8 {
andrewboyson 1:a6b120e4031a 9 //HttpAddF("<button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"%s%d\", \"%s\")'>%s</button>\r\n", name, index, value, label);
andrewboyson 1:a6b120e4031a 10 HttpAddF("<button style='width:0.8em; margin:0; margin-left:0.1em; padding:0;' onclick='AjaxSendNameValue(\"%s%d\", \"%s\")'>%s</button>\r\n", name, index, value, label);
andrewboyson 1:a6b120e4031a 11 }
andrewboyson 1:a6b120e4031a 12
andrewboyson 0:9af80a39adcc 13 static void addLight(int index)
andrewboyson 0:9af80a39adcc 14 {
andrewboyson 1:a6b120e4031a 15 HttpAddText("<div style='display:flex; align-items:center;'>\r\n");
andrewboyson 1:a6b120e4031a 16 HttpAddF (" <input type='text' style='width:6.5em;' id='ajax-name-%d' onchange='AjaxSendNameValue(\"lnam%d\", this.value)'>\r\n", index, index);
andrewboyson 1:a6b120e4031a 17 HttpAddF (" <input type='text' style='width:4.5em;' id='ajax-room-%d' onchange='AjaxSendNameValue(\"lroo%d\", this.value)'>\r\n", index, index);
andrewboyson 1:a6b120e4031a 18 HttpAddF (" <div style='margin-left:0.1em;' class='led' id='ajax-led-%d' dir='ltr'></div>\r\n", index);
andrewboyson 1:a6b120e4031a 19 addButton("lswi", index, "1", "1");
andrewboyson 1:a6b120e4031a 20 addButton("lswi", index, "0", "0");
andrewboyson 1:a6b120e4031a 21 //HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"lswi%d\", \"1\")'>1</button>\r\n", index);
andrewboyson 1:a6b120e4031a 22 //HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"lswi%d\", \"0\")'>0</button>\r\n", index);
andrewboyson 1:a6b120e4031a 23 HttpAddF (" <code style='width:5em; text-align:right;' id='ajax-mac-%d'></code>\r\n", index);
andrewboyson 1:a6b120e4031a 24 HttpAddF (" <div style='width:2em; text-align:right;' id='ajax-age-%d'></div>\r\n", index);
andrewboyson 1:a6b120e4031a 25 HttpAddF (" <div style='width:2em; text-align:right;' id='ajax-signal-%d'></div>\r\n", index);
andrewboyson 1:a6b120e4031a 26 HttpAddF (" <div style='width:2em; text-align:right;' id='ajax-dimmer-%d'></div>\r\n", index);
andrewboyson 1:a6b120e4031a 27 //HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"ldel%d\", \"1\")'>x</button>\r\n", index);
andrewboyson 1:a6b120e4031a 28 //HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"lmov%d\", \"up\")'>^</button>\r\n", index);
andrewboyson 1:a6b120e4031a 29 //HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"lmov%d\", \"down\")'>v</button>\r\n", index);
andrewboyson 1:a6b120e4031a 30 addButton("ldel", index, "1", "x");
andrewboyson 1:a6b120e4031a 31 addButton("lmov", index, "up", "^");
andrewboyson 1:a6b120e4031a 32 addButton("lmov", index, "down", "v");
andrewboyson 0:9af80a39adcc 33 HttpAddText("</div>\r\n");
andrewboyson 0:9af80a39adcc 34 }
andrewboyson 0:9af80a39adcc 35
andrewboyson 0:9af80a39adcc 36 static void addSchedule(int index)
andrewboyson 0:9af80a39adcc 37 {
andrewboyson 2:d3fe00659967 38 HttpAddText("<div style='display:flex; align-items:center;'>\r\n");
andrewboyson 2:d3fe00659967 39 HttpAddF (" <input type='text' style='width:4.5em;' id='sched-name-%d' onchange='AjaxSendNameValue(\"snam%d\", this.value)'>\r\n", index, index);
andrewboyson 2:d3fe00659967 40 HttpAddF (" <input type='text' style='width:3.5em;' id='sched-on-%d' onchange='AjaxSendNameValue(\"s-on%d\", this.value)'>\r\n", index, index);
andrewboyson 2:d3fe00659967 41 HttpAddF (" <input type='text' style='width:3.5em;' id='sched-off-%d' onchange='AjaxSendNameValue(\"soff%d\", this.value)'>\r\n", index, index);
andrewboyson 2:d3fe00659967 42 HttpAddF (" <div style='width:3.5em; text-align:right;' id='act-on-%d'></div>\r\n", index);
andrewboyson 2:d3fe00659967 43 HttpAddF (" <div style='width:3.5em; text-align:right;' id='act-off-%d'></div>\r\n", index);
andrewboyson 2:d3fe00659967 44 HttpAddF (" <div style='width:3.5em; text-align:right;' id='duration-%d'></div>\r\n", index);
andrewboyson 2:d3fe00659967 45 //HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"sdel%d\", \"1\")'>x</button>\r\n", index);
andrewboyson 2:d3fe00659967 46 //HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"smov%d\", \"up\")'>^</button>\r\n", index);
andrewboyson 2:d3fe00659967 47 //HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"smov%d\", \"down\")'>v</button>\r\n", index);
andrewboyson 2:d3fe00659967 48 //HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"sswi%d\", \"1\")'>1</button>\r\n", index);
andrewboyson 2:d3fe00659967 49 //HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"sswi%d\", \"0\")'>0</button>\r\n", index);
andrewboyson 2:d3fe00659967 50 addButton("sswi", index, "1", "1");
andrewboyson 2:d3fe00659967 51 addButton("sswi", index, "0", "0");
andrewboyson 2:d3fe00659967 52 addButton("sdel", index, "1", "x");
andrewboyson 2:d3fe00659967 53 addButton("smov", index, "up", "^");
andrewboyson 2:d3fe00659967 54 addButton("smov", index, "down", "v");
andrewboyson 0:9af80a39adcc 55 HttpAddText("</div>\r\n");
andrewboyson 0:9af80a39adcc 56 }
andrewboyson 0:9af80a39adcc 57
andrewboyson 0:9af80a39adcc 58 void WebWizHtml()
andrewboyson 0:9af80a39adcc 59 {
andrewboyson 0:9af80a39adcc 60 HttpOk("text/html; charset=UTF-8", "no-cache", NULL, NULL);
andrewboyson 0:9af80a39adcc 61 WebAddHeader("Wiz", "settings.css", "wiz.js");
andrewboyson 0:9af80a39adcc 62 WebAddNav(WIZ_PAGE);
andrewboyson 0:9af80a39adcc 63 WebAddH1("Wiz");
andrewboyson 0:9af80a39adcc 64
andrewboyson 0:9af80a39adcc 65 WebAddH2("Trace");
andrewboyson 0:9af80a39adcc 66 WebAddAjaxInputToggle("Wiz trace", "ajax-wiz-trace", "wiztrace");
andrewboyson 0:9af80a39adcc 67
andrewboyson 0:9af80a39adcc 68 WebAddH2("Lights");
andrewboyson 0:9af80a39adcc 69 for (int i = 0; i < 15; i++) addLight(i);
andrewboyson 0:9af80a39adcc 70 WebAddAjaxButton("Switch all on" , "turn-all-on" );
andrewboyson 0:9af80a39adcc 71 WebAddAjaxButton("Switch all off", "turn-all-off");
andrewboyson 0:9af80a39adcc 72
andrewboyson 0:9af80a39adcc 73 WebAddH2("Local times");
andrewboyson 0:9af80a39adcc 74 WebAddAjaxLabelled("Local (L)", "ajax-now-local");
andrewboyson 0:9af80a39adcc 75 WebAddAjaxLabelled("Sunrise (R)", "ajax-sun-rise" );
andrewboyson 0:9af80a39adcc 76 WebAddAjaxLabelled("Sunset (S)", "ajax-sun-set" );
andrewboyson 0:9af80a39adcc 77
andrewboyson 0:9af80a39adcc 78 WebAddH2("Schedule");
andrewboyson 0:9af80a39adcc 79 for (int i = 0; i < 5; i++) addSchedule(i);
andrewboyson 0:9af80a39adcc 80
andrewboyson 0:9af80a39adcc 81 WebAddEnd();
andrewboyson 0:9af80a39adcc 82 }