mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-09 23:16: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/setup_html.h"
|
||||
#include "html/h/hoymiles_html.h"
|
||||
#include "html/h/debug_html.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -24,12 +23,9 @@ app::app() : Main() {
|
|||
mSerialValues = true;
|
||||
mSerialDebug = false;
|
||||
|
||||
memset(mCmds, 0, sizeof(uint32_t)*DBG_CMD_LIST_LEN);
|
||||
//memset(mChannelStat, 0, sizeof(uint32_t) * 4);
|
||||
memset(mPacketIds, 0, sizeof(uint32_t)*DBG_CMD_LIST_LEN);
|
||||
|
||||
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("/hoymiles", std::bind(&app::showHoymiles, this));
|
||||
mWeb->on("/livedata", std::bind(&app::showLiveData, this));
|
||||
mWeb->on("/debug", std::bind(&app::showDebug, this));
|
||||
|
||||
if(mSettingsValid) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
// @TODO reenable
|
||||
//mEep->read(ADDR_INV_INTERVAL, &mSendInterval);
|
||||
//if(mSendInterval < 5)
|
||||
// mSendInterval = 5;
|
||||
mEep->read(ADDR_INV_INTERVAL, &mSendInterval);
|
||||
if(mSendInterval < 5)
|
||||
mSendInterval = 5;
|
||||
|
||||
// pinout
|
||||
|
@ -152,29 +145,29 @@ void app::loop(void) {
|
|||
if(mSys->Radio.checkPaketCrc(p->packet, &len, &rptCnt, p->rxCh)) {
|
||||
// process buffer only on first occurrence
|
||||
if((0 != len) && (0 == rptCnt)) {
|
||||
uint8_t *cmd = &p->packet[9];
|
||||
//DPRINTLN("CMD " + String(*cmd, HEX));
|
||||
uint8_t *packetId = &p->packet[9];
|
||||
//DPRINTLN("CMD " + String(*packetId, HEX));
|
||||
if(mSerialDebug)
|
||||
mSys->Radio.dumpBuf("Payload ", p->packet, len);
|
||||
|
||||
Inverter<> *iv = mSys->findInverter(&p->packet[1]);
|
||||
if(NULL != iv) {
|
||||
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->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]++;
|
||||
else if(*cmd == 0x02) mCmds[1]++;
|
||||
else if(*cmd == 0x03) mCmds[2]++;
|
||||
else if(*cmd == 0x81) mCmds[3]++;
|
||||
else if(*cmd == 0x82) mCmds[4]++;
|
||||
else if(*cmd == 0x83) mCmds[5]++;
|
||||
else if(*cmd == 0x84) mCmds[6]++;
|
||||
else mCmds[7]++;
|
||||
if(*packetId == 0x01) mPacketIds[0]++;
|
||||
else if(*packetId == 0x02) mPacketIds[1]++;
|
||||
else if(*packetId == 0x03) mPacketIds[2]++;
|
||||
else if(*packetId == 0x81) mPacketIds[3]++;
|
||||
else if(*packetId == 0x82) mPacketIds[4]++;
|
||||
else if(*packetId == 0x83) mPacketIds[5]++;
|
||||
else if(*packetId == 0x84) mPacketIds[6]++;
|
||||
else mPacketIds[7]++;
|
||||
}
|
||||
}
|
||||
mSys->BufCtrl.popBack();
|
||||
|
@ -182,24 +175,9 @@ void app::loop(void) {
|
|||
}
|
||||
|
||||
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) {
|
||||
mMqtt.loop();
|
||||
if(++mMqttTicker > mMqttInterval) {
|
||||
if(++mMqttTicker >= mMqttInterval) {
|
||||
mMqttInterval = 0;
|
||||
mMqtt.isConnected(true);
|
||||
char topic[30], val[10];
|
||||
|
@ -220,7 +198,7 @@ void app::loop(void) {
|
|||
}
|
||||
|
||||
if(mSerialValues) {
|
||||
if(++mSerialTicker > mSerialInterval) {
|
||||
if(++mSerialTicker >= mSerialInterval) {
|
||||
mSerialInterval = 0;
|
||||
char topic[30], val[10];
|
||||
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) {
|
||||
String content = "CMDs:\n";
|
||||
String content = "Packets:\n";
|
||||
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 += "\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())
|
||||
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) {
|
||||
Main::saveValues(false); // general configuration
|
||||
|
|
|
@ -47,7 +47,6 @@ class app : public Main {
|
|||
void showStatistics(void);
|
||||
void showHoymiles(void);
|
||||
void showLiveData(void);
|
||||
void showDebug(void);
|
||||
|
||||
void saveValues(bool webSend);
|
||||
void updateCrc(void);
|
||||
|
@ -74,8 +73,7 @@ class app : public Main {
|
|||
uint16_t mSendTicker;
|
||||
uint16_t mSendInterval;
|
||||
|
||||
uint32_t mCmds[DBG_CMD_LIST_LEN+1];
|
||||
//uint32_t mChannelStat[4];
|
||||
uint32_t mPacketIds[DBG_CMD_LIST_LEN+1];
|
||||
uint32_t mRecCnt;
|
||||
|
||||
// timer
|
||||
|
@ -92,8 +90,6 @@ class app : public Main {
|
|||
bool mMqttActive;
|
||||
uint16_t mSerialTicker;
|
||||
uint16_t mSerialInterval;
|
||||
|
||||
uint8_t mPayload[MAX_NUM_PAC_PER_PAYLOAD][MAX_RF_PAYLOAD_SIZE-11];
|
||||
};
|
||||
|
||||
#endif /*__APP_H__*/
|
||||
|
|
|
@ -38,8 +38,6 @@
|
|||
// maximum buffer length of packet received / sent to RF24 module
|
||||
#define MAX_RF_PAYLOAD_SIZE 32
|
||||
|
||||
#define MAX_NUM_PAC_PER_PAYLOAD 4
|
||||
|
||||
// changes the style of "/setup" page, visualized = nicer
|
||||
#define LIVEDATA_VISUALIZED
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
//-------------------------------------
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 3
|
||||
#define VERSION_PATCH 7
|
||||
#define VERSION_PATCH 8
|
||||
|
||||
|
||||
//-------------------------------------
|
||||
|
|
|
@ -205,9 +205,11 @@ class HmRadio {
|
|||
mRxLoopCnt += addLoop;
|
||||
if(mRxLoopCnt != 0) {
|
||||
mRxLoopCnt--;
|
||||
DISABLE_IRQ;
|
||||
mNrf24.stopListening();
|
||||
mNrf24.setChannel(getRxNxtChannel());
|
||||
mNrf24.startListening();
|
||||
RESTORE_IRQ;
|
||||
}
|
||||
return (0 == mRxLoopCnt); // receive finished
|
||||
}
|
||||
|
|
|
@ -27,4 +27,3 @@ convert2Header("index.html")
|
|||
convert2Header("setup.html")
|
||||
convert2Header("hoymiles.html")
|
||||
convert2Header("style.css")
|
||||
convert2Header("debug.html")
|
||||
|
|
|
@ -57,13 +57,13 @@ void Main::setup(uint32_t timeout) {
|
|||
#endif
|
||||
|
||||
if(!startAp) {
|
||||
delay(5000);
|
||||
mTimestamp = getNtpTime();
|
||||
DPRINTLN("[NTP]: " + getDateTimeStr(getNtpTime()));
|
||||
}
|
||||
|
||||
mUpdater->setup(mWeb);
|
||||
mApActive = startAp;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -83,6 +83,11 @@ void Main::loop(void) {
|
|||
}
|
||||
else {
|
||||
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();
|
||||
DPRINTLN("AP will be closed in " + String((mNextTryTs - mApLastTick) / 1000) + " seconds");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue