Added web UI for MCP3008 analog sensors values

This commit is contained in:
Fabio Manganiello 2018-04-30 09:40:44 +02:00
parent b8cba8ec0c
commit b4bd1cb7bb
3 changed files with 52 additions and 0 deletions

View file

@ -0,0 +1,47 @@
$(document).ready(function() {
var $container = $('#sensors-container');
var onEvent = function(event) {
switch (event.args.type) {
case 'platypush.message.event.sensor.SensorDataChangeEvent':
var data = event.args.sensors;
for (var sensor of Object.keys(data)) {
var $sensor = $container.find('[data-sensor-type=' + sensor + ']');
var $sensorValue;
if ($sensor.length === 0) {
$sensor = $('<div></div>')
.addClass('row sensor-data')
.attr('data-sensor-type', sensor);
var $name = $('<div></div>')
.addClass('sensor-name six columns')
.text(sensor);
$sensorValue = $('<div></div>')
.addClass('sensor-value six columns');
$sensor.appendTo($container);
} else {
$sensorValue = $sensor.find('.sensor-value');
}
$sensorValue.text(data[sensor]);
}
break;
}
};
var initEvents = function() {
window.registerEventListener(onEvent);
};
var init = function() {
initEvents();
};
init();
});

View file

@ -0,0 +1,5 @@
<script type="text/javascript" src="{{ url_for('static', filename='js/gpio.sensor.mcp3008.js') }}"></script>
<link rel="stylesheet" href="{{ url_for('static', filename='css/gpio.sensor.mcp3008.css') }}"></script>
<div class="row" id="sensors-container"></div>