mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-10 15:36:38 +02:00
* improved stability (in comparison to 0.3.7)
* reset wifi AP timout once a client is detected * fix #26 wrong variable reset
This commit is contained in:
parent
37206847c5
commit
b485cb8151
7 changed files with 47 additions and 89 deletions
|
@ -3,7 +3,6 @@
|
||||||
#include "html/h/index_html.h"
|
#include "html/h/index_html.h"
|
||||||
#include "html/h/setup_html.h"
|
#include "html/h/setup_html.h"
|
||||||
#include "html/h/hoymiles_html.h"
|
#include "html/h/hoymiles_html.h"
|
||||||
#include "html/h/debug_html.h"
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -24,12 +23,9 @@ app::app() : Main() {
|
||||||
mSerialValues = true;
|
mSerialValues = true;
|
||||||
mSerialDebug = false;
|
mSerialDebug = false;
|
||||||
|
|
||||||
memset(mCmds, 0, sizeof(uint32_t)*DBG_CMD_LIST_LEN);
|
memset(mPacketIds, 0, sizeof(uint32_t)*DBG_CMD_LIST_LEN);
|
||||||
//memset(mChannelStat, 0, sizeof(uint32_t) * 4);
|
|
||||||
|
|
||||||
mSys = new HmSystemType();
|
mSys = new HmSystemType();
|
||||||
|
|
||||||
memset(mPayload, 0, ((MAX_RF_PAYLOAD_SIZE-11) * MAX_NUM_PAC_PER_PAYLOAD));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,7 +46,6 @@ void app::setup(uint32_t timeout) {
|
||||||
mWeb->on("/cmdstat", std::bind(&app::showStatistics, 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("/debug", std::bind(&app::showDebug, this));
|
|
||||||
|
|
||||||
if(mSettingsValid) {
|
if(mSettingsValid) {
|
||||||
uint64_t invSerial;
|
uint64_t invSerial;
|
||||||
|
@ -67,10 +62,8 @@ void app::setup(uint32_t timeout) {
|
||||||
DPRINTLN("add inverter: " + String(invName) + ", SN: " + String(invSerial, HEX) + ", type: " + String(invType));
|
DPRINTLN("add inverter: " + String(invName) + ", SN: " + String(invSerial, HEX) + ", type: " + String(invType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// @TODO reenable
|
mEep->read(ADDR_INV_INTERVAL, &mSendInterval);
|
||||||
//mEep->read(ADDR_INV_INTERVAL, &mSendInterval);
|
if(mSendInterval < 5)
|
||||||
//if(mSendInterval < 5)
|
|
||||||
// mSendInterval = 5;
|
|
||||||
mSendInterval = 5;
|
mSendInterval = 5;
|
||||||
|
|
||||||
// pinout
|
// pinout
|
||||||
|
@ -152,29 +145,29 @@ void app::loop(void) {
|
||||||
if(mSys->Radio.checkPaketCrc(p->packet, &len, &rptCnt, p->rxCh)) {
|
if(mSys->Radio.checkPaketCrc(p->packet, &len, &rptCnt, p->rxCh)) {
|
||||||
// process buffer only on first occurrence
|
// process buffer only on first occurrence
|
||||||
if((0 != len) && (0 == rptCnt)) {
|
if((0 != len) && (0 == rptCnt)) {
|
||||||
uint8_t *cmd = &p->packet[9];
|
uint8_t *packetId = &p->packet[9];
|
||||||
//DPRINTLN("CMD " + String(*cmd, HEX));
|
//DPRINTLN("CMD " + String(*packetId, HEX));
|
||||||
if(mSerialDebug)
|
if(mSerialDebug)
|
||||||
mSys->Radio.dumpBuf("Payload ", p->packet, len);
|
mSys->Radio.dumpBuf("Payload ", p->packet, len);
|
||||||
|
|
||||||
Inverter<> *iv = mSys->findInverter(&p->packet[1]);
|
Inverter<> *iv = mSys->findInverter(&p->packet[1]);
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
for(uint8_t i = 0; i < iv->listLen; i++) {
|
for(uint8_t i = 0; i < iv->listLen; i++) {
|
||||||
if(iv->assign[i].cmdId == *cmd)
|
if(iv->assign[i].cmdId == *packetId)
|
||||||
iv->addValue(i, &p->packet[9]);
|
iv->addValue(i, &p->packet[9]);
|
||||||
}
|
}
|
||||||
iv->doCalculations();
|
iv->doCalculations();
|
||||||
//memcpy(mPayload[(*cmd & 0x7F) - 1], &p->packet[9], MAX_RF_PAYLOAD_SIZE - 11);
|
//memcpy(mPayload[(*packetId & 0x7F) - 1], &p->packet[9], MAX_RF_PAYLOAD_SIZE - 11);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(*cmd == 0x01) mCmds[0]++;
|
if(*packetId == 0x01) mPacketIds[0]++;
|
||||||
else if(*cmd == 0x02) mCmds[1]++;
|
else if(*packetId == 0x02) mPacketIds[1]++;
|
||||||
else if(*cmd == 0x03) mCmds[2]++;
|
else if(*packetId == 0x03) mPacketIds[2]++;
|
||||||
else if(*cmd == 0x81) mCmds[3]++;
|
else if(*packetId == 0x81) mPacketIds[3]++;
|
||||||
else if(*cmd == 0x82) mCmds[4]++;
|
else if(*packetId == 0x82) mPacketIds[4]++;
|
||||||
else if(*cmd == 0x83) mCmds[5]++;
|
else if(*packetId == 0x83) mPacketIds[5]++;
|
||||||
else if(*cmd == 0x84) mCmds[6]++;
|
else if(*packetId == 0x84) mPacketIds[6]++;
|
||||||
else mCmds[7]++;
|
else mPacketIds[7]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mSys->BufCtrl.popBack();
|
mSys->BufCtrl.popBack();
|
||||||
|
@ -182,24 +175,9 @@ void app::loop(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(checkTicker(&mTicker, 1000)) {
|
if(checkTicker(&mTicker, 1000)) {
|
||||||
if(++mSendTicker >= mSendInterval) {
|
|
||||||
mSendTicker = 0;
|
|
||||||
|
|
||||||
if(!mSys->BufCtrl.empty())
|
|
||||||
DPRINTLN("recbuf not empty! #" + String(mSys->BufCtrl.getFill()));
|
|
||||||
Inverter<> *inv;
|
|
||||||
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
|
||||||
inv = mSys->getInverterByPos(i);
|
|
||||||
if(NULL != inv) {
|
|
||||||
mSys->Radio.sendTimePacket(inv->radioId.u64, mTimestamp);
|
|
||||||
yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mMqttActive) {
|
if(mMqttActive) {
|
||||||
mMqtt.loop();
|
mMqtt.loop();
|
||||||
if(++mMqttTicker > mMqttInterval) {
|
if(++mMqttTicker >= mMqttInterval) {
|
||||||
mMqttInterval = 0;
|
mMqttInterval = 0;
|
||||||
mMqtt.isConnected(true);
|
mMqtt.isConnected(true);
|
||||||
char topic[30], val[10];
|
char topic[30], val[10];
|
||||||
|
@ -220,7 +198,7 @@ void app::loop(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mSerialValues) {
|
if(mSerialValues) {
|
||||||
if(++mSerialTicker > mSerialInterval) {
|
if(++mSerialTicker >= mSerialInterval) {
|
||||||
mSerialInterval = 0;
|
mSerialInterval = 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++) {
|
||||||
|
@ -238,6 +216,22 @@ void app::loop(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(++mSendTicker >= mSendInterval) {
|
||||||
|
mSendTicker = 0;
|
||||||
|
|
||||||
|
if(!mSys->BufCtrl.empty())
|
||||||
|
DPRINTLN("recbuf not empty! #" + String(mSys->BufCtrl.getFill()));
|
||||||
|
Inverter<> *inv;
|
||||||
|
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
||||||
|
inv = mSys->getInverterByPos(i);
|
||||||
|
if(NULL != inv) {
|
||||||
|
yield();
|
||||||
|
mSys->Radio.sendTimePacket(inv->radioId.u64, mTimestamp);
|
||||||
|
mRxTicker = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,20 +396,14 @@ void app::showErase() {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::showStatistics(void) {
|
void app::showStatistics(void) {
|
||||||
String content = "CMDs:\n";
|
String content = "Packets:\n";
|
||||||
for(uint8_t i = 0; i < DBG_CMD_LIST_LEN; i ++) {
|
for(uint8_t i = 0; i < DBG_CMD_LIST_LEN; i ++) {
|
||||||
content += String("0x") + String(dbgCmds[i], HEX) + String(": ") + String(mCmds[i]) + String("\n");
|
content += String("0x") + String(dbgCmds[i], HEX) + String(": ") + String(mPacketIds[i]) + String("\n");
|
||||||
}
|
}
|
||||||
content += String("other: ") + String(mCmds[DBG_CMD_LIST_LEN]) + String("\n\n");
|
content += String("other: ") + String(mPacketIds[DBG_CMD_LIST_LEN]) + String("\n\n");
|
||||||
|
|
||||||
content += "Send Cnt: " + String(mSys->Radio.mSendCnt) + String("\n\n");
|
content += "Send Cnt: " + String(mSys->Radio.mSendCnt) + String("\n\n");
|
||||||
|
|
||||||
/*content += "\nCHANNELs:\n";
|
|
||||||
content += String("23: ") + String(mChannelStat[0]) + String("\n");
|
|
||||||
content += String("40: ") + String(mChannelStat[1]) + String("\n");
|
|
||||||
content += String("61: ") + String(mChannelStat[2]) + String("\n");
|
|
||||||
content += String("75: ") + String(mChannelStat[3]) + String("\n");*/
|
|
||||||
|
|
||||||
if(!mSys->Radio.isChipConnected())
|
if(!mSys->Radio.isChipConnected())
|
||||||
content += "WARNING! your NRF24 module can't be reached, check the wiring and pinout (<a href=\"/setup\">setup</a>)\n";
|
content += "WARNING! your NRF24 module can't be reached, check the wiring and pinout (<a href=\"/setup\">setup</a>)\n";
|
||||||
|
|
||||||
|
@ -513,36 +501,6 @@ void app::showLiveData(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
void app::showDebug() {
|
|
||||||
if(mWeb->args() > 0) {
|
|
||||||
/*String html;
|
|
||||||
|
|
||||||
for(uint8_t i = 0; i < MAX_NUM_PAC_PER_PAYLOAD; i ++) {
|
|
||||||
for(uint8_t j = 0; j < (MAX_RF_PAYLOAD_SIZE- 11); j++) {
|
|
||||||
if(mPayload[i][j] < 0x10)
|
|
||||||
html += "0";
|
|
||||||
html += String(mPayload[i][j], HEX) + " ";
|
|
||||||
}
|
|
||||||
html += "\n";
|
|
||||||
}
|
|
||||||
html += "CMDS: ";
|
|
||||||
for(uint8_t i = 0; i < DBG_CMD_LIST_LEN; i ++) {
|
|
||||||
html += String(mCmds[i]) + String(" ");
|
|
||||||
}
|
|
||||||
html += "\n------------------";*/
|
|
||||||
|
|
||||||
mWeb->send(200, "text/plain", "na");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
String html = FPSTR(debug_html);
|
|
||||||
html.replace("{DEVICE}", mDeviceName);
|
|
||||||
html.replace("{VERSION}", mVersion);
|
|
||||||
mWeb->send(200, "text/html", html);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::saveValues(bool webSend = true) {
|
void app::saveValues(bool webSend = true) {
|
||||||
Main::saveValues(false); // general configuration
|
Main::saveValues(false); // general configuration
|
||||||
|
|
|
@ -47,7 +47,6 @@ class app : public Main {
|
||||||
void showStatistics(void);
|
void showStatistics(void);
|
||||||
void showHoymiles(void);
|
void showHoymiles(void);
|
||||||
void showLiveData(void);
|
void showLiveData(void);
|
||||||
void showDebug(void);
|
|
||||||
|
|
||||||
void saveValues(bool webSend);
|
void saveValues(bool webSend);
|
||||||
void updateCrc(void);
|
void updateCrc(void);
|
||||||
|
@ -74,8 +73,7 @@ class app : public Main {
|
||||||
uint16_t mSendTicker;
|
uint16_t mSendTicker;
|
||||||
uint16_t mSendInterval;
|
uint16_t mSendInterval;
|
||||||
|
|
||||||
uint32_t mCmds[DBG_CMD_LIST_LEN+1];
|
uint32_t mPacketIds[DBG_CMD_LIST_LEN+1];
|
||||||
//uint32_t mChannelStat[4];
|
|
||||||
uint32_t mRecCnt;
|
uint32_t mRecCnt;
|
||||||
|
|
||||||
// timer
|
// timer
|
||||||
|
@ -92,8 +90,6 @@ class app : public Main {
|
||||||
bool mMqttActive;
|
bool mMqttActive;
|
||||||
uint16_t mSerialTicker;
|
uint16_t mSerialTicker;
|
||||||
uint16_t mSerialInterval;
|
uint16_t mSerialInterval;
|
||||||
|
|
||||||
uint8_t mPayload[MAX_NUM_PAC_PER_PAYLOAD][MAX_RF_PAYLOAD_SIZE-11];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*__APP_H__*/
|
#endif /*__APP_H__*/
|
||||||
|
|
|
@ -38,8 +38,6 @@
|
||||||
// maximum buffer length of packet received / sent to RF24 module
|
// maximum buffer length of packet received / sent to RF24 module
|
||||||
#define MAX_RF_PAYLOAD_SIZE 32
|
#define MAX_RF_PAYLOAD_SIZE 32
|
||||||
|
|
||||||
#define MAX_NUM_PAC_PER_PAYLOAD 4
|
|
||||||
|
|
||||||
// changes the style of "/setup" page, visualized = nicer
|
// changes the style of "/setup" page, visualized = nicer
|
||||||
#define LIVEDATA_VISUALIZED
|
#define LIVEDATA_VISUALIZED
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 3
|
#define VERSION_MINOR 3
|
||||||
#define VERSION_PATCH 7
|
#define VERSION_PATCH 8
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
|
|
|
@ -205,9 +205,11 @@ class HmRadio {
|
||||||
mRxLoopCnt += addLoop;
|
mRxLoopCnt += addLoop;
|
||||||
if(mRxLoopCnt != 0) {
|
if(mRxLoopCnt != 0) {
|
||||||
mRxLoopCnt--;
|
mRxLoopCnt--;
|
||||||
|
DISABLE_IRQ;
|
||||||
mNrf24.stopListening();
|
mNrf24.stopListening();
|
||||||
mNrf24.setChannel(getRxNxtChannel());
|
mNrf24.setChannel(getRxNxtChannel());
|
||||||
mNrf24.startListening();
|
mNrf24.startListening();
|
||||||
|
RESTORE_IRQ;
|
||||||
}
|
}
|
||||||
return (0 == mRxLoopCnt); // receive finished
|
return (0 == mRxLoopCnt); // receive finished
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,4 +27,3 @@ convert2Header("index.html")
|
||||||
convert2Header("setup.html")
|
convert2Header("setup.html")
|
||||||
convert2Header("hoymiles.html")
|
convert2Header("hoymiles.html")
|
||||||
convert2Header("style.css")
|
convert2Header("style.css")
|
||||||
convert2Header("debug.html")
|
|
||||||
|
|
|
@ -57,13 +57,13 @@ void Main::setup(uint32_t timeout) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!startAp) {
|
if(!startAp) {
|
||||||
|
delay(5000);
|
||||||
mTimestamp = getNtpTime();
|
mTimestamp = getNtpTime();
|
||||||
DPRINTLN("[NTP]: " + getDateTimeStr(getNtpTime()));
|
DPRINTLN("[NTP]: " + getDateTimeStr(getNtpTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
mUpdater->setup(mWeb);
|
mUpdater->setup(mWeb);
|
||||||
mApActive = startAp;
|
mApActive = startAp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,6 +83,11 @@ void Main::loop(void) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(millis() - mApLastTick > 10000) {
|
if(millis() - mApLastTick > 10000) {
|
||||||
|
uint8_t cnt = WiFi.softAPgetStationNum();
|
||||||
|
if(cnt > 0) {
|
||||||
|
DPRINTLN(String(cnt) + " clients connected, resetting AP timeout");
|
||||||
|
mNextTryTs = (millis() + (WIFI_AP_ACTIVE_TIME * 1000));
|
||||||
|
}
|
||||||
mApLastTick = millis();
|
mApLastTick = millis();
|
||||||
DPRINTLN("AP will be closed in " + String((mNextTryTs - mApLastTick) / 1000) + " seconds");
|
DPRINTLN("AP will be closed in " + String((mNextTryTs - mApLastTick) / 1000) + " seconds");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue