From 45f96155b32e498994a8336bd2bed0136581e2c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Tue, 26 Jul 2016 16:53:52 +0200 Subject: [PATCH] Configuration changes, using ArduinoJson for AJAX responses, EmonLiteESP with custom reading callbacks --- code/data/index.html | 126 ++++- code/lib/DebounceEvent/DebounceEvent.cpp | 6 +- code/lib/DebounceEvent/DebounceEvent.h | 5 +- code/lib/EmonLiteESP/EmonLiteESP.cpp | 28 +- code/lib/EmonLiteESP/EmonLiteESP.h | 9 +- code/platformio.ini | 2 + code/src/Config.cpp | 89 +++ code/src/Config.h | 68 +++ code/src/main.cpp | 693 +++++++++-------------- 9 files changed, 564 insertions(+), 462 deletions(-) create mode 100644 code/src/Config.cpp create mode 100644 code/src/Config.h diff --git a/code/data/index.html b/code/data/index.html index 412adf5c..456e2504 100644 --- a/code/data/index.html +++ b/code/data/index.html @@ -1,7 +1,7 @@ - {appname} + ESPurna @@ -51,16 +51,41 @@ setTimeout(update, 200); }); + function init() { + $.ajax({ + 'method': 'GET', + 'url': '/init', + 'dataType': 'json' + }).done(function(data) { + keys = Object.keys(data); + for (index in keys) { + key = "#" + keys[index]; + value = data[keys[index]]; + try { + if ($(key).prop('tagName') == 'INPUT') { + $(key).val(value); + } else { + $(key).html(value); + } + } catch(err) { + // nope + }; + }; + timer = setInterval(update, data.updateInterval); + document.title = data.hostname; + $("[name='pwMainsVoltage']").val(data.pwMainsVoltage); + $("[name='rfDevice']").val(data.rfDevice); + }); + } + function update() { $.ajax({ 'method': 'GET', 'url': '/status', 'dataType': 'json' }).done(function(data) { - $("#device").val(data.device); - $("#network").val(data.network.toUpperCase()); - $("#ip").val(data.ip); $("#mqtt").val(data.mqtt ? "CONNECTED" : "NOT CONNECTED"); + $("#power").val((data.power | 0) + "W"); if (data.relay) { $("#relay").addClass('btn-primary').html("ON"); $("#status").val(1); @@ -72,8 +97,8 @@ } $("#btn-admin").click(function() { - $("#panel-admin").show(); $("#panel-status").hide(); + $("#panel-admin").show(); $("#btn-admin").addClass('btn-primary'); $("#btn-status").removeClass('btn-primary'); }); @@ -96,13 +121,8 @@ event.preventDefault(); }) - function init() { - update(); - timer = setInterval(update, {updateInterval}); - $("[name='rfDevice']").val({rfDevice}); - } - init(); + update(); }); @@ -114,7 +134,7 @@