mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-04-26 20:27:27 +00:00
Made MQTT optional
This commit is contained in:
@@ -24,7 +24,7 @@ bool configuration::save()
|
|||||||
address += saveString(address, ssid);
|
address += saveString(address, ssid);
|
||||||
address += saveString(address, ssidPassword);
|
address += saveString(address, ssidPassword);
|
||||||
address += saveByte(address, meterType);
|
address += saveByte(address, meterType);
|
||||||
address += saveString(address, mqtt);
|
address += saveString(address, mqttHost);
|
||||||
address += saveInt(address, mqttPort);
|
address += saveInt(address, mqttPort);
|
||||||
address += saveString(address, mqttClientID);
|
address += saveString(address, mqttClientID);
|
||||||
address += saveString(address, mqttPublishTopic);
|
address += saveString(address, mqttPublishTopic);
|
||||||
@@ -63,7 +63,7 @@ bool configuration::load()
|
|||||||
ssid = (char*)String("").c_str();
|
ssid = (char*)String("").c_str();
|
||||||
ssidPassword = (char*)String("").c_str();
|
ssidPassword = (char*)String("").c_str();
|
||||||
meterType = (byte)0;
|
meterType = (byte)0;
|
||||||
mqtt = (char*)String("").c_str();
|
mqttHost = (char*)String("").c_str();
|
||||||
mqttClientID = (char*)String("").c_str();
|
mqttClientID = (char*)String("").c_str();
|
||||||
mqttPublishTopic = (char*)String("").c_str();
|
mqttPublishTopic = (char*)String("").c_str();
|
||||||
mqttSubscribeTopic = (char*)String("").c_str();
|
mqttSubscribeTopic = (char*)String("").c_str();
|
||||||
@@ -85,7 +85,7 @@ bool configuration::load()
|
|||||||
address += readString(address, &ssid);
|
address += readString(address, &ssid);
|
||||||
address += readString(address, &ssidPassword);
|
address += readString(address, &ssidPassword);
|
||||||
address += readByte(address, &meterType);
|
address += readByte(address, &meterType);
|
||||||
address += readString(address, &mqtt);
|
address += readString(address, &mqttHost);
|
||||||
address += readInt(address, &mqttPort);
|
address += readInt(address, &mqttPort);
|
||||||
address += readString(address, &mqttClientID);
|
address += readString(address, &mqttClientID);
|
||||||
address += readString(address, &mqttPublishTopic);
|
address += readString(address, &mqttPublishTopic);
|
||||||
@@ -182,11 +182,13 @@ void configuration::print(Stream* debugger)
|
|||||||
debugger->printf("ssid: %s\r\n", this->ssid);
|
debugger->printf("ssid: %s\r\n", this->ssid);
|
||||||
debugger->printf("ssidPassword: %s\r\n", this->ssidPassword);
|
debugger->printf("ssidPassword: %s\r\n", this->ssidPassword);
|
||||||
debugger->printf("meterType: %i\r\n", this->meterType);
|
debugger->printf("meterType: %i\r\n", this->meterType);
|
||||||
debugger->printf("mqtt: %s\r\n", this->mqtt);
|
if(this->mqttHost) {
|
||||||
debugger->printf("mqttPort: %i\r\n", this->mqttPort);
|
debugger->printf("mqttHost: %s\r\n", this->mqttHost);
|
||||||
debugger->printf("mqttClientID: %s\r\n", this->mqttClientID);
|
debugger->printf("mqttPort: %i\r\n", this->mqttPort);
|
||||||
debugger->printf("mqttPublishTopic: %s\r\n", this->mqttPublishTopic);
|
debugger->printf("mqttClientID: %s\r\n", this->mqttClientID);
|
||||||
debugger->printf("mqttSubscribeTopic: %s\r\n", this->mqttSubscribeTopic);
|
debugger->printf("mqttPublishTopic: %s\r\n", this->mqttPublishTopic);
|
||||||
|
debugger->printf("mqttSubscribeTopic: %s\r\n", this->mqttSubscribeTopic);
|
||||||
|
}
|
||||||
|
|
||||||
if (this->isSecure())
|
if (this->isSecure())
|
||||||
{
|
{
|
||||||
@@ -202,6 +204,7 @@ void configuration::print(Stream* debugger)
|
|||||||
debugger->printf("authPass: %s\r\n", this->authPass);
|
debugger->printf("authPass: %s\r\n", this->authPass);
|
||||||
}
|
}
|
||||||
debugger->printf("fuseSize: %i\r\n", this->fuseSize);
|
debugger->printf("fuseSize: %i\r\n", this->fuseSize);
|
||||||
|
debugger->printf("distSys: %i\r\n", this->distSys);
|
||||||
|
|
||||||
debugger->println("-----------------------------------------------");
|
debugger->println("-----------------------------------------------");
|
||||||
}
|
}
|
||||||
@@ -241,7 +244,7 @@ int configuration::readString(int pAddress, char* pString[])
|
|||||||
int configuration::saveString(int pAddress, char* pString)
|
int configuration::saveString(int pAddress, char* pString)
|
||||||
{
|
{
|
||||||
int address = 0;
|
int address = 0;
|
||||||
int length = strlen(pString) + 1;
|
int length = pString ? strlen(pString) + 1 : 0;
|
||||||
EEPROM.put(pAddress + address, length);
|
EEPROM.put(pAddress + address, length);
|
||||||
address++;
|
address++;
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class configuration {
|
|||||||
public:
|
public:
|
||||||
char* ssid;
|
char* ssid;
|
||||||
char* ssidPassword;
|
char* ssidPassword;
|
||||||
char* mqtt;
|
char* mqttHost;
|
||||||
int mqttPort;
|
int mqttPort;
|
||||||
char* mqttClientID;
|
char* mqttClientID;
|
||||||
char* mqttPublishTopic;
|
char* mqttPublishTopic;
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
|
|
||||||
webroot = "web"
|
webroot = "web"
|
||||||
srcroot = "src/web/root"
|
srcroot = "src/web/root"
|
||||||
|
|
||||||
|
shutil.rmtree(srcroot)
|
||||||
|
|
||||||
if not os.path.exists(srcroot):
|
if not os.path.exists(srcroot):
|
||||||
os.mkdir(srcroot)
|
os.mkdir(srcroot)
|
||||||
|
|
||||||
|
|||||||
@@ -91,6 +91,13 @@ void setup() {
|
|||||||
if (!ap.isActivated)
|
if (!ap.isActivated)
|
||||||
{
|
{
|
||||||
setupWiFi();
|
setupWiFi();
|
||||||
|
|
||||||
|
if(ap.config.mqttHost) {
|
||||||
|
mqtt.begin(ap.config.mqttHost, *client);
|
||||||
|
|
||||||
|
// Notify everyone we're here!
|
||||||
|
sendMqttData("Connected!");
|
||||||
|
}
|
||||||
// Configure uart for AMS data
|
// Configure uart for AMS data
|
||||||
if(ap.config.meterType == 3) {
|
if(ap.config.meterType == 3) {
|
||||||
Serial.begin(2400, SERIAL_8N1);
|
Serial.begin(2400, SERIAL_8N1);
|
||||||
@@ -117,16 +124,19 @@ void loop()
|
|||||||
// Turn off the LED
|
// Turn off the LED
|
||||||
led_off();
|
led_off();
|
||||||
|
|
||||||
// allow the MQTT client some resources
|
|
||||||
mqtt.loop();
|
|
||||||
delay(10); // <- fixes some issues with WiFi stability
|
|
||||||
|
|
||||||
// Reconnect to WiFi and MQTT as needed
|
// Reconnect to WiFi and MQTT as needed
|
||||||
if (!mqtt.connected()) {
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
MQTT_connect();
|
WiFi_connect();
|
||||||
} else {
|
|
||||||
readHanPort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ap.config.mqttHost) {
|
||||||
|
mqtt.loop();
|
||||||
|
delay(10); // <- fixes some issues with WiFi stability
|
||||||
|
if(!mqtt.connected()) {
|
||||||
|
MQTT_connect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
readHanPort();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -176,16 +186,6 @@ void setupWiFi()
|
|||||||
if (debugger) debugger->println(" connected");
|
if (debugger) debugger->println(" connected");
|
||||||
|
|
||||||
client = new WiFiClient();
|
client = new WiFiClient();
|
||||||
mqtt.begin(ap.config.mqtt, *client);
|
|
||||||
|
|
||||||
// Direct incoming MQTT messages
|
|
||||||
if (ap.config.mqttSubscribeTopic != 0 && strlen(ap.config.mqttSubscribeTopic) > 0) {
|
|
||||||
mqtt.subscribe(ap.config.mqttSubscribeTopic);
|
|
||||||
mqtt.onMessage(mqttMessageReceived);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify everyone we're here!
|
|
||||||
sendMqttData("Connected!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqttMessageReceived(String &topic, String &payload)
|
void mqttMessageReceived(String &topic, String &payload)
|
||||||
@@ -235,7 +235,7 @@ void readHanPort()
|
|||||||
|
|
||||||
hanToJson(data, ap.config.meterType, hanReader);
|
hanToJson(data, ap.config.meterType, hanReader);
|
||||||
|
|
||||||
if(ap.config.mqtt != 0 && strlen(ap.config.mqtt) != 0 && ap.config.mqttPublishTopic != 0 && strlen(ap.config.mqttPublishTopic) != 0) {
|
if(ap.config.mqttHost != 0 && strlen(ap.config.mqttHost) != 0 && ap.config.mqttPublishTopic != 0 && strlen(ap.config.mqttPublishTopic) != 0) {
|
||||||
// Write the json to the debug port
|
// Write the json to the debug port
|
||||||
if (debugger) {
|
if (debugger) {
|
||||||
debugger->print("Sending data to MQTT: ");
|
debugger->print("Sending data to MQTT: ");
|
||||||
@@ -257,11 +257,7 @@ void readHanPort()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WiFi_connect() {
|
||||||
// Function to connect and reconnect as necessary to the MQTT server.
|
|
||||||
// Should be called in the loop function and it will take care if connecting.
|
|
||||||
void MQTT_connect()
|
|
||||||
{
|
|
||||||
// Connect to WiFi access point.
|
// Connect to WiFi access point.
|
||||||
if (debugger)
|
if (debugger)
|
||||||
{
|
{
|
||||||
@@ -305,13 +301,20 @@ void MQTT_connect()
|
|||||||
debugger->println("WiFi connected");
|
debugger->println("WiFi connected");
|
||||||
debugger->println("IP address: ");
|
debugger->println("IP address: ");
|
||||||
debugger->println(WiFi.localIP());
|
debugger->println(WiFi.localIP());
|
||||||
debugger->print("\nconnecting to MQTT: ");
|
}
|
||||||
debugger->print(ap.config.mqtt);
|
}
|
||||||
|
|
||||||
|
// Function to connect and reconnect as necessary to the MQTT server.
|
||||||
|
// Should be called in the loop function and it will take care if connecting.
|
||||||
|
void MQTT_connect()
|
||||||
|
{
|
||||||
|
if(debugger) {
|
||||||
|
debugger->print("Connecting to MQTT: ");
|
||||||
|
debugger->print(ap.config.mqttHost);
|
||||||
debugger->print(", port: ");
|
debugger->print(", port: ");
|
||||||
debugger->print(ap.config.mqttPort);
|
debugger->print(ap.config.mqttPort);
|
||||||
debugger->println();
|
debugger->println();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for the MQTT connection to complete
|
// Wait for the MQTT connection to complete
|
||||||
while (!mqtt.connected()) {
|
while (!mqtt.connected()) {
|
||||||
// Connect to a unsecure or secure MQTT server
|
// Connect to a unsecure or secure MQTT server
|
||||||
|
|||||||
@@ -4,9 +4,7 @@
|
|||||||
#include "root/index_html.h"
|
#include "root/index_html.h"
|
||||||
#include "root/configuration_html.h"
|
#include "root/configuration_html.h"
|
||||||
#include "root/boot_css.h"
|
#include "root/boot_css.h"
|
||||||
#include "root/application_css.h"
|
|
||||||
#include "root/gaugemeter_js.h"
|
#include "root/gaugemeter_js.h"
|
||||||
#include "root/index_js.h"
|
|
||||||
|
|
||||||
#include "Base64.h"
|
#include "Base64.h"
|
||||||
|
|
||||||
@@ -23,9 +21,7 @@ void AmsWebServer::setup(configuration* config, Stream* debugger) {
|
|||||||
server.on("/", std::bind(&AmsWebServer::indexHtml, this));
|
server.on("/", std::bind(&AmsWebServer::indexHtml, this));
|
||||||
server.on("/configuration", std::bind(&AmsWebServer::configurationHtml, this));
|
server.on("/configuration", std::bind(&AmsWebServer::configurationHtml, this));
|
||||||
server.on("/boot.css", std::bind(&AmsWebServer::bootCss, this));
|
server.on("/boot.css", std::bind(&AmsWebServer::bootCss, this));
|
||||||
server.on("/application.css", std::bind(&AmsWebServer::applicationCss, this));
|
|
||||||
server.on("/gaugemeter.js", std::bind(&AmsWebServer::gaugemeterJs, this));
|
server.on("/gaugemeter.js", std::bind(&AmsWebServer::gaugemeterJs, this));
|
||||||
server.on("/index.js", std::bind(&AmsWebServer::indexJs, this));
|
|
||||||
server.on("/data.json", std::bind(&AmsWebServer::dataJson, this));
|
server.on("/data.json", std::bind(&AmsWebServer::dataJson, this));
|
||||||
|
|
||||||
server.on("/save", std::bind(&AmsWebServer::handleSave, this));
|
server.on("/save", std::bind(&AmsWebServer::handleSave, this));
|
||||||
@@ -158,7 +154,8 @@ void AmsWebServer::configurationHtml() {
|
|||||||
for(int i = 0; i<4; i++) {
|
for(int i = 0; i<4; i++) {
|
||||||
html.replace("${config.meterType" + String(i) + "}", config->meterType == i ? "selected" : "");
|
html.replace("${config.meterType" + String(i) + "}", config->meterType == i ? "selected" : "");
|
||||||
}
|
}
|
||||||
html.replace("${config.mqtt}", config->mqtt);
|
html.replace("${config.mqtt}", config->mqttHost == 0 ? "" : "checked");
|
||||||
|
html.replace("${config.mqttHost}", config->mqttHost);
|
||||||
html.replace("${config.mqttPort}", String(config->mqttPort));
|
html.replace("${config.mqttPort}", String(config->mqttPort));
|
||||||
html.replace("${config.mqttClientID}", config->mqttClientID);
|
html.replace("${config.mqttClientID}", config->mqttClientID);
|
||||||
html.replace("${config.mqttPublishTopic}", config->mqttPublishTopic);
|
html.replace("${config.mqttPublishTopic}", config->mqttPublishTopic);
|
||||||
@@ -186,6 +183,7 @@ void AmsWebServer::configurationHtml() {
|
|||||||
html.replace("${config.meterType" + String(i) + "}", i == 0 ? "selected" : "");
|
html.replace("${config.meterType" + String(i) + "}", i == 0 ? "selected" : "");
|
||||||
}
|
}
|
||||||
html.replace("${config.mqtt}", "");
|
html.replace("${config.mqtt}", "");
|
||||||
|
html.replace("${config.mqttHost}", "");
|
||||||
html.replace("${config.mqttPort}", "1883");
|
html.replace("${config.mqttPort}", "1883");
|
||||||
html.replace("${config.mqttClientID}", "");
|
html.replace("${config.mqttClientID}", "");
|
||||||
html.replace("${config.mqttPublishTopic}", "");
|
html.replace("${config.mqttPublishTopic}", "");
|
||||||
@@ -218,15 +216,6 @@ void AmsWebServer::bootCss() {
|
|||||||
server.send(200, "text/css", BOOT_CSS);
|
server.send(200, "text/css", BOOT_CSS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AmsWebServer::applicationCss() {
|
|
||||||
println("Serving /application.css over http...");
|
|
||||||
|
|
||||||
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
||||||
server.sendHeader("Pragma", "no-cache");
|
|
||||||
server.sendHeader("Expires", "-1");
|
|
||||||
server.send(200, "text/css", APPLICATION_CSS);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AmsWebServer::gaugemeterJs() {
|
void AmsWebServer::gaugemeterJs() {
|
||||||
println("Serving /gaugemeter.js over http...");
|
println("Serving /gaugemeter.js over http...");
|
||||||
|
|
||||||
@@ -236,15 +225,6 @@ void AmsWebServer::gaugemeterJs() {
|
|||||||
server.send(200, "application/javascript", GAUGEMETER_JS);
|
server.send(200, "application/javascript", GAUGEMETER_JS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AmsWebServer::indexJs() {
|
|
||||||
println("Serving /index.js over http...");
|
|
||||||
|
|
||||||
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
||||||
server.sendHeader("Pragma", "no-cache");
|
|
||||||
server.sendHeader("Expires", "-1");
|
|
||||||
server.send(200, "application/javascript", INDEX_JS);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AmsWebServer::dataJson() {
|
void AmsWebServer::dataJson() {
|
||||||
println("Serving /data.json over http...");
|
println("Serving /data.json over http...");
|
||||||
|
|
||||||
@@ -258,9 +238,9 @@ void AmsWebServer::dataJson() {
|
|||||||
int maxPwr = this->maxPwr;
|
int maxPwr = this->maxPwr;
|
||||||
if(maxPwr == 0) {
|
if(maxPwr == 0) {
|
||||||
if(u2 > 0) {
|
if(u2 > 0) {
|
||||||
maxPwr = 25000;
|
maxPwr = 20000;
|
||||||
} else {
|
} else {
|
||||||
maxPwr = 15000;
|
maxPwr = 10000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,41 +274,51 @@ void AmsWebServer::handleSave() {
|
|||||||
|
|
||||||
config->meterType = (byte)server.arg("meterType").toInt();
|
config->meterType = (byte)server.arg("meterType").toInt();
|
||||||
|
|
||||||
temp = server.arg("mqtt");
|
if(server.hasArg("mqtt") && server.arg("mqtt") == "true") {
|
||||||
config->mqtt = new char[temp.length() + 1];
|
println("MQTT enabled");
|
||||||
temp.toCharArray(config->mqtt, temp.length() + 1, 0);
|
temp = server.arg("mqttHost");
|
||||||
|
config->mqttHost = new char[temp.length() + 1];
|
||||||
|
temp.toCharArray(config->mqttHost, temp.length() + 1, 0);
|
||||||
|
|
||||||
config->mqttPort = (int)server.arg("mqttPort").toInt();
|
config->mqttPort = (int)server.arg("mqttPort").toInt();
|
||||||
|
|
||||||
temp = server.arg("mqttClientID");
|
temp = server.arg("mqttClientID");
|
||||||
config->mqttClientID = new char[temp.length() + 1];
|
config->mqttClientID = new char[temp.length() + 1];
|
||||||
temp.toCharArray(config->mqttClientID, temp.length() + 1, 0);
|
temp.toCharArray(config->mqttClientID, temp.length() + 1, 0);
|
||||||
|
|
||||||
temp = server.arg("mqttPublishTopic");
|
temp = server.arg("mqttPublishTopic");
|
||||||
config->mqttPublishTopic = new char[temp.length() + 1];
|
config->mqttPublishTopic = new char[temp.length() + 1];
|
||||||
temp.toCharArray(config->mqttPublishTopic, temp.length() + 1, 0);
|
temp.toCharArray(config->mqttPublishTopic, temp.length() + 1, 0);
|
||||||
|
|
||||||
temp = server.arg("mqttSubscribeTopic");
|
temp = server.arg("mqttSubscribeTopic");
|
||||||
config->mqttSubscribeTopic = new char[temp.length() + 1];
|
config->mqttSubscribeTopic = new char[temp.length() + 1];
|
||||||
temp.toCharArray(config->mqttSubscribeTopic, temp.length() + 1, 0);
|
temp.toCharArray(config->mqttSubscribeTopic, temp.length() + 1, 0);
|
||||||
|
|
||||||
temp = server.arg("mqttUser");
|
temp = server.arg("mqttUser");
|
||||||
config->mqttUser = new char[temp.length() + 1];
|
config->mqttUser = new char[temp.length() + 1];
|
||||||
temp.toCharArray(config->mqttUser, temp.length() + 1, 0);
|
temp.toCharArray(config->mqttUser, temp.length() + 1, 0);
|
||||||
|
|
||||||
temp = server.arg("mqttPass");
|
temp = server.arg("mqttPass");
|
||||||
config->mqttPass = new char[temp.length() + 1];
|
config->mqttPass = new char[temp.length() + 1];
|
||||||
temp.toCharArray(config->mqttPass, temp.length() + 1, 0);
|
temp.toCharArray(config->mqttPass, temp.length() + 1, 0);
|
||||||
|
} else {
|
||||||
|
println("MQTT disabled");
|
||||||
|
config->mqttHost = NULL;
|
||||||
|
config->mqttUser = NULL;
|
||||||
|
config->mqttPass = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
config->authSecurity = (byte)server.arg("authSecurity").toInt();
|
config->authSecurity = (byte)server.arg("authSecurity").toInt();
|
||||||
|
|
||||||
temp = server.arg("authUser");
|
if(config->authSecurity > 0) {
|
||||||
config->authUser = new char[temp.length() + 1];
|
temp = server.arg("authUser");
|
||||||
temp.toCharArray(config->authUser, temp.length() + 1, 0);
|
config->authUser = new char[temp.length() + 1];
|
||||||
|
temp.toCharArray(config->authUser, temp.length() + 1, 0);
|
||||||
|
|
||||||
temp = server.arg("authPass");
|
temp = server.arg("authPass");
|
||||||
config->authPass = new char[temp.length() + 1];
|
config->authPass = new char[temp.length() + 1];
|
||||||
temp.toCharArray(config->authPass, temp.length() + 1, 0);
|
temp.toCharArray(config->authPass, temp.length() + 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
config->fuseSize = (int)server.arg("fuseSize").toInt();
|
config->fuseSize = (int)server.arg("fuseSize").toInt();
|
||||||
|
|
||||||
|
|||||||
@@ -45,9 +45,7 @@ private:
|
|||||||
void indexHtml();
|
void indexHtml();
|
||||||
void configurationHtml();
|
void configurationHtml();
|
||||||
void bootCss();
|
void bootCss();
|
||||||
void applicationCss();
|
|
||||||
void gaugemeterJs();
|
void gaugemeterJs();
|
||||||
void indexJs();
|
|
||||||
void dataJson();
|
void dataJson();
|
||||||
|
|
||||||
void handleSave();
|
void handleSave();
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
.bg-purple {
|
|
||||||
background-color: var(--purple);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.GaugeMeter {
|
|
||||||
position: Relative;
|
|
||||||
text-align: Center;
|
|
||||||
overflow: Hidden;
|
|
||||||
cursor: Default;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.GaugeMeter SPAN, .GaugeMeter B {
|
|
||||||
width: 54%;
|
|
||||||
position: Absolute;
|
|
||||||
text-align: Center;
|
|
||||||
display: Inline-Block;
|
|
||||||
color: RGBa(0,0,0,.8);
|
|
||||||
font-weight: 100;
|
|
||||||
font-family: "Open Sans", Arial;
|
|
||||||
overflow: Hidden;
|
|
||||||
white-space: NoWrap;
|
|
||||||
text-overflow: Ellipsis;
|
|
||||||
margin: 0 23%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.GaugeMeter[data-style="Semi"] B {
|
|
||||||
width: 80%;
|
|
||||||
margin: 0 10%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.GaugeMeter S, .GaugeMeter U {
|
|
||||||
text-decoration: None;
|
|
||||||
font-size: .60em;
|
|
||||||
font-weight: 200;
|
|
||||||
opacity: .6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.GaugeMeter B {
|
|
||||||
color: #000;
|
|
||||||
font-weight: 200;
|
|
||||||
opacity: .8;
|
|
||||||
}
|
|
||||||
@@ -236,6 +236,10 @@ a {
|
|||||||
border-radius: .25rem;
|
border-radius: .25rem;
|
||||||
transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
|
transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
|
||||||
}
|
}
|
||||||
|
.form-control:disabled, .form-control[readonly] {
|
||||||
|
background-color: #e9ecef;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
input:not([type="image" i]) {
|
input:not([type="image" i]) {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,12 @@
|
|||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<link rel="stylesheet" type="text/css" href="boot.css"/>
|
<link rel="stylesheet" type="text/css" href="boot.css"/>
|
||||||
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.css"/>
|
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.css"/>
|
||||||
<link rel="stylesheet" type="text/css" href="application.css"/>
|
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
|
||||||
|
<style>
|
||||||
|
.bg-purple {
|
||||||
|
background-color: var(--purple);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-light">
|
<body class="bg-light">
|
||||||
<main role="main" class="container">
|
<main role="main" class="container">
|
||||||
@@ -75,40 +80,46 @@
|
|||||||
<div class="col-md-6 col-lg-4">
|
<div class="col-md-6 col-lg-4">
|
||||||
<div class="my-2 p-3 bg-white rounded shadow">
|
<div class="my-2 p-3 bg-white rounded shadow">
|
||||||
<h6 class="border-bottom border-gray pb-2 mb-4">MQTT</h6>
|
<h6 class="border-bottom border-gray pb-2 mb-4">MQTT</h6>
|
||||||
|
<div class="row form-group">
|
||||||
|
<label class="col-4">Enable</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<input id="mqttEnable" type="checkbox" name="mqtt" value="true" ${config.mqtt}/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row form-group">
|
<div class="row form-group">
|
||||||
<label class="col-4">Hostname</label>
|
<label class="col-4">Hostname</label>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<input type="text" class="form-control" name="mqtt" value="${config.mqtt}"/>
|
<input type="text" class="form-control mqtt-config" name="mqttHost" value="${config.mqttHost}"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row form-group">
|
<div class="row form-group">
|
||||||
<label class="col-4">Port</label>
|
<label class="col-4">Port</label>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<input type="text" class="form-control" name="mqttPort" value="${config.mqttPort}"/>
|
<input type="text" class="form-control mqtt-config" name="mqttPort" value="${config.mqttPort}"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row form-group">
|
<div class="row form-group">
|
||||||
<label class="col-4">Client ID</label>
|
<label class="col-4">Client ID</label>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<input type="text" class="form-control" name="mqttClientID" value="${config.mqttClientID}"/>
|
<input type="text" class="form-control mqtt-config" name="mqttClientID" value="${config.mqttClientID}"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row form-group">
|
<div class="row form-group">
|
||||||
<label class="col-4">Topic</label>
|
<label class="col-4">Topic</label>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<input type="text" class="form-control" name="mqttPublishTopic" value="${config.mqttPublishTopic}"/>
|
<input type="text" class="form-control mqtt-config" name="mqttPublishTopic" value="${config.mqttPublishTopic}"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row form-group">
|
<div class="row form-group">
|
||||||
<label class="col-4">Username</label>
|
<label class="col-4">Username</label>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<input type="text" class="form-control" name="mqttUser" value="${config.mqttUser}"/>
|
<input type="text" class="form-control mqtt-config" name="mqttUser" value="${config.mqttUser}"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row form-group">
|
<div class="row form-group">
|
||||||
<label class="col-4">Password</label>
|
<label class="col-4">Password</label>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<input type="password" class="form-control" name="mqttPass" value="${config.mqttPass}"/>
|
<input type="password" class="form-control mqtt-config" name="mqttPass" value="${config.mqttPass}"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -119,7 +130,7 @@
|
|||||||
<div class="row form-group">
|
<div class="row form-group">
|
||||||
<label class="col-4">Security</label>
|
<label class="col-4">Security</label>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<select class="form-control" name="authSecurity">
|
<select id="authSecurity" class="form-control" name="authSecurity">
|
||||||
<option value="0" ${config.authSecurity0}>None</option>
|
<option value="0" ${config.authSecurity0}>None</option>
|
||||||
<option value="1" ${config.authSecurity1}>Only configuration</option>
|
<option value="1" ${config.authSecurity1}>Only configuration</option>
|
||||||
<option value="2" ${config.authSecurity2}>Everything</option>
|
<option value="2" ${config.authSecurity2}>Everything</option>
|
||||||
@@ -129,13 +140,13 @@
|
|||||||
<div class="row form-group">
|
<div class="row form-group">
|
||||||
<label class="col-4">Username</label>
|
<label class="col-4">Username</label>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<input type="text" class="form-control" name="authUser" value="${config.authUser}"/>
|
<input type="text" class="form-control auth-config" name="authUser" value="${config.authUser}"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row form-group">
|
<div class="row form-group">
|
||||||
<label class="col-4">Password</label>
|
<label class="col-4">Password</label>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<input type="password" class="form-control" name="authPass" value="${config.authPass}"/>
|
<input type="password" class="form-control auth-config" name="authPass" value="${config.authPass}"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -152,5 +163,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</main>
|
</main>
|
||||||
|
<script>
|
||||||
|
$('#mqttEnable').on('change', function() {
|
||||||
|
var inputs = $('.mqtt-config');
|
||||||
|
inputs.prop('disabled', !$(this).is(':checked'));
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#authSecurity').on('change', function() {
|
||||||
|
var inputs = $('.auth-config');
|
||||||
|
inputs.prop('disabled', $(this).val() == 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
$('#mqttEnable').trigger('change');
|
||||||
|
$('#authSecurity').trigger('change');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
126
web/index.html
126
web/index.html
@@ -6,9 +6,53 @@
|
|||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<link rel="stylesheet" type="text/css" href="boot.css"/>
|
<link rel="stylesheet" type="text/css" href="boot.css"/>
|
||||||
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.css"/>
|
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.css"/>
|
||||||
<link rel="stylesheet" type="text/css" href="application.css"/>
|
|
||||||
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
|
||||||
<script src="gaugemeter.js"></script>
|
<script src="gaugemeter.js"></script>
|
||||||
|
<style>
|
||||||
|
.bg-purple {
|
||||||
|
background-color: var(--purple);
|
||||||
|
}
|
||||||
|
|
||||||
|
.GaugeMeter {
|
||||||
|
position: Relative;
|
||||||
|
text-align: Center;
|
||||||
|
overflow: Hidden;
|
||||||
|
cursor: Default;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.GaugeMeter SPAN, .GaugeMeter B {
|
||||||
|
width: 54%;
|
||||||
|
position: Absolute;
|
||||||
|
text-align: Center;
|
||||||
|
display: Inline-Block;
|
||||||
|
color: RGBa(0,0,0,.8);
|
||||||
|
font-weight: 100;
|
||||||
|
font-family: "Open Sans", Arial;
|
||||||
|
overflow: Hidden;
|
||||||
|
white-space: NoWrap;
|
||||||
|
text-overflow: Ellipsis;
|
||||||
|
margin: 0 23%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.GaugeMeter[data-style="Semi"] B {
|
||||||
|
width: 80%;
|
||||||
|
margin: 0 10%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.GaugeMeter S, .GaugeMeter U {
|
||||||
|
text-decoration: None;
|
||||||
|
font-size: .60em;
|
||||||
|
font-weight: 200;
|
||||||
|
opacity: .6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.GaugeMeter B {
|
||||||
|
color: #000;
|
||||||
|
font-weight: 200;
|
||||||
|
opacity: .8;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-light">
|
<body class="bg-light">
|
||||||
<main role="main" class="container">
|
<main role="main" class="container">
|
||||||
@@ -72,6 +116,84 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
<script src="index.js"></script>
|
<script>
|
||||||
|
$(".GaugeMeter").gaugeMeter();
|
||||||
|
|
||||||
|
var wait = 500;
|
||||||
|
var nextrefresh = wait;
|
||||||
|
var fetch = function() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/data.json',
|
||||||
|
dataType: 'json',
|
||||||
|
}).done(function(json) {
|
||||||
|
$(".SimpleMeter").hide();
|
||||||
|
var el = $(".GaugeMeter");
|
||||||
|
el.show();
|
||||||
|
var rate = 2500;
|
||||||
|
if(json.data) {
|
||||||
|
el.data('percent', json.pct);
|
||||||
|
if(json.data.P) {
|
||||||
|
var num = parseFloat(json.data.P);
|
||||||
|
if(num > 1000) {
|
||||||
|
num = num / 1000;
|
||||||
|
el.data('text', num.toFixed(1));
|
||||||
|
el.data('append','kW');
|
||||||
|
} else {
|
||||||
|
el.data('text', num);
|
||||||
|
el.data('append','W');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
el.gaugeMeter();
|
||||||
|
|
||||||
|
for(var id in json.data) {
|
||||||
|
var str = json.data[id];
|
||||||
|
if(isNaN(str)) {
|
||||||
|
$('#'+id).html(str);
|
||||||
|
} else {
|
||||||
|
var num = parseFloat(str);
|
||||||
|
$('#'+id).html(num.toFixed(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(json.data.U1 > 0) {
|
||||||
|
$('#P1').show();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(json.data.U2 > 0) {
|
||||||
|
$('#P2').show();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(json.data.U3 > 0) {
|
||||||
|
$('#P3').show();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(json.meterType == 3) {
|
||||||
|
rate = 10000;
|
||||||
|
}
|
||||||
|
if(json.currentMillis && json.up) {
|
||||||
|
nextrefresh = rate - ((json.currentMillis - json.up) % rate) + wait;
|
||||||
|
} else {
|
||||||
|
nextrefresh = 2500;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
el.data('percent', 0);
|
||||||
|
el.data('text', '-');
|
||||||
|
el.gaugeMeter();
|
||||||
|
nextrefresh = 2500;
|
||||||
|
}
|
||||||
|
if(!nextrefresh || nextrefresh < 500) {
|
||||||
|
nextrefresh = 2500;
|
||||||
|
}
|
||||||
|
setTimeout(fetch, nextrefresh);
|
||||||
|
}).fail(function() {
|
||||||
|
el.data('percent', 0);
|
||||||
|
el.data('text', '-');
|
||||||
|
el.gaugeMeter();
|
||||||
|
nextrefresh = 10000;
|
||||||
|
setTimeout(fetch, nextrefresh);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
setTimeout(fetch, nextrefresh);
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
77
web/index.js
77
web/index.js
@@ -1,77 +0,0 @@
|
|||||||
$(".GaugeMeter").gaugeMeter();
|
|
||||||
|
|
||||||
var wait = 500;
|
|
||||||
var nextrefresh = wait;
|
|
||||||
var fetch = function() {
|
|
||||||
$.ajax({
|
|
||||||
url: '/data.json',
|
|
||||||
dataType: 'json',
|
|
||||||
}).done(function(json) {
|
|
||||||
$(".SimpleMeter").hide();
|
|
||||||
var el = $(".GaugeMeter");
|
|
||||||
el.show();
|
|
||||||
var rate = 2500;
|
|
||||||
if(json.data) {
|
|
||||||
el.data('percent', json.pct);
|
|
||||||
if(json.data.P) {
|
|
||||||
var num = parseFloat(json.data.P);
|
|
||||||
if(num > 1000) {
|
|
||||||
num = num / 1000;
|
|
||||||
el.data('text', num.toFixed(1));
|
|
||||||
el.data('append','kW');
|
|
||||||
} else {
|
|
||||||
el.data('text', num);
|
|
||||||
el.data('append','W');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
el.gaugeMeter();
|
|
||||||
|
|
||||||
for(var id in json.data) {
|
|
||||||
var str = json.data[id];
|
|
||||||
if(isNaN(str)) {
|
|
||||||
$('#'+id).html(str);
|
|
||||||
} else {
|
|
||||||
var num = parseFloat(str);
|
|
||||||
$('#'+id).html(num.toFixed(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(json.data.U1 > 0) {
|
|
||||||
$('#P1').show();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(json.data.U2 > 0) {
|
|
||||||
$('#P2').show();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(json.data.U3 > 0) {
|
|
||||||
$('#P3').show();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(json.meterType == 3) {
|
|
||||||
rate = 10000;
|
|
||||||
}
|
|
||||||
if(json.currentMillis && json.up) {
|
|
||||||
nextrefresh = rate - ((json.currentMillis - json.up) % rate) + wait;
|
|
||||||
} else {
|
|
||||||
nextrefresh = 2500;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
el.data('percent', 0);
|
|
||||||
el.data('text', '-');
|
|
||||||
el.gaugeMeter();
|
|
||||||
nextrefresh = 2500;
|
|
||||||
}
|
|
||||||
if(!nextrefresh || nextrefresh < 500) {
|
|
||||||
nextrefresh = 2500;
|
|
||||||
}
|
|
||||||
setTimeout(fetch, nextrefresh);
|
|
||||||
}).fail(function() {
|
|
||||||
el.data('percent', 0);
|
|
||||||
el.data('text', '-');
|
|
||||||
el.gaugeMeter();
|
|
||||||
nextrefresh = 10000;
|
|
||||||
setTimeout(fetch, nextrefresh);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
setTimeout(fetch, nextrefresh);
|
|
||||||
Reference in New Issue
Block a user