Browse Source

Fixed minor problem with one ADC not showing up.

software_develop
Maximilian Stiefel 7 years ago
parent
commit
c77ff21c86
  1. 8
      software/app/application.cpp
  2. 78
      software/app/web_interface.cpp
  3. 2
      software/app/web_interface.h
  4. 2
      software/files/config.html
  5. 18
      software/files/index.html
  6. 2
      software/files/index.js

8
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],

78
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 */

2
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];

2
software/files/config.html

@ -66,4 +66,4 @@
</div> <!-- /container -->
</body>
</html>
</html>

18
software/files/index.html

@ -35,10 +35,10 @@
<div class="col-xs-10 col-md-5">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Channel 1</h3>
<h3 class="panel-title">ADC 1</h3>
</div>
<div class="panel-body">
<h1 id="adc_0" class="text-center main">{adc_1}</h1>
<h1 id="adc_1" class="text-center main">{adc_1}</h1>
</div>
</div>
</div>
@ -47,10 +47,10 @@
<div class="col-xs-10 col-md-5">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Channel 2</h3>
<h3 class="panel-title">ADC 2</h3>
</div>
<div class="panel-body">
<h1 id="adc_1" class="text-center main">{adc_2}</h1>
<h1 id="adc_2" class="text-center main">{adc_2}</h1>
</div>
</div>
</div>
@ -61,10 +61,10 @@
<div class="col-xs-10 col-md-5">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Channel 3</h3>
<h3 class="panel-title">ADC 3</h3>
</div>
<div class="panel-body">
<h1 id="adc_2" class="text-center main">{adc_3}</h1>
<h1 id="adc_3" class="text-center main">{adc_3}</h1>
</div>
</div>
</div>
@ -73,10 +73,10 @@
<div class="col-xs-10 col-md-5">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Channel 4</h3>
<h3 class="panel-title">ADC 4</h3>
</div>
<div class="panel-body">
<h1 id="adc_3" class="text-center main">{adc_4}</h1>
<h1 id="adc_4" class="text-center main">{adc_4}</h1>
</div>
</div>
</div>
@ -85,4 +85,4 @@
</div> <!-- /container -->
</body>
</html>
</html>

2
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);
});

Loading…
Cancel
Save