Browse Source

Sensor indexes in web UI

fastled
Xose Pérez 7 years ago
parent
commit
38b2747218
7 changed files with 3032 additions and 3081 deletions
  1. BIN
      code/espurna/data/index.html.gz
  2. +1
    -0
      code/espurna/domoticz.ino
  3. +8
    -0
      code/espurna/sensor.ino
  4. +2986
    -2994
      code/espurna/static/index.html.gz.h
  5. +1
    -0
      code/html/custom.css
  6. +21
    -54
      code/html/custom.js
  7. +15
    -33
      code/html/index.html

BIN
code/espurna/data/index.html.gz View File


+ 1
- 0
code/espurna/domoticz.ino View File

@ -96,6 +96,7 @@ void _domoticzWebSocketOnSend(JsonObject& root) {
JsonObject& element = list.createNestedObject();
element["name"] = magnitudeName(i);
element["type"] = magnitudeType(i);
element["index"] = magnitudeIndex(i);
element["idx"] = getSetting("dczMagnitude", i, 0).toInt();
}


+ 8
- 0
code/espurna/sensor.ino View File

@ -122,6 +122,7 @@ void _sensorWebSocketSendData(JsonObject& root) {
dtostrf(magnitude.current, 1-sizeof(buffer), decimals, buffer);
JsonObject& element = list.createNestedObject();
element["index"] = int(magnitude.global);
element["type"] = int(magnitude.type);
element["value"] = String(buffer);
element["units"] = _sensorUnits(magnitude.type);
@ -546,6 +547,13 @@ unsigned char magnitudeType(unsigned char index) {
return MAGNITUDE_NONE;
}
unsigned char magnitudeIndex(unsigned char index) {
if (index < _magnitudes.size()) {
return int(_magnitudes[index].global);
}
return 0;
}
// -----------------------------------------------------------------------------
void sensorSetup() {


+ 2986
- 2994
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 1
- 0
code/html/custom.css View File

@ -108,6 +108,7 @@ div.hint.inline {
#networks div.more {
display: none;
}
legend.module,
.module {
display: none;
}


+ 21
- 54
code/html/custom.js View File

@ -102,7 +102,6 @@ var is_group = [
"mqttGroup", "mqttGroupInv",
"dczRelayIdx",
"ledMode",
"ntpServer",
"adminPass"
];
@ -397,7 +396,7 @@ function createRelayIdxs(data) {
var template = $("#relayIdxTemplate .pure-g")[0];
for (var i=0; i<data.length; i++) {
var line = $(template).clone();
if (data.length > 1) $("label", line).html("Switch #" + i);
$("label", line).html("Switch #" + i);
$("input", line).attr("name", "dczRelayIdx" + i).attr("tabindex", 40 + i).val(data[i]);
line.appendTo("#domoticzRelays");
}
@ -412,7 +411,7 @@ function createMagnitudeIdxs(data) {
var template = $("#magnitudeIdxTemplate .pure-g")[0];
for (var i=0; i<data.length; i++) {
var line = $(template).clone();
$("label", line).html(magnitudeType(data[i].type));
$("label", line).html(magnitudeType(data[i].type) + " #" + parseInt(data[i].index));
$("div.hint", line).html(data[i].name);
$("input", line).attr("name", "dczMagnitude" + i).attr("tabindex", 40 + i).val(data[i].idx);
line.appendTo("#domoticzMagnitudes");
@ -468,7 +467,7 @@ function initRelays(data) {
var template = $("#relayTemplate .pure-g")[0];
for (var i=0; i<data.length; i++) {
var line = $(template).clone();
if (data.length > 1) $(".relay_id", line).html(" " + (i+1));
$(".id", line).html(i);
$("input", line).attr("data", i).prop("checked", data[i]);
line.appendTo("#relays");
$(":checkbox", line).iphoneStyle({
@ -492,7 +491,7 @@ function initRelayConfig(data) {
for (var i=0; i < data.length; i++) {
var line = $(template).clone();
$("span.gpio", line).html(data[i].gpio);
$("span.id", line).html(i+1);
$("span.id", line).html(i);
$("select[name='relayBoot']", line).val(data[i].boot);
$("select[name='relayPulse']", line).val(data[i].pulse);
$("input[name='relayTime']", line).val(data[i].pulse_ms);
@ -517,7 +516,7 @@ function initMagnitudes(data) {
var template = $("#magnitudeTemplate").children();
for (var i=0; i<data.length; i++) {
var line = $(template).clone();
$("label", line).html(magnitudeType(data[i].type));
$("label", line).html(magnitudeType(data[i].type) + " #" + parseInt(data[i].index));
$("div.hint", line).html(data[i].description);
$("input", line).attr("data", i);
line.appendTo("#magnitudes");
@ -637,7 +636,7 @@ function addRfbNode() {
var template = $("#rfbNodeTemplate").children();
var line = $(template).clone();
var status = true;
$("span", line).html(numNodes+1);
$("span", line).html(numNodes);
$(line).find("input").each(function() {
$(this).attr("data-id", numNodes);
$(this).attr("data-status", status ? 1 : 0);
@ -675,8 +674,6 @@ function rfbSend() {
function processData(data) {
console.log(data);
// title
if ("app_name" in data) {
var title = data.app_name;
@ -726,8 +723,7 @@ function processData(data) {
var nodes = data.rfb;
for (var i in nodes) {
var node = nodes[i];
var element = $("input[name=rfbcode][data-id=" + node["id"] + "][data-status=" + node["status"] + "]");
if (element.length) element.val(node["data"]);
$("input[name=rfbcode][data-id=" + node["id"] + "][data-status=" + node["status"] + "]").val(node["data"]);
}
return;
}
@ -755,10 +751,8 @@ function processData(data) {
}
if (key == "brightness") {
var slider = $("#brightness");
if (slider.length) slider.val(data[key]);
var span = $("span.brightness");
if (span.length) span.html(data[key]);
$("#brightness").val(data[key]);
$("span.brightness").html(data[key]);
return;
}
@ -766,10 +760,8 @@ function processData(data) {
var len = data[key].length;
initChannels(len);
for (var i=0; i<len; i++) {
var slider = $("input.slider[data=" + i + "]");
if (slider.length) slider.val(data[key][i]);
var span = $("span.slider[data=" + i + "]");
if (span.length) span.html(data[key][i]);
$("input.slider[data=" + i + "]").val(data[key][i]);
$("span.slider[data=" + i + "]").html(data[key][i]);
}
return;
}
@ -785,15 +777,11 @@ function processData(data) {
if (key == "magnitudes") {
initMagnitudes(data[key]);
for (var i=0; i<data[key].length; i++) {
var element = $("input[name=magnitude][data=" + i + "]");
if (element.length) {
var error = data[key][i].error || 0;
if (error == 0) {
element.val(data[key][i].value + data[key][i].units);
} else {
element.val(magnitudeError(error));
}
}
var error = data[key][i].error || 0;
var text = (error == 0) ?
data[key][i].value + data[key][i].units
: magnitudeError(error);
$("input[name=magnitude][data=" + i + "]").val(text);
}
return;
}
@ -812,25 +800,14 @@ function processData(data) {
}
if (key == "wifi") {
var networks = data.wifi;
for (var i in networks) {
// add a new row
for (var i in data.wifi) {
var line = addNetwork();
// fill in the blanks
var wifi = data.wifi[i];
Object.keys(wifi).forEach(function(key) {
var element = $("input[name=" + key + "]", line);
if (element.length) element.val(wifi[key]);
$("input[name=" + key + "]", line).val(wifi[key]);
});
}
return;
}
// ---------------------------------------------------------------------
@ -845,6 +822,7 @@ function processData(data) {
// Relay configuration
if (key == "relayConfig") {
initRelayConfig(data[key]);
return;
}
// ---------------------------------------------------------------------
@ -1010,22 +988,13 @@ function connect(host) {
if (websock) websock.close();
websock = new WebSocket(wshost);
websock.onopen = function(evt) {
console.log("Connected");
};
websock.onclose = function(evt) {
console.log("Disconnected");
};
websock.onerror = function(evt) {
console.log("Error: ", evt);
};
websock.onmessage = function(evt) {
var data = getJson(evt.data);
if (data) processData(data);
};
}
function init() {
$(function() {
initMessages();
@ -1060,6 +1029,4 @@ function init() {
connect();
}
$(init);
});

+ 15
- 33
code/html/index.html View File

@ -333,7 +333,7 @@
<fieldset>
<div class="pure-g module module-multirelay"><legend>General</legend></div>
<legend class="module module-multirelay">General</legend>
<div class="pure-g module module-multirelay">
<label class="pure-u-1 pure-u-md-1-4">Switch sync mode</label>
@ -641,17 +641,17 @@
<fieldset>
<div class="pure-g">
<label class="pure-u-1 pure-u-md-1-4">NTP Server 1</label>
<label class="pure-u-1 pure-u-md-1-4">NTP Server #0</label>
<input class="pure-u-1 pure-u-md-3-4" name="ntpServer1" type="text" size="20" tabindex="41" />
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-md-1-4">NTP Server 2</label>
<label class="pure-u-1 pure-u-md-1-4">NTP Server #1</label>
<input class="pure-u-1 pure-u-md-3-4" name="ntpServer2" type="text" size="20" tabindex="42" />
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-md-1-4">NTP Server 3</label>
<label class="pure-u-1 pure-u-md-1-4">NTP Server #2</label>
<input class="pure-u-1 pure-u-md-3-4" name="ntpServer3" type="text" size="20" tabindex="43" />
</div>
@ -684,6 +684,8 @@
<fieldset>
<legend>General</legend>
<div class="pure-g">
<div class="pure-u-1 pure-u-sm-1-4"><label>Enable Domoticz</label></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="dczEnabled" tabindex="30" /></div>
@ -705,33 +707,16 @@
<input class="pure-u-1 pure-u-md-3-4" name="dczTopicOut" type="text" action="reconnect" tabindex="32" />
</div>
<div id="domoticzRelays"></div>
<div id="domoticzMagnitudes"></div>
<div class="pure-g module module-pwr">
<label class="pure-u-1 pure-u-sm-1-4">Power IDX</label>
<div class="pure-u-1 pure-u-sm-1-8"><input class="pure-u-sm-23-24" name="dczPowIdx" type="number" min="0" tabindex="35" data="0" /></div>
<div class="pure-u-1 pure-u-sm-5-8 hint center">Set to 0 to disable notifications.</div>
</div>
<legend>Sensors &amp; actuators</legend>
<div class="pure-g module module-pwr">
<label class="pure-u-1 pure-u-sm-1-4">Energy increment IDX</label>
<div class="pure-u-1 pure-u-sm-1-8"><input class="pure-u-sm-23-24" name="dczEnergyIdx" type="number" min="0" tabindex="36" data="0" /></div>
<div class="pure-u-1 pure-u-sm-5-8 hint center">Set to 0 to disable notifications.</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-sm-1-4">&nbsp;</label>
<div class="pure-u-1 pure-u-sm-5-8 hint center">Set to 0 to disable notifications from that component</div>
</div>
<div class="pure-g module module-pwr">
<label class="pure-u-1 pure-u-sm-1-4">Voltage IDX</label>
<div class="pure-u-1 pure-u-sm-1-8"><input class="pure-u-sm-23-24" name="dczVoltIdx" type="number" min="0" tabindex="37" data="0" /></div>
<div class="pure-u-1 pure-u-sm-5-8 hint center">Set to 0 to disable notifications.</div>
</div>
<div id="domoticzRelays"></div>
<div class="pure-g module module-pwr">
<label class="pure-u-1 pure-u-sm-1-4">Current IDX</label>
<div class="pure-u-1 pure-u-sm-1-8"><input class="pure-u-sm-23-24" name="dczCurrentIdx" type="number" min="0" tabindex="38" data="0" /></div>
<div class="pure-u-1 pure-u-sm-5-8 hint center">Set to 0 to disable notifications.</div>
</div>
<div id="domoticzMagnitudes"></div>
</fieldset>
</div>
@ -912,9 +897,7 @@
<fieldset>
<div class="pure-g">
<legend>&nbsp;Switch <span></span>&nbsp;</legend>
</div>
<legend>Switch #<span></span>&nbsp;</legend>
<div class="pure-g">
<label class="pure-u-1-2 pure-u-sm-1-4">Switch ON</label>
@ -984,13 +967,13 @@
<div id="relayTemplate" class="template">
<div class="pure-g">
<div class="pure-u-1 pure-u-sm-1-4"><label>Switch<span class="relay_id"></span> Status</label></div>
<div class="pure-u-1 pure-u-sm-1-4"><label>Switch #<span class="id"></span></label></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" class="relayStatus pure-u-1 pure-u-sm-1-4" data="0" /></div>
</div>
</div>
<div id="relayConfigTemplate" class="template">
<div class="pure-g"><legend>Switch #<span class="id"></span> (GPIO<span class="gpio"></span>)</legend></div>
<legend>Switch #<span class="id"></span> (GPIO<span class="gpio"></span>)</legend>
<div class="pure-g">
<div class="pure-u-1 pure-u-sm-1-4"><label>Boot mode</label></div>
<select class="pure-u-1 pure-u-sm-3-4" name="relayBoot">
@ -1029,7 +1012,6 @@
<div class="pure-g">
<label class="pure-u-1 pure-u-sm-1-4">Switch</label>
<div class="pure-u-1 pure-u-sm-1-8"><input class="pure-u-sm-23-24 dczRelayIdx" name="dczRelayIdx" type="number" min="0" tabindex="0" data="0" /></div>
<div class="pure-u-1 pure-u-sm-5-8 hint center">Set to 0 to disable notifications.</div>
</div>
</div>


Loading…
Cancel
Save