Only show temp if sensor is attached. Added common functions to get temp and vcc

This commit is contained in:
Gunnar Skjold
2020-02-14 21:48:03 +01:00
parent f484f3eb0e
commit eff00f1fe0
7 changed files with 118 additions and 49 deletions

View File

@@ -153,10 +153,7 @@ void AmsWebServer::indexHtml() {
html.replace("${data.tQO}", tpi > 0 ? String(tqo, 1) : "");
html.replace("${display.accumulative}", tpi > 0 ? "" : "none");
double vcc = 0;
#if defined(ESP8266)
vcc = ((double) ESP.getVcc()) / 1000;
#endif
double vcc = hw.getVcc();
html.replace("${vcc}", vcc > 0 ? String(vcc, 2) : "");
float rssi = WiFi.RSSI();
@@ -321,12 +318,8 @@ void AmsWebServer::dataJson() {
json["maxPower"] = maxPwr;
json["meterType"] = config->getMeterType();
json["currentMillis"] = now;
double vcc = 0;
#if defined(ESP8266)
vcc = ((double) ESP.getVcc()) / 1000;
#endif
json["vcc"] = vcc;
double vcc = hw.getVcc();
json["vcc"] = vcc > 0 ? vcc : 0;
json.createNestedObject("wifi");
float rssi = WiFi.RSSI();

View File

@@ -4,6 +4,7 @@
#include <ArduinoJson.h>
#include <MQTT.h>
#include "AmsConfiguration.h"
#include "HwTools.h"
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
@@ -28,6 +29,7 @@ public:
void setJson(StaticJsonDocument<1024> json);
private:
HwTools hw;
AmsConfiguration* config;
Stream* debugger;
MQTTClient* mqtt;