From c79d77aba9e9cd5a71caa1aa066c64e93cd9fd19 Mon Sep 17 00:00:00 2001 From: Maksim Kudlaev Date: Sat, 23 Jan 2016 18:10:07 +0600 Subject: [PATCH] Add Ajax on web "Control Pins", add control 2 Led Strip --- esp_sensor/esp_sensor.ino | 387 ++++++++++++++++++++++++++++++++++---- 1 file changed, 348 insertions(+), 39 deletions(-) diff --git a/esp_sensor/esp_sensor.ino b/esp_sensor/esp_sensor.ino index 8212055..606fdb5 100644 --- a/esp_sensor/esp_sensor.ino +++ b/esp_sensor/esp_sensor.ino @@ -47,6 +47,7 @@ const char *ver = "1.06"; const char *lux = "Lux"; const char *lightType = "LightType"; +const char *lightType2 = "LightType2"; const char *temperature = "Temp"; const char *humidity = "Humidity"; const char *pressure = "Pressure"; @@ -71,6 +72,7 @@ struct ConfDeviceStruct { char subscribe_topic[32]; char commandPub_topic[32]; uint8_t light_pin; + uint8_t light_pin2; uint8_t motion_pin; uint8_t dht_pin; unsigned long publish_delay; @@ -91,9 +93,10 @@ struct ConfDeviceStruct { "/stateSub/", "/statePub/", "/commandPub/", + 13, 12, + 2, 14, - 13, 10000, 60000, 10000, @@ -115,6 +118,9 @@ struct StringDataStruct { String freeMemoryString; String lightState; String lightOffTimerStting; + String lightState2; + String lightOffTimerStting2; + } StringData = { "None", @@ -126,6 +132,8 @@ struct StringDataStruct { "None", "None", "AUTO", + "5", + "AUTO", "5" }; @@ -145,6 +153,8 @@ unsigned long motionTimer = 4000; unsigned long rebootTimer = 6000; unsigned long subscribeTimer = ConfDevice.subscribe_delay - 5000; unsigned long lightOffTimer = 0; +unsigned long lightOffTimer2 = 0; + boolean run = false; @@ -258,6 +268,94 @@ function handleServerResponse(){\ if(xmlHttp.readyState==4 && xmlHttp.status==200){\ xmlResponse=xmlHttp.responseXML;"; + +const char javaScriptPinControlP[] PROGMEM = +"
\ +
\ +"; + + +const char div1P[] PROGMEM = +"

Control Pins

\ +\ +\ + \ + \ + \ + \ + \ + \ + \ + \ + \ +

Pins

Status

Mode

Timer

Led Strip 1

Control Pins

\ +"

Control Pins

\ \ \ -\ +")); + + + data+=String(F("")); + + data+=String(F("

Pins

Status

Mode

Led Strip

Led Strip 1

")); + + if (pinState == true) { data+=String(F("ON")); } else { data+=String(F("OFF")); } + + data+=String(F("

")); + + data+=StringData.lightState; + + data+=String(F("

")); + + data+=String(timeOff); + + data+=String(F("

Led Strip 2

")); + + if (pinState2 == true) { data+=String(F("ON")); } else { data+=String(F("OFF")); } + + data+=String(F("

")); + + data+=StringData.lightState2; + + data+=String(F("

")); + + data+=String(timeOff2); + + data+=String(F("

")); - StringData.lightState = "AUTO"; - LightControl(); - MqttPubLightState(); - String data = PinControlView(); server.send ( 200, "text/html", data); }); -} + server.on("/control", handleControl); +} + /////////////////////////////////// WEB PAGES End ////////////////////////////////////////////// @@ -1712,6 +2020,7 @@ void setup() { } pinMode(ConfDevice.light_pin, OUTPUT); + pinMode(ConfDevice.light_pin2, OUTPUT); pinMode(ConfDevice.motion_pin, INPUT); // set pin to input @@ -1762,7 +2071,7 @@ void setup() { rootWebPage(); web_espConf(); web_mqttConf(); - web_pinControl(); + web_Control(); server.on("/xml",handleXML); // start Web Server