diff --git a/software/app/application.cpp b/software/app/application.cpp index b74463e..c668595 100644 --- a/software/app/application.cpp +++ b/software/app/application.cpp @@ -89,11 +89,11 @@ void init() { WifiAccessPoint.config("Sensus", "", AUTH_OPEN, false, 3);*/ cWebInterface::GetInstance()->Start(); - //procTimer.initializeMs(HUB_PERIOD, updateSensorHub).start(); + procTimer.initializeMs(HUB_PERIOD, updateSensorHub).start(); //procTimer.initializeMs(1000, AdcTest).start(); - procTimer.initializeMs(5000, SettingsTest).start(); - mylight.SetCurrent(5000); - mylight.RectangleUpdate(); + //procTimer.initializeMs(5000, SettingsTest).start(); + //mylight.SetCurrent(5000); + //mylight.RectangleUpdate(); } void STADisconnect(String ssid, uint8_t ssid_len, uint8_t bssid[6], diff --git a/software/app/web_interface.cpp b/software/app/web_interface.cpp index 9e4dab0..c6f4477 100644 --- a/software/app/web_interface.cpp +++ b/software/app/web_interface.cpp @@ -23,6 +23,14 @@ static void onRefresh(HttpRequest &request, HttpResponse &response) { cWebInterface::GetInstance()->OnRefresh(request, response); } +static void onConfiguration(HttpRequest &request, HttpResponse &response) { + cWebInterface::GetInstance()->OnConfiguration(request, response); +} + +static void onConfiguration_json(HttpRequest &request, HttpResponse &response) { + cWebInterface::GetInstance()->OnConfiguration_json(request, response); +} + cWebInterface::cWebInterface() : m_serverStarted(false) { for (int i = 0; i < 4; i++) { @@ -50,6 +58,8 @@ void cWebInterface::Start() { return; server.addPath("/", onIndex); server.addPath("/state", onRefresh); + server.addPath("/config", onConfiguration); + server.addPath("/config.json", onConfiguration_json); server.setDefaultHandler(onFile); server.listen(80); } @@ -119,5 +129,73 @@ cWebInterface::~cWebInterface() { // TODO Auto-generated destructor stub } +void cWebInterface::OnConfiguration(HttpRequest &request, HttpResponse &response) +{ + + if (request.method == HTTP_POST) + { + debugf("Update config"); + // Update config + if (request.getBody() == NULL) + { + debugf("NULL bodyBuf"); + return; + } + else + { + StaticJsonBuffer<200> jsonBuffer; + JsonObject& root = jsonBuffer.parseObject(request.getBody()); + //root.prettyPrintTo(Serial); //Uncomment it for debuging + + /* if (root["StaSSID"].success()) // Settings + { + uint8_t PrevStaEnable = ActiveConfig.StaEnable; + + ActiveConfig.StaSSID = String((const char *)root["StaSSID"]); + ActiveConfig.StaPassword = String((const char *)root["StaPassword"]); + ActiveConfig.StaEnable = root["StaEnable"]; + + if (PrevStaEnable && ActiveConfig.StaEnable) + { + WifiStation.enable(true); + WifiAccessPoint.enable(false); + WifiStation.config(ActiveConfig.StaSSID, ActiveConfig.StaPassword); + } + else if (ActiveConfig.StaEnable) + { + WifiStation.enable(true, true); + WifiAccessPoint.enable(false, true); + WifiStation.config(ActiveConfig.StaSSID, ActiveConfig.StaPassword); + } + else + { + WifiStation.enable(false, true); + WifiAccessPoint.enable(true, true); + WifiAccessPoint.config("TyTherm", "ENTERYOURPASSWD", AUTH_WPA2_PSK); + } + }*/ + } + //saveConfig(ActiveConfig); + } + else + { + response.setCache(86400, true); // It's important to use cache for better performance. + response.sendFile("config.html"); + } +} + +void cWebInterface::OnConfiguration_json(HttpRequest &request, HttpResponse &response) +{ + JsonObjectStream* stream = new JsonObjectStream(); + JsonObject& json = stream->getRoot(); + + json["StaSSID"] = 22; + json["StaPassword"] = 23; + json["StaEnable"] = 24; + + response.sendDataStream(stream, MIME_JSON); +} + + } /* namespace rijnfel */ diff --git a/software/app/web_interface.h b/software/app/web_interface.h index 8689abd..05f6169 100644 --- a/software/app/web_interface.h +++ b/software/app/web_interface.h @@ -40,6 +40,8 @@ public: public: void OnIndex(HttpRequest &request, HttpResponse &response); void OnRefresh(HttpRequest &request, HttpResponse &response); + void OnConfiguration_json(HttpRequest &request, HttpResponse &response); + void OnConfiguration(HttpRequest &request, HttpResponse &response); private: bool m_serverStarted; int32_t m_adc_value[4]; diff --git a/software/files/config.html b/software/files/config.html index 6a93eb7..1a89210 100644 --- a/software/files/config.html +++ b/software/files/config.html @@ -66,4 +66,4 @@ - \ No newline at end of file + diff --git a/software/files/index.html b/software/files/index.html index 8e0bfb0..0000c43 100644 --- a/software/files/index.html +++ b/software/files/index.html @@ -35,10 +35,10 @@
-

Channel 1

+

ADC 1

-

{adc_1}

+

{adc_1}

@@ -47,10 +47,10 @@
-

Channel 2

+

ADC 2

-

{adc_2}

+

{adc_2}

@@ -61,10 +61,10 @@
-

Channel 3

+

ADC 3

-

{adc_3}

+

{adc_3}

@@ -73,10 +73,10 @@
-

Channel 4

+

ADC 4

-

{adc_4}

+

{adc_4}

@@ -85,4 +85,4 @@ - \ No newline at end of file + diff --git a/software/files/index.js b/software/files/index.js index 779fb88..718b426 100644 --- a/software/files/index.js +++ b/software/files/index.js @@ -2,10 +2,10 @@ $( document ).ready(function() { (function worker() { $.getJSON('/state', function(data) { - document.getElementById('adc_0').textContent = data.adc_0; document.getElementById('adc_1').textContent = data.adc_1; document.getElementById('adc_2').textContent = data.adc_2; document.getElementById('adc_3').textContent = data.adc_3; + document.getElementById('adc_4').textContent = data.adc_4; setTimeout(worker, 1000); });