mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-27 04:33:04 +00:00
Refactored MQTT payload handling into separate classes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "AmsWebServer.h"
|
||||
#include "version.h"
|
||||
#include "AmsStorage.h"
|
||||
#include "hexutils.h"
|
||||
|
||||
#include "root/head_html.h"
|
||||
#include "root/foot_html.h"
|
||||
@@ -101,6 +102,10 @@ void AmsWebServer::setTimezone(Timezone* tz) {
|
||||
this->tz = tz;
|
||||
}
|
||||
|
||||
void AmsWebServer::setMqttEnabled(bool enabled) {
|
||||
mqttEnabled = enabled;
|
||||
}
|
||||
|
||||
void AmsWebServer::loop() {
|
||||
server.handleClient();
|
||||
|
||||
@@ -192,7 +197,7 @@ void AmsWebServer::temperatureJson() {
|
||||
int size = 32 + (count * 72);
|
||||
|
||||
char buf[size];
|
||||
snprintf_P(buf, 16, "{\"c\":%d,\"s\":[", count);
|
||||
snprintf(buf, 16, "{\"c\":%d,\"s\":[", count);
|
||||
|
||||
for(int i = 0; i < count; i++) {
|
||||
TempSensorData* data = hw->getTempSensorData(i);
|
||||
@@ -208,7 +213,7 @@ void AmsWebServer::temperatureJson() {
|
||||
delay(1);
|
||||
}
|
||||
char* pos = buf+strlen(buf);
|
||||
snprintf_P(count == 0 ? pos : pos-1, 8, "]}");
|
||||
snprintf(count == 0 ? pos : pos-1, 8, "]}");
|
||||
|
||||
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
server.sendHeader("Pragma", "no-cache");
|
||||
@@ -391,24 +396,6 @@ void AmsWebServer::configMeterHtml() {
|
||||
server.sendContent_P(FOOT_HTML);
|
||||
}
|
||||
|
||||
String AmsWebServer::toHex(uint8_t* in, uint8_t size) {
|
||||
String hex;
|
||||
for(int i = 0; i < size; i++) {
|
||||
if(in[i] < 0x10) {
|
||||
hex += '0';
|
||||
}
|
||||
hex += String(in[i], HEX);
|
||||
}
|
||||
hex.toUpperCase();
|
||||
return hex;
|
||||
}
|
||||
|
||||
void AmsWebServer::fromHex(uint8_t *out, String in, uint8_t size) {
|
||||
for(int i = 0; i < size*2; i += 2) {
|
||||
out[i/2] = strtol(in.substring(i, i+2).c_str(), 0, 16);
|
||||
}
|
||||
}
|
||||
|
||||
void AmsWebServer::configWifiHtml() {
|
||||
printD("Serving /wifi.html over http...");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user