mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-31 14:11:58 +00:00
Some modifications to increase stability
This commit is contained in:
@@ -155,7 +155,7 @@ void setup() {
|
||||
}
|
||||
|
||||
double vccBootLimit = config.getVccBootLimit();
|
||||
if(vccBootLimit > 0 && (config.getApPin() == -1 || digitalRead(config.getApPin()) == HIGH)) { // Skip if user is holding AP button while booting (HIGH = button is released)
|
||||
if(vccBootLimit > 0 && (config.getApPin() == 0xFF || digitalRead(config.getApPin()) == HIGH)) { // Skip if user is holding AP button while booting (HIGH = button is released)
|
||||
if (vcc < vccBootLimit) {
|
||||
if(Debug.isActive(RemoteDebug::INFO)) {
|
||||
debugI("Voltage is too low, sleeping");
|
||||
@@ -268,7 +268,7 @@ double energy = -1.0;
|
||||
void loop() {
|
||||
Debug.handle();
|
||||
unsigned long now = millis();
|
||||
if(config.getApPin() != INVALID_BUTTON_PIN) {
|
||||
if(config.getApPin() != 0xFF) {
|
||||
if (digitalRead(config.getApPin()) == LOW) {
|
||||
if (buttonActive == false) {
|
||||
buttonActive = true;
|
||||
@@ -715,6 +715,21 @@ void readHanPort() {
|
||||
mqtt.loop();
|
||||
delay(10);
|
||||
}
|
||||
} else {
|
||||
if(strlen(config.getMqttHost()) > 0 && strlen(config.getMqttPublishTopic()) > 0) {
|
||||
byte buf[512];
|
||||
int length = hanReader.getBuffer(buf);
|
||||
String hexstring = "";
|
||||
|
||||
for(int i = 0; i < length; i++) {
|
||||
if(buf[i] < 0x10) {
|
||||
hexstring += '0';
|
||||
}
|
||||
|
||||
hexstring += String(buf[i], HEX);
|
||||
}
|
||||
mqtt.publish(String(config.getMqttPublishTopic()), hexstring);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Auto detect meter if not set
|
||||
@@ -813,14 +828,14 @@ void MQTT_connect() {
|
||||
}
|
||||
lastMqttRetry = millis();
|
||||
if(Debug.isActive(RemoteDebug::INFO)) {
|
||||
debugI("Connecting to MQTT %s:%d", config.getMqttHost(), config.getMqttPort());
|
||||
debugD("Disconnecting MQTT before connecting");
|
||||
}
|
||||
|
||||
mqtt.disconnect();
|
||||
yield();
|
||||
|
||||
WiFiClientSecure *secureClient;
|
||||
Client *client;
|
||||
WiFiClientSecure *secureClient = NULL;
|
||||
Client *client = NULL;
|
||||
if(config.isMqttSsl()) {
|
||||
debugI("MQTT SSL is configured");
|
||||
|
||||
@@ -858,10 +873,16 @@ void MQTT_connect() {
|
||||
client = new WiFiClient();
|
||||
}
|
||||
|
||||
if(Debug.isActive(RemoteDebug::INFO)) {
|
||||
debugI("Connecting to MQTT %s:%d", config.getMqttHost(), config.getMqttPort());
|
||||
}
|
||||
mqtt.begin(config.getMqttHost(), config.getMqttPort(), *client);
|
||||
|
||||
#if defined(ESP8266)
|
||||
if(secureClient) secureClient->setX509Time(timeClient.getEpochTime());
|
||||
if(secureClient) {
|
||||
debugD("Setting NTP time for secure MQTT connection");
|
||||
secureClient->setX509Time(timeClient.getEpochTime());
|
||||
}
|
||||
#endif
|
||||
|
||||
// Connect to a unsecure or secure MQTT server
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "version.h"
|
||||
#include "AmsStorage.h"
|
||||
|
||||
#include "root/head_html.h"
|
||||
#include "root/foot_html.h"
|
||||
#include "root/index_html.h"
|
||||
#include "root/index_js.h"
|
||||
#include "root/setup_html.h"
|
||||
@@ -126,7 +128,6 @@ void AmsWebServer::indexHtml() {
|
||||
return;
|
||||
|
||||
String html = String((const __FlashStringHelper*) INDEX_HTML);
|
||||
html.replace("${version}", VERSION);
|
||||
|
||||
double u1 = data.getL1Voltage();
|
||||
double u2 = data.getL2Voltage();
|
||||
@@ -193,7 +194,6 @@ void AmsWebServer::configMeterHtml() {
|
||||
return;
|
||||
|
||||
String html = String((const __FlashStringHelper*) CONFIGMETER_HTML);
|
||||
html.replace("${version}", VERSION);
|
||||
|
||||
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
server.sendHeader("Pragma", "no-cache");
|
||||
@@ -224,7 +224,6 @@ void AmsWebServer::configWifiHtml() {
|
||||
return;
|
||||
|
||||
String html = String((const __FlashStringHelper*) CONFIGWIFI_HTML);
|
||||
html.replace("${version}", VERSION);
|
||||
|
||||
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
server.sendHeader("Pragma", "no-cache");
|
||||
@@ -250,7 +249,6 @@ void AmsWebServer::configMqttHtml() {
|
||||
return;
|
||||
|
||||
String html = String((const __FlashStringHelper*) CONFIGMQTT_HTML);
|
||||
html.replace("${version}", VERSION);
|
||||
|
||||
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
server.sendHeader("Pragma", "no-cache");
|
||||
@@ -292,8 +290,10 @@ void AmsWebServer::configMqttHtml() {
|
||||
html.replace("${display.key.file}", "none");
|
||||
}
|
||||
|
||||
server.setContentLength(html.length());
|
||||
server.send(200, "text/html", html);
|
||||
server.setContentLength(html.length() + HEAD_HTML_LEN + FOOT_HTML_LEN);
|
||||
server.send_P(200, "text/html", HEAD_HTML);
|
||||
server.sendContent(html);
|
||||
server.sendContent_P(FOOT_HTML);
|
||||
}
|
||||
|
||||
void AmsWebServer::configDomoticzHtml() {
|
||||
@@ -303,7 +303,6 @@ void AmsWebServer::configDomoticzHtml() {
|
||||
return;
|
||||
|
||||
String html = String((const __FlashStringHelper*) CONFIGDOMOTICZ_HTML);
|
||||
html.replace("${version}", VERSION);
|
||||
|
||||
if(WiFi.getMode() != WIFI_AP) {
|
||||
html.replace("boot.css", BOOTSTRAP_URL);
|
||||
@@ -335,7 +334,6 @@ void AmsWebServer::configWebHtml() {
|
||||
return;
|
||||
|
||||
String html = String((const __FlashStringHelper*) CONFIGWEB_HTML);
|
||||
html.replace("${version}", VERSION);
|
||||
|
||||
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
server.sendHeader("Pragma", "no-cache");
|
||||
@@ -765,7 +763,6 @@ void AmsWebServer::configSystemHtml() {
|
||||
return;
|
||||
|
||||
String html = String((const __FlashStringHelper*) CONFIGSYSTEM_HTML);
|
||||
html.replace("${version}", VERSION);
|
||||
|
||||
#if defined(ESP32)
|
||||
html.replace("${gpio.max}", "39");
|
||||
@@ -912,7 +909,6 @@ void AmsWebServer::restartWaitHtml() {
|
||||
return;
|
||||
|
||||
String html = String((const __FlashStringHelper*) RESTARTWAIT_HTML);
|
||||
html.replace("${version}", VERSION);
|
||||
|
||||
if(WiFi.getMode() != WIFI_AP) {
|
||||
html.replace("boot.css", BOOTSTRAP_URL);
|
||||
|
||||
Reference in New Issue
Block a user