mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-10 07:26:38 +02:00
* webinterface refactored completely
This commit is contained in:
parent
3c8a4c49a1
commit
74f053a5ae
12 changed files with 481 additions and 137 deletions
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
#include "html/h/hoymiles_html.h"
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +12,6 @@
|
||||||
app::app() {
|
app::app() {
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::app"));
|
DPRINTLN(DBG_VERBOSE, F("app::app"));
|
||||||
mDns = new DNSServer();
|
mDns = new DNSServer();
|
||||||
//mWeb = new ESP8266WebServer(80);
|
|
||||||
mUdp = new WiFiUDP();
|
mUdp = new WiFiUDP();
|
||||||
mEep = new eep();
|
mEep = new eep();
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
@ -28,12 +26,6 @@ app::app() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
app::~app(void) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::setup(uint32_t timeout) {
|
void app::setup(uint32_t timeout) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::setup"));
|
DPRINTLN(DBG_VERBOSE, F("app::setup"));
|
||||||
|
@ -46,15 +38,6 @@ void app::setup(uint32_t timeout) {
|
||||||
#ifndef AP_ONLY
|
#ifndef AP_ONLY
|
||||||
if(false == apActive)
|
if(false == apActive)
|
||||||
apActive = setupStation(mWifiStationTimeout);
|
apActive = setupStation(mWifiStationTimeout);
|
||||||
#endif
|
|
||||||
|
|
||||||
/*mWeb->on("/cmdstat", std::bind(&app::showStatistics, this));
|
|
||||||
mWeb->on("/hoymiles", std::bind(&app::showHoymiles, this));
|
|
||||||
mWeb->on("/livedata", std::bind(&app::showLiveData, this));
|
|
||||||
mWeb->on("/json", std::bind(&app::showJSON, this));
|
|
||||||
mWeb->on("/api",HTTP_POST, std::bind(&app::webapi, this));*/
|
|
||||||
|
|
||||||
#ifndef AP_ONLY
|
|
||||||
setupMqtt();
|
setupMqtt();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -569,10 +552,26 @@ void app::cbMqtt(char* topic, byte* payload, unsigned int length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/*void app::webapi(void) { // ToDo
|
||||||
|
DPRINTLN(DBG_VERBOSE, F("app::api"));
|
||||||
|
const size_t capacity = 200; // Use arduinojson.org/assistant to compute the capacity.
|
||||||
|
DynamicJsonDocument payload(capacity);
|
||||||
|
|
||||||
|
// Parse JSON object
|
||||||
|
deserializeJson(payload, mWeb->arg("plain"));
|
||||||
|
// ToDo: error handling for payload
|
||||||
|
if (payload["tx_request"] == TX_REQ_INFO){
|
||||||
|
mSys->InfoCmd = payload["cmd"];
|
||||||
|
DPRINTLN(DBG_INFO, F("Will make tx-request 0x15 with subcmd ") + String(mSys->InfoCmd));
|
||||||
|
}
|
||||||
|
mWeb->send ( 200, "text/json", "{success:true}" );
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/*void app::showStatistics(void) {
|
String app::getStatistics(void) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::showStatistics"));
|
|
||||||
String content = F("Receive success: ") + String(mRxSuccess) + "\n";
|
String content = F("Receive success: ") + String(mRxSuccess) + "\n";
|
||||||
content += F("Receive fail: ") + String(mRxFailed) + "\n";
|
content += F("Receive fail: ") + String(mRxFailed) + "\n";
|
||||||
content += F("Frames received: ") + String(mFrameCnt) + "\n";
|
content += F("Frames received: ") + String(mFrameCnt) + "\n";
|
||||||
|
@ -617,43 +616,13 @@ void app::cbMqtt(char* topic, byte* payload, unsigned int length) {
|
||||||
content += F("not ");
|
content += F("not ");
|
||||||
content += F("connected\n");
|
content += F("connected\n");
|
||||||
|
|
||||||
mWeb->send(200, F("text/plain"), content);
|
return content;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/*void app::webapi(void) { // ToDo
|
String app::getLiveData(void) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::api"));
|
|
||||||
DPRINTLN(DBG_DEBUG, mWeb->arg("plain"));
|
|
||||||
const size_t capacity = 200; // Use arduinojson.org/assistant to compute the capacity.
|
|
||||||
DynamicJsonDocument payload(capacity);
|
|
||||||
|
|
||||||
// Parse JSON object
|
|
||||||
deserializeJson(payload, mWeb->arg("plain"));
|
|
||||||
// ToDo: error handling for payload
|
|
||||||
if (payload["tx_request"] == TX_REQ_INFO){
|
|
||||||
mSys->InfoCmd = payload["cmd"];
|
|
||||||
DPRINTLN(DBG_INFO, F("Will make tx-request 0x15 with subcmd ") + String(mSys->InfoCmd));
|
|
||||||
}
|
|
||||||
mWeb->send ( 200, "text/json", "{success:true}" );
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
/*void app::showHoymiles(void) {
|
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::showHoymiles"));
|
|
||||||
String html = FPSTR(hoymiles_html);
|
|
||||||
html.replace(F("{DEVICE}"), mSysConfig.deviceName);
|
|
||||||
html.replace(F("{VERSION}"), version);
|
|
||||||
html.replace(F("{TS}"), String(config.sendInterval) + " ");
|
|
||||||
html.replace(F("{JS_TS}"), String(config.sendInterval * 1000));
|
|
||||||
mWeb->send(200, F("text/html"), html);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
/*void app::showLiveData(void) {
|
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::showLiveData"));
|
|
||||||
String modHtml;
|
String modHtml;
|
||||||
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||||
Inverter<> *iv = mSys->getInverterByPos(id);
|
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||||
|
@ -723,13 +692,13 @@ void app::cbMqtt(char* topic, byte* payload, unsigned int length) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mWeb->send(200, F("text/html"), modHtml);
|
return modHtml;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/*void app::showJSON(void) {
|
String app::getJson(void) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::showJSON"));
|
DPRINTLN(DBG_VERBOSE, F("app::showJson"));
|
||||||
String modJson;
|
String modJson;
|
||||||
|
|
||||||
modJson = F("{\n");
|
modJson = F("{\n");
|
||||||
|
@ -749,12 +718,11 @@ void app::cbMqtt(char* topic, byte* payload, unsigned int length) {
|
||||||
}
|
}
|
||||||
modJson += F("\"json_ts\": \"") + String(getDateTimeStr(mTimestamp)) + F("\"\n}\n");
|
modJson += F("\"json_ts\": \"") + String(getDateTimeStr(mTimestamp)) + F("\"\n}\n");
|
||||||
|
|
||||||
// mWeb->send(200, F("text/json"), modJson);
|
return modJson;
|
||||||
mWeb->send(200, F("application/json"), modJson); // the preferred content-type (https://stackoverflow.com/questions/22406077/what-is-the-exact-difference-between-content-type-text-json-and-application-jso)
|
}
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
void app::sendMqttDiscoveryConfig(void) {
|
void app::sendMqttDiscoveryConfig(void) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::sendMqttDiscoveryConfig"));
|
DPRINTLN(DBG_VERBOSE, F("app::sendMqttDiscoveryConfig"));
|
||||||
|
|
||||||
|
@ -808,6 +776,8 @@ void app::sendMqttDiscoveryConfig(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
const char* app::getFieldDeviceClass(uint8_t fieldId) {
|
const char* app::getFieldDeviceClass(uint8_t fieldId) {
|
||||||
uint8_t pos = 0;
|
uint8_t pos = 0;
|
||||||
for(; pos < DEVICE_CLS_ASSIGN_LIST_LEN; pos++) {
|
for(; pos < DEVICE_CLS_ASSIGN_LIST_LEN; pos++) {
|
||||||
|
@ -817,6 +787,8 @@ const char* app::getFieldDeviceClass(uint8_t fieldId) {
|
||||||
return (pos >= DEVICE_CLS_ASSIGN_LIST_LEN) ? NULL : deviceClasses[deviceFieldAssignment[pos].deviceClsId];
|
return (pos >= DEVICE_CLS_ASSIGN_LIST_LEN) ? NULL : deviceClasses[deviceFieldAssignment[pos].deviceClsId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
const char* app::getFieldStateClass(uint8_t fieldId) {
|
const char* app::getFieldStateClass(uint8_t fieldId) {
|
||||||
uint8_t pos = 0;
|
uint8_t pos = 0;
|
||||||
for(; pos < DEVICE_CLS_ASSIGN_LIST_LEN; pos++) {
|
for(; pos < DEVICE_CLS_ASSIGN_LIST_LEN; pos++) {
|
||||||
|
@ -954,6 +926,10 @@ void app::loadDefaultConfig(void) {
|
||||||
// nrf24
|
// nrf24
|
||||||
mConfig.sendInterval = SEND_INTERVAL;
|
mConfig.sendInterval = SEND_INTERVAL;
|
||||||
mConfig.maxRetransPerPyld = DEF_MAX_RETRANS_PER_PYLD;
|
mConfig.maxRetransPerPyld = DEF_MAX_RETRANS_PER_PYLD;
|
||||||
|
mConfig.pinCs = DEF_RF24_CS_PIN;
|
||||||
|
mConfig.pinCe = DEF_RF24_CE_PIN;
|
||||||
|
mConfig.pinIrq = DEF_RF24_IRQ_PIN;
|
||||||
|
mConfig.amplifierPower = DEF_AMPLIFIERPOWER & 0x03;
|
||||||
|
|
||||||
// ntp
|
// ntp
|
||||||
snprintf(mConfig.ntpAddr, NTP_ADDR_LEN, "%s", NTP_SERVER_NAME);
|
snprintf(mConfig.ntpAddr, NTP_ADDR_LEN, "%s", NTP_SERVER_NAME);
|
||||||
|
@ -968,7 +944,7 @@ void app::loadDefaultConfig(void) {
|
||||||
|
|
||||||
// serial
|
// serial
|
||||||
mConfig.serialInterval = SERIAL_INTERVAL;
|
mConfig.serialInterval = SERIAL_INTERVAL;
|
||||||
mConfig.serialShowIv = true;
|
mConfig.serialShowIv = false;
|
||||||
mConfig.serialDebug = false;
|
mConfig.serialDebug = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1082,7 +1058,6 @@ void app::saveValues(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
time_t app::getNtpTime(void) {
|
time_t app::getNtpTime(void) {
|
||||||
//DPRINTLN(DBG_VERBOSE, F("app::getNtpTime"));
|
//DPRINTLN(DBG_VERBOSE, F("app::getNtpTime"));
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
// #define __MQTT_NO_DISCOVERCONFIG__ // das versenden der MQTTDiscoveryConfig abschalten ( gehört eigentlich ins Setup )
|
// #define __MQTT_NO_DISCOVERCONFIG__ // das versenden der MQTTDiscoveryConfig abschalten ( gehört eigentlich ins Setup )
|
||||||
|
|
||||||
typedef CircularBuffer<packet_t, PACKET_BUFFER_SIZE> BufferType;
|
typedef CircularBuffer<packet_t, PACKET_BUFFER_SIZE> BufferType;
|
||||||
typedef HmRadio<RF24_CE_PIN, RF24_CS_PIN, BufferType> RadioType;
|
typedef HmRadio<DEF_RF24_CE_PIN, DEF_RF24_CS_PIN, BufferType> RadioType;
|
||||||
typedef Inverter<float> InverterType;
|
typedef Inverter<float> InverterType;
|
||||||
typedef HmSystem<RadioType, BufferType, MAX_NUM_INVERTERS, InverterType> HmSystemType;
|
typedef HmSystem<RadioType, BufferType, MAX_NUM_INVERTERS, InverterType> HmSystemType;
|
||||||
|
|
||||||
|
@ -72,13 +72,16 @@ class web;
|
||||||
class app {
|
class app {
|
||||||
public:
|
public:
|
||||||
app();
|
app();
|
||||||
~app();
|
~app() {}
|
||||||
|
|
||||||
void setup(uint32_t timeout);
|
void setup(uint32_t timeout);
|
||||||
void loop(void);
|
void loop(void);
|
||||||
void handleIntr(void);
|
void handleIntr(void);
|
||||||
void cbMqtt(char* topic, byte* payload, unsigned int length);
|
void cbMqtt(char* topic, byte* payload, unsigned int length);
|
||||||
void saveValues(void);
|
void saveValues(void);
|
||||||
|
String getStatistics(void);
|
||||||
|
String getLiveData(void);
|
||||||
|
String getJson(void);
|
||||||
|
|
||||||
uint8_t getIrqPin(void) {
|
uint8_t getIrqPin(void) {
|
||||||
return mConfig.pinIrq;
|
return mConfig.pinIrq;
|
||||||
|
|
|
@ -31,6 +31,14 @@
|
||||||
// default device name
|
// default device name
|
||||||
#define DEF_DEVICE_NAME "AHOY-DTU"
|
#define DEF_DEVICE_NAME "AHOY-DTU"
|
||||||
|
|
||||||
|
// default pinout
|
||||||
|
#define DEF_RF24_CS_PIN 15
|
||||||
|
#define DEF_RF24_CE_PIN 2
|
||||||
|
#define DEF_RF24_IRQ_PIN 0
|
||||||
|
|
||||||
|
// default NRF24 power, possible values (0 - 3)
|
||||||
|
#define DEF_AMPLIFIERPOWER 2
|
||||||
|
|
||||||
// number of packets hold in buffer
|
// number of packets hold in buffer
|
||||||
#define PACKET_BUFFER_SIZE 30
|
#define PACKET_BUFFER_SIZE 30
|
||||||
|
|
||||||
|
@ -43,9 +51,6 @@
|
||||||
// default send interval
|
// default send interval
|
||||||
#define SEND_INTERVAL 30
|
#define SEND_INTERVAL 30
|
||||||
|
|
||||||
// default mqtt interval
|
|
||||||
#define MQTT_INTERVAL 60
|
|
||||||
|
|
||||||
// maximum human readable inverter name length
|
// maximum human readable inverter name length
|
||||||
#define MAX_NAME_LENGTH 16
|
#define MAX_NAME_LENGTH 16
|
||||||
|
|
||||||
|
@ -64,15 +69,15 @@
|
||||||
// threshold of minimum power on which the inverter is marked as inactive
|
// threshold of minimum power on which the inverter is marked as inactive
|
||||||
#define INACT_PWR_THRESH 3
|
#define INACT_PWR_THRESH 3
|
||||||
|
|
||||||
// changes the style of "/setup" page, visualized = nicer
|
|
||||||
#define LIVEDATA_VISUALIZED
|
|
||||||
|
|
||||||
// default ntp server uri
|
// default ntp server uri
|
||||||
#define NTP_SERVER_NAME "pool.ntp.org"
|
#define NTP_SERVER_NAME "pool.ntp.org"
|
||||||
|
|
||||||
// default ntp server port
|
// default ntp server port
|
||||||
#define NTP_LOCAL_PORT 8888
|
#define NTP_LOCAL_PORT 8888
|
||||||
|
|
||||||
|
// default mqtt interval
|
||||||
|
#define MQTT_INTERVAL 60
|
||||||
|
|
||||||
// default MQTT broker uri
|
// default MQTT broker uri
|
||||||
#define DEF_MQTT_BROKER "\0"
|
#define DEF_MQTT_BROKER "\0"
|
||||||
|
|
||||||
|
@ -88,4 +93,7 @@
|
||||||
// default MQTT topic
|
// default MQTT topic
|
||||||
#define DEF_MQTT_TOPIC "inverter"
|
#define DEF_MQTT_TOPIC "inverter"
|
||||||
|
|
||||||
|
// changes the style of "/setup" page, visualized = nicer
|
||||||
|
#define LIVEDATA_VISUALIZED
|
||||||
|
|
||||||
#endif /*__CONFIG_H__*/
|
#endif /*__CONFIG_H__*/
|
||||||
|
|
|
@ -8,21 +8,12 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
//-------------------------------------
|
|
||||||
// PINOUT (Default, can be changed in setup)
|
|
||||||
//-------------------------------------
|
|
||||||
#define RF24_CS_PIN 15
|
|
||||||
#define RF24_CE_PIN 2
|
|
||||||
#define RF24_IRQ_PIN 0
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
// VERSION
|
// VERSION
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 5
|
#define VERSION_MINOR 5
|
||||||
#define VERSION_PATCH 10
|
#define VERSION_PATCH 11
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
|
@ -111,44 +102,7 @@ typedef enum {
|
||||||
#define SER_DEBUG_LEN 1 // uint8_t
|
#define SER_DEBUG_LEN 1 // uint8_t
|
||||||
#define SER_INTERVAL_LEN 2 // uint16_t
|
#define SER_INTERVAL_LEN 2 // uint16_t
|
||||||
|
|
||||||
/*
|
|
||||||
#define ADDR_START 0
|
|
||||||
#define ADDR_SSID ADDR_START
|
|
||||||
#define ADDR_PWD ADDR_SSID + SSID_LEN
|
|
||||||
#define ADDR_DEVNAME ADDR_PWD + PWD_LEN
|
|
||||||
#define ADDR_WIFI_CRC ADDR_DEVNAME + DEVNAME_LEN
|
|
||||||
#define ADDR_START_SETTINGS ADDR_WIFI_CRC + CRC_LEN
|
|
||||||
|
|
||||||
#define ADDR_PINOUT ADDR_START_SETTINGS
|
|
||||||
|
|
||||||
#define ADDR_RF24_AMP_PWR ADDR_PINOUT + PINOUT_LEN
|
|
||||||
|
|
||||||
#define ADDR_INV_ADDR ADDR_RF24_AMP_PWR + RF24_AMP_PWR_LEN
|
|
||||||
#define ADDR_INV_NAME ADDR_INV_ADDR + INV_ADDR_LEN
|
|
||||||
#define ADDR_INV_CH_PWR ADDR_INV_NAME + INV_NAME_LEN
|
|
||||||
#define ADDR_INV_CH_NAME ADDR_INV_CH_PWR + INV_CH_CH_PWR_LEN
|
|
||||||
#define ADDR_INV_INTERVAL ADDR_INV_CH_NAME + INV_CH_CH_NAME_LEN
|
|
||||||
#define ADDR_INV_MAX_RTRY ADDR_INV_INTERVAL + INV_INTERVAL_LEN
|
|
||||||
#define ADDR_INV_PWR_LIM ADDR_INV_MAX_RTRY + INV_MAX_RTRY_LEN
|
|
||||||
|
|
||||||
#define ADDR_NTP_ADDR ADDR_INV_PWR_LIM + INV_PWR_LIM_LEN //Bugfix #125
|
|
||||||
#define ADDR_NTP_PORT ADDR_NTP_ADDR + NTP_ADDR_LEN
|
|
||||||
|
|
||||||
#define ADDR_MQTT_ADDR ADDR_NTP_PORT + NTP_PORT_LEN
|
|
||||||
#define ADDR_MQTT_USER ADDR_MQTT_ADDR + MQTT_ADDR_LEN
|
|
||||||
#define ADDR_MQTT_PWD ADDR_MQTT_USER + MQTT_USER_LEN
|
|
||||||
#define ADDR_MQTT_TOPIC ADDR_MQTT_PWD + MQTT_PWD_LEN
|
|
||||||
#define ADDR_MQTT_INTERVAL ADDR_MQTT_TOPIC + MQTT_TOPIC_LEN
|
|
||||||
#define ADDR_MQTT_PORT ADDR_MQTT_INTERVAL + MQTT_INTERVAL_LEN
|
|
||||||
|
|
||||||
#define ADDR_SER_ENABLE ADDR_MQTT_PORT + MQTT_PORT_LEN
|
|
||||||
#define ADDR_SER_DEBUG ADDR_SER_ENABLE + SER_ENABLE_LEN
|
|
||||||
#define ADDR_SER_INTERVAL ADDR_SER_DEBUG + SER_DEBUG_LEN
|
|
||||||
#define ADDR_NEXT ADDR_SER_INTERVAL + SER_INTERVAL_LEN
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char broker[MQTT_ADDR_LEN];
|
char broker[MQTT_ADDR_LEN];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
|
@ -187,7 +141,7 @@ typedef struct {
|
||||||
bool serialDebug;
|
bool serialDebug;
|
||||||
} config_t;
|
} config_t;
|
||||||
|
|
||||||
// eeprom new
|
|
||||||
#define CFG_MQTT_LEN MQTT_ADDR_LEN + 2 + MQTT_USER_LEN + MQTT_PWD_LEN +MQTT_TOPIC_LEN
|
#define CFG_MQTT_LEN MQTT_ADDR_LEN + 2 + MQTT_USER_LEN + MQTT_PWD_LEN +MQTT_TOPIC_LEN
|
||||||
#define CFG_SYS_LEN DEVNAME_LEN + SSID_LEN + PWD_LEN + 1
|
#define CFG_SYS_LEN DEVNAME_LEN + SSID_LEN + PWD_LEN + 1
|
||||||
#define CFG_LEN 7 + NTP_ADDR_LEN + 2 + CFG_MQTT_LEN + 4
|
#define CFG_LEN 7 + NTP_ADDR_LEN + 2 + CFG_MQTT_LEN + 4
|
||||||
|
|
|
@ -34,5 +34,5 @@ def convert2Header(inFile):
|
||||||
|
|
||||||
convert2Header("index.html")
|
convert2Header("index.html")
|
||||||
convert2Header("setup.html")
|
convert2Header("setup.html")
|
||||||
convert2Header("hoymiles.html")
|
convert2Header("visualization.html")
|
||||||
convert2Header("style.css")
|
convert2Header("style.css")
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
#ifndef __HOYMILES_HTML_H__
|
|
||||||
#define __HOYMILES_HTML_H__
|
|
||||||
const char hoymiles_html[] PROGMEM = "<!doctype html><html><head><title>Index - {DEVICE}</title><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><script type=\"text/javascript\">getAjax('/livedata', 'livedata');window.setInterval(\"getAjax('/livedata', 'livedata')\", {JS_TS});function getAjax(url, resid) {var http = null;http = new XMLHttpRequest();if(http != null) {http.open(\"GET\", url, true);http.onreadystatechange = print;http.send(null);}function print() {if(http.readyState == 4) {document.getElementById(resid).innerHTML = http.responseText;}}}</script><style type=\"text/css\"></style></head><body><h1>AHOY - {DEVICE}</h1><div id=\"content\" class=\"content\"><div id=\"livedata\"></div><p>Every {TS}seconds the values are updated</p></div><div id=\"footer\"><p class=\"left\">© 2022</p><p class=\"left\"><a href=\"/\">Home</a></p><p class=\"right\">AHOY :: {VERSION}</p></div></body></html>";
|
|
||||||
#endif /*__HOYMILES_HTML_H__*/
|
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __INDEX_HTML_H__
|
#ifndef __INDEX_HTML_H__
|
||||||
#define __INDEX_HTML_H__
|
#define __INDEX_HTML_H__
|
||||||
const char index_html[] PROGMEM = "<!doctype html><html><head><title>Index - {DEVICE}</title><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><script type=\"text/javascript\">getAjax('/uptime', 'uptime');getAjax('/time', 'time');getAjax('/cmdstat', 'cmds');window.setInterval(\"getAjax('/uptime', 'uptime')\", {JS_TS});window.setInterval(\"getAjax('/time', 'time')\", {JS_TS});window.setInterval(\"getAjax('/cmdstat', 'cmds')\", {JS_TS});function getAjax(url, resid) {var http = null;http = new XMLHttpRequest();if(http != null) {http.open(\"GET\", url, true);http.onreadystatechange = print;http.send(null);}function print() {if(http.readyState == 4) {document.getElementById(resid).innerHTML = http.responseText;}}}</script></head><body><h1>AHOY - {DEVICE}</h1><div id=\"content\" class=\"content\"><p><a href=\"/hoymiles\">Visualization</a><br/><br/><a href=\"/setup\">Setup</a><br/></p><p><span class=\"des\">Uptime: </span><span id=\"uptime\"></span></p><p><span class=\"des\">Time: </span><span id=\"time\"></span></p><p><span class=\"des\">Statistics: </span><pre id=\"cmds\"></pre></p><p>Every {TS}seconds the values are updated</p><div id=\"note\">This project was started from <a href=\"https://www.mikrocontroller.net/topic/525778\" target=\"_blank\">this discussion. (Mikrocontroller.net)</a><br/>New updates can be found on Github: <a href=\"https://github.com/grindylow/ahoy\" target=\"_blank\">https://github.com/grindylow/ahoy</a><br/><br/>Please report issues using the feature provided by <a href=\"https://github.com/grindylow/ahoy/issues\">Github</a><br/><br/>Discuss with us on <a href=\"https://discord.gg/WzhxEY62mB\">Discord</a><br/><p class=\"lic\"><a href=\"https://creativecommons.org/licenses/by-nc-sa/3.0/de\">Creative Commons - https://creativecommons.org/licenses/by-nc-sa/3.0/de/</a><br/>Check the licenses which are published on <a href=\"https://github.com/grindylow/ahoy\">https://github.com/grindylow/ahoy</a>as well</p></div></div><div id=\"footer\"><p class=\"left\">© 2022</p><p class=\"left\"><a href=\"/update\">Update Firmware</a></p><p class=\"right\">AHOY :: {VERSION}</p><p class=\"right\"><a href=\"/reboot\">Reboot</a></p><p class=\"right\">Git SHA: {BUILD}</p></div></body></html>";
|
const char index_html[] PROGMEM = "<!doctype html><html><head><title>Index - {DEVICE}</title><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><script type=\"text/javascript\">getAjax('/uptime', 'uptime');getAjax('/cmdstat', 'cmds');window.setInterval(\"getAjax('/uptime', 'uptime')\", {JS_TS});window.setInterval(\"getAjax('/cmdstat', 'cmds')\", {JS_TS});function getAjax(url, resid) {var http = null;http = new XMLHttpRequest();if(http != null) {http.open(\"GET\", url, true);http.onreadystatechange = print;http.send(null);}function print() {if(http.readyState == 4) {document.getElementById(resid).innerHTML = http.responseText;}}}</script></head><body><h1>AHOY - {DEVICE}</h1><div id=\"content\" class=\"content\"><p><a href=\"/visualization\">Visualization</a><br/><br/><a href=\"/setup\">Setup</a><br/></p><p><span class=\"des\">Uptime: </span><span id=\"uptime\"></span></p><p><span class=\"des\">Statistics: </span><pre id=\"cmds\"></pre></p><p>Every {TS}seconds the values are updated</p><div id=\"note\">This project was started from <a href=\"https://www.mikrocontroller.net/topic/525778\" target=\"_blank\">this discussion. (Mikrocontroller.net)</a><br/>New updates can be found on Github: <a href=\"https://github.com/grindylow/ahoy\" target=\"_blank\">https://github.com/grindylow/ahoy</a><br/><br/>Please report issues using the feature provided by <a href=\"https://github.com/grindylow/ahoy/issues\">Github</a><br/><br/>Discuss with us on <a href=\"https://discord.gg/WzhxEY62mB\">Discord</a><br/><p class=\"lic\"><a href=\"https://creativecommons.org/licenses/by-nc-sa/3.0/de\">Creative Commons - https://creativecommons.org/licenses/by-nc-sa/3.0/de/</a><br/>Check the licenses which are published on <a href=\"https://github.com/grindylow/ahoy\">https://github.com/grindylow/ahoy</a>as well</p></div></div><div id=\"footer\"><p class=\"left\">© 2022</p><p class=\"left\"><a href=\"/update\">Update Firmware</a></p><p class=\"right\">AHOY :: {VERSION}</p><p class=\"right\"><a href=\"/reboot\">Reboot</a></p><p class=\"right\">Git SHA: {BUILD}</p></div></body></html>";
|
||||||
#endif /*__INDEX_HTML_H__*/
|
#endif /*__INDEX_HTML_H__*/
|
||||||
|
|
4
tools/esp8266/html/h/visualization_html.h
Normal file
4
tools/esp8266/html/h/visualization_html.h
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#ifndef __VISUALIZATION_HTML_H__
|
||||||
|
#define __VISUALIZATION_HTML_H__
|
||||||
|
const char visualization_html[] PROGMEM = "<!doctype html><html><head><title>Index - {DEVICE}</title><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><script type=\"text/javascript\">getAjax('/livedata', 'livedata');window.setInterval(\"getAjax('/livedata', 'livedata')\", {JS_TS});function getAjax(url, resid) {var http = null;http = new XMLHttpRequest();if(http != null) {http.open(\"GET\", url, true);http.onreadystatechange = print;http.send(null);}function print() {if(http.readyState == 4) {document.getElementById(resid).innerHTML = http.responseText;}}}</script><style type=\"text/css\"></style></head><body><h1>AHOY - {DEVICE}</h1><div id=\"content\" class=\"content\"><div id=\"livedata\"></div><p>Every {TS}seconds the values are updated</p></div><div id=\"footer\"><p class=\"left\">© 2022</p><p class=\"left\"><a href=\"/\">Home</a></p><p class=\"right\">AHOY :: {VERSION}</p></div></body></html>";
|
||||||
|
#endif /*__VISUALIZATION_HTML_H__*/
|
|
@ -6,10 +6,8 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
getAjax('/uptime', 'uptime');
|
getAjax('/uptime', 'uptime');
|
||||||
getAjax('/time', 'time');
|
|
||||||
getAjax('/cmdstat', 'cmds');
|
getAjax('/cmdstat', 'cmds');
|
||||||
window.setInterval("getAjax('/uptime', 'uptime')", {JS_TS});
|
window.setInterval("getAjax('/uptime', 'uptime')", {JS_TS});
|
||||||
window.setInterval("getAjax('/time', 'time')", {JS_TS});
|
|
||||||
window.setInterval("getAjax('/cmdstat', 'cmds')", {JS_TS});
|
window.setInterval("getAjax('/cmdstat', 'cmds')", {JS_TS});
|
||||||
|
|
||||||
function getAjax(url, resid) {
|
function getAjax(url, resid) {
|
||||||
|
@ -33,12 +31,11 @@
|
||||||
<h1>AHOY - {DEVICE}</h1>
|
<h1>AHOY - {DEVICE}</h1>
|
||||||
<div id="content" class="content">
|
<div id="content" class="content">
|
||||||
<p>
|
<p>
|
||||||
<a href="/hoymiles">Visualization</a><br/>
|
<a href="/visualization">Visualization</a><br/>
|
||||||
<br/>
|
<br/>
|
||||||
<a href="/setup">Setup</a><br/>
|
<a href="/setup">Setup</a><br/>
|
||||||
</p>
|
</p>
|
||||||
<p><span class="des">Uptime: </span><span id="uptime"></span></p>
|
<p><span class="des">Uptime: </span><span id="uptime"></span></p>
|
||||||
<p><span class="des">Time: </span><span id="time"></span></p>
|
|
||||||
<p><span class="des">Statistics: </span><pre id="cmds"></pre></p>
|
<p><span class="des">Statistics: </span><pre id="cmds"></pre></p>
|
||||||
<p>Every {TS}seconds the values are updated</p>
|
<p>Every {TS}seconds the values are updated</p>
|
||||||
|
|
||||||
|
|
401
tools/esp8266/web.cpp
Normal file
401
tools/esp8266/web.cpp
Normal file
|
@ -0,0 +1,401 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778
|
||||||
|
// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "web.h"
|
||||||
|
|
||||||
|
#include "html/h/index_html.h"
|
||||||
|
#include "html/h/style_css.h"
|
||||||
|
#include "favicon.h"
|
||||||
|
#include "html/h/setup_html.h"
|
||||||
|
#include "html/h/visualization_html.h"
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
web::web(app *main, sysConfig_t *sysCfg, config_t *config, char version[]) {
|
||||||
|
mMain = main;
|
||||||
|
mSysCfg = sysCfg;
|
||||||
|
mConfig = config;
|
||||||
|
mVersion = version;
|
||||||
|
mWeb = new ESP8266WebServer(80);
|
||||||
|
mUpdater = new ESP8266HTTPUpdateServer();
|
||||||
|
mUpdater->setup(mWeb);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::setup(void) {
|
||||||
|
mWeb->begin();
|
||||||
|
mWeb->on("/", std::bind(&web::showIndex, this));
|
||||||
|
mWeb->on("/style.css", std::bind(&web::showCss, this));
|
||||||
|
mWeb->on("/favicon.ico", std::bind(&web::showFavicon, this));
|
||||||
|
mWeb->onNotFound ( std::bind(&web::showNotFound, this));
|
||||||
|
mWeb->on("/uptime", std::bind(&web::showUptime, this));
|
||||||
|
mWeb->on("/reboot", std::bind(&web::showReboot, this));
|
||||||
|
mWeb->on("/erase", std::bind(&web::showErase, this));
|
||||||
|
mWeb->on("/factory", std::bind(&web::showFactoryRst, this));
|
||||||
|
|
||||||
|
mWeb->on("/setup", std::bind(&web::showSetup, this));
|
||||||
|
mWeb->on("/save", std::bind(&web::showSave, this));
|
||||||
|
|
||||||
|
mWeb->on("/cmdstat", std::bind(&web::showStatistics, this));
|
||||||
|
mWeb->on("/visualization", std::bind(&web::showVisualization, this));
|
||||||
|
mWeb->on("/livedata", std::bind(&web::showLiveData, this));
|
||||||
|
mWeb->on("/json", std::bind(&web::showJson, this));
|
||||||
|
mWeb->on("/api", HTTP_POST, std::bind(&web::showWebApi, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::loop(void) {
|
||||||
|
mWeb->handleClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showIndex(void) {
|
||||||
|
DPRINTLN(DBG_VERBOSE, F("showIndex"));
|
||||||
|
String html = FPSTR(index_html);
|
||||||
|
html.replace(F("{DEVICE}"), mSysCfg->deviceName);
|
||||||
|
html.replace(F("{VERSION}"), mVersion);
|
||||||
|
html.replace(F("{TS}"), String(mConfig->sendInterval) + " ");
|
||||||
|
html.replace(F("{JS_TS}"), String(mConfig->sendInterval * 1000));
|
||||||
|
html.replace(F("{BUILD}"), String(AUTO_GIT_HASH));
|
||||||
|
mWeb->send(200, "text/html", html);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showCss(void) {
|
||||||
|
mWeb->send(200, "text/css", FPSTR(style_css));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showFavicon(void) {
|
||||||
|
static const char favicon_type[] PROGMEM = "image/x-icon";
|
||||||
|
static const char favicon_content[] PROGMEM = FAVICON_PANEL_16;
|
||||||
|
mWeb->send_P(200, favicon_type, favicon_content, sizeof(favicon_content));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showNotFound(void) {
|
||||||
|
DPRINTLN(DBG_VERBOSE, F("showNotFound - ") + mWeb->uri());
|
||||||
|
String msg = F("File Not Found\n\nURI: ");
|
||||||
|
msg += mWeb->uri();
|
||||||
|
mWeb->send(404, F("text/plain"), msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showUptime(void) {
|
||||||
|
char time[21] = {0};
|
||||||
|
uint32_t uptime = mMain->getUptime();
|
||||||
|
|
||||||
|
uint32_t upTimeSc = uint32_t((uptime) % 60);
|
||||||
|
uint32_t upTimeMn = uint32_t((uptime / (60)) % 60);
|
||||||
|
uint32_t upTimeHr = uint32_t((uptime / (60 * 60)) % 24);
|
||||||
|
uint32_t upTimeDy = uint32_t((uptime / (60 * 60 * 24)) % 365);
|
||||||
|
|
||||||
|
snprintf(time, 20, "%d Days, %02d:%02d:%02d", upTimeDy, upTimeHr, upTimeMn, upTimeSc);
|
||||||
|
|
||||||
|
mWeb->send(200, "text/plain", String(time) + "; now: " + mMain->getDateTimeStr(mMain->getTimestamp()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showReboot(void) {
|
||||||
|
mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Rebooting ...</title><meta http-equiv=\"refresh\" content=\"10; URL=/\"></head><body>rebooting ... auto reload after 10s</body></html>"));
|
||||||
|
delay(1000);
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showErase() {
|
||||||
|
DPRINTLN(DBG_VERBOSE, F("showErase"));
|
||||||
|
mMain->eraseSettings();
|
||||||
|
showReboot();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showFactoryRst(void) {
|
||||||
|
DPRINTLN(DBG_VERBOSE, F("showFactoryRst"));
|
||||||
|
String content = "";
|
||||||
|
int refresh = 3;
|
||||||
|
if(mWeb->args() > 0) {
|
||||||
|
if(mWeb->arg("reset").toInt() == 1) {
|
||||||
|
mMain->eraseSettings(true);
|
||||||
|
content = F("factory reset: success\n\nrebooting ... ");
|
||||||
|
refresh = 10;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
content = F("factory reset: aborted");
|
||||||
|
refresh = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
content = F("<h1>Factory Reset</h1>"
|
||||||
|
"<p><a href=\"/factory?reset=1\">RESET</a><br/><br/><a href=\"/factory?reset=0\">CANCEL</a><br/></p>");
|
||||||
|
refresh = 120;
|
||||||
|
}
|
||||||
|
mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Factory Reset</title><meta http-equiv=\"refresh\" content=\"") + String(refresh) + F("; URL=/\"></head><body>") + content + F("</body></html>"));
|
||||||
|
if(refresh == 10) {
|
||||||
|
delay(1000);
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showSetup(void) {
|
||||||
|
DPRINTLN(DBG_VERBOSE, F("showSetup"));
|
||||||
|
String html = FPSTR(setup_html);
|
||||||
|
html.replace(F("{SSID}"), mSysCfg->stationSsid);
|
||||||
|
// PWD will be left at the default value (for protection)
|
||||||
|
// -> the PWD will only be changed if it does not match the default "{PWD}"
|
||||||
|
html.replace(F("{DEVICE}"), String(mSysCfg->deviceName));
|
||||||
|
html.replace(F("{VERSION}"), String(mVersion));
|
||||||
|
if(mMain->apActive)
|
||||||
|
html.replace("{IP}", String(F("http://192.168.1.1")));
|
||||||
|
else
|
||||||
|
html.replace("{IP}", (F("http://") + String(WiFi.localIP().toString())));
|
||||||
|
|
||||||
|
String inv = "";
|
||||||
|
Inverter<> *iv;
|
||||||
|
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
||||||
|
iv = mMain->mSys->getInverterByPos(i);
|
||||||
|
|
||||||
|
inv += F("<p class=\"subdes\">Inverter ") + String(i) + "</p>";
|
||||||
|
inv += F("<label for=\"inv") + String(i) + F("Addr\">Address</label>");
|
||||||
|
inv += F("<input type=\"text\" class=\"text\" name=\"inv") + String(i) + F("Addr\" value=\"");
|
||||||
|
if(NULL != iv)
|
||||||
|
inv += String(iv->serial.u64, HEX);
|
||||||
|
inv += F("\"/ maxlength=\"12\" onkeyup=\"checkSerial()\">");
|
||||||
|
|
||||||
|
inv += F("<label for=\"inv") + String(i) + F("Name\">Name</label>");
|
||||||
|
inv += F("<input type=\"text\" class=\"text\" name=\"inv") + String(i) + F("Name\" value=\"");
|
||||||
|
if(NULL != iv)
|
||||||
|
inv += String(iv->name);
|
||||||
|
inv += F("\"/ maxlength=\"") + String(MAX_NAME_LENGTH) + "\">";
|
||||||
|
|
||||||
|
inv += F("<label for=\"inv") + String(i) + F("ActivePowerLimit\">Active Power Limit (W)</label>");
|
||||||
|
inv += F("<input type=\"text\" class=\"text\" name=\"inv") + String(i) + F("ActivePowerLimit\" value=\"");
|
||||||
|
if(NULL != iv)
|
||||||
|
inv += String(iv->powerLimit[0]);
|
||||||
|
inv += F("\"/ maxlength=\"") + String(6) + "\">";
|
||||||
|
|
||||||
|
inv += F("<label for=\"inv") + String(i) + F("ModPwr0\" name=\"lbl") + String(i);
|
||||||
|
inv += F("ModPwr\">Max Module Power (Wp)</label>");
|
||||||
|
for(uint8_t j = 0; j < 4; j++) {
|
||||||
|
inv += F("<input type=\"text\" class=\"text sh\" name=\"inv") + String(i) + F("ModPwr") + String(j) + F("\" value=\"");
|
||||||
|
if(NULL != iv)
|
||||||
|
inv += String(iv->chMaxPwr[j]);
|
||||||
|
inv += F("\"/ maxlength=\"4\">");
|
||||||
|
}
|
||||||
|
inv += F("<br/><label for=\"inv") + String(i) + F("ModName0\" name=\"lbl") + String(i);
|
||||||
|
inv += F("ModName\">Module Name</label>");
|
||||||
|
for(uint8_t j = 0; j < 4; j++) {
|
||||||
|
inv += F("<input type=\"text\" class=\"text sh\" name=\"inv") + String(i) + F("ModName") + String(j) + F("\" value=\"");
|
||||||
|
if(NULL != iv)
|
||||||
|
inv += String(iv->chName[j]);
|
||||||
|
inv += F("\"/ maxlength=\"") + String(MAX_NAME_LENGTH) + "\">";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
html.replace(F("{INVERTERS}"), String(inv));
|
||||||
|
|
||||||
|
|
||||||
|
// pinout
|
||||||
|
String pinout;
|
||||||
|
for(uint8_t i = 0; i < 3; i++) {
|
||||||
|
pinout += F("<label for=\"") + String(pinArgNames[i]) + "\">" + String(pinNames[i]) + F("</label>");
|
||||||
|
pinout += F("<select name=\"") + String(pinArgNames[i]) + "\">";
|
||||||
|
for(uint8_t j = 0; j <= 16; j++) {
|
||||||
|
pinout += F("<option value=\"") + String(j) + "\"";
|
||||||
|
switch(i) {
|
||||||
|
default: if(j == mConfig->pinCs) pinout += F(" selected"); break;
|
||||||
|
case 1: if(j == mConfig->pinCe) pinout += F(" selected"); break;
|
||||||
|
case 2: if(j == mConfig->pinIrq) pinout += F(" selected"); break;
|
||||||
|
}
|
||||||
|
pinout += ">" + String(wemosPins[j]) + F("</option>");
|
||||||
|
}
|
||||||
|
pinout += F("</select>");
|
||||||
|
}
|
||||||
|
html.replace(F("{PINOUT}"), String(pinout));
|
||||||
|
|
||||||
|
|
||||||
|
// nrf24l01+
|
||||||
|
String rf24;
|
||||||
|
for(uint8_t i = 0; i <= 3; i++) {
|
||||||
|
rf24 += F("<option value=\"") + String(i) + "\"";
|
||||||
|
if(i == mConfig->amplifierPower)
|
||||||
|
rf24 += F(" selected");
|
||||||
|
rf24 += ">" + String(rf24AmpPowerNames[i]) + F("</option>");
|
||||||
|
}
|
||||||
|
html.replace(F("{RF24}"), String(rf24));
|
||||||
|
|
||||||
|
|
||||||
|
html.replace(F("{INV_INTVL}"), String(mConfig->sendInterval));
|
||||||
|
html.replace(F("{INV_RETRIES}"), String(mConfig->maxRetransPerPyld));
|
||||||
|
|
||||||
|
html.replace(F("{SER_INTVL}"), String(mConfig->serialInterval));
|
||||||
|
html.replace(F("{SER_VAL_CB}"), (mConfig->serialShowIv) ? "checked" : "");
|
||||||
|
html.replace(F("{SER_DBG_CB}"), (mConfig->serialDebug) ? "checked" : "");
|
||||||
|
|
||||||
|
html.replace(F("{NTP_ADDR}"), String(mConfig->ntpAddr));
|
||||||
|
html.replace(F("{NTP_PORT}"), String(mConfig->ntpPort));
|
||||||
|
|
||||||
|
html.replace(F("{MQTT_ADDR}"), String(mConfig->mqtt.broker));
|
||||||
|
html.replace(F("{MQTT_PORT}"), String(mConfig->mqtt.port));
|
||||||
|
html.replace(F("{MQTT_USER}"), String(mConfig->mqtt.user));
|
||||||
|
html.replace(F("{MQTT_PWD}"), String(mConfig->mqtt.pwd));
|
||||||
|
html.replace(F("{MQTT_TOPIC}"), String(mConfig->mqtt.topic));
|
||||||
|
html.replace(F("{MQTT_INTVL}"), String("0"));
|
||||||
|
|
||||||
|
mWeb->send(200, F("text/html"), html);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showSave(void) {
|
||||||
|
DPRINTLN(DBG_VERBOSE, F("showSave"));
|
||||||
|
|
||||||
|
if(mWeb->args() > 0) {
|
||||||
|
char buf[20] = {0};
|
||||||
|
|
||||||
|
// general
|
||||||
|
if(mWeb->arg("ssid") != "")
|
||||||
|
mWeb->arg("ssid").toCharArray(mSysCfg->stationSsid, SSID_LEN);
|
||||||
|
if(mWeb->arg("pwd") != "{PWD}")
|
||||||
|
mWeb->arg("pwd").toCharArray(mSysCfg->stationPwd, PWD_LEN);
|
||||||
|
if(mWeb->arg("device") != "")
|
||||||
|
mWeb->arg("device").toCharArray(mSysCfg->deviceName, DEVNAME_LEN);
|
||||||
|
|
||||||
|
// inverter
|
||||||
|
Inverter<> *iv;
|
||||||
|
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
||||||
|
iv = mMain->mSys->getInverterByPos(i, false);
|
||||||
|
// address
|
||||||
|
mWeb->arg("inv" + String(i) + "Addr").toCharArray(buf, 20);
|
||||||
|
if(strlen(buf) == 0)
|
||||||
|
memset(buf, 0, 20);
|
||||||
|
iv->serial.u64 = mMain->Serial2u64(buf);
|
||||||
|
|
||||||
|
// active power limit
|
||||||
|
uint16_t actPwrLimit = mWeb->arg("inv" + String(i) + "ActivePowerLimit").toInt();
|
||||||
|
if (actPwrLimit != 0xffff && actPwrLimit > 0)
|
||||||
|
iv->powerLimit[0] = actPwrLimit;
|
||||||
|
|
||||||
|
// name
|
||||||
|
mWeb->arg("inv" + String(i) + "Name").toCharArray(iv->name, MAX_NAME_LENGTH);
|
||||||
|
|
||||||
|
// max channel power / name
|
||||||
|
for(uint8_t j = 0; j < 4; j++) {
|
||||||
|
iv->chMaxPwr[j] = mWeb->arg("inv" + String(i) + "ModPwr" + String(j)).toInt() & 0xffff;
|
||||||
|
mWeb->arg("inv" + String(i) + "ModName" + String(j)).toCharArray(iv->chName[j], MAX_NAME_LENGTH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(mWeb->arg("invInterval") != "")
|
||||||
|
mConfig->sendInterval = mWeb->arg("invInterval").toInt();
|
||||||
|
if(mWeb->arg("invRetry") != "")
|
||||||
|
mConfig->sendInterval = mWeb->arg("invRetry").toInt();
|
||||||
|
|
||||||
|
// pinout
|
||||||
|
uint8_t pin;
|
||||||
|
for(uint8_t i = 0; i < 3; i ++) {
|
||||||
|
pin = mWeb->arg(String(pinArgNames[i])).toInt();
|
||||||
|
switch(i) {
|
||||||
|
default: mConfig->pinCs = pin; break;
|
||||||
|
case 1: mConfig->pinCe = pin; break;
|
||||||
|
case 2: mConfig->pinIrq = pin; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// nrf24 amplifier power
|
||||||
|
mConfig->amplifierPower = mWeb->arg("rf24Power").toInt() & 0x03;
|
||||||
|
|
||||||
|
// ntp
|
||||||
|
if(mWeb->arg("ntpAddr") != "") {
|
||||||
|
mWeb->arg("ntpAddr").toCharArray(mConfig->ntpAddr, NTP_ADDR_LEN);
|
||||||
|
mConfig->ntpPort = mWeb->arg("ntpPort").toInt() & 0xffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
// mqtt
|
||||||
|
if(mWeb->arg("mqttAddr") != "") {
|
||||||
|
mWeb->arg("mqttAddr").toCharArray(mConfig->mqtt.broker, MQTT_ADDR_LEN);
|
||||||
|
mWeb->arg("mqttUser").toCharArray(mConfig->mqtt.user, MQTT_USER_LEN);
|
||||||
|
mWeb->arg("mqttPwd").toCharArray(mConfig->mqtt.pwd, MQTT_PWD_LEN);
|
||||||
|
mWeb->arg("mqttTopic").toCharArray(mConfig->mqtt.topic, MQTT_TOPIC_LEN);
|
||||||
|
mConfig->mqtt.port = mWeb->arg("mqttPort").toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
// serial console
|
||||||
|
if(mWeb->arg("serIntvl") != "") {
|
||||||
|
mConfig->serialInterval = mWeb->arg("serIntvl").toInt() & 0xffff;
|
||||||
|
|
||||||
|
mConfig->serialDebug = (mWeb->arg("serEn") == "on");
|
||||||
|
mConfig->serialShowIv = (mWeb->arg("serDbg") == "on");
|
||||||
|
}
|
||||||
|
|
||||||
|
mMain->saveValues();
|
||||||
|
|
||||||
|
if(mWeb->arg("reboot") == "on")
|
||||||
|
showReboot();
|
||||||
|
else
|
||||||
|
mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Setup saved</title><meta http-equiv=\"refresh\" content=\"0; URL=/setup\"></head><body>"
|
||||||
|
"<p>saved</p></body></html>"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showStatistics(void) {
|
||||||
|
DPRINTLN(DBG_VERBOSE, F("web::showStatistics"));
|
||||||
|
mWeb->send(200, F("text/plain"), mMain->getStatistics());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showVisualization(void) {
|
||||||
|
DPRINTLN(DBG_VERBOSE, F("web::showVisualization"));
|
||||||
|
String html = FPSTR(visualization_html);
|
||||||
|
html.replace(F("{DEVICE}"), mSysCfg->deviceName);
|
||||||
|
html.replace(F("{VERSION}"), mVersion);
|
||||||
|
html.replace(F("{TS}"), String(mConfig->sendInterval) + " ");
|
||||||
|
html.replace(F("{JS_TS}"), String(mConfig->sendInterval * 1000));
|
||||||
|
mWeb->send(200, F("text/html"), html);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showLiveData(void) {
|
||||||
|
DPRINTLN(DBG_VERBOSE, F("web::showLiveData"));
|
||||||
|
mWeb->send(200, F("text/html"), mMain->getLiveData());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showJson(void) {
|
||||||
|
DPRINTLN(DBG_VERBOSE, F("web::showJson"));
|
||||||
|
mWeb->send(200, F("application/json"), mMain->getJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void web::showWebApi(void) {
|
||||||
|
DPRINTLN(DBG_VERBOSE, F("web::showWebApi"));
|
||||||
|
DPRINTLN(DBG_DEBUG, mWeb->arg("plain"));
|
||||||
|
const size_t capacity = 200; // Use arduinojson.org/assistant to compute the capacity.
|
||||||
|
DynamicJsonDocument payload(capacity);
|
||||||
|
|
||||||
|
// Parse JSON object
|
||||||
|
deserializeJson(payload, mWeb->arg("plain"));
|
||||||
|
// ToDo: error handling for payload
|
||||||
|
if (payload["tx_request"] == TX_REQ_INFO) {
|
||||||
|
mMain->mSys->InfoCmd = payload["cmd"];
|
||||||
|
DPRINTLN(DBG_INFO, F("Will make tx-request 0x15 with subcmd ") + String(mMain->mSys->InfoCmd));
|
||||||
|
}
|
||||||
|
mWeb->send ( 200, "text/json", "{success:true}" );
|
||||||
|
}
|
|
@ -33,6 +33,12 @@ class web {
|
||||||
void showSetup(void);
|
void showSetup(void);
|
||||||
void showSave(void);
|
void showSave(void);
|
||||||
|
|
||||||
|
void showStatistics(void);
|
||||||
|
void showVisualization(void);
|
||||||
|
void showLiveData(void);
|
||||||
|
void showJson(void);
|
||||||
|
void showWebApi(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ESP8266WebServer *mWeb;
|
ESP8266WebServer *mWeb;
|
||||||
ESP8266HTTPUpdateServer *mUpdater;
|
ESP8266HTTPUpdateServer *mUpdater;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue