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: [https://lastminuteengineers.com/multiple-ds18b20-esp8266-nodemcu-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 +="xhttp.open(\"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";
or
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!