Hi all.
I am building an AC remote controller with a Nano ESP32, inspired by the examples found on this tutorial.
It should gather temperature and RH data and show it on a simple web page, with a couple of controls to interact with my AC unit.
I'm currently stumped because I stored the HTML code for the web page in a string:
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<style>
html {
font-family: Arial;
display: inline-block;
margin: 0px auto;
text-align: center;
}
h2 { font-size: 3.0rem; }
p { font-size: 3.0rem; }
.units { font-size: 1.2rem; }
.dht-labels{
font-size: 1.5rem;
vertical-align:middle;
padding-bottom: 15px;
}
.slider { -webkit-appearance: none; margin: 14px; width: 360px; height: 25px; background: #FFD65C;
outline: none; -webkit-transition: .2s; transition: opacity .2s;}
.slider::-webkit-slider-thumb {-webkit-appearance: none; appearance: none; width: 35px; height: 35px; background: #003249; cursor: pointer;}
.slider::-moz-range-thumb { width: 35px; height: 35px; background: #003249; cursor: pointer; }
</style>
</head>
<body>
<h2>ESP32 AC Control</h2>
<p>
<i class="fas fa-thermometer-half" style="color:#059e8a;"></i>
<span class="dht-labels">Temperature</span>
<span id="temperature">%TEMPERATURE%</span>
<sup class="units">°C</sup>
</p>
<p>
<i class="fas fa-tint" style="color:#00add6;"></i>
<span class="dht-labels">Humidity</span>
<span id="humidity">%HUMIDITY%</span>
<sup class="units">%</sup>
</p>
<p><span id="textSliderValue">Target: %SETTEMP%</span></p>
<p><input type="range" onchange="updateTempSlider(this)" id="tempSlider" min="18" max="28" value="%SETTEMP%" step="1" class="slider"></p>
<p>
<select name="Mode" id="setMode" onchange="updateCommand(this)")>
<option value="0">Spento</option>
<option value="1">Riscaldamento</option>
<option value="2">Raffreddamento</option>
<option value="3">Deumidificatore</option>
</select>
<select name="Fan" id="setFan" onchange="updateCommand(this)")>
<option value="0">Auto</option>
<option value="1">Silenzioso</option>
<option value="2">1/4</option>
<option value="3">2/4</option>
<option value="4">3/4</option>
<option value="5">4/4</option>
</select>
</p>
</body>
<script>
function updateCommand(element) {
var xhr = new XMLHttpRequest();
xhr.open("GET", "/sendCommand?setMode="+document.getElementById("setMode").value +"&setTemp="+document.getElementById("tempSlider").value + "&setFan="+document.getElementById("setFan").value, true);
xhr.send();
}
function updateTempSlider(element) {
var sliderValue = document.getElementById("tempSlider").value;
document.getElementById("textSliderValue").innerHTML = "Target: " + sliderValue;
if (document.getElementById("setMode").value="0") {
if (sliderValue>24) {
document.getElementById("setMode").value="2";
}
else {
document.getElementById("setMode").value="1" ;
}
}
updateCommand();
}
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("temperature").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/temperature", true);
xhttp.send();
}, 10000 ) ;
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("humidity").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/humidity", true);
xhttp.send();
}, 10000 ) ;
</script>
</html>)rawliteral";
but the js part doesn't seem to work; inspecting the web page with whe browser's debugger I found a couple of weird lines that should not be there, right after the \<script\> tag:
(nothing weird before this line)
<script>
#line 110 "/home/max/.arduino15/RemoteSketchbook/ArduinoCloud/111621719352800137854/Sensore_TLC/Sensore_TLC.ino"
function updateTempSlider(element);
#line 105 "/home/max/.arduino15/RemoteSketchbook/ArduinoCloud/111621719352800137854/Sensore_TLC/Sensore_TLC.ino"
function updateCommand(element) {
(nothing weird after)
What happened?
How do I get rid of these two lines that crash my web page?