Files
iot/views/accontrol.ejs
d-popov d8a37e4b44 source now in separate modules;
Implemented MQTT coms.
Using Tasmota for ESP8266;
IR working reliably
2020-05-02 11:45:35 +03:00

86 lines
2.9 KiB
Plaintext

<h2>AC Control for <% if (model.user) {model.user.username; } %></h2>
<h4 id="current">Retrieving current conditions...</h4>
<!-- class="form-inline" -->
<form id="accontrol" action="/n/accontrol" method="POST">
<div class="form-group ">
<input type='checkbox' name='power' <%= model.data.power|true ? "checked" : "" %> data-toggle='toggle'
data-style='android' data-on='ON' data-off='Off' />
</div>
<div class="form-group">
<input type='checkbox' name='heat' <%= model.data.heat|true ? "checked" : "" %> data-toggle='toggle' data-on='Heat'
data-off='Cool' data-onstyle='warning' data-offstyle='info' />
</div>
<div class="form-group">
<input type='number' name='temp' value='<%= model.data.temp|22 %>' min='16' max='32' step='0.5' />
</div>
<div class="form-group">
<input type='checkbox' name='econo'<%= model.data.econo ? "checked" : "" %> data-toggle='toggle' data-style='android' data-on='Eco' data-off='Normal' data-onstyle='info' data-offstyle='warning'/>
</div>
<div class="form-group">
<label></label>
<input type='checkbox' name='swing'<%= model.data.swing ? "checked" : "" %> data-toggle='toggle' data-style='android' data-on='Swing' data-off='No Swing' data-onstyle='info' data-offstyle='warning'/>
</div>
<div class="form-group">
<input id='set' type='submit' class='button' value='SET!'>
</div>
</form>
INFO:
<%= model.info %>
<div class="form-group">
<h3 id="ws"></h3>
</div>
<%- contentFor('head') %>
<script>
const url = 'wss://iot.d-popov.com/n/ws'
const connection = new WebSocket(url)
connection.onopen = (d) => {
console.log(`WebSocket error: ${d}`)
}
connection.onerror = error => {
console.log(`WebSocket error: ${error}`)
//console.log(inspect(error));
}
connection.onmessage = e => {
console.log(`ws data `);
console.log(e.data);
$('#ws').html(e.data);
}
</script>
<%- contentFor('scripts') %>
<script>
window.onload = function () {
$.getJSON("/n/dht?e=now", function(data){
if(data && data.dht){
$('#current').text( "A23 Currently is " + data.dht.temp + "°C, " + data.dht.hum +"% RH. Dew Point at:" + data.dht.dew );
}else {
//chart.title.set("text", "A23 conditions");
}
});
}
$(function(){
console.log("ready");
$("#set").click(function(e){
e.preventDefault();
$.post(
$("#accontrol").prop("action"),
$("#accontrol").serialize(),
function(data, result, response) {
// ... do something with response from server
console.log('sent');
},
//'json' // I expect a JSON response
);
});
});
</script>