ESP-12 Spa pool monitor

My first post, apologies for any mistakes!
I am using an ESP-12 set up as a web server in Station mode with two DS18B20'S and an LDR attached. All are verified working as they should.
I have been following this tutorial: []
Sensor data is sent to a web page but I am trying to use an LDR (light dependent resistor) to indicate that the spa pump light is on. The ADC values are updated on the web page.

I would like to receive the ADC values and test to see if the reading is greater than 500. If true I would like to display "Pump motor ON" else "Pump motor OFF". I cannot figure out where to put my function to test the ADC values. Any help gratefully accepted!

The page is displayed using the
String SendHTML(float tempSensor1,float tempSensor2,float tempSensor3, int ldr_value)
function and the following script is used to update the data.

ptr +="<script>\n";
ptr +="setInterval(loadDoc,1000);\n";
ptr +="function loadDoc() {\n";
ptr +="var xhttp = new XMLHttpRequest();\n";
ptr +="xhttp.onreadystatechange = function() {\n";
ptr +="if (this.readyState == 4 && this.status == 200) {\n";
ptr +="document.body.innerHTML =this.responseText}\n";
ptr +="};\n";
ptr +="\"GET\", \"/\", true);\n";
ptr +="xhttp.send();\n";
ptr +="}\n";
ptr +="</script>\n";

I've tried adding a second function within the

  ptr +="function test(){\n"
  ptr +="if(ldr_value<500){motor_state=\"ON\";}\n";
  ptr +="if{ldr_value>500){motor_state=\"OFF\"}};\n";


  ptr +="function test(){\n"
  ptr +="if(ldr_value<500){\;"
  ptr +="motor_state=\"ON\";}\n";
  ptr +="else{motor_state=\"OFF\"}};\n";

and I've tried adding the function as a second "script"...
The "motor state" ON is displayed but never updated to "OFF".
Where should the function go?
I'm I not writing it correctly?

Thanks in advance for any help!

Don't try to check the LDR in your HTML. Check it in the Arduino code and use the result to decide whether to add on or off the the HTML String you're building.

Thanks for your reply. Initially I thought that checking the LDR in arduino code would be simple. That was until I tried to parse the resultant text string to the HTML. I then got some weird compiler error about String conversion.
I've tried it again and it works! Thank you so much for your suggestion!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.