Add PWM controlled by web
This commit is contained in:
parent
0ccf653cc6
commit
997f63b917
@ -11,4 +11,5 @@ int MqttDryPublish(int dry);
|
||||
int MqttIPPublish(const String &ip);
|
||||
void MqttCheckSubscription();
|
||||
void MqttChangeGpioValue(int gpio, int value);
|
||||
void MqttChangePWMValue(int gpio, int value);
|
||||
bool MqttIsConfigured();
|
||||
|
@ -1,6 +1,8 @@
|
||||
const int gpioWebConf[] = CONFIG_WEB_CONTROLLED_GPIO;
|
||||
const int pwmWebConf[] = CONFIG_CONTROLLED_PWM;
|
||||
|
||||
String gpioControlHTML = "";
|
||||
String pwmControlHTML = "";
|
||||
|
||||
void WebHandleRoot() {
|
||||
|
||||
@ -20,7 +22,7 @@ void WebHandleRoot() {
|
||||
#ifdef CONFIG_ENABLE_DRY_SENSOR
|
||||
"Dryness " + String((dryness*100)/1024) + "%<br/>"
|
||||
#endif
|
||||
"</fieldset>" + gpioControlHTML + "<fieldset>"
|
||||
"</fieldset>" + gpioControlHTML + pwmControlHTML + "<fieldset>"
|
||||
"<legend>Settings</legend>"
|
||||
"<a href=\"/setup\">Enter Setup</a><br/>"
|
||||
"<a href=\"/otamode\">Put device in OTA mode</a><br/>"
|
||||
@ -120,6 +122,16 @@ void WebHandleGpio() {
|
||||
server.send(200, "text/html", "<h1>GPIO" + server.arg("gpio") + " changed to " + server.arg("value") + "</h1>");
|
||||
}
|
||||
|
||||
void WebHandlePWM() {
|
||||
if (!server.hasArg("gpio") || !server.hasArg("value")) {
|
||||
server.send(500, "text/plain", "Bad arguments\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
MqttChangePWMValue(server.arg("gpio").toInt(), server.arg("value").toInt());
|
||||
server.send(200, "text/html", "<h1>PWM" + server.arg("gpio") + " changed to " + server.arg("value") + "</h1>");
|
||||
}
|
||||
|
||||
boolean WebSetIp(IPAddress &addr, const char *id, const char *error) {
|
||||
if (server.arg(id) != "" && !addr.fromString(server.arg(id).c_str())) {
|
||||
WebSendError(error);
|
||||
@ -247,13 +259,35 @@ void WebBuildGpioControl(){
|
||||
}
|
||||
}
|
||||
|
||||
void WebBuildPwmControl(){
|
||||
if (NB_ELEMENTS(pwmWebConf) > 0){
|
||||
pwmControlHTML += "<fieldset>"
|
||||
"<legend>PWM</legend>";
|
||||
for (uint i = 0 ; i < NB_ELEMENTS(pwmWebConf) ; i++) {
|
||||
pwmControlHTML += "PWM " + String(pwmWebConf[i]) + "<br/>";
|
||||
pwmControlHTML += "<input type=\"range\" min=\"0\" max=\"1023\""
|
||||
"style=\"background:#eee\""
|
||||
"onChange=\"setPWM(this.value," + String(pwmWebConf[i]) + ")\" />";
|
||||
}
|
||||
pwmControlHTML += "<script type=\"text/javascript\">"
|
||||
"function setPWM(newValue, gpio){"
|
||||
" var xmlHttp = new XMLHttpRequest();"
|
||||
" xmlHttp.open( \"GET\", \"/pwm?gpio=\"+ gpio + \"&value=\" + newValue, true );" // false for synchronous request
|
||||
" xmlHttp.send( null );}"
|
||||
"</script>";
|
||||
pwmControlHTML += "</fieldset>";
|
||||
}
|
||||
}
|
||||
|
||||
void WebSetupServer(int ) {
|
||||
WebBuildGpioControl();
|
||||
WebBuildPwmControl();
|
||||
|
||||
server.on("/", WebHandleRoot);
|
||||
server.on("/setup", WebHandleSetup);
|
||||
server.on("/save", WebHandleSave);
|
||||
server.on("/gpio", WebHandleGpio);
|
||||
server.on("/pwm", WebHandlePWM);
|
||||
server.on("/otamode", WebHandleOTA);
|
||||
server.on("/reboot", WebHandleReboot);
|
||||
server.on("/wifiStatus", WebHandleWifiStatus);
|
||||
|
Loading…
Reference in New Issue
Block a user