diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 53047522..b1688fdd 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -7,6 +7,7 @@ //----------------------------------------------------------------------------- app::app() : Main() { + DPRINTLN(F("app::app():Main")); mSendTicker = 0xffff; mSendInterval = 0; mMqttTicker = 0xffff; @@ -40,6 +41,7 @@ app::~app(void) { //----------------------------------------------------------------------------- void app::setup(uint32_t timeout) { + DPRINTLN(F("app::setup")); Main::setup(timeout); mWeb->on("/", std::bind(&app::showIndex, this)); @@ -150,11 +152,17 @@ void app::setup(uint32_t timeout) { //----------------------------------------------------------------------------- void app::loop(void) { + //DPRINT(F("a")); + //DPRINTLN(F("a")); + //app_loops++; Main::loop(); mSys->Radio.loop(); if(checkTicker(&mRxTicker, 5)) { + //DPRINTLN(F("app_loops =") + String(app_loops)); + //app_loops=0; + //DPRINT(F("a")); bool rxRdy = mSys->Radio.switchRxCh(); if(!mSys->BufCtrl.empty()) { @@ -291,6 +299,7 @@ void app::loop(void) { //----------------------------------------------------------------------------- void app::handleIntr(void) { + DPRINTLN(F("app::handleIntr")); mSys->Radio.handleIntr(); } @@ -298,6 +307,7 @@ void app::handleIntr(void) { //----------------------------------------------------------------------------- bool app::buildPayload(uint8_t id) { //DPRINTLN("Payload"); + DPRINTLN(F("app::buildPayload")); uint16_t crc = 0xffff, crcRcv; if(mPayload[id].maxPackId > MAX_PAYLOAD_ENTRIES) mPayload[id].maxPackId = MAX_PAYLOAD_ENTRIES; @@ -322,6 +332,8 @@ bool app::buildPayload(uint8_t id) { //----------------------------------------------------------------------------- void app::processPayload(bool retransmit) { + //DPRINTLN(F("app::processPayload")); + //DPRINT(F("p")); for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { Inverter<> *iv = mSys->getInverterByPos(id); if(NULL != iv) { @@ -379,15 +391,19 @@ void app::processPayload(bool retransmit) { //----------------------------------------------------------------------------- void app::showIndex(void) { + DPRINTLN(F("app::showIndex")); String html = FPSTR(index_html); html.replace(F("{DEVICE}"), mDeviceName); html.replace(F("{VERSION}"), mVersion); + html.replace(F("{TS}"), String(mSendInterval) + " "); + html.replace(F("{JS_TS}"), String(mSendInterval * 1000)); mWeb->send(200, "text/html", html); } //----------------------------------------------------------------------------- void app::showSetup(void) { + DPRINTLN(F("app::showSetup")); // overrides same method in main.cpp uint16_t interval; @@ -516,12 +532,14 @@ void app::showSetup(void) { //----------------------------------------------------------------------------- void app::showSave(void) { + DPRINTLN(F("app::showSave")); saveValues(true); } //----------------------------------------------------------------------------- void app::showErase() { + DPRINTLN(F("app::showErase")); eraseSettings(); showReboot(); } @@ -529,6 +547,7 @@ void app::showErase() { //----------------------------------------------------------------------------- void app::showStatistics(void) { + DPRINTLN(F("app::showStatistics")); String content = F("Receive success: ") + String(mRxSuccess) + "\n"; content += F("Receive fail: ") + String(mRxFailed) + "\n"; content += F("Send Cnt: ") + String(mSys->Radio.mSendCnt) + String("\n\n"); @@ -577,6 +596,7 @@ void app::showStatistics(void) { //----------------------------------------------------------------------------- void app::showHoymiles(void) { + DPRINTLN(F("app::showHoymiles")); String html = FPSTR(hoymiles_html); html.replace(F("{DEVICE}"), mDeviceName); html.replace(F("{VERSION}"), mVersion); @@ -588,6 +608,7 @@ void app::showHoymiles(void) { //----------------------------------------------------------------------------- void app::showLiveData(void) { + DPRINTLN(F("app::showLiveData")); String modHtml; for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { Inverter<> *iv = mSys->getInverterByPos(id); @@ -660,6 +681,7 @@ void app::showLiveData(void) { //----------------------------------------------------------------------------- void app::saveValues(bool webSend = true) { + DPRINTLN(F("app::saveValues")); Main::saveValues(false); // general configuration if(mWeb->args() > 0) { @@ -761,6 +783,7 @@ void app::saveValues(bool webSend = true) { //----------------------------------------------------------------------------- void app::updateCrc(void) { + DPRINTLN(F("app::updateCrc")); Main::updateCrc(); uint16_t crc; diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h index 055ea44f..30ba1639 100644 --- a/tools/esp8266/app.h +++ b/tools/esp8266/app.h @@ -43,6 +43,7 @@ class app : public Main { void loop(void); void handleIntr(void); + uint8_t app_loops; uint8_t getIrqPin(void) { return mSys->Radio.pinIrq; } diff --git a/tools/esp8266/config.h b/tools/esp8266/config.h index f7e89ebe..c803bb9c 100644 --- a/tools/esp8266/config.h +++ b/tools/esp8266/config.h @@ -7,7 +7,7 @@ // access point info -#define WIFI_AP_SSID "AHOY DTU" +#define WIFI_AP_SSID "AHOY-DTU" #define WIFI_AP_PWD "esp_8266" // stay in access point mode all the time //#define AP_ONLY @@ -24,7 +24,7 @@ #define WIFI_AP_ACTIVE_TIME 60 // default device name -#define DEF_DEVICE_NAME "ESP-DTU" +#define DEF_DEVICE_NAME "AHOY-DTU" // number of packets hold in buffer #define PACKET_BUFFER_SIZE 30 diff --git a/tools/esp8266/hmInverter.h b/tools/esp8266/hmInverter.h index b19289e2..ee90a6af 100644 --- a/tools/esp8266/hmInverter.h +++ b/tools/esp8266/hmInverter.h @@ -81,6 +81,7 @@ class Inverter { } void init(void) { + DPRINTLN(F("hmInverter.h:init")); getAssignment(); toRadioId(); record = new RECORDTYPE[listLen]; @@ -89,6 +90,7 @@ class Inverter { } uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId) { + DPRINTLN(F("hmInverter.h:getPosByChFld")); uint8_t pos = 0; for(; pos < listLen; pos++) { if((assign[pos].ch == channel) && (assign[pos].fieldId == fieldId)) @@ -98,18 +100,22 @@ class Inverter { } const char *getFieldName(uint8_t pos) { + DPRINTLN(F("hmInverter.h:getFieldName")); return fields[assign[pos].fieldId]; } const char *getUnit(uint8_t pos) { + DPRINTLN(F("hmInverter.h:getUnit")); return units[assign[pos].unitId]; } uint8_t getChannel(uint8_t pos) { + DPRINTLN(F("hmInverter.h:getChannel")); return assign[pos].ch; } void addValue(uint8_t pos, uint8_t buf[]) { + DPRINTLN(F("hmInverter.h:addValue")); uint8_t ptr = assign[pos].start; uint8_t end = ptr + assign[pos].num; uint16_t div = assign[pos].div; @@ -126,10 +132,12 @@ class Inverter { } RECORDTYPE getValue(uint8_t pos) { + DPRINTLN(F("hmInverter.h:getValue")); return record[pos]; } void doCalculations(void) { + DPRINTLN(F("hmInverter.h:doCalculations")); for(uint8_t i = 0; i < listLen; i++) { if(CMD_CALC == assign[i].div) { record[i] = calcFunctions[assign[i].start].func(this, assign[i].num); @@ -138,10 +146,12 @@ class Inverter { } bool isAvailable(uint32_t timestamp) { + DPRINTLN(F("hmInverter.h:isAvailable")); return ((timestamp - ts) < INACT_THRES_SEC); } bool isProducing(uint32_t timestamp) { + DPRINTLN(F("hmInverter.h:isProducing")); if(isAvailable(timestamp)) { uint8_t pos = getPosByChFld(CH0, FLD_PAC); return (getValue(pos) > INACT_PWR_THRESH); @@ -150,11 +160,13 @@ class Inverter { } uint32_t getLastTs(void) { + DPRINTLN(F("hmInverter.h:getLastTs")); return ts; } private: void toRadioId(void) { + DPRINTLN(F("hmInverter.h:toRadioId")); radioId.u64 = 0ULL; radioId.b[4] = serial.b[0]; radioId.b[3] = serial.b[1]; @@ -164,6 +176,7 @@ class Inverter { } void getAssignment(void) { + DPRINTLN(F("hmInverter.h:getAssignment")); if(INV_TYPE_1CH == type) { listLen = (uint8_t)(HM1CH_LIST_LEN); assign = (byteAssign_t*)hm1chAssignment; @@ -196,6 +209,7 @@ class Inverter { template static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) { + DPRINTLN(F("hmInverter.h:calcYieldTotalCh0")); if(NULL != iv) { T yield = 0; for(uint8_t i = 1; i <= iv->channels; i++) { @@ -209,6 +223,7 @@ static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) { template static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) { + DPRINTLN(F("hmInverter.h:calcYieldDayCh0")); if(NULL != iv) { T yield = 0; for(uint8_t i = 1; i <= iv->channels; i++) { @@ -222,6 +237,7 @@ static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) { template static T calcUdcCh(Inverter<> *iv, uint8_t arg0) { + DPRINTLN(F("hmInverter.h:calcUdcCh")); // arg0 = channel of source for(uint8_t i = 0; i < iv->listLen; i++) { if((FLD_UDC == iv->assign[i].fieldId) && (arg0 == iv->assign[i].ch)) { @@ -234,6 +250,7 @@ static T calcUdcCh(Inverter<> *iv, uint8_t arg0) { template static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) { + DPRINTLN(F("hmInverter.h:calcPowerDcCh0")); if(NULL != iv) { T dcPower = 0; for(uint8_t i = 1; i <= iv->channels; i++) { @@ -247,6 +264,7 @@ static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) { template static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) { + DPRINTLN(F("hmInverter.h:calcEfficiencyCh0")); if(NULL != iv) { uint8_t pos = iv->getPosByChFld(CH0, FLD_PAC); T acPower = iv->getValue(pos); @@ -263,6 +281,7 @@ static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) { template static T calcIrradiation(Inverter<> *iv, uint8_t arg0) { + DPRINTLN(F("hmInverter.h:calcIrradiation")); // arg0 = channel if(NULL != iv) { uint8_t pos = iv->getPosByChFld(arg0, FLD_PDC); diff --git a/tools/esp8266/hmRadio.h b/tools/esp8266/hmRadio.h index 708e9ef5..dae10b31 100644 --- a/tools/esp8266/hmRadio.h +++ b/tools/esp8266/hmRadio.h @@ -13,10 +13,11 @@ #define DTU_RADIO_ID ((uint64_t)0x1234567801ULL) #define DUMMY_RADIO_ID ((uint64_t)0xDEADBEEF01ULL) +#define RX_CHANNELS 5 #define RX_LOOP_CNT 600 -const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"}; +const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"}; //----------------------------------------------------------------------------- @@ -48,14 +49,17 @@ template > 8)); @@ -180,6 +189,7 @@ class HmRadio { } bool checkPaketCrc(uint8_t buf[], uint8_t *len, uint8_t rxCh) { + DPRINTLN(F("hmRadio.h:checkPaketCrc")); *len = (buf[0] >> 2); if(*len > (MAX_RF_PAYLOAD_SIZE - 2)) *len = MAX_RF_PAYLOAD_SIZE - 2; @@ -193,7 +203,10 @@ class HmRadio { return valid; } - bool switchRxCh(uint16_t addLoop = 0) { + bool switchRxCh(uint8_t addLoop = 0) { + //DPRINTLN(F("hmRadio.h:switchRxCh")); + //DPRINT(F("R")); + mRxLoopCnt += addLoop; if(mRxLoopCnt != 0) { mRxLoopCnt--; @@ -207,6 +220,7 @@ class HmRadio { } void dumpBuf(const char *info, uint8_t buf[], uint8_t len) { + //DPRINTLN(F("hmRadio.h:dumpBuf")); if(NULL != info) DPRINT(String(info)); for(uint8_t i = 0; i < len; i++) { @@ -217,6 +231,7 @@ class HmRadio { } bool isChipConnected(void) { + DPRINTLN(F("hmRadio.h:isChipConnected")); return mNrf24.isChipConnected(); } @@ -231,6 +246,7 @@ class HmRadio { private: void sendPacket(uint64_t invId, uint8_t buf[], uint8_t len, bool clear=false) { + DPRINTLN(F("hmRadio.h:sendPacket")); //DPRINTLN("sent packet: #" + String(mSendCnt)); //dumpBuf("SEN ", buf, len); if(mSerialDebug) { @@ -273,7 +289,8 @@ class HmRadio { } uint8_t getRxNxtChannel(void) { - if(++mRxChIdx >= 5) + + if(++mRxChIdx >= RX_CHANNELS) mRxChIdx = 0; return mRxChLst[mRxChIdx]; } @@ -282,7 +299,8 @@ class HmRadio { uint8_t mTxChLst[1]; //uint8_t mTxChIdx; - uint8_t mRxChLst[5]; + uint8_t mRxChLst[RX_CHANNELS]; + uint8_t mRxChIdx; uint16_t mRxLoopCnt; diff --git a/tools/esp8266/hmSystem.h b/tools/esp8266/hmSystem.h index a5b665e5..0306dbac 100644 --- a/tools/esp8266/hmSystem.h +++ b/tools/esp8266/hmSystem.h @@ -24,10 +24,12 @@ class HmSystem { } void setup() { + DPRINTLN(F("hmSystem.h:setup")); Radio.setup(&BufCtrl); } INVERTERTYPE *addInverter(const char *name, uint64_t serial, uint16_t chMaxPwr[]) { + DPRINTLN(F("hmSystem.h:addInverter")); if(MAX_INVERTER <= mNumInv) { DPRINT(F("max number of inverters reached!")); return NULL; @@ -64,6 +66,7 @@ class HmSystem { } INVERTERTYPE *findInverter(uint8_t buf[]) { + DPRINTLN(F("hmSystem.h:findInverter")); INVERTERTYPE *p; for(uint8_t i = 0; i < mNumInv; i++) { p = &mInverter[i]; @@ -77,6 +80,7 @@ class HmSystem { } INVERTERTYPE *getInverterByPos(uint8_t pos) { + //DPRINTLN(F("hmSystem.h:getInverterByPos")); if(mInverter[pos].serial.u64 != 0ULL) return &mInverter[pos]; else @@ -84,6 +88,7 @@ class HmSystem { } uint8_t getNumInverters(void) { + //DPRINTLN(F("hmSystem.h:getNumInverters")); return mNumInv; } diff --git a/tools/esp8266/html/h/index_html.h b/tools/esp8266/html/h/index_html.h index c75e9d64..ac8cca39 100644 --- a/tools/esp8266/html/h/index_html.h +++ b/tools/esp8266/html/h/index_html.h @@ -1,4 +1,4 @@ #ifndef __INDEX_HTML_H__ #define __INDEX_HTML_H__ -const char index_html[] PROGMEM = "Index - {DEVICE}

AHOY - {DEVICE}

Visualization

Setup

Uptime:

Time:

Statistics:

This project was started from this discussion. (Mikrocontroller.net)
New updates can be found on Github: https://github.com/grindylow/ahoy

Please report issues using the feature provided by Github.

© 2022

Update Firmware

AHOY :: {VERSION}

Reboot

"; +const char index_html[] PROGMEM = "Index - {DEVICE}

AHOY - {DEVICE}

Visualization

Setup

Uptime:

Time:

Statistics:

Every {TS}seconds the values are updated

This project was started from this discussion. (Mikrocontroller.net)
New updates can be found on Github: https://github.com/grindylow/ahoy

Please report issues using the feature provided by Github.

© 2022

Update Firmware

AHOY :: {VERSION}

Reboot

"; #endif /*__INDEX_HTML_H__*/ diff --git a/tools/esp8266/html/index.html b/tools/esp8266/html/index.html index 541caeb1..a5b1f633 100644 --- a/tools/esp8266/html/index.html +++ b/tools/esp8266/html/index.html @@ -5,9 +5,9 @@