diff --git a/ahoy.code-workspace b/ahoy.code-workspace new file mode 100644 index 00000000..20d5909e --- /dev/null +++ b/ahoy.code-workspace @@ -0,0 +1,45 @@ +{ + "folders": [ + { + "path": "." + }, + { + "path": "src" + } + ], + "settings": { + "files.associations": { + "algorithm": "cpp", + "array": "cpp", + "chrono": "cpp", + "deque": "cpp", + "format": "cpp", + "forward_list": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iterator": "cpp", + "list": "cpp", + "memory": "cpp", + "queue": "cpp", + "random": "cpp", + "regex": "cpp", + "vector": "cpp", + "xhash": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xmemory": "cpp", + "xstring": "cpp", + "xtree": "cpp", + "xutility": "cpp", + "*.tcc": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "string_view": "cpp", + "sstream": "cpp", + "istream": "cpp", + "ostream": "cpp" + }, + "editor.formatOnSave": false + } +} \ No newline at end of file diff --git a/src/CHANGES.md b/src/CHANGES.md index d566216a..316224ab 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,5 +1,12 @@ # Development Changes +## 0.8.57 - 2024-01-15 +* merge PR: fix immediate clearing of display after sunset #1364 +* merge PR: MI-MQTT and last retransmit #1363 +* fixed DTU-ID, now built from the unique part of the MAC +* fix lang in `/system` #1346 +* added protection to prevent update to wrong firmware (environment check) + ## 0.8.56 - 2024-01-15 * potential fix of update problems and random reboots #1359 #1354 diff --git a/src/app.cpp b/src/app.cpp index bd5402e8..f7efe827 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -46,7 +46,7 @@ void app::setup() { } #if defined(ESP32) if(mConfig->cmt.enabled) { - mCmtRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, mConfig->cmt.pinSclk, mConfig->cmt.pinSdio, mConfig->cmt.pinCsb, mConfig->cmt.pinFcsb, false); + mCmtRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, mConfig->cmt.pinSclk, mConfig->cmt.pinSdio, mConfig->cmt.pinCsb, mConfig->cmt.pinFcsb); } #endif #ifdef ETHERNET diff --git a/src/defines.h b/src/defines.h index e895981d..b5ed892f 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,11 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 8 +<<<<<<< HEAD #define VERSION_PATCH 560001 +======= +#define VERSION_PATCH 57 +>>>>>>> f503516c9feba7a7cc6fb427954165ce05cd7746 //------------------------------------- typedef struct { diff --git a/src/hm/CommQueue.h b/src/hm/CommQueue.h index 4e73d53a..13decc01 100644 --- a/src/hm/CommQueue.h +++ b/src/hm/CommQueue.h @@ -11,10 +11,9 @@ #include "hmInverter.h" #include "../utils/dbg.h" -// needs a '+1' because the comparison does not send if attempts is equal 0 -#define DEFAULT_ATTEMPS 5 + 1 -#define MORE_ATTEMPS_ALARMDATA 15 + 1 -#define MORE_ATTEMPS_GRIDONPROFILEPARA 15 + 1 +#define DEFAULT_ATTEMPS 5 +#define MORE_ATTEMPS_ALARMDATA 15 +#define MORE_ATTEMPS_GRIDONPROFILEPARA 15 template class CommQueue { diff --git a/src/hm/Communication.h b/src/hm/Communication.h index a8a46e1a..7b5c84f9 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -91,6 +91,7 @@ class Communication : public CommQueue<> { mIsRetransmit = false; if(NULL == q->iv->radio) cmdDone(false); // can't communicate while radio is not defined! + mFirstTry = q->iv->isAvailable(); q->iv->mCmd = q->cmd; q->iv->mIsSingleframeReq = false; mState = States::START; @@ -140,8 +141,25 @@ class Communication : public CommQueue<> { if((IV_HMS == q->iv->ivGen) || (IV_HMT == q->iv->ivGen)) { q->iv->radio->switchFrequency(q->iv, HOY_BOOT_FREQ_KHZ, (q->iv->config->frequency*FREQ_STEP_KHZ + HOY_BASE_FREQ_KHZ)); mWaitTime.startTimeMonitor(1000); - } else if(IV_MI == q->iv->ivGen) - q->iv->mIvTxCnt++; + } else { + if(IV_MI == q->iv->ivGen) + q->iv->mIvTxCnt++; + if(mFirstTry) { + mFirstTry = false; + setAttempt(); + mHeu.evalTxChQuality(q->iv, false, 0, 0); + //q->iv->radioStatistics.rxFailNoAnser++; + q->iv->radioStatistics.retransmits++; + mWaitTime.stopTimeMonitor(); + mState = States::START; + + /*if(*mSerialDebug) { + DPRINT_IVID(DBG_INFO, q->iv->id); + DBGPRINTLN(F("second try")); + }*/ + return; + } + } } closeRequest(q, false); break; @@ -178,11 +196,11 @@ class Communication : public CommQueue<> { yield(); } - if(0 == q->attempts) { + /*if(0 == q->attempts) { DPRINT_IVID(DBG_INFO, q->iv->id); DBGPRINT(F("no attempts left")); closeRequest(q, false); - } else { + } else {*/ if(q->iv->ivGen != IV_MI) { mState = States::CHECK_PACKAGE; } else { @@ -207,7 +225,7 @@ class Communication : public CommQueue<> { closeRequest(q, true); } } - } + //} } break; @@ -235,6 +253,12 @@ class Communication : public CommQueue<> { } if(framnr) { + if(0 == q->attempts) { + DPRINT_IVID(DBG_INFO, q->iv->id); + DBGPRINT(F("no attempts left")); + closeRequest(q, false); + return; + } setAttempt(); if(*mSerialDebug) { @@ -516,15 +540,15 @@ class Communication : public CommQueue<> { } void sendRetransmit(const queue_s *q, uint8_t i) { - if(q->attempts) { + //if(q->attempts) { q->iv->radio->sendCmdPacket(q->iv, TX_REQ_INFO, (SINGLE_FRAME + i), true); q->iv->radioStatistics.retransmits++; mWaitTime.startTimeMonitor(SINGLEFR_TIMEOUT); // timeout mState = States::WAIT; - } else { + /*} else { //add(q, true); closeRequest(q, false); - } + }*/ } private: @@ -547,7 +571,6 @@ class Communication : public CommQueue<> { q->iv->mGotLastMsg = false; q->iv->miMultiParts = 0; mIsRetransmit = false; - mFirstTry = false; // for correct reset mState = States::RESET; DBGPRINTLN(F("-----")); } @@ -604,6 +627,8 @@ class Communication : public CommQueue<> { rec->ts = q->ts; q->iv->setValue(1, rec, (uint32_t) ((p->packet[24] << 8) + p->packet[25])/1); q->iv->miMultiParts +=4; + rec->mqttSentStatus = MqttSentStatus::NEW_DATA; + } else if ( p->packet[9] == 0x01 || p->packet[9] == 0x10 ) {//second frame for MI, 3rd gen. answers in 0x10 DPRINT_IVID(DBG_INFO, q->iv->id); if ( p->packet[9] == 0x01 ) { @@ -620,6 +645,7 @@ class Communication : public CommQueue<> { record_t<> *rec = q->iv->getRecordStruct(InverterDevInform_Simple); // choose the record structure rec->ts = q->ts; q->iv->setValue(0, rec, (uint32_t) ((((p->packet[10] << 8) | p->packet[11]) << 8 | p->packet[12]) << 8 | p->packet[13])/1); + rec->mqttSentStatus = MqttSentStatus::NEW_DATA; if(*mSerialDebug) { DPRINT(DBG_INFO,F("HW_FB_TLmValue ")); @@ -667,6 +693,7 @@ class Communication : public CommQueue<> { inline void miGPFDecode(packet_t *p, const queue_s *q) { record_t<> *rec = q->iv->getRecordStruct(InverterDevInform_Simple); // choose the record structure rec->ts = q->ts; + rec->mqttSentStatus = MqttSentStatus::NEW_DATA; q->iv->setValue(2, rec, (uint32_t) (((p->packet[10] << 8) | p->packet[11]))); //FLD_GRID_PROFILE_CODE q->iv->setValue(3, rec, (uint32_t) (((p->packet[12] << 8) | p->packet[13]))); //FLD_GRID_PROFILE_VERSION @@ -849,6 +876,8 @@ class Communication : public CommQueue<> { if (!stsok) { q->iv->setValue(q->iv->getPosByChFld(0, FLD_EVT, rec), rec, prntsts); q->iv->lastAlarm[0] = alarm_t(prntsts, q->ts, 0); + rec->ts = q->ts; + rec->mqttSentStatus = MqttSentStatus::NEW_DATA; } if (q->iv->alarmMesIndex < rec->record[q->iv->getPosByChFld(0, FLD_EVT, rec)]) { @@ -907,17 +936,12 @@ class Communication : public CommQueue<> { iv->setValue(iv->getPosByChFld(0, FLD_PAC, rec), rec, (float) ac_pow/10); iv->doCalculations(); + rec->mqttSentStatus = MqttSentStatus::NEW_DATA; // update status state-machine, if (ac_pow) iv->isProducing(); - //closeRequest(iv, iv->miMultiParts > 5); - - //mHeu.setGotAll(iv); - //cmdDone(false); if(NULL != mCbPayload) (mCbPayload)(RealTimeRunData_Debug, iv); - - //mState = States::RESET; // everything ok, next request } private: diff --git a/src/hm/radio.h b/src/hm/radio.h index e5eda128..1422b285 100644 --- a/src/hm/radio.h +++ b/src/hm/radio.h @@ -103,16 +103,19 @@ class Radio { void generateDtuSn(void) { uint32_t chipID = 0; #ifdef ESP32 - uint64_t MAC = ESP.getEfuseMac(); - chipID = ((MAC >> 8) & 0xFF0000) | ((MAC >> 24) & 0xFF00) | ((MAC >> 40) & 0xFF); + chipID = (ESP.getEfuseMac() & 0xffffffff); #else chipID = ESP.getChipId(); #endif - mDtuSn = 0x80000000; // the first digit is an 8 for DTU production year 2022, the rest is filled with the ESP chipID in decimal - for(int i = 0; i < 7; i++) { - mDtuSn |= (chipID % 10) << (i * 4); - chipID /= 10; + + uint8_t t; + for(int i = 0; i < (7 << 2); i += 4) { + t = (chipID >> i) & 0x0f; + if(t > 0x09) + t -= 6; + mDtuSn |= (t << i); } + mDtuSn |= 0x80000000; // the first digit is an 8 for DTU production year 2022, the rest is filled with the ESP chipID in decimal } uint32_t mDtuSn; diff --git a/src/plugins/Display/Display_Mono.h b/src/plugins/Display/Display_Mono.h index c8d25f8b..58b4224f 100644 --- a/src/plugins/Display/Display_Mono.h +++ b/src/plugins/Display/Display_Mono.h @@ -81,7 +81,7 @@ class DisplayMono { mDispWidth = mDisplay->getDisplayWidth(); mDispHeight = mDisplay->getDisplayHeight(); mDispSwitchTime.stopTimeMonitor(); - if (mCfg->graph_ratio == 100) // if graph ratio is 100% start in graph mode + if (100 == mCfg->graph_ratio) // if graph ratio is 100% start in graph mode mDispSwitchState = DispSwitchState::GRAPH; else if (mCfg->graph_ratio != 0) mDispSwitchTime.startTimeMonitor(150 * (100 - mCfg->graph_ratio)); // start display mode change only if ratio is neither 0 nor 100 @@ -90,39 +90,82 @@ class DisplayMono { // pixelshift screensaver with wipe effect void calcPixelShift(int range) { int8_t mod = (millis() / 10000) % ((range >> 1) << 2); - mPixelshift = mCfg->screenSaver == 1 ? ((mod < range) ? mod - (range >> 1) : -(mod - range - (range >> 1) + 1)) : 0; + mPixelshift = (1 == mCfg->screenSaver) ? ((mod < range) ? mod - (range >> 1) : -(mod - range - (range >> 1) + 1)) : 0; } + protected: + enum class PowerGraphState { + NO_TIME_SYNC, + IN_PERIOD, + WAIT_4_NEW_PERIOD, + WAIT_4_RESTART + }; + + // initialize power graph and allocate data buffer based on pixel width void initPowerGraph(uint8_t width, uint8_t height) { DBGPRINTLN(F("---- Init Power Graph ----")); mPgWidth = width; mPgHeight = height; mPgData = new float[mPgWidth]; + mPgState = PowerGraphState::NO_TIME_SYNC; resetPowerGraph(); -/* - Inverter<> *iv; - mPgMaxAvailPower = 0; - uint8_t nInv = mSys->getNumInverters(); - for (uint8_t i = 0; i < nInv; i++) { - iv = mSys->getInverterByPos(i); - if (iv == NULL) - continue; - for (uint8_t ch = 0; ch < 6; ch++) { - mPgMaxAvailPower += iv->config->chMaxPwr[ch]; - } - } - DBGPRINTLN("max. Power = " + String(mPgMaxAvailPower));*/ } + // add new value to power graph and maintain state engine for period times void addPowerGraphEntry(float val) { - if ((nullptr != mPgData) && (mDisplayData->utcTs > 0)) { // precondition: power graph initialized and utc time available - calcPowerGraphValues(); - //mPgData[mPgLastPos] = std::max(mPgData[mPgLastPos], (uint8_t) (val * 255.0 / mPgMaxAvailPower)); // normalizing of data to 0-255 - mPgData[mPgLastPos] = std::max(mPgData[mPgLastPos], val); - mPgMaxPwr = std::max(mPgMaxPwr, val); // max value of stored data for scaling of y-axis + if (nullptr == mPgData) // power graph not initialized + return; + + bool storeStartEndTimes = false; + bool store_entry = false; + switch(mPgState) { + case PowerGraphState::NO_TIME_SYNC: + if ((mDisplayData->pGraphStartTime > 0) + && (mDisplayData->pGraphEndTime > 0) // wait until period data is available ... + && (mDisplayData->utcTs >= mDisplayData->pGraphStartTime) + && (mDisplayData->utcTs < mDisplayData->pGraphEndTime)) // and current time is in period + { + storeStartEndTimes = true; // period was received -> store + store_entry = true; + mPgState = PowerGraphState::IN_PERIOD; + } + break; + case PowerGraphState::IN_PERIOD: + if (mDisplayData->utcTs > mPgEndTime) // check if end of day is reached ... + mPgState = PowerGraphState::WAIT_4_NEW_PERIOD; // then wait for new period setting + else + store_entry = true; + break; + case PowerGraphState::WAIT_4_NEW_PERIOD: + if ((mPgStartTime != mDisplayData->pGraphStartTime) || (mPgEndTime != mDisplayData->pGraphEndTime)) { // wait until new time period was received ... + storeStartEndTimes = true; // and store it for next period + mPgState = PowerGraphState::WAIT_4_RESTART; + } + break; + case PowerGraphState::WAIT_4_RESTART: + if ((mDisplayData->utcTs >= mPgStartTime) && (mDisplayData->utcTs < mPgEndTime)) { // wait until current time is in period again ... + resetPowerGraph(); // then reset power graph data + store_entry = true; + mPgState = PowerGraphState::IN_PERIOD; + } + break; + } + + // store start and end times of current time period and calculate period length + if (storeStartEndTimes) { + mPgStartTime = mDisplayData->pGraphStartTime; + mPgEndTime = mDisplayData->pGraphEndTime; + mPgPeriod = mDisplayData->pGraphEndTime - mDisplayData->pGraphStartTime; // time period of power graph in sec for scaling of x-axis + } + + if (store_entry) { + mPgLastPos = std::min((uint8_t) sss2PgPos(mDisplayData->utcTs - mPgStartTime), (uint8_t) (mPgWidth - 1)); // current datapoint based on seconds since start + mPgData[mPgLastPos] = std::max(mPgData[mPgLastPos], val); // update current datapoint to maximum of all seen values + mPgMaxPwr = std::max(mPgMaxPwr, val); // update max value of stored data for scaling of y-axis } } + // plot power graph to given display offset void plotPowerGraph(uint8_t xoff, uint8_t yoff) { if (nullptr == mPgData) // power graph not initialized return; @@ -146,7 +189,7 @@ class DisplayMono { tm.Minute = 0; tm.Second = 0; for (; tm.Hour <= endHour; tm.Hour++) { - uint8_t x_pos_screen = getPowerGraphXpos(sss2pgpos((uint32_t) makeTime(tm) - mDisplayData->pGraphStartTime)); // scale horizontal axis + uint8_t x_pos_screen = getPowerGraphXpos(sss2PgPos((uint32_t) makeTime(tm) - mDisplayData->pGraphStartTime)); // scale horizontal axis mDisplay->drawPixel(xoff + x_pos_screen, yoff - 1); } @@ -163,8 +206,8 @@ class DisplayMono { // draw curve for (uint8_t i = 1; i <= mPgLastPos; i++) { - mDisplay->drawLine(xoff + getPowerGraphXpos(i - 1), yoff - getPowerGraphYpos(i - 1), - xoff + getPowerGraphXpos(i), yoff - getPowerGraphYpos(i)); + mDisplay->drawLine(xoff + getPowerGraphXpos(i - 1), yoff - getPowerGraphValueYpos(i - 1), + xoff + getPowerGraphXpos(i), yoff - getPowerGraphValueYpos(i)); } // print max power value @@ -195,6 +238,7 @@ class DisplayMono { return change; } + // reset power graph void resetPowerGraph() { if (mPgData != nullptr) { mPgMaxPwr = 0.0; @@ -205,34 +249,28 @@ class DisplayMono { } } - uint8_t sss2pgpos(uint seconds_since_start) { - uint32_t diff = (mDisplayData->pGraphEndTime - mDisplayData->pGraphStartTime); - if(diff) - return (seconds_since_start * (mPgWidth - 1) / diff); - return 0; - } - - void calcPowerGraphValues() { - mPgPeriod = mDisplayData->pGraphEndTime - mDisplayData->pGraphStartTime; // length of power graph for scaling of x-axis - uint32_t oldTimeOfDay = mPgTimeOfDay; - mPgTimeOfDay = (mDisplayData->utcTs > mDisplayData->pGraphStartTime) ? mDisplayData->utcTs - mDisplayData->pGraphStartTime : 0; // current time of day with respect to current sunrise time - if (oldTimeOfDay > mPgTimeOfDay) // new day -> reset old data - resetPowerGraph(); - if(0 == mPgPeriod) - mPgPeriod = 1; - mPgLastPos = std::min((uint8_t) (mPgTimeOfDay * (mPgWidth - 1) / mPgPeriod), (uint8_t) (mPgWidth - 1)); // current datapoint based on currenct time of day + // get power graph datapoint index, scaled to current time period, by seconds since start + uint8_t sss2PgPos(uint seconds_since_start) { + if(mPgPeriod) + return (seconds_since_start * (mPgWidth - 1) / mPgPeriod); + else + return 0; } - uint8_t getPowerGraphXpos(uint8_t p) { + // get X-position of power graph, scaled to lastpos, by according data point index + uint8_t getPowerGraphXpos(uint8_t p) { if ((p <= mPgLastPos) && (mPgLastPos > 0)) return((p * (mPgWidth - 1)) / mPgLastPos); // scaling of x-axis - return 0; + else + return 0; } - uint8_t getPowerGraphYpos(uint8_t p) { + // get Y-position of power graph, scaled to maximum value, by according datapoint index + uint8_t getPowerGraphValueYpos(uint8_t p) { if ((p < mPgWidth) && (mPgMaxPwr > 0)) return((mPgData[p] * (uint32_t) mPgHeight / mPgMaxPwr)); // scaling of data to graph height - return 0; + else + return 0; } protected: @@ -254,9 +292,11 @@ class DisplayMono { float *mPgData = nullptr; uint8_t mPgHeight = 0; float mPgMaxPwr = 0.0; - uint32_t mPgPeriod = 0; // seconds - uint32_t mPgTimeOfDay = 0; + uint32_t mPgStartTime = 0; + uint32_t mPgEndTime = 0; + uint32_t mPgPeriod = 0; // seconds uint8_t mPgLastPos = 0; + PowerGraphState mPgState = PowerGraphState::NO_TIME_SYNC; uint16_t mDispHeight; uint8_t mLuminance; diff --git a/src/plugins/Display/Display_Mono_128X64.h b/src/plugins/Display/Display_Mono_128X64.h index 34f35834..b4aa08cc 100644 --- a/src/plugins/Display/Display_Mono_128X64.h +++ b/src/plugins/Display/Display_Mono_128X64.h @@ -89,9 +89,8 @@ class DisplayMono128X64 : public DisplayMono { calcPixelShift(pixelShiftRange); // add new power data to power graph - if (mDisplayData->nrProducing > 0) { + if (mDisplayData->nrProducing > 0) addPowerGraphEntry(mDisplayData->totalPower); - } // print Date and time if (0 != mDisplayData->utcTs) diff --git a/src/web/RestApi.h b/src/web/RestApi.h index edf92a97..097adac3 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -326,8 +326,8 @@ class RestApi { void getHtmlSystem(AsyncWebServerRequest *request, JsonObject obj) { getSysInfo(request, obj.createNestedObject(F("system"))); getGeneric(request, obj.createNestedObject(F("generic"))); - char tmp[100]; - snprintf(tmp, 100, "%s

%s", FACTORY_RESET, BTN_REBOOT); + char tmp[200]; + snprintf(tmp, 200, "%s

%s", FACTORY_RESET, BTN_REBOOT); obj[F("html")] = String(tmp); } diff --git a/src/web/html/update.html b/src/web/html/update.html index 3fed75a5..52ace5f1 100644 --- a/src/web/html/update.html +++ b/src/web/html/update.html @@ -10,7 +10,7 @@
{#SELECT_FILE} (*.bin) -

{#INSTALLED_VERSION}:

+

{#INSTALLED_VERSION}:

@@ -23,17 +23,34 @@
{#HTML_FOOTER}