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

Dependents:   heating

Committer:
andrewboyson
Date:
Sun May 16 19:00:29 2021 +0000
Revision:
3:d33dda272a7f
Parent:
2:d3fe00659967
Stopped the debug messages in the log (chnaged DEBUG from true to false)

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