mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-10 23:46:37 +02:00
* first refactored version which is accessible through web interface
This commit is contained in:
parent
15402dbd99
commit
3c8a4c49a1
5 changed files with 123 additions and 409 deletions
|
@ -13,11 +13,14 @@
|
||||||
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);
|
//mWeb = new ESP8266WebServer(80);
|
||||||
mUdp = new WiFiUDP();
|
mUdp = new WiFiUDP();
|
||||||
mEep = new eep();
|
mEep = new eep();
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
mWebInst = new web(this, &mSysConfig, &mConfig, mVersion);
|
||||||
|
mWebInst->setup();
|
||||||
|
|
||||||
resetSystem();
|
resetSystem();
|
||||||
loadDefaultConfig();
|
loadDefaultConfig();
|
||||||
|
|
||||||
|
@ -41,31 +44,34 @@ void app::setup(uint32_t timeout) {
|
||||||
loadEEpconfig();
|
loadEEpconfig();
|
||||||
|
|
||||||
#ifndef AP_ONLY
|
#ifndef AP_ONLY
|
||||||
if(false == sysConfig.apActive)
|
if(false == apActive)
|
||||||
sysConfig.apActive = setupStation(mWifiStationTimeout);
|
apActive = setupStation(mWifiStationTimeout);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//mWeb->on("/setup", std::bind(&app::showSetup, this));
|
/*mWeb->on("/cmdstat", std::bind(&app::showStatistics, this));
|
||||||
//mWeb->on("/save", std::bind(&app::showSave, this));
|
|
||||||
mWeb->on("/cmdstat", std::bind(&app::showStatistics, this));
|
|
||||||
mWeb->on("/hoymiles", std::bind(&app::showHoymiles, this));
|
mWeb->on("/hoymiles", std::bind(&app::showHoymiles, this));
|
||||||
mWeb->on("/livedata", std::bind(&app::showLiveData, this));
|
mWeb->on("/livedata", std::bind(&app::showLiveData, this));
|
||||||
mWeb->on("/json", std::bind(&app::showJSON, this));
|
mWeb->on("/json", std::bind(&app::showJSON, this));
|
||||||
mWeb->on("/api",HTTP_POST, std::bind(&app::webapi, this));
|
mWeb->on("/api",HTTP_POST, std::bind(&app::webapi, this));*/
|
||||||
|
|
||||||
#ifndef AP_ONLY
|
#ifndef AP_ONLY
|
||||||
setupMqtt();
|
setupMqtt();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mSys->setup(&config);
|
mSys->setup(&mConfig);
|
||||||
|
|
||||||
if(!mWifiSettingsValid)
|
if(!mWifiSettingsValid) {
|
||||||
DPRINTLN(DBG_WARN, F("your settings are not valid! check [IP]/setup"));
|
DPRINTLN(DBG_WARN, F("your settings are not valid! check [IP]/setup"));
|
||||||
|
apActive = true;
|
||||||
|
mApLastTick = millis();
|
||||||
|
mNextTryTs = (millis() + (WIFI_AP_ACTIVE_TIME * 1000));
|
||||||
|
setupAp(WIFI_AP_SSID, WIFI_AP_PWD);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
DPRINTLN(DBG_INFO, F("\n\n----------------------------------------"));
|
DPRINTLN(DBG_INFO, F("\n\n----------------------------------------"));
|
||||||
DPRINTLN(DBG_INFO, F("Welcome to AHOY!"));
|
DPRINTLN(DBG_INFO, F("Welcome to AHOY!"));
|
||||||
DPRINT(DBG_INFO, F("\npoint your browser to http://"));
|
DPRINT(DBG_INFO, F("\npoint your browser to http://"));
|
||||||
if(sysConfig.apActive)
|
if(apActive)
|
||||||
DBGPRINTLN(F("192.168.1.1"));
|
DBGPRINTLN(F("192.168.1.1"));
|
||||||
else
|
else
|
||||||
DBGPRINTLN(WiFi.localIP());
|
DBGPRINTLN(WiFi.localIP());
|
||||||
|
@ -78,12 +84,12 @@ void app::setup(uint32_t timeout) {
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::MainLoop(void) {
|
void app::MainLoop(void) {
|
||||||
//DPRINTLN(DBG_VERBOSE, F("M"));
|
//DPRINTLN(DBG_VERBOSE, F("M"));
|
||||||
if(sysConfig.apActive) {
|
if(apActive) {
|
||||||
mDns->processNextRequest();
|
mDns->processNextRequest();
|
||||||
#ifndef AP_ONLY
|
#ifndef AP_ONLY
|
||||||
if(checkTicker(&mNextTryTs, (WIFI_AP_ACTIVE_TIME * 1000))) {
|
if(checkTicker(&mNextTryTs, (WIFI_AP_ACTIVE_TIME * 1000))) {
|
||||||
sysConfig.apActive = setupStation(mWifiStationTimeout);
|
apActive = setupStation(mWifiStationTimeout);
|
||||||
if(sysConfig.apActive) {
|
if(apActive) {
|
||||||
if(strlen(WIFI_AP_PWD) < 8)
|
if(strlen(WIFI_AP_PWD) < 8)
|
||||||
DPRINTLN(DBG_ERROR, F("password must be at least 8 characters long"));
|
DPRINTLN(DBG_ERROR, F("password must be at least 8 characters long"));
|
||||||
mApLastTick = millis();
|
mApLastTick = millis();
|
||||||
|
@ -95,7 +101,7 @@ void app::MainLoop(void) {
|
||||||
if(millis() - mApLastTick > 10000) {
|
if(millis() - mApLastTick > 10000) {
|
||||||
uint8_t cnt = WiFi.softAPgetStationNum();
|
uint8_t cnt = WiFi.softAPgetStationNum();
|
||||||
if(cnt > 0) {
|
if(cnt > 0) {
|
||||||
DPRINTLN(DBG_INFO, String(cnt) + F(" clients connected, resetting AP timeout"));
|
DPRINTLN(DBG_INFO, String(cnt) + F(" client connected, resetting AP timeout"));
|
||||||
mNextTryTs = (millis() + (WIFI_AP_ACTIVE_TIME * 1000));
|
mNextTryTs = (millis() + (WIFI_AP_ACTIVE_TIME * 1000));
|
||||||
}
|
}
|
||||||
mApLastTick = millis();
|
mApLastTick = millis();
|
||||||
|
@ -104,27 +110,25 @@ void app::MainLoop(void) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
mWeb->handleClient();
|
|
||||||
|
mWebInst->loop();
|
||||||
|
|
||||||
if(checkTicker(&mUptimeTicker, mUptimeInterval)) {
|
if(checkTicker(&mUptimeTicker, mUptimeInterval)) {
|
||||||
mUptimeSecs++;
|
mUptimeSecs++;
|
||||||
if(0 != mTimestamp)
|
if(0 != mTimestamp)
|
||||||
mTimestamp++;
|
mTimestamp++;
|
||||||
else {
|
else {
|
||||||
if(!sysConfig.apActive) {
|
if(!apActive) {
|
||||||
mTimestamp = getNtpTime();
|
mTimestamp = getNtpTime();
|
||||||
DPRINTLN(DBG_INFO, "[NTP]: " + getDateTimeStr(mTimestamp));
|
DPRINTLN(DBG_INFO, "[NTP]: " + getDateTimeStr(mTimestamp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if(++mHeapStatCnt >= 10) {
|
|
||||||
mHeapStatCnt = 0;
|
|
||||||
stats();
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if((WiFi.status() != WL_CONNECTED) && wifiWasEstablished) {
|
||||||
DPRINTLN(DBG_INFO, "[WiFi]: Connection Lost");
|
if(!apActive) {
|
||||||
setupStation(mWifiStationTimeout);
|
DPRINTLN(DBG_INFO, "[WiFi]: Connection Lost");
|
||||||
|
setupStation(mWifiStationTimeout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +144,6 @@ void app::loop(void) {
|
||||||
if(checkTicker(&mRxTicker, 5)) {
|
if(checkTicker(&mRxTicker, 5)) {
|
||||||
//DPRINTLN(DBG_VERBOSE, F("app_loops =") + String(app_loops));
|
//DPRINTLN(DBG_VERBOSE, F("app_loops =") + String(app_loops));
|
||||||
app_loops=0;
|
app_loops=0;
|
||||||
DPRINT(DBG_VERBOSE, F("a"));
|
|
||||||
|
|
||||||
bool rxRdy = mSys->Radio.switchRxCh();
|
bool rxRdy = mSys->Radio.switchRxCh();
|
||||||
|
|
||||||
|
@ -150,7 +153,7 @@ void app::loop(void) {
|
||||||
|
|
||||||
if(mSys->Radio.checkPaketCrc(p->packet, &len, p->rxCh)) {
|
if(mSys->Radio.checkPaketCrc(p->packet, &len, p->rxCh)) {
|
||||||
// process buffer only on first occurrence
|
// process buffer only on first occurrence
|
||||||
if(config.serialDebug) {
|
if(mConfig.serialDebug) {
|
||||||
DPRINT(DBG_INFO, "RX " + String(len) + "B Ch" + String(p->rxCh) + " | ");
|
DPRINT(DBG_INFO, "RX " + String(len) + "B Ch" + String(p->rxCh) + " | ");
|
||||||
mSys->Radio.dumpBuf(NULL, p->packet, len);
|
mSys->Radio.dumpBuf(NULL, p->packet, len);
|
||||||
}
|
}
|
||||||
|
@ -257,7 +260,7 @@ void app::loop(void) {
|
||||||
mMqtt.loop();
|
mMqtt.loop();
|
||||||
|
|
||||||
if(checkTicker(&mTicker, 1000)) {
|
if(checkTicker(&mTicker, 1000)) {
|
||||||
if((++mMqttTicker >= mMqttInterval) && (mMqttInterval != 0xffff)) {
|
if((++mMqttTicker >= mMqttInterval) && (mMqttInterval != 0xffff) && mMqttActive) {
|
||||||
mMqttTicker = 0;
|
mMqttTicker = 0;
|
||||||
mMqtt.isConnected(true);
|
mMqtt.isConnected(true);
|
||||||
char topic[30], val[10];
|
char topic[30], val[10];
|
||||||
|
@ -275,11 +278,11 @@ void app::loop(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
snprintf(val, 10, "%ld", millis()/1000);
|
snprintf(val, 10, "%ld", millis()/1000);
|
||||||
|
|
||||||
#ifndef __MQTT_NO_DISCOVERCONFIG__
|
#ifndef __MQTT_NO_DISCOVERCONFIG__
|
||||||
// MQTTDiscoveryConfig nur wenn nicht abgeschaltet.
|
// MQTTDiscoveryConfig nur wenn nicht abgeschaltet.
|
||||||
sendMqttDiscoveryConfig();
|
sendMqttDiscoveryConfig();
|
||||||
#endif
|
#endif
|
||||||
mMqtt.sendMsg("uptime", val);
|
mMqtt.sendMsg("uptime", val);
|
||||||
|
|
||||||
#ifdef __MQTT_TEST__
|
#ifdef __MQTT_TEST__
|
||||||
|
@ -288,8 +291,8 @@ void app::loop(void) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if(config.serialShowIv) {
|
if(mConfig.serialShowIv) {
|
||||||
if(++mSerialTicker >= config.serialInterval) {
|
if(++mSerialTicker >= mConfig.serialInterval) {
|
||||||
mSerialTicker = 0;
|
mSerialTicker = 0;
|
||||||
char topic[30], val[10];
|
char topic[30], val[10];
|
||||||
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||||
|
@ -312,15 +315,15 @@ void app::loop(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(++mSendTicker >= config.sendInterval) {
|
if(++mSendTicker >= mConfig.sendInterval) {
|
||||||
mSendTicker = 0;
|
mSendTicker = 0;
|
||||||
|
|
||||||
if(0 != mTimestamp) {
|
if(0 != mTimestamp) {
|
||||||
if(config.serialDebug)
|
if(mConfig.serialDebug)
|
||||||
DPRINTLN(DBG_DEBUG, F("Free heap: 0x") + String(ESP.getFreeHeap(), HEX));
|
DPRINTLN(DBG_DEBUG, F("Free heap: 0x") + String(ESP.getFreeHeap(), HEX));
|
||||||
|
|
||||||
if(!mSys->BufCtrl.empty()) {
|
if(!mSys->BufCtrl.empty()) {
|
||||||
if(config.serialDebug)
|
if(mConfig.serialDebug)
|
||||||
DPRINTLN(DBG_DEBUG, F("recbuf not empty! #") + String(mSys->BufCtrl.getFill()));
|
DPRINTLN(DBG_DEBUG, F("recbuf not empty! #") + String(mSys->BufCtrl.getFill()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +342,7 @@ void app::loop(void) {
|
||||||
|
|
||||||
if(!mPayload[iv->id].complete) {
|
if(!mPayload[iv->id].complete) {
|
||||||
mRxFailed++;
|
mRxFailed++;
|
||||||
if(config.serialDebug) {
|
if(mConfig.serialDebug) {
|
||||||
DPRINT(DBG_INFO, F("Inverter #") + String(iv->id) + " ");
|
DPRINT(DBG_INFO, F("Inverter #") + String(iv->id) + " ");
|
||||||
DPRINTLN(DBG_INFO, F("no Payload received! (retransmits: ") + String(mPayload[iv->id].retransmits) + ")");
|
DPRINTLN(DBG_INFO, F("no Payload received! (retransmits: ") + String(mPayload[iv->id].retransmits) + ")");
|
||||||
}
|
}
|
||||||
|
@ -354,11 +357,11 @@ void app::loop(void) {
|
||||||
mPayload[iv->id].ts = mTimestamp;
|
mPayload[iv->id].ts = mTimestamp;
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
if(config.serialDebug)
|
if(mConfig.serialDebug)
|
||||||
DPRINTLN(DBG_DEBUG, F("app:loop WiFi WiFi.status ") + String(WiFi.status()) );
|
DPRINTLN(DBG_DEBUG, F("app:loop WiFi WiFi.status ") + String(WiFi.status()) );
|
||||||
DPRINTLN(DBG_INFO, F("Requesting Inverter SN ") + String(iv->serial.u64, HEX));
|
DPRINTLN(DBG_INFO, F("Requesting Inverter SN ") + String(iv->serial.u64, HEX));
|
||||||
if(iv->devControlRequest && iv->powerLimit[0] > 0){ // prevent to "switch off"
|
if(iv->devControlRequest && iv->powerLimit[0] > 0){ // prevent to "switch off"
|
||||||
if(config.serialDebug)
|
if(mConfig.serialDebug)
|
||||||
DPRINTLN(DBG_INFO, F("Devcontrol request ") + String(iv->devControlCmd) + F(" power limit ") + String(iv->powerLimit[0]));
|
DPRINTLN(DBG_INFO, F("Devcontrol request ") + String(iv->devControlCmd) + F(" power limit ") + String(iv->powerLimit[0]));
|
||||||
mSys->Radio.sendControlPacket(iv->radioId.u64,iv->devControlCmd ,iv->powerLimit);
|
mSys->Radio.sendControlPacket(iv->radioId.u64,iv->devControlCmd ,iv->powerLimit);
|
||||||
} else {
|
} else {
|
||||||
|
@ -367,7 +370,7 @@ void app::loop(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(config.serialDebug)
|
else if(mConfig.serialDebug)
|
||||||
DPRINTLN(DBG_WARN, F("time not set, can't request inverter!"));
|
DPRINTLN(DBG_WARN, F("time not set, can't request inverter!"));
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
|
@ -422,12 +425,12 @@ void app::processPayload(bool retransmit) {
|
||||||
if(!buildPayload(iv->id)) {
|
if(!buildPayload(iv->id)) {
|
||||||
if(mPayload[iv->id].requested) {
|
if(mPayload[iv->id].requested) {
|
||||||
if(retransmit) {
|
if(retransmit) {
|
||||||
if(mPayload[iv->id].retransmits < config.maxRetransPerPyld) {
|
if(mPayload[iv->id].retransmits < mConfig.maxRetransPerPyld) {
|
||||||
mPayload[iv->id].retransmits++;
|
mPayload[iv->id].retransmits++;
|
||||||
if(mPayload[iv->id].maxPackId != 0) {
|
if(mPayload[iv->id].maxPackId != 0) {
|
||||||
for(uint8_t i = 0; i < (mPayload[iv->id].maxPackId-1); i ++) {
|
for(uint8_t i = 0; i < (mPayload[iv->id].maxPackId-1); i ++) {
|
||||||
if(mPayload[iv->id].len[i] == 0) {
|
if(mPayload[iv->id].len[i] == 0) {
|
||||||
if(config.serialDebug)
|
if(mConfig.serialDebug)
|
||||||
DPRINTLN(DBG_ERROR, F("while retrieving data: Frame ") + String(i+1) + F(" missing: Request Retransmit"));
|
DPRINTLN(DBG_ERROR, F("while retrieving data: Frame ") + String(i+1) + F(" missing: Request Retransmit"));
|
||||||
mSys->Radio.sendCmdPacket(iv->radioId.u64, TX_REQ_INFO, (SINGLE_FRAME+i), true);
|
mSys->Radio.sendCmdPacket(iv->radioId.u64, TX_REQ_INFO, (SINGLE_FRAME+i), true);
|
||||||
break; // only retransmit one frame per loop
|
break; // only retransmit one frame per loop
|
||||||
|
@ -436,7 +439,7 @@ void app::processPayload(bool retransmit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(config.serialDebug)
|
if(mConfig.serialDebug)
|
||||||
DPRINTLN(DBG_ERROR, F("while retrieving data: last frame missing: Request Retransmit"));
|
DPRINTLN(DBG_ERROR, F("while retrieving data: last frame missing: Request Retransmit"));
|
||||||
if(0x00 != mLastPacketId)
|
if(0x00 != mLastPacketId)
|
||||||
mSys->Radio.sendCmdPacket(iv->radioId.u64, TX_REQ_INFO, mLastPacketId, true);
|
mSys->Radio.sendCmdPacket(iv->radioId.u64, TX_REQ_INFO, mLastPacketId, true);
|
||||||
|
@ -459,7 +462,7 @@ void app::processPayload(bool retransmit) {
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
offs-=2;
|
offs-=2;
|
||||||
if(config.serialDebug) {
|
if(mConfig.serialDebug) {
|
||||||
DPRINT(DBG_INFO, F("Payload (") + String(offs) + "): ");
|
DPRINT(DBG_INFO, F("Payload (") + String(offs) + "): ");
|
||||||
mSys->Radio.dumpBuf(NULL, payload, offs);
|
mSys->Radio.dumpBuf(NULL, payload, offs);
|
||||||
}
|
}
|
||||||
|
@ -568,7 +571,7 @@ void app::cbMqtt(char* topic, byte* payload, unsigned int length) {
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::showStatistics(void) {
|
/*void app::showStatistics(void) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::showStatistics"));
|
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";
|
||||||
|
@ -615,10 +618,11 @@ void app::showStatistics(void) {
|
||||||
content += F("connected\n");
|
content += F("connected\n");
|
||||||
|
|
||||||
mWeb->send(200, F("text/plain"), content);
|
mWeb->send(200, F("text/plain"), content);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::webapi(void) { // ToDo
|
/*void app::webapi(void) { // ToDo
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::api"));
|
DPRINTLN(DBG_VERBOSE, F("app::api"));
|
||||||
DPRINTLN(DBG_DEBUG, mWeb->arg("plain"));
|
DPRINTLN(DBG_DEBUG, mWeb->arg("plain"));
|
||||||
const size_t capacity = 200; // Use arduinojson.org/assistant to compute the capacity.
|
const size_t capacity = 200; // Use arduinojson.org/assistant to compute the capacity.
|
||||||
|
@ -632,23 +636,23 @@ void app::webapi(void) { // ToDo
|
||||||
DPRINTLN(DBG_INFO, F("Will make tx-request 0x15 with subcmd ") + String(mSys->InfoCmd));
|
DPRINTLN(DBG_INFO, F("Will make tx-request 0x15 with subcmd ") + String(mSys->InfoCmd));
|
||||||
}
|
}
|
||||||
mWeb->send ( 200, "text/json", "{success:true}" );
|
mWeb->send ( 200, "text/json", "{success:true}" );
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::showHoymiles(void) {
|
/*void app::showHoymiles(void) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::showHoymiles"));
|
DPRINTLN(DBG_VERBOSE, F("app::showHoymiles"));
|
||||||
String html = FPSTR(hoymiles_html);
|
String html = FPSTR(hoymiles_html);
|
||||||
html.replace(F("{DEVICE}"), sysConfig.deviceName);
|
html.replace(F("{DEVICE}"), mSysConfig.deviceName);
|
||||||
html.replace(F("{VERSION}"), version);
|
html.replace(F("{VERSION}"), version);
|
||||||
html.replace(F("{TS}"), String(config.sendInterval) + " ");
|
html.replace(F("{TS}"), String(config.sendInterval) + " ");
|
||||||
html.replace(F("{JS_TS}"), String(config.sendInterval * 1000));
|
html.replace(F("{JS_TS}"), String(config.sendInterval * 1000));
|
||||||
mWeb->send(200, F("text/html"), html);
|
mWeb->send(200, F("text/html"), html);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::showLiveData(void) {
|
/*void app::showLiveData(void) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::showLiveData"));
|
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++) {
|
||||||
|
@ -720,11 +724,11 @@ void app::showLiveData(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mWeb->send(200, F("text/html"), modHtml);
|
mWeb->send(200, F("text/html"), modHtml);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::showJSON(void) {
|
/*void app::showJSON(void) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::showJSON"));
|
DPRINTLN(DBG_VERBOSE, F("app::showJSON"));
|
||||||
String modJson;
|
String modJson;
|
||||||
|
|
||||||
|
@ -747,7 +751,7 @@ void app::showJSON(void) {
|
||||||
|
|
||||||
// mWeb->send(200, F("text/json"), modJson);
|
// mWeb->send(200, F("text/json"), 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)
|
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)
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -772,7 +776,7 @@ void app::sendMqttDiscoveryConfig(void) {
|
||||||
} else {
|
} else {
|
||||||
snprintf(name, 32, "%s CH%d %s", iv->name, iv->assign[i].ch, iv->getFieldName(i));
|
snprintf(name, 32, "%s CH%d %s", iv->name, iv->assign[i].ch, iv->getFieldName(i));
|
||||||
}
|
}
|
||||||
snprintf(stateTopic, 64, "%s/%s/ch%d/%s", config.mqtt.topic, iv->name, iv->assign[i].ch, iv->getFieldName(i));
|
snprintf(stateTopic, 64, "%s/%s/ch%d/%s", mConfig.mqtt.topic, iv->name, iv->assign[i].ch, iv->getFieldName(i));
|
||||||
snprintf(discoveryTopic, 64, "%s/sensor/%s/ch%d_%s/config", MQTT_DISCOVERY_PREFIX, iv->name, iv->assign[i].ch, iv->getFieldName(i));
|
snprintf(discoveryTopic, 64, "%s/sensor/%s/ch%d_%s/config", MQTT_DISCOVERY_PREFIX, iv->name, iv->assign[i].ch, iv->getFieldName(i));
|
||||||
snprintf(uniq_id, 32, "ch%d_%s", iv->assign[i].ch, iv->getFieldName(i));
|
snprintf(uniq_id, 32, "ch%d_%s", iv->assign[i].ch, iv->getFieldName(i));
|
||||||
const char* devCls = getFieldDeviceClass(iv->assign[i].fieldId);
|
const char* devCls = getFieldDeviceClass(iv->assign[i].fieldId);
|
||||||
|
@ -839,14 +843,7 @@ void app::setupAp(const char *ssid, const char *pwd) {
|
||||||
WiFi.softAPConfig(apIp, apIp, IPAddress(255, 255, 255, 0));
|
WiFi.softAPConfig(apIp, apIp, IPAddress(255, 255, 255, 0));
|
||||||
WiFi.softAP(ssid, pwd);
|
WiFi.softAP(ssid, pwd);
|
||||||
|
|
||||||
mDns->start(mDnsPort, "*", apIp);
|
mDns->start(53, "*", apIp);
|
||||||
|
|
||||||
/*mWeb->onNotFound([&]() {
|
|
||||||
showSetup();
|
|
||||||
});
|
|
||||||
mWeb->on("/", std::bind(&app::showSetup, this));
|
|
||||||
|
|
||||||
mWeb->begin();*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -864,15 +861,15 @@ bool app::setupStation(uint32_t timeout) {
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(sysConfig.stationSsid, sysConfig.stationPwd);
|
WiFi.begin(mSysConfig.stationSsid, mSysConfig.stationPwd);
|
||||||
if(String(sysConfig.deviceName) != "")
|
if(String(mSysConfig.deviceName) != "")
|
||||||
WiFi.hostname(sysConfig.deviceName);
|
WiFi.hostname(mSysConfig.deviceName);
|
||||||
|
|
||||||
delay(2000);
|
delay(2000);
|
||||||
DPRINTLN(DBG_INFO, F("connect to network '") + String(sysConfig.stationSsid) + F("' ..."));
|
DPRINTLN(DBG_INFO, F("connect to network '") + String(mSysConfig.stationSsid) + F("' ..."));
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(100);
|
delay(100);
|
||||||
if(cnt % 100 == 0)
|
if(cnt % 40 == 0)
|
||||||
Serial.println(".");
|
Serial.println(".");
|
||||||
else
|
else
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
|
@ -891,7 +888,7 @@ bool app::setupStation(uint32_t timeout) {
|
||||||
Serial.println(".");
|
Serial.println(".");
|
||||||
|
|
||||||
if(false == startAp) {
|
if(false == startAp) {
|
||||||
mWeb->begin();
|
wifiWasEstablished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
@ -903,6 +900,7 @@ bool app::setupStation(uint32_t timeout) {
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::resetSystem(void) {
|
void app::resetSystem(void) {
|
||||||
mWifiStationTimeout = 10;
|
mWifiStationTimeout = 10;
|
||||||
|
wifiWasEstablished = false;
|
||||||
mNextTryTs = 0;
|
mNextTryTs = 0;
|
||||||
mApLastTick = 0;
|
mApLastTick = 0;
|
||||||
|
|
||||||
|
@ -942,36 +940,36 @@ void app::resetSystem(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::loadDefaultConfig(void) {
|
void app::loadDefaultConfig(void) {
|
||||||
memset(&sysConfig, 0, sizeof(sysConfig_t));
|
memset(&mSysConfig, 0, sizeof(sysConfig_t));
|
||||||
memset(&config, 0, sizeof(config_t));
|
memset(&mConfig, 0, sizeof(config_t));
|
||||||
snprintf(version, 12, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
|
snprintf(mVersion, 12, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
|
||||||
|
|
||||||
snprintf(sysConfig.deviceName, DEVNAME_LEN, "%s", DEF_DEVICE_NAME);
|
snprintf(mSysConfig.deviceName, DEVNAME_LEN, "%s", DEF_DEVICE_NAME);
|
||||||
|
|
||||||
// wifi
|
// wifi
|
||||||
snprintf(sysConfig.stationSsid, SSID_LEN, "%s", FB_WIFI_SSID);
|
snprintf(mSysConfig.stationSsid, SSID_LEN, "%s", FB_WIFI_SSID);
|
||||||
snprintf(sysConfig.stationPwd, PWD_LEN, "%s", FB_WIFI_PWD);
|
snprintf(mSysConfig.stationPwd, PWD_LEN, "%s", FB_WIFI_PWD);
|
||||||
sysConfig.apActive = false;
|
apActive = false;
|
||||||
|
|
||||||
// nrf24
|
// nrf24
|
||||||
config.sendInterval = SEND_INTERVAL;
|
mConfig.sendInterval = SEND_INTERVAL;
|
||||||
config.maxRetransPerPyld = DEF_MAX_RETRANS_PER_PYLD;
|
mConfig.maxRetransPerPyld = DEF_MAX_RETRANS_PER_PYLD;
|
||||||
|
|
||||||
// ntp
|
// ntp
|
||||||
snprintf(config.ntpAddr, NTP_ADDR_LEN, "%s", NTP_SERVER_NAME);
|
snprintf(mConfig.ntpAddr, NTP_ADDR_LEN, "%s", NTP_SERVER_NAME);
|
||||||
config.ntpPort = NTP_LOCAL_PORT;
|
mConfig.ntpPort = NTP_LOCAL_PORT;
|
||||||
|
|
||||||
// mqtt
|
// mqtt
|
||||||
snprintf(config.mqtt.broker, MQTT_ADDR_LEN, "%s", DEF_MQTT_BROKER);
|
snprintf(mConfig.mqtt.broker, MQTT_ADDR_LEN, "%s", DEF_MQTT_BROKER);
|
||||||
config.mqtt.port = DEF_MQTT_PORT;
|
mConfig.mqtt.port = DEF_MQTT_PORT;
|
||||||
snprintf(config.mqtt.user, MQTT_USER_LEN, "%s", DEF_MQTT_USER);
|
snprintf(mConfig.mqtt.user, MQTT_USER_LEN, "%s", DEF_MQTT_USER);
|
||||||
snprintf(config.mqtt.pwd, MQTT_PWD_LEN, "%s", DEF_MQTT_PWD);
|
snprintf(mConfig.mqtt.pwd, MQTT_PWD_LEN, "%s", DEF_MQTT_PWD);
|
||||||
snprintf(config.mqtt.topic, MQTT_TOPIC_LEN, "%s", DEF_MQTT_TOPIC);
|
snprintf(mConfig.mqtt.topic, MQTT_TOPIC_LEN, "%s", DEF_MQTT_TOPIC);
|
||||||
|
|
||||||
// serial
|
// serial
|
||||||
config.serialInterval = SERIAL_INTERVAL;
|
mConfig.serialInterval = SERIAL_INTERVAL;
|
||||||
config.serialShowIv = true;
|
mConfig.serialShowIv = true;
|
||||||
config.serialDebug = false;
|
mConfig.serialDebug = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -980,11 +978,11 @@ void app::loadEEpconfig(void) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::loadEEpconfig"));
|
DPRINTLN(DBG_VERBOSE, F("app::loadEEpconfig"));
|
||||||
|
|
||||||
if(mWifiSettingsValid)
|
if(mWifiSettingsValid)
|
||||||
mEep->read(ADDR_CFG_SYS, (uint8_t*) &sysConfig, CFG_SYS_LEN);
|
mEep->read(ADDR_CFG_SYS, (uint8_t*) &mSysConfig, CFG_SYS_LEN);
|
||||||
if(mSettingsValid) {
|
if(mSettingsValid) {
|
||||||
mEep->read(ADDR_CFG, (uint8_t*) &config, CFG_LEN);
|
mEep->read(ADDR_CFG, (uint8_t*) &mConfig, CFG_LEN);
|
||||||
|
|
||||||
mSendTicker = config.sendInterval;
|
mSendTicker = mConfig.sendInterval;
|
||||||
mSerialTicker = 0;
|
mSerialTicker = 0;
|
||||||
|
|
||||||
// inverter
|
// inverter
|
||||||
|
@ -1012,7 +1010,7 @@ void app::loadEEpconfig(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: the original mqttinterval value is not needed any more
|
// TODO: the original mqttinterval value is not needed any more
|
||||||
mMqttInterval += config.sendInterval;
|
mMqttInterval += mConfig.sendInterval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1022,7 +1020,7 @@ void app::loadEEpconfig(void) {
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::setupMqtt(void) {
|
void app::setupMqtt(void) {
|
||||||
if(mSettingsValid) {
|
if(mSettingsValid) {
|
||||||
if(config.mqtt.broker[0] > 0) {
|
if(mConfig.mqtt.broker[0] > 0) {
|
||||||
mMqttActive = true;
|
mMqttActive = true;
|
||||||
if(mMqttInterval < MIN_MQTT_INTERVAL)
|
if(mMqttInterval < MIN_MQTT_INTERVAL)
|
||||||
mMqttInterval = MIN_MQTT_INTERVAL;
|
mMqttInterval = MIN_MQTT_INTERVAL;
|
||||||
|
@ -1031,14 +1029,14 @@ void app::setupMqtt(void) {
|
||||||
mMqttInterval = 0xffff;
|
mMqttInterval = 0xffff;
|
||||||
|
|
||||||
mMqttTicker = 0;
|
mMqttTicker = 0;
|
||||||
mMqtt.setup(&config.mqtt, sysConfig.deviceName);
|
mMqtt.setup(&mConfig.mqtt, mSysConfig.deviceName);
|
||||||
mMqtt.setCallback(std::bind(&app::cbMqtt, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
mMqtt.setCallback(std::bind(&app::cbMqtt, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||||
|
|
||||||
|
|
||||||
if(mMqttActive) {
|
if(mMqttActive) {
|
||||||
mMqtt.sendMsg("version", version);
|
mMqtt.sendMsg("version", mVersion);
|
||||||
if(mMqtt.isConnected())
|
if(mMqtt.isConnected())
|
||||||
mMqtt.sendMsg("device", sysConfig.deviceName);
|
mMqtt.sendMsg("device", mSysConfig.deviceName);
|
||||||
|
|
||||||
/*char topic[30];
|
/*char topic[30];
|
||||||
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
||||||
|
@ -1062,8 +1060,8 @@ void app::setupMqtt(void) {
|
||||||
void app::saveValues(void) {
|
void app::saveValues(void) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::saveValues"));
|
DPRINTLN(DBG_VERBOSE, F("app::saveValues"));
|
||||||
|
|
||||||
mEep->write(ADDR_CFG_SYS, (uint8_t*)&sysConfig, CFG_SYS_LEN);
|
mEep->write(ADDR_CFG_SYS, (uint8_t*)&mSysConfig, CFG_SYS_LEN);
|
||||||
mEep->write(ADDR_CFG, (uint8_t*)&config, CFG_LEN);
|
mEep->write(ADDR_CFG, (uint8_t*)&mConfig, CFG_LEN);
|
||||||
Inverter<> *iv;
|
Inverter<> *iv;
|
||||||
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
||||||
iv = mSys->getInverterByPos(i);
|
iv = mSys->getInverterByPos(i);
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "CircularBuffer.h"
|
#include "CircularBuffer.h"
|
||||||
#include "hmSystem.h"
|
#include "hmSystem.h"
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
|
#include "web.h"
|
||||||
|
|
||||||
// hier läst sich das Verhalten der app in Bezug auf MQTT
|
// hier läst sich das Verhalten der app in Bezug auf MQTT
|
||||||
// durch PER-Conpiler defines anpassen
|
// durch PER-Conpiler defines anpassen
|
||||||
|
@ -66,6 +67,7 @@ const byte mDnsPort = 53;
|
||||||
#define NTP_PACKET_SIZE 48
|
#define NTP_PACKET_SIZE 48
|
||||||
#define TIMEZONE 1 // Central European time +1
|
#define TIMEZONE 1 // Central European time +1
|
||||||
|
|
||||||
|
class web;
|
||||||
|
|
||||||
class app {
|
class app {
|
||||||
public:
|
public:
|
||||||
|
@ -79,7 +81,7 @@ class app {
|
||||||
void saveValues(void);
|
void saveValues(void);
|
||||||
|
|
||||||
uint8_t getIrqPin(void) {
|
uint8_t getIrqPin(void) {
|
||||||
return config.pinIrq;
|
return mConfig.pinIrq;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Serial2u64(const char *val) {
|
uint64_t Serial2u64(const char *val) {
|
||||||
|
@ -133,9 +135,8 @@ class app {
|
||||||
uint8_t app_loops;
|
uint8_t app_loops;
|
||||||
HmSystemType *mSys;
|
HmSystemType *mSys;
|
||||||
ESP8266WebServer *mWeb;
|
ESP8266WebServer *mWeb;
|
||||||
sysConfig_t sysConfig;
|
bool apActive;
|
||||||
config_t config;
|
bool wifiWasEstablished;
|
||||||
char version[12];
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void MainLoop(void);
|
void MainLoop(void);
|
||||||
|
@ -254,6 +255,10 @@ class app {
|
||||||
|
|
||||||
bool mShowRebootRequest;
|
bool mShowRebootRequest;
|
||||||
|
|
||||||
|
web *mWebInst;
|
||||||
|
sysConfig_t mSysConfig;
|
||||||
|
config_t mConfig;
|
||||||
|
char mVersion[12];
|
||||||
|
|
||||||
uint16_t mSendTicker;
|
uint16_t mSendTicker;
|
||||||
uint8_t mSendLastIvId;
|
uint8_t mSendLastIvId;
|
||||||
|
|
|
@ -163,7 +163,6 @@ typedef struct {
|
||||||
// wifi
|
// wifi
|
||||||
char stationSsid[SSID_LEN];
|
char stationSsid[SSID_LEN];
|
||||||
char stationPwd[PWD_LEN];
|
char stationPwd[PWD_LEN];
|
||||||
bool apActive;
|
|
||||||
} sysConfig_t;
|
} sysConfig_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -7,10 +7,8 @@
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "web.h"
|
|
||||||
|
|
||||||
app myApp;
|
app myApp;
|
||||||
web *mWebInst;
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
IRAM_ATTR void handleIntr(void) {
|
IRAM_ATTR void handleIntr(void) {
|
||||||
|
@ -21,7 +19,6 @@ IRAM_ATTR void handleIntr(void) {
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void setup() {
|
void setup() {
|
||||||
myApp.setup(WIFI_TRY_CONNECT_TIME);
|
myApp.setup(WIFI_TRY_CONNECT_TIME);
|
||||||
mWebInst = new web(&myApp);
|
|
||||||
|
|
||||||
// TODO: move to HmRadio
|
// TODO: move to HmRadio
|
||||||
attachInterrupt(digitalPinToInterrupt(myApp.getIrqPin()), handleIntr, FALLING);
|
attachInterrupt(digitalPinToInterrupt(myApp.getIrqPin()), handleIntr, FALLING);
|
||||||
|
|
|
@ -12,320 +12,35 @@
|
||||||
|
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
#include "html/h/index_html.h"
|
class app;
|
||||||
#include "html/h/style_css.h"
|
|
||||||
#include "favicon.h"
|
|
||||||
#include "html/h/setup_html.h"
|
|
||||||
|
|
||||||
|
|
||||||
class web {
|
class web {
|
||||||
public:
|
public:
|
||||||
web(app *main) {
|
web(app *main, sysConfig_t *sysCfg, config_t *config, char version[]);
|
||||||
mMain = main;
|
~web() {}
|
||||||
mWeb = main->mWeb;
|
|
||||||
//mWeb = new ESP8266WebServer(80);
|
|
||||||
mUpdater = new ESP8266HTTPUpdateServer();
|
|
||||||
mUpdater->setup(mWeb);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup(void) {
|
void setup(void);
|
||||||
mWeb->on("/", std::bind(&web::showIndex, this));
|
void loop(void);
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
void showIndex(void) {
|
|
||||||
DPRINTLN(DBG_VERBOSE, F("showIndex"));
|
|
||||||
String html = FPSTR(index_html);
|
|
||||||
html.replace(F("{DEVICE}"), mMain->sysConfig.deviceName);
|
|
||||||
html.replace(F("{VERSION}"), mMain->version);
|
|
||||||
html.replace(F("{TS}"), String(mMain->config.sendInterval) + " ");
|
|
||||||
html.replace(F("{JS_TS}"), String(mMain->config.sendInterval * 1000));
|
|
||||||
html.replace(F("{BUILD}"), String(AUTO_GIT_HASH));
|
|
||||||
mWeb->send(200, "text/html", html);
|
|
||||||
}
|
|
||||||
|
|
||||||
void showCss(void) {
|
|
||||||
mWeb->send(200, "text/css", FPSTR(style_css));
|
|
||||||
}
|
|
||||||
|
|
||||||
void 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 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 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) + mMain->getDateTimeStr(mMain->getTimestamp()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void 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 showErase() {
|
|
||||||
DPRINTLN(DBG_VERBOSE, F("showErase"));
|
|
||||||
mMain->eraseSettings();
|
|
||||||
showReboot();
|
|
||||||
}
|
|
||||||
|
|
||||||
void 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 showSetup(void) {
|
|
||||||
DPRINTLN(DBG_VERBOSE, F("showSetup"));
|
|
||||||
String html = FPSTR(setup_html);
|
|
||||||
html.replace(F("{SSID}"), mMain->sysConfig.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(mMain->sysConfig.deviceName));
|
|
||||||
html.replace(F("{VERSION}"), String(mMain->version));
|
|
||||||
if(mMain->sysConfig.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 == mMain->config.pinCs) pinout += F(" selected"); break;
|
|
||||||
case 1: if(j == mMain->config.pinCe) pinout += F(" selected"); break;
|
|
||||||
case 2: if(j == mMain->config.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 == mMain->config.amplifierPower)
|
|
||||||
rf24 += F(" selected");
|
|
||||||
rf24 += ">" + String(rf24AmpPowerNames[i]) + F("</option>");
|
|
||||||
}
|
|
||||||
html.replace(F("{RF24}"), String(rf24));
|
|
||||||
|
|
||||||
|
|
||||||
html.replace(F("{INV_INTVL}"), String(mMain->config.sendInterval));
|
|
||||||
html.replace(F("{INV_RETRIES}"), String(mMain->config.maxRetransPerPyld));
|
|
||||||
|
|
||||||
html.replace(F("{SER_INTVL}"), String(mMain->config.serialInterval));
|
|
||||||
html.replace(F("{SER_VAL_CB}"), (mMain->config.serialShowIv) ? "checked" : "");
|
|
||||||
html.replace(F("{SER_DBG_CB}"), (mMain->config.serialDebug) ? "checked" : "");
|
|
||||||
|
|
||||||
html.replace(F("{NTP_ADDR}"), String(mMain->config.ntpAddr));
|
|
||||||
html.replace(F("{NTP_PORT}"), String(mMain->config.ntpPort));
|
|
||||||
|
|
||||||
html.replace(F("{MQTT_ADDR}"), String(mMain->config.mqtt.broker));
|
|
||||||
html.replace(F("{MQTT_PORT}"), String(mMain->config.mqtt.port));
|
|
||||||
html.replace(F("{MQTT_USER}"), String(mMain->config.mqtt.user));
|
|
||||||
html.replace(F("{MQTT_PWD}"), String(mMain->config.mqtt.pwd));
|
|
||||||
html.replace(F("{MQTT_TOPIC}"), String(mMain->config.mqtt.topic));
|
|
||||||
html.replace(F("{MQTT_INTVL}"), String("0"));
|
|
||||||
|
|
||||||
mWeb->send(200, F("text/html"), html);
|
|
||||||
}
|
|
||||||
|
|
||||||
void showSave(void) {
|
|
||||||
DPRINTLN(DBG_VERBOSE, F("showSave"));
|
|
||||||
|
|
||||||
if(mWeb->args() > 0) {
|
|
||||||
char buf[20] = {0};
|
|
||||||
|
|
||||||
// general
|
|
||||||
if(mWeb->arg("ssid") != "")
|
|
||||||
mWeb->arg("ssid").toCharArray(mMain->sysConfig.stationSsid, SSID_LEN);
|
|
||||||
if(mWeb->arg("pwd") != "{PWD}")
|
|
||||||
mWeb->arg("pwd").toCharArray(mMain->sysConfig.stationPwd, PWD_LEN);
|
|
||||||
if(mWeb->arg("device") != "")
|
|
||||||
mWeb->arg("device").toCharArray(mMain->sysConfig.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") != "")
|
|
||||||
mMain->config.sendInterval = mWeb->arg("invInterval").toInt();
|
|
||||||
if(mWeb->arg("invRetry") != "")
|
|
||||||
mMain->config.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: mMain->config.pinCs = pin; break;
|
|
||||||
case 1: mMain->config.pinCe = pin; break;
|
|
||||||
case 2: mMain->config.pinIrq = pin; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// nrf24 amplifier power
|
|
||||||
mMain->config.amplifierPower = mWeb->arg("rf24Power").toInt() & 0x03;
|
|
||||||
|
|
||||||
// ntp
|
|
||||||
if(mWeb->arg("ntpAddr") != "") {
|
|
||||||
mWeb->arg("ntpAddr").toCharArray(mMain->config.ntpAddr, NTP_ADDR_LEN);
|
|
||||||
mMain->config.ntpPort = mWeb->arg("ntpPort").toInt() & 0xffff;
|
|
||||||
}
|
|
||||||
|
|
||||||
// mqtt
|
|
||||||
if(mWeb->arg("mqttAddr") != "") {
|
|
||||||
mWeb->arg("mqttAddr").toCharArray(mMain->config.mqtt.broker, MQTT_ADDR_LEN);
|
|
||||||
mWeb->arg("mqttUser").toCharArray(mMain->config.mqtt.user, MQTT_USER_LEN);
|
|
||||||
mWeb->arg("mqttPwd").toCharArray(mMain->config.mqtt.pwd, MQTT_PWD_LEN);
|
|
||||||
mWeb->arg("mqttTopic").toCharArray(mMain->config.mqtt.topic, MQTT_TOPIC_LEN);
|
|
||||||
mMain->config.mqtt.port = mWeb->arg("mqttPort").toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
// serial console
|
|
||||||
if(mWeb->arg("serIntvl") != "") {
|
|
||||||
mMain->config.serialInterval = mWeb->arg("serIntvl").toInt() & 0xffff;
|
|
||||||
|
|
||||||
mMain->config.serialDebug = (mWeb->arg("serEn") == "on");
|
|
||||||
mMain->config.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 showIndex(void);
|
||||||
|
void showCss(void);
|
||||||
|
void showFavicon(void);
|
||||||
|
void showNotFound(void);
|
||||||
|
void showUptime(void);
|
||||||
|
void showReboot(void);
|
||||||
|
void showErase();
|
||||||
|
void showFactoryRst(void);
|
||||||
|
void showSetup(void);
|
||||||
|
void showSave(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ESP8266WebServer *mWeb;
|
ESP8266WebServer *mWeb;
|
||||||
ESP8266HTTPUpdateServer *mUpdater;
|
ESP8266HTTPUpdateServer *mUpdater;
|
||||||
app *mMain;
|
|
||||||
|
|
||||||
|
config_t *mConfig;
|
||||||
|
sysConfig_t *mSysCfg;
|
||||||
|
char *mVersion;
|
||||||
|
app *mMain;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*__WEB_H__*/
|
#endif /*__WEB_H__*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue