From aa9da851a1b59dad6f48a9c3b0dcc9c05e1188a6 Mon Sep 17 00:00:00 2001
From: Patrick Amrhein
Date: Sun, 2 Jun 2024 18:42:25 +0200
Subject: [PATCH] merge development03
---
.gitattributes | 1 +
.github/workflows/compile_development.yml | 33 +-
.gitignore | 1 +
manual/factory_firmware.md | 56 +++
patches/GxEPD2_HAL.patch | 392 +++++++++++++++
patches/GxEPD2_SW_SPI.patch | 362 --------------
.../htmlPreprocessorDefines.cpython-311.pyc | Bin 0 -> 2175 bytes
scripts/add_littlefs_binary.py | 79 +++
scripts/applyPatches.py | 6 +-
scripts/convertHtml.py | 11 +
scripts/getVersion.py | 3 +-
src/CHANGES.md | 102 ++++
src/app.cpp | 126 +++--
src/app.h | 39 +-
src/appInterface.h | 4 +
src/config/config.h | 7 +-
src/config/settings.h | 67 ++-
src/defines.h | 65 +--
src/hm/CommQueue.h | 27 +-
src/hm/Communication.h | 4 +-
src/hm/{hmRadio.h => NrfRadio.h} | 73 +--
src/hm/{radio.h => Radio.h} | 2 +-
src/hm/hmDefines.h | 63 ++-
src/hm/hmInverter.h | 139 ++++--
src/hm/hmSystem.h | 18 +-
src/hm/nrfHal.h | 18 +-
src/hms/{hmsRadio.h => CmtRadio.h} | 32 +-
src/hms/cmt2300a.h | 4 +-
src/hms/cmtHal.h | 16 +-
src/hms/hmsDefines.h | 73 ++-
src/network/AhoyEthernet.h | 54 +-
src/network/AhoyEthernetSpi.h | 31 +-
src/network/AhoyNetwork.h | 27 +-
src/network/AhoyWifiAp.h | 2 +
src/network/AhoyWifiEsp32.h | 64 ++-
src/network/AhoyWifiEsp8266.h | 15 +-
src/platformio.ini | 9 +-
src/plugins/Display/Display.h | 10 +-
src/plugins/Display/Display_ePaper.cpp | 24 +-
src/plugins/Display/Display_ePaper.h | 7 +
src/plugins/Display/epdHal.h | 304 ++++++++++++
src/plugins/MaxPower.h | 67 +++
src/plugins/history.h | 6 +-
src/publisher/pubMqtt.h | 18 +-
src/publisher/pubMqttIvData.h | 77 ++-
src/utils/dbg.h | 2 +-
src/utils/spiPatcher.cpp | 3 +-
src/utils/spiPatcher.h | 78 ++-
src/web/Protection.h | 2 +-
src/web/RestApi.h | 115 +++--
src/web/html/about.html | 2 +-
src/web/html/api.js | 8 +-
src/web/html/colorBright.css | 1 +
src/web/html/colorDark.css | 1 +
src/web/html/history.html | 32 +-
src/web/html/index.html | 24 +-
src/web/html/serial.html | 7 +-
src/web/html/setup.html | 77 ++-
src/web/html/style.css | 11 +-
src/web/html/system.html | 7 +-
src/web/html/update.html | 23 +-
src/web/html/visualization.html | 37 +-
src/web/html/wizard.html | 60 ++-
src/web/lang.h | 24 +
src/web/lang.json | 36 +-
src/web/web.h | 8 +-
tools/NodeRED/flows-mqtt-json-example.json | 466 ++++++++++++++++++
67 files changed, 2601 insertions(+), 961 deletions(-)
create mode 100644 .gitattributes
create mode 100644 manual/factory_firmware.md
create mode 100644 patches/GxEPD2_HAL.patch
delete mode 100644 patches/GxEPD2_SW_SPI.patch
create mode 100644 scripts/__pycache__/htmlPreprocessorDefines.cpython-311.pyc
create mode 100644 scripts/add_littlefs_binary.py
rename src/hm/{hmRadio.h => NrfRadio.h} (91%)
rename src/hm/{radio.h => Radio.h} (99%)
rename src/hms/{hmsRadio.h => CmtRadio.h} (91%)
create mode 100644 src/plugins/Display/epdHal.h
create mode 100644 src/plugins/MaxPower.h
create mode 100644 tools/NodeRED/flows-mqtt-json-example.json
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..9fcb3325
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+patches/GxEPD2_HAL.patch eol=lf
\ No newline at end of file
diff --git a/.github/workflows/compile_development.yml b/.github/workflows/compile_development.yml
index 1d536b5e..b5e0e0e1 100644
--- a/.github/workflows/compile_development.yml
+++ b/.github/workflows/compile_development.yml
@@ -70,6 +70,11 @@ jobs:
- name: Run PlatformIO
run: pio run -d src -e ${{ matrix.variant }}
+ - name: Compress .elf
+ uses: edgarrc/action-7z@v1
+ with:
+ args: 7z a -t7z -mx=9 src/.pio/build/${{ matrix.variant }}/firmware.elf.7z ./src/.pio/build/${{ matrix.variant }}/firmware.elf
+
- name: Rename Firmware
run: python scripts/getVersion.py ${{ matrix.variant }} >> $GITHUB_OUTPUT
@@ -132,6 +137,11 @@ jobs:
- name: Run PlatformIO
run: pio run -d src -e ${{ matrix.variant }}
+ - name: Compress .elf
+ uses: edgarrc/action-7z@v1
+ with:
+ args: 7z a -t7z -mx=9 src/.pio/build/${{ matrix.variant }}/firmware.elf.7z ./src/.pio/build/${{ matrix.variant }}/firmware.elf
+
- name: Rename Firmware
run: python scripts/getVersion.py ${{ matrix.variant }} >> $GITHUB_OUTPUT
@@ -188,15 +198,6 @@ jobs:
with:
name: dev-*
- - name: Create Artifact
- uses: actions/upload-artifact@v4
- with:
- name: dev-${{ steps.version_name.outputs.name }}
- path: |
- ${{ steps.version_name.outputs.name }}/*
- manual/User_Manual.md
- manual/Getting_Started.md
-
- name: Deploy
uses: nogsantos/scp-deploy@master
with:
@@ -206,3 +207,17 @@ jobs:
port: ${{ secrets.FW_SSH_PORT }}
user: ${{ secrets.FW_SSH_USER }}
key: ${{ secrets.FW_SSH_KEY }}
+
+ - name: Clean elf files (7z compressed) for Artifact
+ run: |
+ rm -f \
+ ${{ steps.version_name.outputs.name }}/*/*.elf.7z
+
+ - name: Create Artifact
+ uses: actions/upload-artifact@v4
+ with:
+ name: dev-${{ steps.version_name.outputs.name }}
+ path: |
+ ${{ steps.version_name.outputs.name }}/*
+ manual/User_Manual.md
+ manual/Getting_Started.md
diff --git a/.gitignore b/.gitignore
index b5c699cc..bb6620a2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@
src/config/config_override.h
src/web/html/h/*
src/web/html/tmp/*
+src/data/*
/**/Debug
/**/v16/*
*.db
diff --git a/manual/factory_firmware.md b/manual/factory_firmware.md
new file mode 100644
index 00000000..a4025eea
--- /dev/null
+++ b/manual/factory_firmware.md
@@ -0,0 +1,56 @@
+# Generate factory firmware (ESP32)
+
+If the firmware should already contain predefined settings this guide will help you to compile these into a single binary file.
+
+## Generate default settings
+
+First install on the requested platform the standard firmware and configure everything to your needs. Once you did all changes store them and export them to a `json` file.
+
+## Further prepare default settings
+
+First create a directory `data` inside the following project path: `src/`.
+
+As the export removes all your passwords you need to add them again to the `json` file. Open the `json` file with a text editor and search for all the `"pwd":""` sections. Between the second bunch of quotation marks you have to place the password.
+
+*Note: It's recommended to keep all information in one line to save space on the ESP littlefs partition*
+
+Next rename your export file to `settings.json` and move it to the new created directory. It should be look similar to this:
+
+```
+ahoy
+ |-- src
+ |-- data
+ |-- settings.json
+ |-- config
+ |-- network
+ ...
+```
+
+## build firmware
+
+Choose your prefered environment and build firmware as usual. Once the process is finished you should find along with the standard `firmware.bin` an additional file called `firmware.factory.bin`. Both files are located here: `src/.pio/build/[ENVIRONMENT]/`
+
+## Upload to device
+
+Navigate to the firmware output directory `src/.pio/build/[ENVIRONMENT]/` and open a terminal or vice versa.
+
+Python:
+`esptool.py -b 921600 write_flash --flash_mode dio --flash_size detect 0x0 firmware.factory.bin`
+
+Windows:
+`esptool.exe -b 921600 write_flash --flash_mode dio --flash_size detect 0x0 firmware.factory.bin`
+
+The upload should be finished within one minute.
+
+## Testing
+
+Reboot your ESP an check if all your settings are present.
+
+## Keep updated with 'Mainline'
+
+From time to time a new version of AhoyDTU will be published. To get the changes into your already prepared factory binary generation environment you have to do only a few steps:
+
+1. pull new changes from remote: `git pull`
+2. check if the `data` folder is still there and contains the `settings.json`
+3. build and upload
+4. enjoy
diff --git a/patches/GxEPD2_HAL.patch b/patches/GxEPD2_HAL.patch
new file mode 100644
index 00000000..d7b394eb
--- /dev/null
+++ b/patches/GxEPD2_HAL.patch
@@ -0,0 +1,392 @@
+diff --git a/src/GxEPD2_EPD.cpp b/src/GxEPD2_EPD.cpp
+index 8df8bef..e9dfb19 100644
+--- a/src/GxEPD2_EPD.cpp
++++ b/src/GxEPD2_EPD.cpp
+@@ -17,11 +17,10 @@
+ #include
+ #endif
+
+-GxEPD2_EPD::GxEPD2_EPD(int16_t cs, int16_t dc, int16_t rst, int16_t busy, int16_t busy_level, uint32_t busy_timeout,
++GxEPD2_EPD::GxEPD2_EPD(GxEPD2_HalInterface *hal, int16_t busy_level, uint32_t busy_timeout,
+ uint16_t w, uint16_t h, GxEPD2::Panel p, bool c, bool pu, bool fpu) :
+ WIDTH(w), HEIGHT(h), panel(p), hasColor(c), hasPartialUpdate(pu), hasFastPartialUpdate(fpu),
+- _cs(cs), _dc(dc), _rst(rst), _busy(busy), _busy_level(busy_level), _busy_timeout(busy_timeout), _diag_enabled(false),
+- _pSPIx(&SPI), _spi_settings(4000000, MSBFIRST, SPI_MODE0)
++ _hal(hal), _busy_level(busy_level), _busy_timeout(busy_timeout), _diag_enabled(false)
+ {
+ _initial_write = true;
+ _initial_refresh = true;
+@@ -54,44 +53,10 @@ void GxEPD2_EPD::init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset
+ Serial.begin(serial_diag_bitrate);
+ _diag_enabled = true;
+ }
+- if (_cs >= 0)
+- {
+- digitalWrite(_cs, HIGH); // preset (less glitch for any analyzer)
+- pinMode(_cs, OUTPUT);
+- digitalWrite(_cs, HIGH); // set (needed e.g. for RP2040)
+- }
+- if (_dc >= 0)
+- {
+- digitalWrite(_dc, HIGH); // preset (less glitch for any analyzer)
+- pinMode(_dc, OUTPUT);
+- digitalWrite(_dc, HIGH); // set (needed e.g. for RP2040)
+- }
+- _reset();
+- if (_busy >= 0)
+- {
+- pinMode(_busy, INPUT);
+- }
+- _pSPIx->begin();
+- if (_busy == MISO) // may be overridden
+- {
+- pinMode(_busy, INPUT);
+- }
+- if (_dc == MISO) // may be overridden, TTGO T5 V2.66
+- {
+- pinMode(_dc, OUTPUT);
+- }
+- if (_cs == MISO) // may be overridden
+- {
+- pinMode(_cs, INPUT);
+- }
+ }
+
+ void GxEPD2_EPD::end()
+ {
+- _pSPIx->end();
+- if (_cs >= 0) pinMode(_cs, INPUT);
+- if (_dc >= 0) pinMode(_dc, INPUT);
+- if (_rst >= 0) pinMode(_rst, INPUT);
+ }
+
+ void GxEPD2_EPD::setBusyCallback(void (*busyCallback)(const void*), const void* busy_callback_parameter)
+@@ -100,34 +65,27 @@ void GxEPD2_EPD::setBusyCallback(void (*busyCallback)(const void*), const void*
+ _busy_callback_parameter = busy_callback_parameter;
+ }
+
+-void GxEPD2_EPD::selectSPI(SPIClass& spi, SPISettings spi_settings)
+-{
+- _pSPIx = &spi;
+- _spi_settings = spi_settings;
+-}
+-
+ void GxEPD2_EPD::_reset()
+ {
+- if (_rst >= 0)
+ {
+ if (_pulldown_rst_mode)
+ {
+- digitalWrite(_rst, LOW);
+- pinMode(_rst, OUTPUT);
+- digitalWrite(_rst, LOW);
++ _hal->rst(LOW);
++ _hal->rstMode(OUTPUT);
++ _hal->rst(LOW);
+ delay(_reset_duration);
+- pinMode(_rst, INPUT_PULLUP);
++ _hal->rstMode(INPUT_PULLUP);
+ delay(_reset_duration > 10 ? _reset_duration : 10);
+ }
+ else
+ {
+- digitalWrite(_rst, HIGH); // NEEDED for Waveshare "clever" reset circuit, power controller before reset pulse, preset (less glitch for any analyzer)
+- pinMode(_rst, OUTPUT);
+- digitalWrite(_rst, HIGH); // NEEDED for Waveshare "clever" reset circuit, power controller before reset pulse, set (needed e.g. for RP2040)
++ _hal->rst(HIGH); // NEEDED for Waveshare "clever" reset circuit, power controller before reset pulse, preset (less glitch for any analyzer)
++ _hal->rstMode(OUTPUT);
++ _hal->rst(HIGH); // NEEDED for Waveshare "clever" reset circuit, power controller before reset pulse, set (needed e.g. for RP2040)
+ delay(10); // NEEDED for Waveshare "clever" reset circuit, at least delay(2);
+- digitalWrite(_rst, LOW);
++ _hal->rst(LOW);
+ delay(_reset_duration);
+- digitalWrite(_rst, HIGH);
++ _hal->rst(HIGH);
+ delay(_reset_duration > 10 ? _reset_duration : 10);
+ }
+ _hibernating = false;
+@@ -136,16 +94,15 @@ void GxEPD2_EPD::_reset()
+
+ void GxEPD2_EPD::_waitWhileBusy(const char* comment, uint16_t busy_time)
+ {
+- if (_busy >= 0)
+ {
+ delay(1); // add some margin to become active
+ unsigned long start = micros();
+ while (1)
+ {
+- if (digitalRead(_busy) != _busy_level) break;
++ if (_hal->getBusy() != _busy_level) break;
+ if (_busy_callback) _busy_callback(_busy_callback_parameter);
+ else delay(1);
+- if (digitalRead(_busy) != _busy_level) break;
++ if (_hal->getBusy() != _busy_level) break;
+ if (micros() - start > _busy_timeout)
+ {
+ Serial.println("Busy Timeout!");
+@@ -169,120 +126,59 @@ void GxEPD2_EPD::_waitWhileBusy(const char* comment, uint16_t busy_time)
+ }
+ (void) start;
+ }
+- else delay(busy_time);
+ }
+
+ void GxEPD2_EPD::_writeCommand(uint8_t c)
+ {
+- _pSPIx->beginTransaction(_spi_settings);
+- if (_dc >= 0) digitalWrite(_dc, LOW);
+- if (_cs >= 0) digitalWrite(_cs, LOW);
+- _pSPIx->transfer(c);
+- if (_cs >= 0) digitalWrite(_cs, HIGH);
+- if (_dc >= 0) digitalWrite(_dc, HIGH);
+- _pSPIx->endTransaction();
++ _hal->writeCmd(c);
+ }
+
+ void GxEPD2_EPD::_writeData(uint8_t d)
+ {
+- _pSPIx->beginTransaction(_spi_settings);
+- if (_cs >= 0) digitalWrite(_cs, LOW);
+- _pSPIx->transfer(d);
+- if (_cs >= 0) digitalWrite(_cs, HIGH);
+- _pSPIx->endTransaction();
++ _hal->write(d);
+ }
+
+ void GxEPD2_EPD::_writeData(const uint8_t* data, uint16_t n)
+ {
+- _pSPIx->beginTransaction(_spi_settings);
+- if (_cs >= 0) digitalWrite(_cs, LOW);
+- for (uint16_t i = 0; i < n; i++)
+- {
+- _pSPIx->transfer(*data++);
+- }
+- if (_cs >= 0) digitalWrite(_cs, HIGH);
+- _pSPIx->endTransaction();
++ _hal->write(data, n);
+ }
+
+ void GxEPD2_EPD::_writeDataPGM(const uint8_t* data, uint16_t n, int16_t fill_with_zeroes)
+ {
+- _pSPIx->beginTransaction(_spi_settings);
+- if (_cs >= 0) digitalWrite(_cs, LOW);
+- for (uint16_t i = 0; i < n; i++)
+- {
+- _pSPIx->transfer(pgm_read_byte(&*data++));
+- }
+- while (fill_with_zeroes > 0)
+- {
+- _pSPIx->transfer(0x00);
+- fill_with_zeroes--;
+- }
+- if (_cs >= 0) digitalWrite(_cs, HIGH);
+- _pSPIx->endTransaction();
++ _hal->write(data, n, fill_with_zeroes);
+ }
+
+ void GxEPD2_EPD::_writeDataPGM_sCS(const uint8_t* data, uint16_t n, int16_t fill_with_zeroes)
+ {
+- _pSPIx->beginTransaction(_spi_settings);
+- for (uint8_t i = 0; i < n; i++)
+- {
+- if (_cs >= 0) digitalWrite(_cs, LOW);
+- _pSPIx->transfer(pgm_read_byte(&*data++));
+- if (_cs >= 0) digitalWrite(_cs, HIGH);
+- }
+- while (fill_with_zeroes > 0)
+- {
+- if (_cs >= 0) digitalWrite(_cs, LOW);
+- _pSPIx->transfer(0x00);
+- fill_with_zeroes--;
+- if (_cs >= 0) digitalWrite(_cs, HIGH);
++ _hal->write(data, n);
++ if (fill_with_zeroes > 0) {
++ uint8_t buf[fill_with_zeroes];
++ memset(buf, 0, fill_with_zeroes);
++ _hal->write(buf, fill_with_zeroes);
+ }
+- _pSPIx->endTransaction();
+ }
+
+ void GxEPD2_EPD::_writeCommandData(const uint8_t* pCommandData, uint8_t datalen)
+ {
+- _pSPIx->beginTransaction(_spi_settings);
+- if (_dc >= 0) digitalWrite(_dc, LOW);
+- if (_cs >= 0) digitalWrite(_cs, LOW);
+- _pSPIx->transfer(*pCommandData++);
+- if (_dc >= 0) digitalWrite(_dc, HIGH);
+- for (uint8_t i = 0; i < datalen - 1; i++) // sub the command
+- {
+- _pSPIx->transfer(*pCommandData++);
+- }
+- if (_cs >= 0) digitalWrite(_cs, HIGH);
+- _pSPIx->endTransaction();
++ _hal->writeCmd(pCommandData, datalen, false);
+ }
+
+ void GxEPD2_EPD::_writeCommandDataPGM(const uint8_t* pCommandData, uint8_t datalen)
+ {
+- _pSPIx->beginTransaction(_spi_settings);
+- if (_dc >= 0) digitalWrite(_dc, LOW);
+- if (_cs >= 0) digitalWrite(_cs, LOW);
+- _pSPIx->transfer(pgm_read_byte(&*pCommandData++));
+- if (_dc >= 0) digitalWrite(_dc, HIGH);
+- for (uint8_t i = 0; i < datalen - 1; i++) // sub the command
+- {
+- _pSPIx->transfer(pgm_read_byte(&*pCommandData++));
+- }
+- if (_cs >= 0) digitalWrite(_cs, HIGH);
+- _pSPIx->endTransaction();
++ _hal->writeCmd(pCommandData, datalen, true);
+ }
+
+ void GxEPD2_EPD::_startTransfer()
+ {
+- _pSPIx->beginTransaction(_spi_settings);
+- if (_cs >= 0) digitalWrite(_cs, LOW);
++ _hal->startTransfer();
+ }
+
+ void GxEPD2_EPD::_transfer(uint8_t value)
+ {
+- _pSPIx->transfer(value);
++ _hal->transfer(value);
+ }
+
+ void GxEPD2_EPD::_endTransfer()
+ {
+- if (_cs >= 0) digitalWrite(_cs, HIGH);
+- _pSPIx->endTransaction();
++ _hal->endTransfer();
+ }
+diff --git a/src/GxEPD2_EPD.h b/src/GxEPD2_EPD.h
+index 34c1145..1e8ea64 100644
+--- a/src/GxEPD2_EPD.h
++++ b/src/GxEPD2_EPD.h
+@@ -13,9 +13,9 @@
+ #define _GxEPD2_EPD_H_
+
+ #include
+-#include
+
+ #include
++#include
+
+ #pragma GCC diagnostic ignored "-Wunused-parameter"
+ //#pragma GCC diagnostic ignored "-Wsign-compare"
+@@ -31,7 +31,7 @@ class GxEPD2_EPD
+ const bool hasPartialUpdate;
+ const bool hasFastPartialUpdate;
+ // constructor
+- GxEPD2_EPD(int16_t cs, int16_t dc, int16_t rst, int16_t busy, int16_t busy_level, uint32_t busy_timeout,
++ GxEPD2_EPD(GxEPD2_HalInterface *hal, int16_t busy_level, uint32_t busy_timeout,
+ uint16_t w, uint16_t h, GxEPD2::Panel p, bool c, bool pu, bool fpu);
+ virtual void init(uint32_t serial_diag_bitrate = 0); // serial_diag_bitrate = 0 : disabled
+ virtual void init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration = 10, bool pulldown_rst_mode = false);
+@@ -97,7 +97,6 @@ class GxEPD2_EPD
+ {
+ return (a > b ? a : b);
+ };
+- void selectSPI(SPIClass& spi, SPISettings spi_settings);
+ protected:
+ void _reset();
+ void _waitWhileBusy(const char* comment = 0, uint16_t busy_time = 5000);
+@@ -112,16 +111,15 @@ class GxEPD2_EPD
+ void _transfer(uint8_t value);
+ void _endTransfer();
+ protected:
+- int16_t _cs, _dc, _rst, _busy, _busy_level;
++ GxEPD2_HalInterface *_hal;
++ int16_t _busy_level;
+ uint32_t _busy_timeout;
+ bool _diag_enabled, _pulldown_rst_mode;
+- SPIClass* _pSPIx;
+- SPISettings _spi_settings;
+ bool _initial_write, _initial_refresh;
+ bool _power_is_on, _using_partial_mode, _hibernating;
+ bool _init_display_done;
+ uint16_t _reset_duration;
+- void (*_busy_callback)(const void*);
++ void (*_busy_callback)(const void*);
+ const void* _busy_callback_parameter;
+ };
+
+diff --git a/src/GxEPD2_Hal.h b/src/GxEPD2_Hal.h
+new file mode 100644
+index 0000000..13424b6
+--- /dev/null
++++ b/src/GxEPD2_Hal.h
+@@ -0,0 +1,19 @@
++#pragma once
++
++class GxEPD2_HalInterface {
++ public:
++ virtual void rstMode(uint8_t mode) = 0;
++ virtual void rst(bool level) = 0;
++ virtual int getBusy(void) = 0;
++ virtual bool isRst(void) = 0;
++
++ virtual void write(uint8_t buf) = 0;
++ virtual void write(const uint8_t *buf, uint16_t n) = 0;
++ virtual void write(const uint8_t *buf, uint16_t n, int16_t fill_with_zeroes) = 0;
++ virtual void writeCmd(const uint8_t val) = 0;
++ virtual void writeCmd(const uint8_t* pCommandData, uint8_t datalen, bool isPGM) = 0;
++
++ virtual void startTransfer(void) = 0;
++ virtual void endTransfer(void) = 0;
++ virtual void transfer(const uint8_t val) = 0;
++};
+diff --git a/src/epd/GxEPD2_150_BN.cpp b/src/epd/GxEPD2_150_BN.cpp
+index bfb3ddf..dba3d78 100644
+--- a/src/epd/GxEPD2_150_BN.cpp
++++ b/src/epd/GxEPD2_150_BN.cpp
+@@ -14,8 +14,8 @@
+
+ #include "GxEPD2_150_BN.h"
+
+-GxEPD2_150_BN::GxEPD2_150_BN(int16_t cs, int16_t dc, int16_t rst, int16_t busy) :
+- GxEPD2_EPD(cs, dc, rst, busy, HIGH, 10000000, WIDTH, HEIGHT, panel, hasColor, hasPartialUpdate, hasFastPartialUpdate)
++GxEPD2_150_BN::GxEPD2_150_BN(GxEPD2_HalInterface *hal) :
++ GxEPD2_EPD(hal, HIGH, 10000000, WIDTH, HEIGHT, panel, hasColor, hasPartialUpdate, hasFastPartialUpdate)
+ {
+ }
+
+@@ -269,7 +269,7 @@ void GxEPD2_150_BN::refresh(int16_t x, int16_t y, int16_t w, int16_t h)
+ int16_t y1 = y < 0 ? 0 : y; // limit
+ w1 = x1 + w1 < int16_t(WIDTH) ? w1 : int16_t(WIDTH) - x1; // limit
+ h1 = y1 + h1 < int16_t(HEIGHT) ? h1 : int16_t(HEIGHT) - y1; // limit
+- if ((w1 <= 0) || (h1 <= 0)) return;
++ if ((w1 <= 0) || (h1 <= 0)) return;
+ // make x1, w1 multiple of 8
+ w1 += x1 % 8;
+ if (w1 % 8 > 0) w1 += 8 - w1 % 8;
+@@ -287,7 +287,7 @@ void GxEPD2_150_BN::powerOff()
+ void GxEPD2_150_BN::hibernate()
+ {
+ _PowerOff();
+- if (_rst >= 0)
++ if (_hal->isRst())
+ {
+ _writeCommand(0x10); // deep sleep mode
+ _writeData(0x1); // enter deep sleep
+diff --git a/src/epd/GxEPD2_150_BN.h b/src/epd/GxEPD2_150_BN.h
+index bc46a45..954b9c4 100644
+--- a/src/epd/GxEPD2_150_BN.h
++++ b/src/epd/GxEPD2_150_BN.h
+@@ -16,6 +16,7 @@
+ #define _GxEPD2_150_BN_H_
+
+ #include "../GxEPD2_EPD.h"
++#include "../GxEPD2_Hal.h"
+
+ class GxEPD2_150_BN : public GxEPD2_EPD
+ {
+@@ -33,7 +34,7 @@ class GxEPD2_150_BN : public GxEPD2_EPD
+ static const uint16_t full_refresh_time = 4000; // ms, e.g. 3825000us
+ static const uint16_t partial_refresh_time = 800; // ms, e.g. 736000us
+ // constructor
+- GxEPD2_150_BN(int16_t cs, int16_t dc, int16_t rst, int16_t busy);
++ GxEPD2_150_BN(GxEPD2_HalInterface *hal);
+ // methods (virtual)
+ // Support for Bitmaps (Sprites) to Controller Buffer and to Screen
+ void clearScreen(uint8_t value = 0xFF); // init controller memory and screen (default white)
diff --git a/patches/GxEPD2_SW_SPI.patch b/patches/GxEPD2_SW_SPI.patch
deleted file mode 100644
index dc3fa9ca..00000000
--- a/patches/GxEPD2_SW_SPI.patch
+++ /dev/null
@@ -1,362 +0,0 @@
-diff --git a/src/GxEPD2_EPD.cpp b/src/GxEPD2_EPD.cpp
-index 8df8bef..91d7f49 100644
---- a/src/GxEPD2_EPD.cpp
-+++ b/src/GxEPD2_EPD.cpp
-@@ -19,9 +19,9 @@
-
- GxEPD2_EPD::GxEPD2_EPD(int16_t cs, int16_t dc, int16_t rst, int16_t busy, int16_t busy_level, uint32_t busy_timeout,
- uint16_t w, uint16_t h, GxEPD2::Panel p, bool c, bool pu, bool fpu) :
-- WIDTH(w), HEIGHT(h), panel(p), hasColor(c), hasPartialUpdate(pu), hasFastPartialUpdate(fpu),
-+ WIDTH(w), HEIGHT(h), panel(p), hasColor(c), hasPartialUpdate(pu), hasFastPartialUpdate(fpu), _sck(-1), _mosi(-1),
- _cs(cs), _dc(dc), _rst(rst), _busy(busy), _busy_level(busy_level), _busy_timeout(busy_timeout), _diag_enabled(false),
-- _pSPIx(&SPI), _spi_settings(4000000, MSBFIRST, SPI_MODE0)
-+ _spi_settings(4000000, MSBFIRST, SPI_MODE0)
- {
- _initial_write = true;
- _initial_refresh = true;
-@@ -71,27 +71,30 @@ void GxEPD2_EPD::init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset
- {
- pinMode(_busy, INPUT);
- }
-- _pSPIx->begin();
-- if (_busy == MISO) // may be overridden
-- {
-- pinMode(_busy, INPUT);
-- }
-- if (_dc == MISO) // may be overridden, TTGO T5 V2.66
-- {
-- pinMode(_dc, OUTPUT);
-- }
-- if (_cs == MISO) // may be overridden
-+ if (_sck < 0) SPI.begin();
-+}
-+
-+void GxEPD2_EPD::init(int16_t sck, int16_t mosi, uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration, bool pulldown_rst_mode)
-+{
-+ if ((sck >= 0) && (mosi >= 0))
- {
-- pinMode(_cs, INPUT);
-- }
-+ _sck = sck;
-+ _mosi = mosi;
-+ digitalWrite(_sck, LOW);
-+ digitalWrite(_mosi, LOW);
-+ pinMode(_sck, OUTPUT);
-+ pinMode(_mosi, OUTPUT);
-+ } else _sck = -1;
-+ init(serial_diag_bitrate, initial, reset_duration, pulldown_rst_mode);
- }
-
- void GxEPD2_EPD::end()
- {
-- _pSPIx->end();
- if (_cs >= 0) pinMode(_cs, INPUT);
- if (_dc >= 0) pinMode(_dc, INPUT);
- if (_rst >= 0) pinMode(_rst, INPUT);
-+ if (_sck >= 0) pinMode(_sck, INPUT);
-+ if (_mosi >= 0) pinMode(_mosi, INPUT);
- }
-
- void GxEPD2_EPD::setBusyCallback(void (*busyCallback)(const void*), const void* busy_callback_parameter)
-@@ -100,12 +103,6 @@ void GxEPD2_EPD::setBusyCallback(void (*busyCallback)(const void*), const void*
- _busy_callback_parameter = busy_callback_parameter;
- }
-
--void GxEPD2_EPD::selectSPI(SPIClass& spi, SPISettings spi_settings)
--{
-- _pSPIx = &spi;
-- _spi_settings = spi_settings;
--}
--
- void GxEPD2_EPD::_reset()
- {
- if (_rst >= 0)
-@@ -174,115 +171,201 @@ void GxEPD2_EPD::_waitWhileBusy(const char* comment, uint16_t busy_time)
-
- void GxEPD2_EPD::_writeCommand(uint8_t c)
- {
-- _pSPIx->beginTransaction(_spi_settings);
-+ _beginTransaction(_spi_settings);
- if (_dc >= 0) digitalWrite(_dc, LOW);
- if (_cs >= 0) digitalWrite(_cs, LOW);
-- _pSPIx->transfer(c);
-+ _spi_write(c);
- if (_cs >= 0) digitalWrite(_cs, HIGH);
- if (_dc >= 0) digitalWrite(_dc, HIGH);
-- _pSPIx->endTransaction();
-+ _endTransaction();
- }
-
- void GxEPD2_EPD::_writeData(uint8_t d)
- {
-- _pSPIx->beginTransaction(_spi_settings);
-+ _beginTransaction(_spi_settings);
- if (_cs >= 0) digitalWrite(_cs, LOW);
-- _pSPIx->transfer(d);
-+ _spi_write(d);
- if (_cs >= 0) digitalWrite(_cs, HIGH);
-- _pSPIx->endTransaction();
-+ _endTransaction();
- }
-
- void GxEPD2_EPD::_writeData(const uint8_t* data, uint16_t n)
- {
-- _pSPIx->beginTransaction(_spi_settings);
-+ _beginTransaction(_spi_settings);
- if (_cs >= 0) digitalWrite(_cs, LOW);
-- for (uint16_t i = 0; i < n; i++)
-+ for (uint8_t i = 0; i < n; i++)
- {
-- _pSPIx->transfer(*data++);
-+ _spi_write(*data++);
- }
- if (_cs >= 0) digitalWrite(_cs, HIGH);
-- _pSPIx->endTransaction();
-+ _endTransaction();
- }
-
- void GxEPD2_EPD::_writeDataPGM(const uint8_t* data, uint16_t n, int16_t fill_with_zeroes)
- {
-- _pSPIx->beginTransaction(_spi_settings);
-+ _beginTransaction(_spi_settings);
- if (_cs >= 0) digitalWrite(_cs, LOW);
-- for (uint16_t i = 0; i < n; i++)
-+ for (uint8_t i = 0; i < n; i++)
- {
-- _pSPIx->transfer(pgm_read_byte(&*data++));
-+ _spi_write(pgm_read_byte(&*data++));
- }
- while (fill_with_zeroes > 0)
- {
-- _pSPIx->transfer(0x00);
-+ _spi_write(0x00);
- fill_with_zeroes--;
- }
- if (_cs >= 0) digitalWrite(_cs, HIGH);
-- _pSPIx->endTransaction();
-+ _endTransaction();
- }
-
- void GxEPD2_EPD::_writeDataPGM_sCS(const uint8_t* data, uint16_t n, int16_t fill_with_zeroes)
- {
-- _pSPIx->beginTransaction(_spi_settings);
-+ _beginTransaction(_spi_settings);
- for (uint8_t i = 0; i < n; i++)
- {
- if (_cs >= 0) digitalWrite(_cs, LOW);
-- _pSPIx->transfer(pgm_read_byte(&*data++));
-+ _spi_write(pgm_read_byte(&*data++));
- if (_cs >= 0) digitalWrite(_cs, HIGH);
- }
- while (fill_with_zeroes > 0)
- {
- if (_cs >= 0) digitalWrite(_cs, LOW);
-- _pSPIx->transfer(0x00);
-+ _spi_write(0x00);
- fill_with_zeroes--;
- if (_cs >= 0) digitalWrite(_cs, HIGH);
- }
-- _pSPIx->endTransaction();
-+ _endTransaction();
- }
-
- void GxEPD2_EPD::_writeCommandData(const uint8_t* pCommandData, uint8_t datalen)
- {
-- _pSPIx->beginTransaction(_spi_settings);
-+ _beginTransaction(_spi_settings);
- if (_dc >= 0) digitalWrite(_dc, LOW);
- if (_cs >= 0) digitalWrite(_cs, LOW);
-- _pSPIx->transfer(*pCommandData++);
-+ _spi_write(*pCommandData++);
- if (_dc >= 0) digitalWrite(_dc, HIGH);
- for (uint8_t i = 0; i < datalen - 1; i++) // sub the command
- {
-- _pSPIx->transfer(*pCommandData++);
-+ _spi_write(*pCommandData++);
- }
- if (_cs >= 0) digitalWrite(_cs, HIGH);
-- _pSPIx->endTransaction();
-+ _endTransaction();
- }
-
- void GxEPD2_EPD::_writeCommandDataPGM(const uint8_t* pCommandData, uint8_t datalen)
- {
-- _pSPIx->beginTransaction(_spi_settings);
-+ _beginTransaction(_spi_settings);
- if (_dc >= 0) digitalWrite(_dc, LOW);
- if (_cs >= 0) digitalWrite(_cs, LOW);
-- _pSPIx->transfer(pgm_read_byte(&*pCommandData++));
-+ _spi_write(pgm_read_byte(&*pCommandData++));
- if (_dc >= 0) digitalWrite(_dc, HIGH);
- for (uint8_t i = 0; i < datalen - 1; i++) // sub the command
- {
-- _pSPIx->transfer(pgm_read_byte(&*pCommandData++));
-+ _spi_write(pgm_read_byte(&*pCommandData++));
- }
- if (_cs >= 0) digitalWrite(_cs, HIGH);
-- _pSPIx->endTransaction();
-+ _endTransaction();
- }
-
- void GxEPD2_EPD::_startTransfer()
- {
-- _pSPIx->beginTransaction(_spi_settings);
-+ _beginTransaction(_spi_settings);
- if (_cs >= 0) digitalWrite(_cs, LOW);
- }
-
- void GxEPD2_EPD::_transfer(uint8_t value)
- {
-- _pSPIx->transfer(value);
-+ _spi_write(value);
- }
-
- void GxEPD2_EPD::_endTransfer()
- {
- if (_cs >= 0) digitalWrite(_cs, HIGH);
-- _pSPIx->endTransaction();
-+ _endTransaction();
-+}
-+
-+void GxEPD2_EPD::_beginTransaction(const SPISettings& settings)
-+{
-+ if (_sck < 0) SPI.beginTransaction(settings);
-+}
-+
-+void GxEPD2_EPD::_spi_write(uint8_t data)
-+{
-+ if (_sck < 0) SPI.transfer(data);
-+ else
-+ {
-+#if defined (ESP8266)
-+ yield();
-+#endif
-+ for (int i = 0; i < 8; i++)
-+ {
-+ digitalWrite(_mosi, (data & 0x80) ? HIGH : LOW);
-+ data <<= 1;
-+ digitalWrite(_sck, HIGH);
-+ digitalWrite(_sck, LOW);
-+ }
-+ }
-+}
-+
-+void GxEPD2_EPD::_endTransaction()
-+{
-+ if (_sck < 0) SPI.endTransaction();
-+}
-+
-+uint8_t GxEPD2_EPD::_readData()
-+{
-+ uint8_t data = 0;
-+ _beginTransaction(_spi_settings);
-+ if (_cs >= 0) digitalWrite(_cs, LOW);
-+ if (_sck < 0)
-+ {
-+ data = SPI.transfer(0);
-+ }
-+ else
-+ {
-+ pinMode(_mosi, INPUT);
-+ for (int i = 0; i < 8; i++)
-+ {
-+ data <<= 1;
-+ digitalWrite(_sck, HIGH);
-+ data |= digitalRead(_mosi);
-+ digitalWrite(_sck, LOW);
-+ }
-+ pinMode(_mosi, OUTPUT);
-+ }
-+ if (_cs >= 0) digitalWrite(_cs, HIGH);
-+ _endTransaction();
-+ return data;
-+}
-+
-+void GxEPD2_EPD::_readData(uint8_t* data, uint16_t n)
-+{
-+ _beginTransaction(_spi_settings);
-+ if (_cs >= 0) digitalWrite(_cs, LOW);
-+ if (_sck < 0)
-+ {
-+ for (uint8_t i = 0; i < n; i++)
-+ {
-+ *data++ = SPI.transfer(0);
-+ }
-+ }
-+ else
-+ {
-+ pinMode(_mosi, INPUT);
-+ for (uint8_t i = 0; i < n; i++)
-+ {
-+ *data = 0;
-+ for (int i = 0; i < 8; i++)
-+ {
-+ *data <<= 1;
-+ digitalWrite(_sck, HIGH);
-+ *data |= digitalRead(_mosi);
-+ digitalWrite(_sck, LOW);
-+ }
-+ data++;
-+ }
-+ pinMode(_mosi, OUTPUT);
-+ }
-+ if (_cs >= 0) digitalWrite(_cs, HIGH);
-+ _endTransaction();
- }
-diff --git a/src/GxEPD2_EPD.h b/src/GxEPD2_EPD.h
-index 34c1145..c480b7d 100644
---- a/src/GxEPD2_EPD.h
-+++ b/src/GxEPD2_EPD.h
-@@ -8,6 +8,10 @@
- // Version: see library.properties
- //
- // Library: https://github.com/ZinggJM/GxEPD2
-+// To use SW SPI with GxEPD2:
-+// add the special call to the added init method BEFORE the normal init method:
-+// display.epd2.init(SW_SCK, SW_MOSI, 115200, true, 20, false); // define or replace SW_SCK, SW_MOSI
-+// display.init(115200); // needed to init upper level
-
- #ifndef _GxEPD2_EPD_H_
- #define _GxEPD2_EPD_H_
-@@ -35,6 +39,7 @@ class GxEPD2_EPD
- uint16_t w, uint16_t h, GxEPD2::Panel p, bool c, bool pu, bool fpu);
- virtual void init(uint32_t serial_diag_bitrate = 0); // serial_diag_bitrate = 0 : disabled
- virtual void init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration = 10, bool pulldown_rst_mode = false);
-+ virtual void init(int16_t sck, int16_t mosi, uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration = 20, bool pulldown_rst_mode = false);
- virtual void end(); // release SPI and control pins
- // Support for Bitmaps (Sprites) to Controller Buffer and to Screen
- virtual void clearScreen(uint8_t value) = 0; // init controller memory and screen (default white)
-@@ -97,7 +102,6 @@ class GxEPD2_EPD
- {
- return (a > b ? a : b);
- };
-- void selectSPI(SPIClass& spi, SPISettings spi_settings);
- protected:
- void _reset();
- void _waitWhileBusy(const char* comment = 0, uint16_t busy_time = 5000);
-@@ -111,17 +115,22 @@ class GxEPD2_EPD
- void _startTransfer();
- void _transfer(uint8_t value);
- void _endTransfer();
-+ void _beginTransaction(const SPISettings& settings);
-+ void _spi_write(uint8_t data);
-+ void _endTransaction();
-+ public:
-+ uint8_t _readData();
-+ void _readData(uint8_t* data, uint16_t n);
- protected:
-- int16_t _cs, _dc, _rst, _busy, _busy_level;
-+ int16_t _cs, _dc, _rst, _busy, _busy_level, _sck, _mosi;;
- uint32_t _busy_timeout;
- bool _diag_enabled, _pulldown_rst_mode;
-- SPIClass* _pSPIx;
- SPISettings _spi_settings;
- bool _initial_write, _initial_refresh;
- bool _power_is_on, _using_partial_mode, _hibernating;
- bool _init_display_done;
- uint16_t _reset_duration;
-- void (*_busy_callback)(const void*);
-+ void (*_busy_callback)(const void*);
- const void* _busy_callback_parameter;
- };
-
diff --git a/scripts/__pycache__/htmlPreprocessorDefines.cpython-311.pyc b/scripts/__pycache__/htmlPreprocessorDefines.cpython-311.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..6dca7de6a79130b4cda26f55fab17c7adff71d33
GIT binary patch
literal 2175
zcma)7-A~(A6u;LWiAiXaETEEfqM;0dyHTo@wS1`+f`C?a>43hBxvFSvASEQ>+9?fk
zq)h5VS|QCuk&;c7mM5l(zhzQV<-xLqG-=vH-?H(t_GLRZFEgygJGPdT_G9^+k&@wI3KpBw%%8Gai
z@$6gkcqoidq?jMjfM|G+=71EC(y}LF745+4KCB%y)-h5{{K?pd??HWnFjxY5sL+l*
zxVZRWaU#G|2Ad#}m|`%}^N7M@gWi
zI2lhH@>NQ;?StHd`lX??UFoRf5K`^!ffcC@^D;mt=~iu}7Maa6B7N!%vtj8YGb&xO
zHE~U@-Fo>t;Ox!aCfANjb1ElNzQ(p{Z=G#e9uX76HZf^-H+!z#wsY+M4D2y)@yuw~
zsIse6y9A6>Na`daj#Ehd41p!To@>eJsMjO-&4)#hxD;>GSdlwp)rZFSJipIMY>Tqx
zGp(|n;H8Flr%$5LtuiI6Z8U8=<{$?llUvIdP6;XlW!e#XNX(lwY{Ag%mvfKb{sZH!
znfC?_Qv(NgdWVAdmx6p?Ga}28*jgZ-kYWK@Sy7}-DW>%CPJ`V_N=eD+xF1=KFIX%^
zB*PAsDy~GM1|5}R24l{kW;YW`%AnUI#h?>O#j0MzwvqsuBHv-qkyrxovSQd1D~ckK
zn1QzpI-Z2yu^~wbgNZ`<8~C|_CE2W_Kz$H1qYXB^E`>KpKk(+REP*G`6Sxbzt_tU?
za=y&8?&!?S=uTH=R(E@AsGIHk(XJ#D+hR5}N$oda2X=)9QSdU!>4RJuOUU#(HWDg`G9jAe 0:
build_flags = build_flags + [flags[i]]
+def parseDefinesH():
+ global build_flags
+ pattern = r'^\s*#\s*define\s+(\w+)'
+
+ with open("defines.h", "r") as f:
+ for line in f:
+ match = re.match(pattern, line)
+ if match:
+ build_flags += [match.group(1)]
+
def get_build_flags():
getFlagsOfEnv("env:" + env['PIOENV'])
config = configparser.ConfigParser()
config.read('platformio.ini')
+ parseDefinesH()
# translate board
board = config["env:" + env['PIOENV']]['board']
diff --git a/scripts/getVersion.py b/scripts/getVersion.py
index a60a772d..f579b56a 100644
--- a/scripts/getVersion.py
+++ b/scripts/getVersion.py
@@ -76,8 +76,9 @@ def renameFw(path_define, env):
fname = version[:-1] + "_" + sha + "_" + env + ".bin"
os.rename("src/.pio/build/" + env + "/firmware.bin", dst + fname)
+ os.rename("src/.pio/build/" + env + "/firmware.elf.7z", dst + fname[:-3] + "elf.7z")
- if env[:5] == "esp32":
+ if env[:5] == "esp32" or env[:4] == "open":
os.rename("src/.pio/build/" + env + "/bootloader.bin", dst + "bootloader.bin")
os.rename("src/.pio/build/" + env + "/partitions.bin", dst + "partitions.bin")
genOtaBin(dst)
diff --git a/src/CHANGES.md b/src/CHANGES.md
index 73c5c5d4..f4c5d4ce 100644
--- a/src/CHANGES.md
+++ b/src/CHANGES.md
@@ -1,5 +1,107 @@
# Development Changes
+## 0.8.123 - 2024-05-30
+* fix ESP8266, ESP32 static IP #1643 #1608
+* update MqTT library which enhances stability #1646
+* merge PR: MQTT JSON Payload pro Kanal und total, auswählbar #1541
+* add option to publish mqtt as json
+* publish rssi not on ch0 any more, published on `topic/rssi`
+* add total power to index page (if multiple inverters are configured)
+* show device name in html title #1639
+* update AsyncWebserver library to `3.2.2`
+* add environment name to filename of coredump
+
+## 0.8.122 - 2024-05-23
+* add button for donwloading coredump (ESP32 variants only)
+
+## 0.8.121 - 2024-05-20
+* fix ESP32 factory image generation
+* fix plot of history graph #1635
+
+## 0.8.120 - 2024-05-18
+* fix crash if invalid serial number was set -> inverter will be disabled automatically
+* improved and fixed factory image generation
+* fix HMT-1800-4T number of inputs #1628
+
+## 0.8.119 - 2024-05-17
+* fix reset values at midnight if WiFi isn't available #1620
+* fix typo in English versions
+* add yield day to history graph #1614
+* added script and [instructions](../manual/factory_firmware.md) how to generate factory firmware which includes predefined settings
+* merge PR: Fix MI overnight behaviour #1626
+
+## 0.8.118 - 2024-05-10
+* possible fix reset max values #1609
+* slightly improved WiFi reconnect
+* update AsyncWebserver to `3.2.0`
+
+## 0.8.117 - 2024-05-09
+* fix reboot issue #1607 #1606
+* fix max temperature tooltip if only one inverter is configured #1605
+
+## 0.8.116 - 2024-05-05
+* calculation of max AC power
+* fix counter overflow communication queue
+* added max inverter temperature
+
+## 0.8.115 - 2024-05-03
+* fix inverter communication with manual time sync #1603
+* improved queue, only add new object once they not exist in queue
+* added option to reset values on communication start (sunrise)
+* fixed calculation of max AC power (API, MqTT)
+
+## 0.8.114 - 2024-04-29
+* fix ESP8266 compile
+* fix history graph
+* fix close button color of modal windows in dark mode #1598
+* fix only one total field in `/live` #1579
+
+## 0.8.113 - 2024-04-25
+* code cleanup
+* fix ESP32-C3 compile
+
+## 0.8.112 - 2024-04-24
+* improved wizard
+* converted ePaper and Ethernet to hal-SPI
+* improved network connection
+
+## 0.8.111 - 2024-04-17
+* fix MqTT discovery field `ALARM_MES_ID` #1591
+* fix Wifi reconnect for ESP32 #1589 #1575
+* open link from `index.html` in new tab #1588 #1587
+* merge PR: Disable upload and import buttons when no file is selected #1586 #1519
+
+## 0.8.110 - 2024-04-11
+* revert CMT2300A changes #1553
+* merged PR: fix closing tag #1584
+* add disable retain flag #1582
+* fix German translation #1569
+* improved `Wizard`
+
+## 0.8.109 - 2024-04-09
+* fix hal patch
+
+## 0.8.108 - 2024-04-09
+* point to git SHA for `NRF24` library
+
+## 0.8.107 - 2024-04-08
+* fix boot loop on `reboot on midnight` feature #1542, #1599, #1566, #1571
+* fix German translation #1569
+* improved `Wizard`
+
+## 0.8.106 - 2024-04-05
+* fix bootloop with CMT and NRF on ESP32 #1566 #1562
+* possible fix of #1553
+* change MqTT return value of power limit acknowledge from `boolean` to `float`. The value returned is the same as it was set to confirm reception (not the read back value)
+
+## 0.8.105 - 2024-04-05
+* cleanup of `defines.h`
+* fix compile of esp32-minimal
+
+## 0.8.104 - 2024-04-04
+* fix reboot on inverter save (ESP32) #1559
+* fix NRF and Ethernet #1506
+
## 0.8.103 - 2024-04-02
* merge PR: fix: get refresh property from object #1552
* merge PR: fix typos and spelling in Github Issue template #1550
diff --git a/src/app.cpp b/src/app.cpp
index 76ae0fbe..348af81c 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -37,25 +37,16 @@ void app::setup() {
resetSystem();
esp_task_wdt_reset();
- mSettings.setup();
- mSettings.getPtr(mConfig);
+ mSettings.setup(mConfig);
ah::Scheduler::setup(mConfig->inst.startWithoutTime);
DPRINT(DBG_INFO, F("Settings valid: "));
- DSERIAL.flush();
- if (mSettings.getValid())
- DBGPRINTLN(F("true"));
- else
- DBGPRINTLN(F("false"));
+ DBGPRINTLN(mConfig->valid ? F("true") : F("false"));
esp_task_wdt_reset();
- if(mConfig->nrf.enabled) {
- mNrfRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs, mConfig->nrf.pinSclk, mConfig->nrf.pinMosi, mConfig->nrf.pinMiso);
- }
+ mNrfRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, &mConfig->nrf);
#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, mConfig->sys.region);
- }
+ mCmtRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, &mConfig->cmt, mConfig->sys.region);
#endif
#ifdef ETHERNET
@@ -63,21 +54,21 @@ void app::setup() {
mNetwork = static_cast(new AhoyEthernet());
#else
mNetwork = static_cast(new AhoyWifi());
- #endif // ETHERNET
+ #endif
mNetwork->setup(mConfig, &mTimestamp, [this](bool gotIp) { this->onNetwork(gotIp); }, [this](bool gotTime) { this->onNtpUpdate(gotTime); });
mNetwork->begin();
esp_task_wdt_reset();
mCommunication.setup(&mTimestamp, &mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace);
- mCommunication.addPayloadListener(std::bind(&app::payloadEventListener, this, std::placeholders::_1, std::placeholders::_2));
+ mCommunication.addPayloadListener([this] (uint8_t cmd, Inverter<> *iv) { payloadEventListener(cmd, iv); });
#if defined(PLUGIN_ZEROEXPORT) || defined(ENABLE_MQTT)
mCommunication.addPowerLimitAckListener([this] (Inverter<> *iv) {
#if defined(PLUGIN_ZEROEXPORT)
mZeroExport.eventAckSetLimit(iv);
#endif /*PLUGIN_ZEROEXPORT*/
#if defined(ENABLE_MQTT)
- mMqtt.setPowerLimitAck(iv);
+ mMqtt.setPowerLimitAck(iv);
#endif
});
#endif /*defined(PLUGIN_ZEROEXPORT) || defined(ENABLE_MQTT)*/
@@ -110,7 +101,6 @@ void app::setup() {
esp_task_wdt_reset();
// when WiFi is in client mode, then enable mqtt broker
- #if !defined(AP_ONLY)
#if defined(ENABLE_MQTT)
mMqttEnabled = (mConfig->mqtt.broker[0] > 0);
if (mMqttEnabled) {
@@ -120,7 +110,6 @@ void app::setup() {
mCommunication.addAlarmListener([this](Inverter<> *iv) { mMqtt.alarmEvent(iv); });
}
#endif
- #endif
setupLed();
esp_task_wdt_reset();
@@ -133,6 +122,7 @@ void app::setup() {
mDbgSyslog.setup(mConfig); // be sure to init after mWeb.setup (webSerial uses also debug callback)
#endif
// Plugins
+ mMaxPower.setup(&mTimestamp, mConfig->inst.sendInterval);
#if defined(PLUGIN_DISPLAY)
if (DISP_TYPE_T0_NONE != mConfig->plugin.display.type)
#if defined(ESP32)
@@ -162,9 +152,7 @@ void app::setup() {
#if defined(ENABLE_SIMULATOR)
mSimulator.setup(&mSys, &mTimestamp, 0);
- mSimulator.addPayloadListener([this](uint8_t cmd, Inverter<> *iv) {
- payloadEventListener(cmd, iv);
- });
+ mSimulator.addPayloadListener([this](uint8_t cmd, Inverter<> *iv) { payloadEventListener(cmd, iv); });
#endif /*ENABLE_SIMULATOR*/
esp_task_wdt_reset();
@@ -175,12 +163,10 @@ void app::setup() {
void app::loop(void) {
esp_task_wdt_reset();
- if(mConfig->nrf.enabled)
- mNrfRadio.loop();
+ mNrfRadio.loop();
#if defined(ESP32)
- if(mConfig->cmt.enabled)
- mCmtRadio.loop();
+ mCmtRadio.loop();
#endif
ah::Scheduler::loop();
@@ -205,12 +191,14 @@ void app::loop(void) {
//-----------------------------------------------------------------------------
void app::onNetwork(bool gotIp) {
mNetworkConnected = gotIp;
- ah::Scheduler::resetTicker();
- regularTickers(); //reinstall regular tickers
- every(std::bind(&app::tickSend, this), mConfig->inst.sendInterval, "tSend");
- mMqttReconnect = true;
- mSunrise = 0; // needs to be set to 0, to reinstall sunrise and ivComm tickers!
- once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2");
+ if(gotIp) {
+ ah::Scheduler::resetTicker();
+ regularTickers(); //reinstall regular tickers
+ every(std::bind(&app::tickSend, this), mConfig->inst.sendInterval, "tSend");
+ mTickerInstallOnce = true;
+ mSunrise = 0; // needs to be set to 0, to reinstall sunrise and ivComm tickers!
+ once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2");
+ }
}
//-----------------------------------------------------------------------------
@@ -220,6 +208,9 @@ void app::regularTickers(void) {
everySec([this]() { mProtection->tickSecond(); }, "prot");
everySec([this]() {mNetwork->tickNetworkLoop(); }, "net");
+ if(mConfig->inst.startWithoutTime && !mNetworkConnected)
+ every(std::bind(&app::tickSend, this), mConfig->inst.sendInterval, "tSend");
+
// Plugins
#if defined(PLUGIN_DISPLAY)
if (DISP_TYPE_T0_NONE != mConfig->plugin.display.type)
@@ -253,40 +244,37 @@ void app::onNtpUpdate(bool gotTime) {
mCalculatedTimezoneOffset = (int8_t)((mConfig->sun.lon >= 0 ? mConfig->sun.lon + 7.5 : mConfig->sun.lon - 7.5) / 15) * 3600;
tickCalcSunrise();
}
-}
-//-----------------------------------------------------------------------------
-void app::updateNtp(void) {
- #if defined(ENABLE_MQTT)
- if (mMqttReconnect && mMqttEnabled) {
- mMqtt.tickerSecond();
- everySec(std::bind(&PubMqttType::tickerSecond, &mMqtt), "mqttS");
- everyMin(std::bind(&PubMqttType::tickerMinute, &mMqtt), "mqttM");
- }
- #endif /*ENABLE_MQTT*/
+ if (mTickerInstallOnce) {
+ mTickerInstallOnce = false;
+ #if defined(ENABLE_MQTT)
+ if (mMqttEnabled) {
+ mMqtt.tickerSecond();
+ everySec(std::bind(&PubMqttType::tickerSecond, &mMqtt), "mqttS");
+ everyMin(std::bind(&PubMqttType::tickerMinute, &mMqtt), "mqttM");
+ }
+ #endif /*ENABLE_MQTT*/
- // only install schedulers once even if NTP wasn't successful in first loop
- if (mMqttReconnect) { // @TODO: mMqttReconnect is variable which scope has changed
if (mConfig->inst.rstValsNotAvail)
everyMin(std::bind(&app::tickMinute, this), "tMin");
- uint32_t localTime = gTimezone.toLocal(mTimestamp);
- uint32_t midTrig = gTimezone.toUTC(localTime - (localTime % 86400) + 86400); // next midnight local time
- onceAt(std::bind(&app::tickMidnight, this), midTrig, "midNi");
+ if(mNtpReceived) {
+ uint32_t localTime = gTimezone.toLocal(mTimestamp);
+ uint32_t midTrig = gTimezone.toUTC(localTime - (localTime % 86400) + 86400); // next midnight local time
+ onceAt(std::bind(&app::tickMidnight, this), midTrig, "midNi");
- if (mConfig->sys.schedReboot) {
- uint32_t rebootTrig = gTimezone.toUTC(localTime - (localTime % 86400) + 86410); // reboot 10 secs after midnght
- if (rebootTrig <= mTimestamp) { //necessary for times other than midnight to prevent reboot loop
- rebootTrig += 86400;
+ if (mConfig->sys.schedReboot) {
+ uint32_t rebootTrig = gTimezone.toUTC(localTime - (localTime % 86400) + 86410); // reboot 10 secs after midnght
+ onceAt(std::bind(&app::tickReboot, this), rebootTrig, "midRe");
}
- onceAt(std::bind(&app::tickReboot, this), rebootTrig, "midRe");
}
}
+}
+//-----------------------------------------------------------------------------
+void app::updateNtp(void) {
if(mNtpReceived)
onNtpUpdate(true);
-
- mMqttReconnect = false;
}
//-----------------------------------------------------------------------------
@@ -302,8 +290,6 @@ void app::tickNtpUpdate(void) {
updateNtp();
- mMqttReconnect = false;
-
once(std::bind(&app::tickNtpUpdate, this), nxtTrig, "ntp");
}
@@ -345,6 +331,8 @@ void app::tickIVCommunication(void) {
if (mTimestamp >= (mSunset + mConfig->sun.offsetSecEvening)) { // current time is past communication stop, nothing to do. Next update will be done at midnight by tickCalcSunrise
nxtTrig = 0;
} else { // current time lies within communication start/stop time, set next trigger to communication stop
+ if((!iv->commEnabled) && mConfig->inst.rstValsCommStart)
+ zeroValues = true;
iv->commEnabled = true;
nxtTrig = mSunset + mConfig->sun.offsetSecEvening;
}
@@ -417,18 +405,9 @@ void app::tickMidnight(void) {
// reset alarms
if(InverterStatus::OFF == iv->getStatus())
iv->resetAlarms();
-
- // clear max values
- if(mConfig->inst.rstMaxValsMidNight) {
- record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
- for(uint8_t i = 0; i <= iv->channels; i++) {
- uint8_t pos = iv->getPosByChFld(i, FLD_MP, rec);
- iv->setValue(pos, rec, 0.0f);
- }
- }
}
- if (mConfig->inst.rstYieldMidNight) {
+ if (mConfig->inst.rstValsAtMidNight) {
zeroIvValues(!CHECK_AVAIL, !SKIP_YIELD_DAY);
#if defined(ENABLE_MQTT)
@@ -512,6 +491,9 @@ bool app::sendIv(Inverter<> *iv) {
void app:: zeroIvValues(bool checkAvail, bool skipYieldDay) {
Inverter<> *iv;
bool changed = false;
+
+ mMaxPower.reset();
+
// set values to zero, except yields
for (uint8_t id = 0; id < mSys.getNumInverters(); id++) {
iv = mSys.getInverterByPos(id);
@@ -542,18 +524,21 @@ void app:: zeroIvValues(bool checkAvail, bool skipYieldDay) {
pos = iv->getPosByChFld(ch, fld, rec);
iv->setValue(pos, rec, 0.0f);
}
- // zero max power
- if(!skipYieldDay) {
+ // zero max power and max temperature
+ if(mConfig->inst.rstIncludeMaxVals) {
pos = iv->getPosByChFld(ch, FLD_MP, rec);
iv->setValue(pos, rec, 0.0f);
- }
- iv->resetAlarms();
+ pos = iv->getPosByChFld(ch, FLD_MT, rec);
+ iv->setValue(pos, rec, 0.0f);
+ iv->resetAlarms(true);
+ } else
+ iv->resetAlarms();
iv->doCalculations();
}
}
if(changed)
- payloadEventListener(RealTimeRunData_Debug, NULL);
+ payloadEventListener(RealTimeRunData_Debug, nullptr);
}
//-----------------------------------------------------------------------------
@@ -618,6 +603,7 @@ void app::resetSystem(void) {
mNetworkConnected = false;
mNtpReceived = false;
+ mTickerInstallOnce = false;
}
//-----------------------------------------------------------------------------
diff --git a/src/app.h b/src/app.h
index 2c82ac31..f432e52f 100644
--- a/src/app.h
+++ b/src/app.h
@@ -17,9 +17,9 @@
#include "defines.h"
#include "appInterface.h"
#include "hm/hmSystem.h"
-#include "hm/hmRadio.h"
+#include "hm/NrfRadio.h"
#if defined(ESP32)
-#include "hms/hmsRadio.h"
+#include "hms/CmtRadio.h"
#endif
#if defined(ENABLE_MQTT)
#include "publisher/pubMqtt.h"
@@ -31,6 +31,7 @@
#include "utils/syslog.h"
#include "web/RestApi.h"
#include "web/Protection.h"
+#include "plugins/MaxPower.h"
#if defined(ENABLE_HISTORY)
#include "plugins/history.h"
#endif /*ENABLE_HISTORY*/
@@ -175,7 +176,7 @@ class app : public IApp, public ah::Scheduler {
#if !defined(ETHERNET)
bool getAvailNetworks(JsonObject obj) override {
- return mNetwork->getAvailNetworks(obj);
+ return mNetwork->getAvailNetworks(obj, this);
}
void setupStation(void) override {
@@ -211,6 +212,10 @@ class app : public IApp, public ah::Scheduler {
return mVersionModules;
}
+ void addOnce(ah::scdCb c, uint32_t timeout, const char *name) override {
+ once(c, timeout, name);
+ }
+
uint32_t getSunrise() override {
return mSunrise;
}
@@ -220,7 +225,7 @@ class app : public IApp, public ah::Scheduler {
}
bool getSettingsValid() override {
- return mSettings.getValid();
+ return mConfig->valid;
}
bool getRebootRequestState() override {
@@ -306,8 +311,14 @@ class app : public IApp, public ah::Scheduler {
DBGPRINTLN(String(newTime));
if(0 == newTime)
mNetwork->updateNtpTime();
- else
+ else {
Scheduler::setTimestamp(newTime);
+ onNtpUpdate(false);
+ }
+ }
+
+ float getTotalMaxPower(void) override {
+ return mMaxPower.getTotalMaxPower();
}
uint16_t getHistoryValue(uint8_t type, uint16_t i) override {
@@ -357,15 +368,14 @@ class app : public IApp, public ah::Scheduler {
void zeroIvValues(bool checkAvail = false, bool skipYieldDay = true);
void payloadEventListener(uint8_t cmd, Inverter<> *iv) {
- #if !defined(AP_ONLY)
+ mMaxPower.payloadEvent(cmd, iv);
#if defined(ENABLE_MQTT)
if (mMqttEnabled)
mMqtt.payloadEventListener(cmd, iv);
- #endif /*ENABLE_MQTT*/
#endif
#if defined(PLUGIN_DISPLAY)
- if(DISP_TYPE_T0_NONE != mConfig->plugin.display.type)
- mDisplay.payloadEventListener(cmd);
+ if(DISP_TYPE_T0_NONE != mConfig->plugin.display.type)
+ mDisplay.payloadEventListener(cmd);
#endif
updateLed();
}
@@ -417,7 +427,7 @@ class app : public IApp, public ah::Scheduler {
void notAvailChanged(void);
HmSystemType mSys;
- HmRadio<> mNrfRadio;
+ NrfRadio<> mNrfRadio;
Communication mCommunication;
bool mShowRebootRequest = false;
@@ -429,8 +439,7 @@ class app : public IApp, public ah::Scheduler {
#ifdef ENABLE_SYSLOG
DbgSyslog mDbgSyslog;
#endif
- //PayloadType mPayload;
- //MiPayloadType mMiPayload;
+
PubSerialType mPubSerial;
#if !defined(ETHERNET)
//Improv mImprov;
@@ -455,11 +464,10 @@ class app : public IApp, public ah::Scheduler {
bool mNetworkConnected = false;
- // mqtt
#if defined(ENABLE_MQTT)
PubMqttType mMqtt;
- #endif /*ENABLE_MQTT*/
- bool mMqttReconnect = false;
+ #endif
+ bool mTickerInstallOnce = false;
bool mMqttEnabled = false;
// sun
@@ -467,6 +475,7 @@ class app : public IApp, public ah::Scheduler {
uint32_t mSunrise = 0, mSunset = 0;
// plugins
+ MaxPower mMaxPower;
#if defined(PLUGIN_DISPLAY)
DisplayType mDisplay;
DisplayData mDispData;
diff --git a/src/appInterface.h b/src/appInterface.h
index a1f5cd0e..f2292ec8 100644
--- a/src/appInterface.h
+++ b/src/appInterface.h
@@ -8,6 +8,7 @@
#include "defines.h"
#include "ESPAsyncWebServer.h"
+#include "utils/scheduler.h"
// abstract interface to App. Make members of App accessible from child class
// like web or API without forward declaration
@@ -25,6 +26,8 @@ class IApp {
virtual const char *getVersion() = 0;
virtual const char *getVersionModules() = 0;
+ virtual void addOnce(ah::scdCb c, uint32_t timeout, const char *name) = 0;
+
#if !defined(ETHERNET)
virtual bool getAvailNetworks(JsonObject obj) = 0;
virtual void setupStation(void) = 0;
@@ -61,6 +64,7 @@ class IApp {
virtual void resetLockTimeout(void) = 0;
virtual bool isProtected(const char *clientIp, const char *token, bool askedFromWeb) const = 0;
+ virtual float getTotalMaxPower(void) = 0;
virtual uint16_t getHistoryValue(uint8_t type, uint16_t i) = 0;
virtual uint32_t getHistoryPeriod(uint8_t type) = 0;
virtual uint16_t getHistoryMaxDay() = 0;
diff --git a/src/config/config.h b/src/config/config.h
index 7254d13d..4b8b9ca2 100644
--- a/src/config/config.h
+++ b/src/config/config.h
@@ -28,6 +28,11 @@
// If the next line is uncommented, Ahoy will stay in access point mode all the time
//#define AP_ONLY
+#if defined(AP_ONLY)
+ #if defined(ENABLE_MQTT)
+ #undef ENABLE_MQTT
+ #endif
+#endif
// timeout for automatic logoff (20 minutes)
#define LOGOUT_TIMEOUT (20 * 60)
@@ -145,7 +150,7 @@
#ifndef DEF_MOTION_SENSOR_PIN
#define DEF_MOTION_SENSOR_PIN DEF_PIN_OFF
#endif
-#else
+#else // ESP8266
#ifndef DEF_NRF_CS_PIN
#define DEF_NRF_CS_PIN 15
#endif
diff --git a/src/config/settings.h b/src/config/settings.h
index e54dce4d..32d23511 100644
--- a/src/config/settings.h
+++ b/src/config/settings.h
@@ -33,7 +33,6 @@
#define CONFIG_VERSION 11
-
#define PROT_MASK_INDEX 0x0001
#define PROT_MASK_LIVE 0x0002
#define PROT_MASK_SERIAL 0x0004
@@ -55,6 +54,20 @@
#define DEF_PROT_MQTT 0x0000
+#define SSID_LEN 32
+#define PWD_LEN 64
+#define DEVNAME_LEN 16
+#define NTP_ADDR_LEN 32 // DNS Name
+
+#define MQTT_ADDR_LEN 64 // DNS Name
+#define MQTT_CLIENTID_LEN 22 // number of chars is limited to 23 up to v3.1 of MQTT
+#define MQTT_USER_LEN 65 // there is another byte necessary for \0
+#define MQTT_PWD_LEN 65
+#define MQTT_TOPIC_LEN 65
+
+#define MQTT_MAX_PACKET_SIZE 384
+
+
typedef struct {
uint8_t ip[4]; // ip address
uint8_t mask[4]; // sub mask
@@ -151,7 +164,9 @@ typedef struct {
char user[MQTT_USER_LEN];
char pwd[MQTT_PWD_LEN];
char topic[MQTT_TOPIC_LEN];
+ bool json;
uint16_t interval;
+ bool enableRetain;
} cfgMqtt_t;
typedef struct {
@@ -171,10 +186,11 @@ typedef struct {
cfgIv_t iv[MAX_NUM_INVERTERS];
uint16_t sendInterval;
- bool rstYieldMidNight;
+ bool rstValsAtMidNight;
bool rstValsNotAvail;
bool rstValsCommStop;
- bool rstMaxValsMidNight;
+ bool rstValsCommStart;
+ bool rstIncludeMaxVals;
bool startWithoutTime;
bool readGrid;
} cfgInst_t;
@@ -369,8 +385,9 @@ class settings {
std::fill(reinterpret_cast(&mCfg), reinterpret_cast(&mCfg) + sizeof(mCfg), 0);
}
- void setup() {
+ void setup(settings_t *&c) {
DPRINTLN(DBG_INFO, F("Initializing FS .."));
+ c = &mCfg;
mCfg.valid = false;
#if !defined(ESP32)
@@ -406,14 +423,6 @@ class settings {
DPRINTLN(DBG_INFO, F("FS stopped"));
}
- void getPtr(settings_t *&cfg) {
- cfg = &mCfg;
- }
-
- bool getValid(void) {
- return mCfg.valid;
- }
-
inline bool getLastSaveSucceed() {
return mLastSaveSucceed;
}
@@ -622,14 +631,17 @@ class settings {
snprintf(mCfg.mqtt.pwd, MQTT_PWD_LEN, "%s", DEF_MQTT_PWD);
snprintf(mCfg.mqtt.topic, MQTT_TOPIC_LEN, "%s", DEF_MQTT_TOPIC);
mCfg.mqtt.interval = 0; // off
-
- mCfg.inst.sendInterval = SEND_INTERVAL;
- mCfg.inst.rstYieldMidNight = false;
- mCfg.inst.rstValsNotAvail = false;
- mCfg.inst.rstValsCommStop = false;
- mCfg.inst.startWithoutTime = false;
- mCfg.inst.rstMaxValsMidNight = false;
- mCfg.inst.readGrid = true;
+ mCfg.mqtt.json = false; // off
+ mCfg.mqtt.enableRetain = true;
+
+ mCfg.inst.sendInterval = SEND_INTERVAL;
+ mCfg.inst.rstValsAtMidNight = false;
+ mCfg.inst.rstValsNotAvail = false;
+ mCfg.inst.rstValsCommStop = false;
+ mCfg.inst.rstValsCommStart = false;
+ mCfg.inst.startWithoutTime = false;
+ mCfg.inst.rstIncludeMaxVals = false;
+ mCfg.inst.readGrid = true;
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
mCfg.inst.iv[i].powerLevel = 0xff; // impossible high value
@@ -974,16 +986,20 @@ class settings {
obj[F("user")] = mCfg.mqtt.user;
obj[F("pwd")] = mCfg.mqtt.pwd;
obj[F("topic")] = mCfg.mqtt.topic;
+ obj[F("json")] = mCfg.mqtt.json;
obj[F("intvl")] = mCfg.mqtt.interval;
+ obj[F("retain")] = mCfg.mqtt.enableRetain;
} else {
getVal(obj, F("port"), &mCfg.mqtt.port);
getVal(obj, F("intvl"), &mCfg.mqtt.interval);
+ getVal(obj, F("json"), &mCfg.mqtt.json);
getChar(obj, F("broker"), mCfg.mqtt.broker, MQTT_ADDR_LEN);
getChar(obj, F("user"), mCfg.mqtt.user, MQTT_USER_LEN);
getChar(obj, F("clientId"), mCfg.mqtt.clientId, MQTT_CLIENTID_LEN);
getChar(obj, F("pwd"), mCfg.mqtt.pwd, MQTT_PWD_LEN);
getChar(obj, F("topic"), mCfg.mqtt.topic, MQTT_TOPIC_LEN);
+ getVal(obj, F("retain"), &mCfg.mqtt.enableRetain);
}
}
@@ -1205,21 +1221,23 @@ class settings {
if(set) {
obj[F("intvl")] = mCfg.inst.sendInterval;
// obj[F("en")] = (bool)mCfg.inst.enabled;
- obj[F("rstMidNight")] = (bool)mCfg.inst.rstYieldMidNight;
+ obj[F("rstMidNight")] = (bool)mCfg.inst.rstValsAtMidNight;
obj[F("rstNotAvail")] = (bool)mCfg.inst.rstValsNotAvail;
obj[F("rstComStop")] = (bool)mCfg.inst.rstValsCommStop;
+ obj[F("rstComStart")] = (bool)mCfg.inst.rstValsCommStart;
obj[F("strtWthtTime")] = (bool)mCfg.inst.startWithoutTime;
- obj[F("rstMaxMidNight")] = (bool)mCfg.inst.rstMaxValsMidNight;
+ obj[F("rstMaxMidNight")] = (bool)mCfg.inst.rstIncludeMaxVals;
obj[F("rdGrid")] = (bool)mCfg.inst.readGrid;
}
else {
getVal(obj, F("intvl"), &mCfg.inst.sendInterval);
// getVal(obj, F("en"), &mCfg.inst.enabled);
- getVal(obj, F("rstMidNight"), &mCfg.inst.rstYieldMidNight);
+ getVal(obj, F("rstMidNight"), &mCfg.inst.rstValsAtMidNight);
getVal(obj, F("rstNotAvail"), &mCfg.inst.rstValsNotAvail);
getVal(obj, F("rstComStop"), &mCfg.inst.rstValsCommStop);
+ getVal(obj, F("rstComStart"), &mCfg.inst.rstValsCommStart);
getVal(obj, F("strtWthtTime"), &mCfg.inst.startWithoutTime);
- getVal(obj, F("rstMaxMidNight"), &mCfg.inst.rstMaxValsMidNight);
+ getVal(obj, F("rstMaxMidNight"), &mCfg.inst.rstIncludeMaxVals);
getVal(obj, F("rdGrid"), &mCfg.inst.readGrid);
}
@@ -1294,6 +1312,7 @@ class settings {
}
#endif
+ private:
settings_t mCfg;
bool mLastSaveSucceed = 0;
};
diff --git a/src/defines.h b/src/defines.h
index c68bc63a..d7a4927d 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 8
-#define VERSION_PATCH 1030020
+#define VERSION_PATCH 1230001
//-------------------------------------
typedef struct {
uint8_t ch;
@@ -23,41 +23,6 @@ typedef struct {
uint16_t millis;
} packet_t;
-typedef enum {
- InverterDevInform_Simple = 0, // 0x00
- InverterDevInform_All = 1, // 0x01
- GridOnProFilePara = 2, // 0x02
- HardWareConfig = 3, // 0x03
- SimpleCalibrationPara = 4, // 0x04
- SystemConfigPara = 5, // 0x05
- RealTimeRunData_Debug = 11, // 0x0b
- RealTimeRunData_Reality = 12, // 0x0c
- RealTimeRunData_A_Phase = 13, // 0x0d
- RealTimeRunData_B_Phase = 14, // 0x0e
- RealTimeRunData_C_Phase = 15, // 0x0f
- AlarmData = 17, // 0x11, Alarm data - all unsent alarms
- AlarmUpdate = 18, // 0x12, Alarm data - all pending alarms
- RecordData = 19, // 0x13
- InternalData = 20, // 0x14
- GetLossRate = 21, // 0x15
- GetSelfCheckState = 30, // 0x1e
- InitDataState = 0xff
-} InfoCmdType;
-
-typedef enum {
- TurnOn = 0, // 0x00
- TurnOff = 1, // 0x01
- Restart = 2, // 0x02
- Lock = 3, // 0x03
- Unlock = 4, // 0x04
- ActivePowerContr = 11, // 0x0b
- ReactivePowerContr = 12, // 0x0c
- PFSet = 13, // 0x0d
- CleanState_LockAndAlarm = 20, // 0x14
- SelfInspection = 40, // 0x28, self-inspection of grid-connected protection files
- Init = 0xff
-} DevControlCmdType;
-
typedef enum {
AbsolutNonPersistent = 0UL, // 0x0000
RelativNonPersistent = 1UL, // 0x0001
@@ -70,13 +35,6 @@ union serial_u {
uint8_t b[8];
};
-#define MIN_SERIAL_INTERVAL 2 // 5
-#define MIN_SEND_INTERVAL 15
-#define MIN_MQTT_INTERVAL 60
-
-
-enum {MQTT_STATUS_OFFLINE = 0, MQTT_STATUS_PARTIAL, MQTT_STATUS_ONLINE};
-
enum {
DISP_TYPE_T0_NONE = 0,
DISP_TYPE_T1_SSD1306_128X64 = 1,
@@ -88,27 +46,6 @@ enum {
DISP_TYPE_T10_EPAPER = 10
};
-
-//-------------------------------------
-// EEPROM
-//-------------------------------------
-#define SSID_LEN 32
-#define PWD_LEN 64
-#define DEVNAME_LEN 16
-#define NTP_ADDR_LEN 32 // DNS Name
-
-#define ZEXPORT_ADDR_LEN 100 // Zero-Export Address
-
-#define MQTT_ADDR_LEN 64 // DNS Name
-#define MQTT_CLIENTID_LEN 22 // number of chars is limited to 23 up to v3.1 of MQTT
-#define MQTT_USER_LEN 65 // there is another byte necessary for \0
-#define MQTT_PWD_LEN 65
-#define MQTT_TOPIC_LEN 65
-
-#define MQTT_MAX_PACKET_SIZE 384
-
-//#define PLUGIN_ZEROEXPORT
-
typedef struct {
uint32_t rxFail;
uint32_t rxFailNoAnswer;
diff --git a/src/hm/CommQueue.h b/src/hm/CommQueue.h
index 328309ac..bf6f6861 100644
--- a/src/hm/CommQueue.h
+++ b/src/hm/CommQueue.h
@@ -19,13 +19,19 @@ template
class CommQueue {
public:
void addImportant(Inverter<> *iv, uint8_t cmd) {
- dec(&mRdPtr);
- mQueue[mRdPtr] = queue_s(iv, cmd, true);
+ queue_s q(iv, cmd, true);
+ if(!isIncluded(&q)) {
+ dec(&mRdPtr);
+ mQueue[mRdPtr] = q;
+ }
}
void add(Inverter<> *iv, uint8_t cmd) {
- mQueue[mWrPtr] = queue_s(iv, cmd, false);
- inc(&mWrPtr);
+ queue_s q(iv, cmd, false);
+ if(!isIncluded(&q)) {
+ mQueue[mWrPtr] = q;
+ inc(&mWrPtr);
+ }
}
void chgCmd(Inverter<> *iv, uint8_t cmd) {
@@ -117,6 +123,19 @@ class CommQueue {
--(*ptr);
}
+ private:
+ bool isIncluded(const queue_s *q) {
+ uint8_t ptr = mRdPtr;
+ while (ptr != mWrPtr) {
+ if(mQueue[ptr].cmd == q->cmd) {
+ if(mQueue[ptr].iv->id == q->iv->id)
+ return true;
+ }
+ inc(&ptr);
+ }
+ return false;
+ }
+
protected:
std::array mQueue;
uint8_t mWrPtr = 0;
diff --git a/src/hm/Communication.h b/src/hm/Communication.h
index 883f3fd9..2950ebea 100644
--- a/src/hm/Communication.h
+++ b/src/hm/Communication.h
@@ -174,8 +174,6 @@ class Communication : public CommQueue<> {
mFirstTry = false;
mHeu.evalTxChQuality(q->iv, false, 0, 0);
mHeu.getTxCh(q->iv);
- //q->iv->radioStatistics.rxFailNoAnser++; // should only be one of fail or retransmit.
- //q->iv->radioStatistics.txCnt--;
q->iv->radioStatistics.retransmits++;
q->iv->radio->mRadioWaitTime.stopTimeMonitor();
mState = States::START;
@@ -927,7 +925,7 @@ class Communication : public CommQueue<> {
uint8_t oldState = rec->record[q->iv->getPosByChFld(0, FLD_EVT, rec)];
if ( prntsts != oldState ) { // sth.'s changed?
stsok = false;
- if(!oldState) { // initial zero value? => just write this channel to main state and raise changed flags
+ if( (!oldState) || (!q->iv->alarmCnt) ) { // initial zero value? => just write this channel to main state and raise changed flags
changedStatus = true;
q->iv->alarmCnt = 1; // minimum...
} else {
diff --git a/src/hm/hmRadio.h b/src/hm/NrfRadio.h
similarity index 91%
rename from src/hm/hmRadio.h
rename to src/hm/NrfRadio.h
index eb44dd8c..21d0c676 100644
--- a/src/hm/hmRadio.h
+++ b/src/hm/NrfRadio.h
@@ -8,9 +8,10 @@
#include
#include "SPI.h"
-#include "radio.h"
+#include "Radio.h"
#include "../config/config.h"
-#if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL)
+#include "../config/settings.h"
+#if defined(SPI_HAL)
#include "nrfHal.h"
#endif
@@ -28,24 +29,30 @@ const char* const rf24AmpPowerNames[] = {"MIN", "LOW", "HIGH", "MAX"};
//-----------------------------------------------------------------------------
// HM Radio class
//-----------------------------------------------------------------------------
-template
-class HmRadio : public Radio {
+template
+class NrfRadio : public Radio {
public:
- HmRadio() {
+ NrfRadio() {
mDtuSn = DTU_SN;
mIrqRcvd = false;
- #if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL)
+ #if defined(SPI_HAL)
//mNrf24.reset(new RF24());
#else
- mNrf24.reset(new RF24(CE_PIN, CS_PIN, SPI_SPEED));
+ mNrf24.reset(new RF24(DEF_NRF_CE_PIN, DEF_NRF_CS_PIN, SPI_SPEED));
#endif
}
- ~HmRadio() {}
+ ~NrfRadio() {}
- void setup(bool *serialDebug, bool *privacyMode, bool *printWholeTrace, uint8_t irq = IRQ_PIN, uint8_t ce = CE_PIN, uint8_t cs = CS_PIN, uint8_t sclk = SCLK_PIN, uint8_t mosi = MOSI_PIN, uint8_t miso = MISO_PIN) {
- DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setup"));
+ void setup(bool *serialDebug, bool *privacyMode, bool *printWholeTrace, cfgNrf24_t *cfg) {
+ DPRINTLN(DBG_VERBOSE, F("NrfRadio::setup"));
- pinMode(irq, INPUT_PULLUP);
+ mCfg = cfg;
+ //uint8_t irq = IRQ_PIN, uint8_t ce = CE_PIN, uint8_t cs = CS_PIN, uint8_t sclk = SCLK_PIN, uint8_t mosi = MOSI_PIN, uint8_t miso = MISO_PIN
+
+ if(!mCfg->enabled)
+ return;
+
+ pinMode(mCfg->pinIrq, INPUT_PULLUP);
mSerialDebug = serialDebug;
mPrivacyMode = privacyMode;
@@ -55,8 +62,8 @@ class HmRadio : public Radio {
mDtuRadioId = ((uint64_t)(((mDtuSn >> 24) & 0xFF) | ((mDtuSn >> 8) & 0xFF00) | ((mDtuSn << 8) & 0xFF0000) | ((mDtuSn << 24) & 0xFF000000)) << 8) | 0x01;
#ifdef ESP32
- #if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL)
- mNrfHal.init(mosi, miso, sclk, cs, ce, SPI_SPEED);
+ #if defined(SPI_HAL)
+ mNrfHal.init(mCfg->pinMosi, mCfg->pinMiso, mCfg->pinSclk, mCfg->pinCs, mCfg->pinCe, SPI_SPEED);
mNrf24.reset(new RF24(&mNrfHal));
#else
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
@@ -64,7 +71,7 @@ class HmRadio : public Radio {
#else
mSpi.reset(new SPIClass(VSPI));
#endif
- mSpi->begin(sclk, miso, mosi, cs);
+ mSpi->begin(mCfg->pinSclk, mCfg->pinMiso, mCfg->pinMosi, mCfg->pinCs);
#endif
#else
//the old ESP82xx cannot freely place their SPI pins
@@ -72,10 +79,10 @@ class HmRadio : public Radio {
mSpi->begin();
#endif
- #if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL)
+ #if defined(SPI_HAL)
mNrf24->begin();
#else
- mNrf24->begin(mSpi.get(), ce, cs);
+ mNrf24->begin(mSpi.get(), mCfg->pinCe, mCfg->pinCs);
#endif
mNrf24->setRetries(3, 15); // wait 3*250 = 750us, 16 * 250us -> 4000us = 4ms
@@ -99,21 +106,24 @@ class HmRadio : public Radio {
}
// returns true if communication is active
- bool loop(void) override {
+ void loop(void) {
+ if(!mCfg->enabled)
+ return;
+
if (!mIrqRcvd && !mNRFisInRX)
- return false; // first quick check => nothing to do at all here
+ return; // first quick check => nothing to do at all here
if(NULL == mLastIv) // prevent reading on NULL object!
- return false;
+ return;
if(!mIrqRcvd) { // no news from nRF, check timers
if ((millis() - mTimeslotStart) < innerLoopTimeout)
- return true; // nothing to do, still waiting
+ return; // nothing to do, still waiting
if (mRadioWaitTime.isTimeout()) { // timeout reached!
mNRFisInRX = false;
rx_ready = false;
- return false;
+ return;
}
// otherwise switch to next RX channel
@@ -132,7 +142,7 @@ class HmRadio : public Radio {
mNrf24->setChannel(mRfChLst[tempRxChIdx]);
isRxInit = false;
- return true; // communicating, but changed RX channel
+ return; // communicating, but changed RX channel
} else {
// here we got news from the nRF
mIrqRcvd = false;
@@ -145,7 +155,7 @@ class HmRadio : public Radio {
if(mNRFisInRX) {
DPRINTLN(DBG_WARN, F("unexpected tx irq!"));
- return false;
+ return;
}
mNRFisInRX = true;
@@ -181,18 +191,23 @@ class HmRadio : public Radio {
}
}
rx_ready = false; // reset
- return mNRFisInRX;
+ return;
}
}
- return false;
+ return;
}
bool isChipConnected(void) const override {
+ if(!mCfg->enabled)
+ return false;
return mNrf24->isChipConnected();
}
void sendControlPacket(Inverter<> *iv, uint8_t cmd, uint16_t *data, bool isRetransmit) override {
+ if(!mCfg->enabled)
+ return;
+
DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINT(F("sendControlPacket cmd: "));
DBGHEXLN(cmd);
@@ -279,13 +294,14 @@ class HmRadio : public Radio {
}
uint8_t getDataRate(void) const {
- if(!mNrf24->isChipConnected())
+ if(!isChipConnected())
return 3; // unknown
return mNrf24->getDataRate();
}
bool isPVariant(void) const {
- return mNrf24->isPVariant();
+ if(!isChipConnected())
+ return mNrf24->isPVariant();
}
private:
@@ -413,6 +429,7 @@ class HmRadio : public Radio {
}
uint64_t mDtuRadioId = 0ULL;
+ cfgNrf24_t *mCfg = nullptr;
const uint8_t mRfChLst[RF_CHANNELS] = {03, 23, 40, 61, 75}; // channel List:2403, 2423, 2440, 2461, 2475MHz
uint8_t mTxChIdx = 0;
uint8_t mRxChIdx = 0;
@@ -432,7 +449,7 @@ class HmRadio : public Radio {
std::unique_ptr mSpi;
std::unique_ptr mNrf24;
- #if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL)
+ #if defined(SPI_HAL)
nrfHal mNrfHal;
#endif
Inverter<> *mLastIv = NULL;
diff --git a/src/hm/radio.h b/src/hm/Radio.h
similarity index 99%
rename from src/hm/radio.h
rename to src/hm/Radio.h
index 31643980..12e80850 100644
--- a/src/hm/radio.h
+++ b/src/hm/Radio.h
@@ -33,7 +33,7 @@ class Radio {
virtual uint16_t getBaseFreqMhz() { return 0; }
virtual uint16_t getBootFreqMhz() { return 0; }
virtual std::pair getFreqRangeMhz(void) { return std::make_pair(0, 0); }
- virtual bool loop(void) = 0;
+ virtual void loop(void) = 0;
Radio() : mTxBuf{} {}
diff --git a/src/hm/hmDefines.h b/src/hm/hmDefines.h
index 6ba92774..4287d26e 100644
--- a/src/hm/hmDefines.h
+++ b/src/hm/hmDefines.h
@@ -9,6 +9,41 @@
#include "../utils/dbg.h"
#include
+typedef enum {
+ InverterDevInform_Simple = 0, // 0x00
+ InverterDevInform_All = 1, // 0x01
+ GridOnProFilePara = 2, // 0x02
+ HardWareConfig = 3, // 0x03
+ SimpleCalibrationPara = 4, // 0x04
+ SystemConfigPara = 5, // 0x05
+ RealTimeRunData_Debug = 11, // 0x0b
+ RealTimeRunData_Reality = 12, // 0x0c
+ RealTimeRunData_A_Phase = 13, // 0x0d
+ RealTimeRunData_B_Phase = 14, // 0x0e
+ RealTimeRunData_C_Phase = 15, // 0x0f
+ AlarmData = 17, // 0x11, Alarm data - all unsent alarms
+ AlarmUpdate = 18, // 0x12, Alarm data - all pending alarms
+ RecordData = 19, // 0x13
+ InternalData = 20, // 0x14
+ GetLossRate = 21, // 0x15
+ GetSelfCheckState = 30, // 0x1e
+ InitDataState = 0xff
+} InfoCmdType;
+
+typedef enum {
+ TurnOn = 0, // 0x00
+ TurnOff = 1, // 0x01
+ Restart = 2, // 0x02
+ Lock = 3, // 0x03
+ Unlock = 4, // 0x04
+ ActivePowerContr = 11, // 0x0b
+ ReactivePowerContr = 12, // 0x0c
+ PFSet = 13, // 0x0d
+ CleanState_LockAndAlarm = 20, // 0x14
+ SelfInspection = 40, // 0x28, self-inspection of grid-connected protection files
+ Init = 0xff
+} DevControlCmdType;
+
// inverter generations
enum {IV_MI = 0, IV_HM, IV_HMS, IV_HMT, IV_UNKNOWN};
const char* const generationNames[] = {"MI", "HM", "HMS", "HMT", "UNKNOWN"};
@@ -24,20 +59,20 @@ enum {FLD_UDC = 0, FLD_IDC, FLD_PDC, FLD_YD, FLD_YW, FLD_YT,
FLD_IRR, FLD_Q, FLD_EVT, FLD_FW_VERSION, FLD_FW_BUILD_YEAR,
FLD_FW_BUILD_MONTH_DAY, FLD_FW_BUILD_HOUR_MINUTE, FLD_BOOTLOADER_VER,
FLD_ACT_ACTIVE_PWR_LIMIT, FLD_PART_NUM, FLD_HW_VERSION, FLD_GRID_PROFILE_CODE,
- FLD_GRID_PROFILE_VERSION, /*FLD_ACT_REACTIVE_PWR_LIMIT, FLD_ACT_PF,*/ FLD_LAST_ALARM_CODE, FLD_MP};
+ FLD_GRID_PROFILE_VERSION, /*FLD_ACT_REACTIVE_PWR_LIMIT, FLD_ACT_PF,*/ FLD_LAST_ALARM_CODE, FLD_MP, FLD_MT};
const char* const fields[] = {"U_DC", "I_DC", "P_DC", "YieldDay", "YieldWeek", "YieldTotal",
- "U_AC", "U_AC_1N", "U_AC_2N", "U_AC_3N", "UAC_12", "UAC_23", "UAC_31", "I_AC",
- "IAC_1", "I_AC_2", "I_AC_3", "P_AC", "F_AC", "Temp", "PF_AC", "Efficiency", "Irradiation","Q_AC",
+ "U_AC", "U_AC_1N", "U_AC_2N", "U_AC_3N", "U_AC_12", "U_AC_23", "U_AC_31", "I_AC",
+ "I_AC_1", "I_AC_2", "I_AC_3", "P_AC", "F_AC", "Temp", "PF_AC", "Efficiency", "Irradiation","Q_AC",
"ALARM_MES_ID","FWVersion","FWBuildYear","FWBuildMonthDay","FWBuildHourMinute","BootloaderVersion",
"active_PowerLimit", "HWPartNumber", "HWVersion", "GridProfileCode",
- "GridProfileVersion", /*"reactivePowerLimit","Powerfactor",*/ "LastAlarmCode", "MaxPower"};
+ "GridProfileVersion", /*"reactivePowerLimit","Powerfactor",*/ "LastAlarmCode", "MaxPower", "MaxTemp"};
const char* const notAvail = "n/a";
const uint8_t fieldUnits[] = {UNIT_V, UNIT_A, UNIT_W, UNIT_WH, UNIT_KWH, UNIT_KWH,
UNIT_V, UNIT_V, UNIT_V, UNIT_V, UNIT_V, UNIT_V, UNIT_V, UNIT_A, UNIT_A, UNIT_A, UNIT_A,
UNIT_W, UNIT_HZ, UNIT_C, UNIT_NONE, UNIT_PCT, UNIT_PCT, UNIT_VAR,
- UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_PCT, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_W};
+ UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_PCT, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_NONE, UNIT_W, UNIT_C};
// mqtt discovery device classes
enum {DEVICE_CLS_NONE = 0, DEVICE_CLS_CURRENT, DEVICE_CLS_ENERGY, DEVICE_CLS_PWR, DEVICE_CLS_VOLTAGE, DEVICE_CLS_FREQ, DEVICE_CLS_TEMP};
@@ -68,7 +103,7 @@ const byteAssign_fieldDeviceClass deviceFieldAssignment[] = {
#define DEVICE_CLS_ASSIGN_LIST_LEN (sizeof(deviceFieldAssignment) / sizeof(byteAssign_fieldDeviceClass))
// indices to calculation functions, defined in hmInverter.h
-enum {CALC_YT_CH0 = 0, CALC_YD_CH0, CALC_UDC_CH, CALC_PDC_CH0, CALC_EFF_CH0, CALC_IRR_CH, CALC_MPAC_CH0, CALC_MPDC_CH};
+enum {CALC_YT_CH0 = 0, CALC_YD_CH0, CALC_UDC_CH, CALC_PDC_CH0, CALC_EFF_CH0, CALC_IRR_CH, CALC_MPAC_CH0, CALC_MPDC_CH, CALC_MT_CH0};
enum {CMD_CALC = 0xffff};
@@ -173,7 +208,8 @@ const byteAssign_t hm1chAssignment[] = {
{ FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC },
{ FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC },
{ FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC },
- { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC }
+ { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC },
+ { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC }
};
#define HM1CH_LIST_LEN (sizeof(hm1chAssignment) / sizeof(byteAssign_t))
#define HM1CH_PAYLOAD_LEN 30
@@ -211,7 +247,8 @@ const byteAssign_t hm2chAssignment[] = {
{ FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC },
{ FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC },
{ FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC },
- { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC }
+ { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC },
+ { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC }
};
#define HM2CH_LIST_LEN (sizeof(hm2chAssignment) / sizeof(byteAssign_t))
@@ -266,7 +303,8 @@ const byteAssign_t hm4chAssignment[] = {
{ FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC },
{ FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC },
{ FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC },
- { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC }
+ { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC },
+ { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC }
};
#define HM4CH_LIST_LEN (sizeof(hm4chAssignment) / sizeof(byteAssign_t))
#define HM4CH_PAYLOAD_LEN 62
@@ -351,8 +389,11 @@ const devInfo_t devInfo[] = {
{ 0x102271, 2000 }, // v2 black backplane, 16A
// HMT
- { 0x103311, 1800 },
- { 0x103331, 2250 }
+ { 0x103241, 1600 }, // -4T
+ { 0x103251, 1800 }, // -4T
+ { 0x103271, 2000 }, // -4T
+ { 0x103311, 1800 }, // -6T
+ { 0x103331, 2250 } // -6T
};
#define MI_REQ_CH1 0x09
diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h
index 1d7e6620..b72ec5ab 100644
--- a/src/hm/hmInverter.h
+++ b/src/hm/hmInverter.h
@@ -22,7 +22,7 @@
#include
#include "../config/settings.h"
-#include "radio.h"
+#include "Radio.h"
/**
* For values which are of interest and not transmitted by the inverter can be
* calculated automatically.
@@ -33,28 +33,31 @@
// prototypes
template
-static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0);
+T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0);
template
-static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0);
+T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0);
template
-static T calcUdcCh(Inverter<> *iv, uint8_t arg0);
+T calcUdcCh(Inverter<> *iv, uint8_t arg0);
template
-static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0);
+T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0);
template
-static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0);
+T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0);
template
-static T calcIrradiation(Inverter<> *iv, uint8_t arg0);
+T calcIrradiation(Inverter<> *iv, uint8_t arg0);
template
-static T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0);
+T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0);
template
-static T calcMaxPowerDc(Inverter<> *iv, uint8_t arg0);
+T calcMaxPowerDc(Inverter<> *iv, uint8_t arg0);
+
+template
+T calcMaxTemperature(Inverter<> *iv, uint8_t arg0);
template
using func_t = T (Inverter<> *, uint8_t);
@@ -84,7 +87,7 @@ struct record_t {
byteAssign_t* assign = nullptr; // assignment of bytes in payload
uint8_t length = 0; // length of the assignment list
T *record = nullptr; // data pointer
- uint32_t ts = 0; // timestamp of last received payload
+ uint32_t ts = 0; // Timestamp of last received payload
uint8_t pyldLen = 0; // expected payload length for plausibility check
MqttSentStatus mqttSentStatus = MqttSentStatus:: NEW_DATA; // indicates the current MqTT sent status
};
@@ -100,14 +103,15 @@ struct alarm_t {
// list of all available functions, mapped in hmDefines.h
template
const calcFunc_t calcFunctions[] = {
- { CALC_YT_CH0, &calcYieldTotalCh0 },
- { CALC_YD_CH0, &calcYieldDayCh0 },
- { CALC_UDC_CH, &calcUdcCh },
- { CALC_PDC_CH0, &calcPowerDcCh0 },
- { CALC_EFF_CH0, &calcEffiencyCh0 },
- { CALC_IRR_CH, &calcIrradiation },
- { CALC_MPAC_CH0, &calcMaxPowerAcCh0 },
- { CALC_MPDC_CH, &calcMaxPowerDc }
+ { CALC_YT_CH0, &calcYieldTotalCh0 },
+ { CALC_YD_CH0, &calcYieldDayCh0 },
+ { CALC_UDC_CH, &calcUdcCh },
+ { CALC_PDC_CH0, &calcPowerDcCh0 },
+ { CALC_EFF_CH0, &calcEffiencyCh0 },
+ { CALC_IRR_CH, &calcIrradiation },
+ { CALC_MPAC_CH0, &calcMaxPowerAcCh0 },
+ { CALC_MPDC_CH, &calcMaxPowerDc },
+ { CALC_MT_CH0, &calcMaxTemperature }
};
template
@@ -146,7 +150,8 @@ class Inverter {
statistics_t radioStatistics; // information about transmitted, failed, ... packets
HeuristicInv heuristics; // heuristic information / logic
uint8_t curCmtFreq = 0; // current used CMT frequency, used to check if freq. was changed during runtime
- uint32_t tsMaxAcPower = 0; // holds the timestamp when the MaxAC power was seen
+ uint32_t tsMaxAcPower = 0; // holds the Timestamp when the MaxAC power was seen
+ uint32_t tsMaxTemperature = 0; // holds the Timestamp when the max temperature was seen
bool commEnabled = true; // 'pause night communication' sets this field to false
public:
@@ -189,7 +194,7 @@ class Inverter {
cb(InverterDevInform_Simple, false); // get hardware version
} else if((alarmLastId != alarmMesIndex) && (alarmMesIndex != 0)) {
cb(AlarmData, false); // get last alarms
- } else if((0 == mGridLen) && generalConfig->readGrid) { // read grid profile
+ } else if((0 == mGridLen) && GeneralConfig->readGrid) { // read grid profile
cb(GridOnProFilePara, false);
} else if (mGetLossInterval > AHOY_GET_LOSS_INTERVAL) { // get loss rate
mGetLossInterval = 1;
@@ -213,7 +218,7 @@ class Inverter {
if (getChannelFieldValue(CH0, FLD_PART_NUM, rec) == 0) {
cb(0x0f, false); // hard- and firmware version for missing HW part nr, delivered by frame 1
mIvRxCnt +=2;
- } else if((getChannelFieldValue(CH0, FLD_GRID_PROFILE_CODE, rec) == 0) && generalConfig->readGrid) // read grid profile
+ } else if((getChannelFieldValue(CH0, FLD_GRID_PROFILE_CODE, rec) == 0) && GeneralConfig->readGrid) // read grid profile
cb(0x10, false); // legacy GPF command
}
}
@@ -229,19 +234,20 @@ class Inverter {
initAssignment(&recordAlarm, AlarmData);
toRadioId();
curCmtFreq = this->config->frequency; // update to frequency read from settings
+ resetAlarms(true);
}
uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId, record_t<> *rec) {
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getPosByChFld"));
- if(NULL != rec) {
- uint8_t pos = 0;
- for(; pos < rec->length; pos++) {
- if((rec->assign[pos].ch == channel) && (rec->assign[pos].fieldId == fieldId))
- break;
- }
- return (pos >= rec->length) ? 0xff : pos;
- } else
+ if(nullptr == rec)
return 0xff;
+
+ uint8_t pos = 0;
+ for(; pos < rec->length; pos++) {
+ if((rec->assign[pos].ch == channel) && (rec->assign[pos].fieldId == fieldId))
+ break;
+ }
+ return (pos >= rec->length) ? 0xff : pos;
}
byteAssign_t *getByteAssign(uint8_t pos, record_t<> *rec) {
@@ -270,15 +276,18 @@ class Inverter {
if(InverterStatus::OFF != status) {
mDevControlRequest = true;
devControlCmd = cmd;
- //app->triggerTickSend(); // done in RestApi.h, because of "chicken-and-egg problem ;-)"
+ assert(App);
+ App->triggerTickSend(id);
+ return true;
}
- return (InverterStatus::OFF != status);
+ return false;
}
bool setDevCommand(uint8_t cmd) {
- if(InverterStatus::OFF != status)
+ bool retval = (InverterStatus::OFF != status);
+ if(retval)
devControlCmd = cmd;
- return (InverterStatus::OFF != status);
+ return retval;
}
void addValue(uint8_t pos, const uint8_t buf[], record_t<> *rec) {
@@ -354,7 +363,7 @@ class Inverter {
bool setValue(uint8_t pos, record_t<> *rec, REC_TYP val) {
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:setValue"));
- if(NULL == rec)
+ if(nullptr == rec)
return false;
if(pos > rec->length)
return false;
@@ -408,14 +417,14 @@ class Inverter {
if(recordMeas.ts == 0)
return false;
- if(((*timestamp) - recordMeas.ts) < INVERTER_INACT_THRES_SEC)
+ if(((*Timestamp) - recordMeas.ts) < INVERTER_INACT_THRES_SEC)
avail = true;
if(avail) {
if(status < InverterStatus::PRODUCING)
status = InverterStatus::STARTING;
} else {
- if(((*timestamp) - recordMeas.ts) > INVERTER_OFF_THRES_SEC) {
+ if(((*Timestamp) - recordMeas.ts) > INVERTER_OFF_THRES_SEC) {
if(status != InverterStatus::OFF) {
status = InverterStatus::OFF;
actPowerLimit = 0xffff; // power limit will be read once inverter becomes available
@@ -529,6 +538,10 @@ class Inverter {
rec->length = (uint8_t)(HMS4CH_LIST_LEN);
rec->assign = reinterpret_cast(const_cast(hms4chAssignment));
rec->pyldLen = HMS4CH_PAYLOAD_LEN;
+ } else if(IV_HMT == ivGen){
+ rec->length = (uint8_t)(HMT4CH_LIST_LEN);
+ rec->assign = reinterpret_cast(const_cast(hmt4chAssignment));
+ rec->pyldLen = HMT4CH_PAYLOAD_LEN;
}
channels = 4;
}
@@ -576,7 +589,7 @@ class Inverter {
}
}
- void resetAlarms() {
+ void resetAlarms(bool clearTs = false) {
lastAlarm.fill({0, 0, 0});
mAlarmNxtWrPos = 0;
alarmCnt = 0;
@@ -584,6 +597,11 @@ class Inverter {
memset(mOffYD, 0, sizeof(float) * 6);
memset(mLastYD, 0, sizeof(float) * 6);
+
+ if(clearTs) {
+ tsMaxAcPower = *Timestamp;
+ tsMaxTemperature = *Timestamp;
+ }
}
bool parseGetLossRate(const uint8_t pyld[], uint8_t len) {
@@ -816,8 +834,9 @@ class Inverter {
}
public:
- static uint32_t *timestamp; // system timestamp
- static cfgInst_t *generalConfig; // general inverter configuration from setup
+ static uint32_t *Timestamp; // system timestamp
+ static cfgInst_t *GeneralConfig; // general inverter configuration from setup
+ static IApp *App;
uint16_t mDtuRxCnt = 0;
uint16_t mDtuTxCnt = 0;
@@ -835,9 +854,11 @@ class Inverter {
};
template
-uint32_t *Inverter::timestamp {0};
+uint32_t *Inverter::Timestamp {0};
+template
+cfgInst_t *Inverter::GeneralConfig {0};
template
-cfgInst_t *Inverter::generalConfig {0};
+IApp *Inverter::App {nullptr};
/**
@@ -847,7 +868,7 @@ cfgInst_t *Inverter::generalConfig {0};
*/
template
-static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
+T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcYieldTotalCh0"));
if(NULL != iv) {
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
@@ -861,7 +882,7 @@ static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
}
template
-static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
+T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcYieldDayCh0"));
if(NULL != iv) {
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
@@ -875,7 +896,7 @@ static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
}
template
-static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
+T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcUdcCh"));
// arg0 = channel of source
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
@@ -889,7 +910,7 @@ static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
}
template
-static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
+T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcPowerDcCh0"));
if(NULL != iv) {
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
@@ -903,7 +924,7 @@ static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
}
template
-static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
+T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcEfficiencyCh0"));
if(NULL != iv) {
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
@@ -919,7 +940,7 @@ static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
}
template
-static T calcIrradiation(Inverter<> *iv, uint8_t arg0) {
+T calcIrradiation(Inverter<> *iv, uint8_t arg0) {
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcIrradiation"));
// arg0 = channel
if(NULL != iv) {
@@ -931,7 +952,7 @@ static T calcIrradiation(Inverter<> *iv, uint8_t arg0) {
}
template
-static T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0) {
+T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0) {
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcMaxPowerAcCh0"));
T acMaxPower = 0.0;
if(NULL != iv) {
@@ -944,7 +965,7 @@ static T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0) {
}
}
if(acPower > acMaxPower) {
- iv->tsMaxAcPower = *iv->timestamp;
+ iv->tsMaxAcPower = *iv->Timestamp;
return acPower;
}
}
@@ -952,7 +973,7 @@ static T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0) {
}
template
-static T calcMaxPowerDc(Inverter<> *iv, uint8_t arg0) {
+T calcMaxPowerDc(Inverter<> *iv, uint8_t arg0) {
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcMaxPowerDc"));
// arg0 = channel
T dcMaxPower = 0.0;
@@ -971,4 +992,22 @@ static T calcMaxPowerDc(Inverter<> *iv, uint8_t arg0) {
return dcMaxPower;
}
+template
+T calcMaxTemperature(Inverter<> *iv, uint8_t arg0) {
+ DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcMaxTemperature"));
+ // arg0 = channel
+ if(NULL != iv) {
+ record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
+ T temp = iv->getChannelFieldValue(arg0, FLD_T, rec);
+ T maxTemp = iv->getChannelFieldValue(arg0, FLD_MT, rec);
+
+ if(temp > maxTemp) {
+ iv->tsMaxTemperature = *iv->Timestamp;
+ return temp;
+ }
+ return maxTemp;
+ }
+ return 0;
+}
+
#endif /*__HM_INVERTER_H__*/
diff --git a/src/hm/hmSystem.h b/src/hm/hmSystem.h
index 3b43b9f0..81507105 100644
--- a/src/hm/hmSystem.h
+++ b/src/hm/hmSystem.h
@@ -16,8 +16,9 @@ class HmSystem {
HmSystem() {}
void setup(uint32_t *timestamp, cfgInst_t *config, IApp *app) {
- INVERTERTYPE::timestamp = timestamp;
- INVERTERTYPE::generalConfig = config;
+ INVERTERTYPE::Timestamp = timestamp;
+ INVERTERTYPE::GeneralConfig = config;
+ INVERTERTYPE::App = app;
//mInverter[0].app = app;
}
@@ -25,7 +26,7 @@ class HmSystem {
DPRINTLN(DBG_VERBOSE, F("hmSystem.h:addInverter"));
INVERTERTYPE *iv = &mInverter[id];
iv->id = id;
- iv->config = &mInverter[0].generalConfig->iv[id];
+ iv->config = &INVERTERTYPE::GeneralConfig->iv[id];
DPRINT(DBG_VERBOSE, "SERIAL: " + String(iv->config->serial.b[5], HEX));
DPRINTLN(DBG_VERBOSE, " " + String(iv->config->serial.b[4], HEX));
if((iv->config->serial.b[5] == 0x11) || (iv->config->serial.b[5] == 0x10)) {
@@ -68,11 +69,16 @@ class HmSystem {
iv->ivRadioType = INV_RADIO_TYPE_NRF;
}
} else if(iv->config->serial.b[5] == 0x13) {
- iv->ivGen = IV_HMT;
+ iv->ivGen = IV_HMT;
+ if(iv->config->serial.b[4] == 0x61)
+ iv->type = INV_TYPE_4CH;
+ else
iv->type = INV_TYPE_6CH;
- iv->ivRadioType = INV_RADIO_TYPE_CMT;
+
+ iv->ivRadioType = INV_RADIO_TYPE_CMT;
} else if(iv->config->serial.u64 != 0ULL) {
DPRINTLN(DBG_ERROR, F("inverter type can't be detected!"));
+ iv->config->enabled = false;
return;
} else
iv->ivGen = IV_UNKNOWN;
@@ -115,6 +121,8 @@ class HmSystem {
DPRINTLN(DBG_VERBOSE, F("hmSystem.h:getInverterByPos"));
if(pos >= MAX_INVERTER)
return nullptr;
+ else if(nullptr == mInverter[pos].config)
+ return nullptr;
else if((mInverter[pos].config->serial.u64 != 0ULL) || (false == check))
return &mInverter[pos];
else
diff --git a/src/hm/nrfHal.h b/src/hm/nrfHal.h
index 89fe0885..a838f8bc 100644
--- a/src/hm/nrfHal.h
+++ b/src/hm/nrfHal.h
@@ -9,7 +9,6 @@
#pragma once
#include "../utils/spiPatcher.h"
-
#include
#include
@@ -18,9 +17,7 @@
class nrfHal: public RF24_hal, public SpiPatcherHandle {
public:
- nrfHal() {
- mSpiPatcher = SpiPatcher::getInstance(SPI2_HOST);
- }
+ nrfHal() {}
void patch() override {
esp_rom_gpio_connect_out_signal(mPinMosi, spi_periph_signal[mHostDevice].spid_out, false, false);
@@ -42,7 +39,13 @@ class nrfHal: public RF24_hal, public SpiPatcherHandle {
mPinEn = static_cast(en);
mSpiSpeed = speed;
- mHostDevice = mSpiPatcher->getDevice();
+ #if defined(CONFIG_IDF_TARGET_ESP32S3)
+ mHostDevice = SPI2_HOST;
+ #else
+ mHostDevice = (14 == sclk) ? SPI2_HOST : SPI_HOST_OTHER;
+ #endif
+
+ mSpiPatcher = SpiPatcher::getInstance(mHostDevice);
gpio_reset_pin(mPinMosi);
gpio_set_direction(mPinMosi, GPIO_MODE_OUTPUT);
@@ -56,6 +59,7 @@ class nrfHal: public RF24_hal, public SpiPatcherHandle {
gpio_set_level(mPinClk, 0);
gpio_reset_pin(mPinCs);
+ request_spi();
spi_device_interface_config_t devcfg = {
.command_bits = 0,
.address_bits = 0,
@@ -72,14 +76,14 @@ class nrfHal: public RF24_hal, public SpiPatcherHandle {
.pre_cb = nullptr,
.post_cb = nullptr
};
- ESP_ERROR_CHECK(spi_bus_add_device(mHostDevice, &devcfg, &spi));
+ mSpiPatcher->addDevice(mHostDevice, &devcfg, &spi);
+ release_spi();
gpio_reset_pin(mPinEn);
gpio_set_direction(mPinEn, GPIO_MODE_OUTPUT);
gpio_set_level(mPinEn, 0);
}
-
bool begin() override {
return true;
}
diff --git a/src/hms/hmsRadio.h b/src/hms/CmtRadio.h
similarity index 91%
rename from src/hms/hmsRadio.h
rename to src/hms/CmtRadio.h
index 54975197..b6405329 100644
--- a/src/hms/hmsRadio.h
+++ b/src/hms/CmtRadio.h
@@ -7,7 +7,7 @@
#define __HMS_RADIO_H__
#include "cmt2300a.h"
-#include "../hm/radio.h"
+#include "../hm/Radio.h"
//#define CMT_SWITCH_CHANNEL_CYCLE 5
@@ -15,25 +15,34 @@ template
class CmtRadio : public Radio {
typedef Cmt2300a CmtType;
public:
- void setup(bool *serialDebug, bool *privacyMode, bool *printWholeTrace, uint8_t pinSclk, uint8_t pinSdio, uint8_t pinCsb, uint8_t pinFcsb, uint8_t region = 0, bool genDtuSn = true) {
- mCmt.setup(pinSclk, pinSdio, pinCsb, pinFcsb);
- reset(genDtuSn, static_cast(region));
+ void setup(bool *serialDebug, bool *privacyMode, bool *printWholeTrace, cfgCmt_t *cfg, uint8_t region = 0, bool genDtuSn = true) {
+ mCfg = cfg;
+
+ if(!cfg->enabled)
+ return;
+
mPrivacyMode = privacyMode;
mSerialDebug = serialDebug;
mPrintWholeTrace = printWholeTrace;
mTxBuf.fill(0);
+
+ mCmt.setup(cfg->pinSclk, cfg->pinSdio, cfg->pinCsb, cfg->pinFcsb);
+ reset(genDtuSn, static_cast(region));
}
- bool loop() override {
+ void loop() override {
+ if(!mCfg->enabled)
+ return;
+
mCmt.loop();
if((!mIrqRcvd) && (!mRqstGetRx))
- return false;
+ return;
getRx();
if(CmtStatus::SUCCESS == mCmt.goRx()) {
mIrqRcvd = false;
mRqstGetRx = false;
}
- return false;
+ return;
}
bool isChipConnected(void) const override {
@@ -41,6 +50,9 @@ class CmtRadio : public Radio {
}
void sendControlPacket(Inverter<> *iv, uint8_t cmd, uint16_t *data, bool isRetransmit) override {
+ if(!mCfg->enabled)
+ return;
+
DPRINT(DBG_INFO, F("sendControlPacket cmd: "));
DBGHEXLN(cmd);
initPacket(iv->radioId.u64, TX_REQ_DEVCONTROL, SINGLE_FRAME);
@@ -59,6 +71,9 @@ class CmtRadio : public Radio {
}
bool switchFrequency(Inverter<> *iv, uint32_t fromkHz, uint32_t tokHz) override {
+ if(!isChipConnected())
+ return false;
+
uint8_t fromCh = mCmt.freq2Chan(fromkHz);
uint8_t toCh = mCmt.freq2Chan(tokHz);
@@ -68,6 +83,8 @@ class CmtRadio : public Radio {
bool switchFrequencyCh(Inverter<> *iv, uint8_t fromCh, uint8_t toCh) override {
if((0xff == fromCh) || (0xff == toCh))
return false;
+ if(!isChipConnected())
+ return false;
mCmt.switchChannel(fromCh);
sendSwitchChCmd(iv, toCh);
@@ -188,6 +205,7 @@ class CmtRadio : public Radio {
}
CmtType mCmt;
+ cfgCmt_t *mCfg = nullptr;
bool mCmtAvail = false;
bool mRqstGetRx = false;
uint32_t mMillis = 0;
diff --git a/src/hms/cmt2300a.h b/src/hms/cmt2300a.h
index 23911b15..ed3aab54 100644
--- a/src/hms/cmt2300a.h
+++ b/src/hms/cmt2300a.h
@@ -6,7 +6,7 @@
#ifndef __CMT2300A_H__
#define __CMT2300A_H__
-#if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL)
+#if defined(SPI_HAL)
#include "cmtHal.h"
#else
#include "esp32_3wSpi.h"
@@ -545,7 +545,7 @@ class Cmt2300a {
}
private:
- #if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL)
+ #if defined(SPI_HAL)
cmtHal mSpi;
#else
esp32_3wSpi mSpi;
diff --git a/src/hms/cmtHal.h b/src/hms/cmtHal.h
index a4bec587..8556a043 100644
--- a/src/hms/cmtHal.h
+++ b/src/hms/cmtHal.h
@@ -16,9 +16,7 @@
class cmtHal : public SpiPatcherHandle {
public:
- cmtHal() {
- mSpiPatcher = SpiPatcher::getInstance(DEF_CMT_SPI_HOST);
- }
+ cmtHal() {}
void patch() override {
esp_rom_gpio_connect_out_signal(mPinSdio, spi_periph_signal[mHostDevice].spid_out, false, false);
@@ -39,7 +37,13 @@ class cmtHal : public SpiPatcherHandle {
mPinFcs = static_cast(fcs);
mSpiSpeed = speed;
- mHostDevice = mSpiPatcher->getDevice();
+ #if defined(CONFIG_IDF_TARGET_ESP32S3)
+ mHostDevice = SPI2_HOST;
+ #else
+ mHostDevice = (14 == clk) ? SPI2_HOST : SPI_HOST_OTHER;
+ #endif
+
+ mSpiPatcher = SpiPatcher::getInstance(mHostDevice);
gpio_reset_pin(mPinSdio);
gpio_set_direction(mPinSdio, GPIO_MODE_INPUT_OUTPUT);
@@ -50,6 +54,7 @@ class cmtHal : public SpiPatcherHandle {
gpio_set_level(mPinClk, 0);
gpio_reset_pin(mPinCs);
+ request_spi();
spi_device_interface_config_t devcfg_reg = {
.command_bits = 1,
.address_bits = 7,
@@ -66,7 +71,8 @@ class cmtHal : public SpiPatcherHandle {
.pre_cb = nullptr,
.post_cb = nullptr
};
- ESP_ERROR_CHECK(spi_bus_add_device(mHostDevice, &devcfg_reg, &spi_reg));
+ mSpiPatcher->addDevice(mHostDevice, &devcfg_reg, &spi_reg);
+ release_spi();
gpio_reset_pin(mPinFcs);
spi_device_interface_config_t devcfg_fifo = {
diff --git a/src/hms/hmsDefines.h b/src/hms/hmsDefines.h
index 61275dc1..07aec682 100644
--- a/src/hms/hmsDefines.h
+++ b/src/hms/hmsDefines.h
@@ -33,7 +33,8 @@ const byteAssign_t hms1chAssignment[] = {
{ FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC },
{ FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC },
{ FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC },
- { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC }
+ { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC },
+ { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC }
};
#define HMS1CH_LIST_LEN (sizeof(hms1chAssignment) / sizeof(byteAssign_t))
#define HMS1CH_PAYLOAD_LEN 30
@@ -70,7 +71,8 @@ const byteAssign_t hms2chAssignment[] = {
{ FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC },
{ FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC },
{ FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC },
- { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC }
+ { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC },
+ { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC }
};
#define HMS2CH_LIST_LEN (sizeof(hms2chAssignment) / sizeof(byteAssign_t))
#define HMS2CH_PAYLOAD_LEN 42
@@ -123,11 +125,73 @@ const byteAssign_t hms4chAssignment[] = {
{ FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC },
{ FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC },
{ FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC },
- { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC }
+ { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC },
+ { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC }
};
#define HMS4CH_LIST_LEN (sizeof(hms4chAssignment) / sizeof(byteAssign_t))
#define HMS4CH_PAYLOAD_LEN 66
+//-------------------------------------
+// HMT-1600, HMT-1800, HMT-2000
+//-------------------------------------
+const byteAssign_t hmt4chAssignment[] = {
+ { FLD_UDC, UNIT_V, CH1, 2, 2, 10 },
+ { FLD_IDC, UNIT_A, CH1, 4, 2, 100 },
+ { FLD_PDC, UNIT_W, CH1, 8, 2, 10 },
+ { FLD_YT, UNIT_KWH, CH1, 12, 4, 1000 },
+ { FLD_YD, UNIT_WH, CH1, 20, 2, 1 },
+ { FLD_IRR, UNIT_PCT, CH1, CALC_IRR_CH, CH1, CMD_CALC },
+ { FLD_MP, UNIT_W, CH1, CALC_MPDC_CH, CH1, CMD_CALC },
+
+ { FLD_UDC, UNIT_V, CH2, CALC_UDC_CH, CH1, CMD_CALC },
+ { FLD_IDC, UNIT_A, CH2, 6, 2, 100 },
+ { FLD_PDC, UNIT_W, CH2, 10, 2, 10 },
+ { FLD_YT, UNIT_KWH, CH2, 16, 4, 1000 },
+ { FLD_YD, UNIT_WH, CH2, 22, 2, 1 },
+ { FLD_IRR, UNIT_PCT, CH2, CALC_IRR_CH, CH2, CMD_CALC },
+ { FLD_MP, UNIT_W, CH2, CALC_MPDC_CH, CH2, CMD_CALC },
+
+ { FLD_UDC, UNIT_V, CH3, 24, 2, 10 },
+ { FLD_IDC, UNIT_A, CH3, 26, 2, 100 },
+ { FLD_PDC, UNIT_W, CH3, 30, 2, 10 },
+ { FLD_YT, UNIT_KWH, CH3, 34, 4, 1000 },
+ { FLD_YD, UNIT_WH, CH3, 42, 2, 1 },
+ { FLD_IRR, UNIT_PCT, CH3, CALC_IRR_CH, CH3, CMD_CALC },
+ { FLD_MP, UNIT_W, CH3, CALC_MPDC_CH, CH3, CMD_CALC },
+
+ { FLD_UDC, UNIT_V, CH4, CALC_UDC_CH, CH3, CMD_CALC },
+ { FLD_IDC, UNIT_A, CH4, 28, 2, 100 },
+ { FLD_PDC, UNIT_W, CH4, 32, 2, 10 },
+ { FLD_YT, UNIT_KWH, CH4, 38, 4, 1000 },
+ { FLD_YD, UNIT_WH, CH4, 44, 2, 1 },
+ { FLD_IRR, UNIT_PCT, CH4, CALC_IRR_CH, CH4, CMD_CALC },
+ { FLD_MP, UNIT_W, CH4, CALC_MPDC_CH, CH4, CMD_CALC },
+
+ { FLD_UAC_1N, UNIT_V, CH0, 68, 2, 10 },
+ { FLD_UAC_2N, UNIT_V, CH0, 70, 2, 10 },
+ { FLD_UAC_3N, UNIT_V, CH0, 72, 2, 10 },
+ { FLD_UAC_12, UNIT_V, CH0, 74, 2, 10 },
+ { FLD_UAC_23, UNIT_V, CH0, 76, 2, 10 },
+ { FLD_UAC_31, UNIT_V, CH0, 78, 2, 10 },
+ { FLD_F, UNIT_HZ, CH0, 80, 2, 100 },
+ { FLD_PAC, UNIT_W, CH0, 82, 2, 10 },
+ { FLD_Q, UNIT_VAR, CH0, 84, 2, 10 },
+ { FLD_IAC_1, UNIT_A, CH0, 86, 2, 100 },
+ { FLD_IAC_2, UNIT_A, CH0, 88, 2, 100 },
+ { FLD_IAC_3, UNIT_A, CH0, 90, 2, 100 },
+ { FLD_PF, UNIT_NONE, CH0, 92, 2, 1000 },
+ { FLD_T, UNIT_C, CH0, 94, 2, 10 },
+ { FLD_EVT, UNIT_NONE, CH0, 96, 2, 1 },
+ { FLD_YD, UNIT_WH, CH0, CALC_YD_CH0, 0, CMD_CALC },
+ { FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC },
+ { FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC },
+ { FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC },
+ { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC },
+ { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC }
+};
+#define HMT4CH_LIST_LEN (sizeof(hmt4chAssignment) / sizeof(byteAssign_t))
+#define HMT4CH_PAYLOAD_LEN 98
+
//-------------------------------------
// HMT-1800, HMT-2250
//-------------------------------------
@@ -199,7 +263,8 @@ const byteAssign_t hmt6chAssignment[] = {
{ FLD_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC },
{ FLD_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC },
{ FLD_EFF, UNIT_PCT, CH0, CALC_EFF_CH0, 0, CMD_CALC },
- { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC }
+ { FLD_MP, UNIT_W, CH0, CALC_MPAC_CH0, 0, CMD_CALC },
+ { FLD_MT, UNIT_C, CH0, CALC_MT_CH0, 0, CMD_CALC }
};
#define HMT6CH_LIST_LEN (sizeof(hmt6chAssignment) / sizeof(byteAssign_t))
#define HMT6CH_PAYLOAD_LEN 98
diff --git a/src/network/AhoyEthernet.h b/src/network/AhoyEthernet.h
index db624a41..90255b26 100644
--- a/src/network/AhoyEthernet.h
+++ b/src/network/AhoyEthernet.h
@@ -23,30 +23,20 @@ class AhoyEthernet : public AhoyNetwork {
mEthSpi.begin(mConfig->sys.eth.pinMiso, mConfig->sys.eth.pinMosi, mConfig->sys.eth.pinSclk, mConfig->sys.eth.pinCs, mConfig->sys.eth.pinIrq, mConfig->sys.eth.pinRst);
ETH.setHostname(mConfig->sys.deviceName);
-
- // static IP
- setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
- return ETH.config(ip, gateway, mask, dns1, dns2);
- });
}
- void tickNetworkLoop() override {
- if(mAp.isEnabled())
- mAp.tickLoop();
-
- switch(mStatus) {
- case NetworkState::DISCONNECTED:
- if(mConnected) {
- mConnected = false;
- mOnNetworkCB(false);
- mAp.enable();
+ void OnEvent(WiFiEvent_t event) override {
+ switch(event) {
+ case ARDUINO_EVENT_ETH_CONNECTED:
+ if(NetworkState::CONNECTED != mStatus) {
+ mStatus = NetworkState::CONNECTED;
+ DPRINTLN(DBG_INFO, F("Network connected"));
+ setStaticIp();
}
break;
- case NetworkState::CONNECTED:
- break;
-
- case NetworkState::GOT_IP:
+ case ARDUINO_EVENT_ETH_GOT_IP:
+ mStatus = NetworkState::GOT_IP;
if(!mConnected) {
mAp.disable();
mConnected = true;
@@ -55,13 +45,39 @@ class AhoyEthernet : public AhoyNetwork {
mOnNetworkCB(true);
}
break;
+
+ case ARDUINO_EVENT_ETH_STOP:
+ [[fallthrough]];
+ case ARDUINO_EVENT_ETH_DISCONNECTED:
+ mStatus = NetworkState::DISCONNECTED;
+ if(mConnected) {
+ mConnected = false;
+ mOnNetworkCB(false);
+ mAp.enable();
+ }
+ break;
+
+ default:
+ break;
}
}
+ void tickNetworkLoop() override {
+ if(mAp.isEnabled())
+ mAp.tickLoop();
+ }
+
String getIp(void) override {
return ETH.localIP().toString();
}
+ private:
+ void setStaticIp() override {
+ setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
+ return ETH.config(ip, gateway, mask, dns1, dns2);
+ });
+ }
+
private:
AhoyEthernetSpi mEthSpi;
};
diff --git a/src/network/AhoyEthernetSpi.h b/src/network/AhoyEthernetSpi.h
index b41431b4..ab2eab9e 100644
--- a/src/network/AhoyEthernetSpi.h
+++ b/src/network/AhoyEthernetSpi.h
@@ -12,7 +12,7 @@
#include
#include
#include
-#include
+#include "../utils/spiPatcher.h"
// Functions from WiFiGeneric
void tcpipInit();
@@ -44,23 +44,14 @@ class AhoyEthernetSpi {
gpio_reset_pin(static_cast(pin_int));
gpio_set_pull_mode(static_cast(pin_int), GPIO_PULLUP_ONLY);
+ #if defined(CONFIG_IDF_TARGET_ESP32S3)
+ mHostDevice = SPI3_HOST;
+ #else
+ mHostDevice = (14 == pin_sclk) ? SPI2_HOST : SPI3_HOST;
+ #endif
- spi_bus_config_t buscfg = {
- .mosi_io_num = pin_mosi,
- .miso_io_num = pin_miso,
- .sclk_io_num = pin_sclk,
- .quadwp_io_num = -1,
- .quadhd_io_num = -1,
- .data4_io_num = -1,
- .data5_io_num = -1,
- .data6_io_num = -1,
- .data7_io_num = -1,
- .max_transfer_sz = 0, // uses default value internally
- .flags = 0,
- .intr_flags = 0
- };
-
- ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));
+ mSpiPatcher = SpiPatcher::getInstance(mHostDevice, false);
+ mSpiPatcher->initBus(pin_mosi, pin_miso, pin_sclk, SPI_DMA_CH_AUTO);
spi_device_interface_config_t devcfg = {
.command_bits = 16, // actually address phase
@@ -79,8 +70,7 @@ class AhoyEthernetSpi {
.post_cb = nullptr
};
- spi_device_handle_t spi;
- ESP_ERROR_CHECK(spi_bus_add_device(SPI3_HOST, &devcfg, &spi));
+ mSpiPatcher->addDevice(mHostDevice, &devcfg, &spi);
// Reset sequence
if(-1 != pin_rst) {
@@ -137,6 +127,9 @@ class AhoyEthernetSpi {
private:
esp_eth_handle_t eth_handle;
esp_netif_t *eth_netif;
+ spi_host_device_t mHostDevice;
+ spi_device_handle_t spi;
+ SpiPatcher *mSpiPatcher;
};
#endif /*__ETH_SPI_H__*/
diff --git a/src/network/AhoyNetwork.h b/src/network/AhoyNetwork.h
index 55c5d193..7bc0bab2 100644
--- a/src/network/AhoyNetwork.h
+++ b/src/network/AhoyNetwork.h
@@ -28,7 +28,6 @@ class AhoyNetwork {
if('\0' == mConfig->sys.deviceName[0])
snprintf(mConfig->sys.deviceName, DEVNAME_LEN, "%s", DEF_DEVICE_NAME);
- WiFi.hostname(mConfig->sys.deviceName);
mAp.setup(&mConfig->sys);
@@ -90,14 +89,9 @@ class AhoyNetwork {
}
#if !defined(ETHERNET)
- bool getAvailNetworks(JsonObject obj) {
- JsonArray nets = obj.createNestedArray(F("networks"));
-
+ bool getAvailNetworks(JsonObject obj, IApp *app) {
if(!mScanActive) {
- mScanActive = true;
- if(NetworkState::GOT_IP != mStatus)
- WiFi.disconnect();
- WiFi.scanNetworks(true, true);
+ app->addOnce([this]() {scan();}, 1, "scan");
return false;
}
@@ -106,6 +100,7 @@ class AhoyNetwork {
return false;
if(n > 0) {
+ JsonArray nets = obj.createNestedArray(F("networks"));
int sort[n];
sortRSSI(&sort[0], n);
for (int i = 0; i < n; ++i) {
@@ -118,9 +113,20 @@ class AhoyNetwork {
return true;
}
+
+ void scan(void) {
+ mScanActive = true;
+ if(mWifiConnecting) {
+ mWifiConnecting = false;
+ WiFi.disconnect();
+ }
+ WiFi.scanNetworks(true, true);
+ }
#endif
protected:
+ virtual void setStaticIp() = 0;
+
void setupIp(std::function cb) {
if(mConfig->sys.ip.ip[0] != 0) {
IPAddress ip(mConfig->sys.ip.ip);
@@ -133,7 +139,7 @@ class AhoyNetwork {
}
}
- void OnEvent(WiFiEvent_t event) {
+ virtual void OnEvent(WiFiEvent_t event) {
switch(event) {
case SYSTEM_EVENT_STA_CONNECTED:
[[fallthrough]];
@@ -228,6 +234,9 @@ class AhoyNetwork {
uint32_t *mUtcTimestamp = nullptr;
bool mConnected = false;
bool mScanActive = false;
+ #if !defined(ETHERNET)
+ bool mWifiConnecting = false;
+ #endif
OnNetworkCB mOnNetworkCB;
OnTimeCB mOnTimeCB;
diff --git a/src/network/AhoyWifiAp.h b/src/network/AhoyWifiAp.h
index ce2bbd1b..669e8ec8 100644
--- a/src/network/AhoyWifiAp.h
+++ b/src/network/AhoyWifiAp.h
@@ -44,6 +44,7 @@ class AhoyWifiAp {
WiFi.softAPConfig(mIp, mIp, IPAddress(255, 255, 255, 0));
WiFi.softAP(WIFI_AP_SSID, mCfg->apPwd);
+ mDns.setErrorReplyCode(DNSReplyCode::NoError);
mDns.start(53, "*", mIp);
mEnabled = true;
@@ -62,6 +63,7 @@ class AhoyWifiAp {
#if defined(ETHERNET)
WiFi.mode(WIFI_OFF);
#else
+ WiFi.scanDelete();
WiFi.mode(WIFI_STA);
#endif
diff --git a/src/network/AhoyWifiEsp32.h b/src/network/AhoyWifiEsp32.h
index a3bbb9cf..89c9bbb4 100644
--- a/src/network/AhoyWifiEsp32.h
+++ b/src/network/AhoyWifiEsp32.h
@@ -17,40 +17,36 @@ class AhoyWifi : public AhoyNetwork {
void begin() override {
mAp.enable();
- // static IP
- setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
- return WiFi.config(ip, gateway, mask, dns1, dns2);
- });
+ if(String(FB_WIFI_SSID) == mConfig->sys.stationSsid)
+ return; // no station wifi defined
+ WiFi.disconnect(); // clean up
WiFi.setHostname(mConfig->sys.deviceName);
#if !defined(AP_ONLY)
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
+ setStaticIp();
WiFi.begin(mConfig->sys.stationSsid, mConfig->sys.stationPwd, WIFI_ALL_CHANNEL_SCAN);
+ mWifiConnecting = true;
DBGPRINT(F("connect to network '"));
DBGPRINT(mConfig->sys.stationSsid);
+ DBGPRINTLN(F("'"));
#endif
}
- void tickNetworkLoop() override {
- if(mAp.isEnabled())
- mAp.tickLoop();
-
- switch(mStatus) {
- case NetworkState::DISCONNECTED:
- if(mConnected) {
- mConnected = false;
- mOnNetworkCB(false);
- mAp.enable();
- MDNS.end();
+ void OnEvent(WiFiEvent_t event) override {
+ switch(event) {
+ case SYSTEM_EVENT_STA_CONNECTED:
+ if(NetworkState::CONNECTED != mStatus) {
+ mStatus = NetworkState::CONNECTED;
+ mWifiConnecting = false;
+ DPRINTLN(DBG_INFO, F("Network connected"));
}
break;
- case NetworkState::CONNECTED:
- break;
-
- case NetworkState::GOT_IP:
+ case SYSTEM_EVENT_STA_GOT_IP:
+ mStatus = NetworkState::GOT_IP;
if(mAp.isEnabled())
mAp.disable();
@@ -58,16 +54,44 @@ class AhoyWifi : public AhoyNetwork {
mConnected = true;
ah::welcome(WiFi.localIP().toString(), F("Station"));
MDNS.begin(mConfig->sys.deviceName);
- MDNS.addServiceTxt("http", "tcp", "path", "/");
mOnNetworkCB(true);
}
break;
+
+ case ARDUINO_EVENT_WIFI_STA_LOST_IP:
+ [[fallthrough]];
+ case ARDUINO_EVENT_WIFI_STA_STOP:
+ [[fallthrough]];
+ case SYSTEM_EVENT_STA_DISCONNECTED:
+ mStatus = NetworkState::DISCONNECTED;
+ if(mConnected) {
+ mConnected = false;
+ mOnNetworkCB(false);
+ MDNS.end();
+ begin();
+ }
+ break;
+
+ default:
+ break;
}
}
+ void tickNetworkLoop() override {
+ if(mAp.isEnabled())
+ mAp.tickLoop();
+ }
+
String getIp(void) override {
return WiFi.localIP().toString();
}
+
+ private:
+ void setStaticIp() override {
+ setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
+ return WiFi.config(ip, gateway, mask, dns1, dns2);
+ });
+ }
};
#endif /*ESP32 & !ETHERNET*/
diff --git a/src/network/AhoyWifiEsp8266.h b/src/network/AhoyWifiEsp8266.h
index 2497448b..b6ea65d2 100644
--- a/src/network/AhoyWifiEsp8266.h
+++ b/src/network/AhoyWifiEsp8266.h
@@ -18,11 +18,6 @@ class AhoyWifi : public AhoyNetwork {
void begin() override {
mAp.enable();
- // static IP
- setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
- return WiFi.config(ip, gateway, mask, dns1, dns2);
- });
-
WiFi.setHostname(mConfig->sys.deviceName);
mBSSIDList.clear();
}
@@ -37,6 +32,7 @@ class AhoyWifi : public AhoyNetwork {
case NetworkState::DISCONNECTED:
if(mConnected) {
mConnected = false;
+ mWifiConnecting = false;
mOnNetworkCB(false);
mAp.enable();
MDNS.end();
@@ -75,12 +71,15 @@ class AhoyWifi : public AhoyNetwork {
DBGPRINT(" " + String(bssid[j], HEX));
}
DBGPRINTLN("");
+ setStaticIp();
WiFi.begin(mConfig->sys.stationSsid, mConfig->sys.stationPwd, 0, &bssid[0]);
+ mWifiConnecting = true;
break;
case NetworkState::CONNECTING:
if (isTimeout(TIMEOUT)) {
WiFi.disconnect();
+ mWifiConnecting = false;
mStatus = mBSSIDList.empty() ? NetworkState::DISCONNECTED : NetworkState::SCAN_READY;
}
break;
@@ -117,6 +116,12 @@ class AhoyWifi : public AhoyNetwork {
}
private:
+ void setStaticIp() override {
+ setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
+ return WiFi.config(ip, gateway, mask, dns1, dns2);
+ });
+ }
+
bool getBSSIDs() {
bool result = false;
int n = WiFi.scanComplete();
diff --git a/src/platformio.ini b/src/platformio.ini
index 9d25a742..f041b798 100644
--- a/src/platformio.ini
+++ b/src/platformio.ini
@@ -23,7 +23,7 @@ extra_scripts =
pre:../scripts/convertHtml.py
pre:../scripts/applyPatches.py
pre:../scripts/reduceGxEPD2.py
- ;;post:../scripts/add_littlefs_binary.py
+ post:../scripts/add_littlefs_binary.py
lib_deps =
https://github.com/esphome/ESPAsyncWebServer @ ^3.2.2
@@ -155,7 +155,7 @@ monitor_filters =
platform = espressif32@6.6.0
board = lolin_d32
build_flags = ${env.build_flags}
- ;;-DSPI_HAL
+ -DSPI_HAL
monitor_filters =
esp32_exception_decoder
@@ -229,7 +229,7 @@ platform = espressif32@6.6.0
board = lolin_s2_mini
build_flags = ${env.build_flags}
-DUSE_HSPI_FOR_EPD
- ;;-DSPI_HAL
+ -DSPI_HAL
-DENABLE_MQTT
-DPLUGIN_DISPLAY
-DENABLE_HISTORY
@@ -262,7 +262,7 @@ platform = espressif32@6.6.0
board = lolin_c3_mini
build_flags = ${env.build_flags}
-DUSE_HSPI_FOR_EPD
- ;;-DSPI_HAL
+ -DSPI_HAL
-DENABLE_MQTT
-DPLUGIN_DISPLAY
-DENABLE_HISTORY
@@ -353,6 +353,7 @@ build_flags = ${env:opendtufusion-zero_export.build_flags}
[env:opendtufusion-ethernet]
platform = espressif32@6.6.0
+platform = espressif32@6.6.0
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
build_flags = ${env:opendtufusion-minimal.build_flags}
diff --git a/src/plugins/Display/Display.h b/src/plugins/Display/Display.h
index e263d667..0ce1522c 100644
--- a/src/plugins/Display/Display.h
+++ b/src/plugins/Display/Display.h
@@ -7,7 +7,7 @@
#include
#include "../../hm/hmSystem.h"
-#include "../../hm/hmRadio.h"
+#include "../../hm/NrfRadio.h"
#include "../../utils/helper.h"
#include "../plugin_lang.h"
#include "Display_Mono.h"
@@ -25,9 +25,9 @@ class Display {
mMono = NULL;
}
- void setup(IApp *app, display_t *cfg, HMSYSTEM *sys, RADIO *hmradio, RADIO *hmsradio, uint32_t *utcTs) {
+ void setup(IApp *app, display_t *cfg, HMSYSTEM *sys, RADIO *nrfRadio, RADIO *hmsradio, uint32_t *utcTs) {
mApp = app;
- mHmRadio = hmradio;
+ mNrfRadio = nrfRadio;
mHmsRadio = hmsradio;
mCfg = cfg;
mSys = sys;
@@ -149,7 +149,7 @@ class Display {
mDisplayData.totalYieldDay = totalYieldDay;
mDisplayData.totalYieldTotal = totalYieldTotal;
bool nrf_en = mApp->getNrfEnabled();
- bool nrf_ok = nrf_en && mHmRadio->isChipConnected();
+ bool nrf_ok = nrf_en && mNrfRadio->isChipConnected();
#if defined(ESP32)
bool cmt_en = mApp->getCmtEnabled();
bool cmt_ok = cmt_en && mHmsRadio->isChipConnected();
@@ -231,7 +231,7 @@ class Display {
uint32_t *mUtcTs = nullptr;
display_t *mCfg = nullptr;
HMSYSTEM *mSys = nullptr;
- RADIO *mHmRadio = nullptr;
+ RADIO *mNrfRadio = nullptr;
RADIO *mHmsRadio = nullptr;
uint16_t mRefreshCycle = 0;
diff --git a/src/plugins/Display/Display_ePaper.cpp b/src/plugins/Display/Display_ePaper.cpp
index 6d9d929e..86bb0d32 100644
--- a/src/plugins/Display/Display_ePaper.cpp
+++ b/src/plugins/Display/Display_ePaper.cpp
@@ -1,17 +1,12 @@
#include "Display_ePaper.h"
-#ifdef ESP8266
-#include
-#elif defined(ESP32)
+#if defined(ESP32)
#include
-#endif
#include "../../utils/helper.h"
#include "imagedata.h"
#include "defines.h"
#include "../plugin_lang.h"
-#if defined(ESP32)
-
static const uint32_t spiClk = 4000000; // 4 MHz
#if defined(ESP32) && defined(USE_HSPI_FOR_EPD)
@@ -34,13 +29,18 @@ void DisplayEPaper::init(uint8_t type, uint8_t _CS, uint8_t _DC, uint8_t _RST, u
if (DISP_TYPE_T10_EPAPER == type) {
Serial.begin(115200);
- _display = new GxEPD2_BW(GxEPD2_150_BN(_CS, _DC, _RST, _BUSY));
-#if defined(ESP32) && defined(USE_HSPI_FOR_EPD)
- hspi.begin(_SCK, _BUSY, _MOSI, _CS);
- _display->epd2.selectSPI(hspi, SPISettings(spiClk, MSBFIRST, SPI_MODE0));
-#elif defined(ESP32)
- _display->epd2.init(_SCK, _MOSI, 115200, true, 20, false);
+#if defined(SPI_HAL)
+ hal.init(_MOSI, _DC, _SCK, _CS, _RST, _BUSY);
+ _display = new GxEPD2_BW(GxEPD2_150_BN(&hal));
+#else
+ _display = new GxEPD2_BW(GxEPD2_150_BN(_CS, _DC, _RST, _BUSY));
+ #if defined(USE_HSPI_FOR_EPD)
+ hspi.begin(_SCK, _BUSY, _MOSI, _CS);
+ _display->epd2.selectSPI(hspi, SPISettings(spiClk, MSBFIRST, SPI_MODE0));
+ #elif defined(PLUGIN_DISPLAY)
+ _display->epd2.init(_SCK, _MOSI, 115200, true, 20, false);
+ #endif
#endif
_display->init(115200, true, 20, false);
_display->setRotation(mDisplayRotation);
diff --git a/src/plugins/Display/Display_ePaper.h b/src/plugins/Display/Display_ePaper.h
index c26d3b42..4fbb0959 100644
--- a/src/plugins/Display/Display_ePaper.h
+++ b/src/plugins/Display/Display_ePaper.h
@@ -12,7 +12,11 @@
#define EPAPER_MAX_TEXT_LEN 35
#include
+#if defined(SPI_HAL)
+#include "epdHal.h"
+#else
#include
+#endif
// FreeFonts from Adafruit_GFX
#include
@@ -60,6 +64,9 @@ class DisplayEPaper {
const char* _version;
RefreshStatus mRefreshState, mNextRefreshState;
uint8_t mSecondCnt;
+ #if defined(SPI_HAL)
+ epdHal hal;
+ #endif
};
#endif // ESP32
diff --git a/src/plugins/Display/epdHal.h b/src/plugins/Display/epdHal.h
new file mode 100644
index 00000000..1718b838
--- /dev/null
+++ b/src/plugins/Display/epdHal.h
@@ -0,0 +1,304 @@
+//-----------------------------------------------------------------------------
+// 2024 Ahoy, https://github.com/lumpapu/ahoy
+// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/4.0/deed
+//-----------------------------------------------------------------------------
+
+#ifndef __EPD_HAL_H__
+#define __EPD_HAL_H__
+
+#pragma once
+#include "../../utils/spiPatcher.h"
+#include
+#include
+
+
+#define EPD_DEFAULT_SPI_SPEED 4000000 // 4 MHz
+
+class epdHal: public GxEPD2_HalInterface, public SpiPatcherHandle {
+ public:
+ epdHal() {}
+
+ void patch() override {
+ esp_rom_gpio_connect_out_signal(mPinMosi, spi_periph_signal[mHostDevice].spid_out, false, false);
+ esp_rom_gpio_connect_in_signal(mPinBusy, spi_periph_signal[mHostDevice].spiq_in, false);
+ esp_rom_gpio_connect_out_signal(mPinClk, spi_periph_signal[mHostDevice].spiclk_out, false, false);
+ }
+
+ void unpatch() override {
+ esp_rom_gpio_connect_out_signal(mPinMosi, SIG_GPIO_OUT_IDX, false, false);
+ esp_rom_gpio_connect_in_signal(mPinBusy, GPIO_MATRIX_CONST_ZERO_INPUT, false);
+ esp_rom_gpio_connect_out_signal(mPinClk, SIG_GPIO_OUT_IDX, false, false);
+ }
+
+ void init(int8_t mosi, int8_t dc, int8_t sclk, int8_t cs, int8_t rst, int8_t busy, int32_t speed = EPD_DEFAULT_SPI_SPEED) {
+ mPinMosi = static_cast(mosi);
+ mPinDc = static_cast(dc);
+ mPinClk = static_cast(sclk);
+ mPinCs = static_cast(cs);
+ mPinRst = static_cast(rst);
+ mPinBusy = static_cast(busy);
+ mSpiSpeed = speed;
+
+ #if defined(CONFIG_IDF_TARGET_ESP32S3)
+ mHostDevice = SPI3_HOST;
+ #else
+ mHostDevice = (14 == sclk) ? SPI2_HOST : SPI_HOST_OTHER;
+ #endif
+
+ mSpiPatcher = SpiPatcher::getInstance(mHostDevice);
+
+ gpio_reset_pin(mPinMosi);
+ gpio_set_direction(mPinMosi, GPIO_MODE_OUTPUT);
+ gpio_set_level(mPinMosi, 1);
+
+ gpio_reset_pin(mPinClk);
+ gpio_set_direction(mPinClk, GPIO_MODE_OUTPUT);
+ gpio_set_level(mPinClk, 0);
+
+ gpio_reset_pin(mPinCs);
+ spi_device_interface_config_t devcfg = {
+ .command_bits = 0,
+ .address_bits = 0,
+ .dummy_bits = 0,
+ .mode = 0,
+ .duty_cycle_pos = 0,
+ .cs_ena_pretrans = 0,
+ .cs_ena_posttrans = 0,
+ .clock_speed_hz = mSpiSpeed,
+ .input_delay_ns = 0,
+ .spics_io_num = mPinCs,
+ .flags = 0,
+ .queue_size = 1,
+ .pre_cb = nullptr,
+ .post_cb = nullptr
+ };
+ mSpiPatcher->addDevice(mHostDevice, &devcfg, &spi);
+
+ if(GPIO_NUM_NC != mPinRst) {
+ gpio_reset_pin(mPinRst);
+ gpio_set_direction(mPinRst, GPIO_MODE_OUTPUT);
+ gpio_set_level(mPinRst, HIGH);
+ }
+
+ gpio_reset_pin(mPinDc);
+ gpio_set_direction(mPinDc, GPIO_MODE_OUTPUT);
+ gpio_set_level(mPinDc, HIGH);
+
+ //gpio_reset_pin(mPinBusy);
+ //gpio_set_direction(mPinBusy, GPIO_MODE_INPUT);
+ }
+
+ void rstMode(uint8_t mode) override {
+ if(GPIO_NUM_NC != mPinRst)
+ gpio_set_direction(mPinRst, static_cast(mode));
+ }
+
+ void rst(bool level) override {
+ if(GPIO_NUM_NC != mPinRst)
+ gpio_set_level(mPinRst, level);
+ }
+
+ int getBusy(void) override {
+ return gpio_get_level(mPinBusy);
+ }
+
+ bool isRst(void) override {
+ return (GPIO_NUM_NC != mPinRst);
+ }
+
+ void write(uint8_t buf) override {
+ uint8_t data[1];
+ data[0] = buf;
+ request_spi();
+
+ size_t spiLen = static_cast(1u) << 3;
+ spi_transaction_t t = {
+ .flags = 0,
+ .cmd = 0,
+ .addr = 0,
+ .length = spiLen,
+ .rxlength = spiLen,
+ .user = NULL,
+ .tx_buffer = data,
+ .rx_buffer = data
+ };
+ ESP_ERROR_CHECK(spi_device_polling_transmit(spi, &t));
+
+ release_spi();
+ }
+
+ void write(const uint8_t *buf, uint16_t n) override {
+ uint8_t data[n];
+ std::copy(&buf[0], &buf[n], &data[0]);
+
+ request_spi();
+
+ size_t spiLen = static_cast(n) << 3;
+ spi_transaction_t t = {
+ .flags = 0,
+ .cmd = 0,
+ .addr = 0,
+ .length = spiLen,
+ .rxlength = spiLen,
+ .user = NULL,
+ .tx_buffer = data,
+ .rx_buffer = data
+ };
+ ESP_ERROR_CHECK(spi_device_polling_transmit(spi, &t));
+
+ release_spi();
+ }
+
+ void write(const uint8_t *buf, uint16_t n, int16_t fill_with_zeroes) override {
+ uint8_t data[n + fill_with_zeroes];
+ memset(data, 0, (n + fill_with_zeroes));
+ for (uint16_t i = 0; i < n; i++) {
+ data[i] = pgm_read_byte(&*buf++);
+ }
+
+ request_spi();
+ spi_transaction_t t = {
+ .flags = SPI_TRANS_CS_KEEP_ACTIVE,
+ .cmd = 0,
+ .addr = 0,
+ .length = 1u,
+ .rxlength = 1u,
+ .user = NULL,
+ .tx_buffer = data,
+ .rx_buffer = data
+ };
+
+ size_t offs = 0;
+ spi_device_acquire_bus(spi, portMAX_DELAY);
+ while(offs < (n + fill_with_zeroes)) {
+ t.length = (64u << 3);
+ t.rxlength = t.length;
+ t.tx_buffer = &data[offs];
+ offs += 64;
+ ESP_ERROR_CHECK(spi_device_polling_transmit(spi, &t));
+ }
+ spi_device_release_bus(spi);
+
+ release_spi();
+ }
+
+ void writeCmd(const uint8_t val) override {
+ uint8_t data[1];
+ data[0] = val;
+
+ request_spi();
+ gpio_set_level(mPinDc, LOW);
+
+ size_t spiLen = static_cast(1u) << 3;
+ spi_transaction_t t = {
+ .flags = 0,
+ .cmd = 0,
+ .addr = 0,
+ .length = spiLen,
+ .rxlength = spiLen,
+ .user = NULL,
+ .tx_buffer = data,
+ .rx_buffer = data
+ };
+ ESP_ERROR_CHECK(spi_device_polling_transmit(spi, &t));
+ gpio_set_level(mPinDc, HIGH);
+
+ release_spi();
+ }
+
+ void writeCmd(const uint8_t *buf, uint8_t n, bool isPGM) override {
+ uint8_t data[n-1];
+ data[0] = (isPGM) ? pgm_read_byte(&*buf++) : buf[0];
+
+ request_spi();
+ gpio_set_level(mPinDc, LOW);
+ spi_device_acquire_bus(spi, portMAX_DELAY);
+
+ size_t spiLen = static_cast(1u) << 3;
+ spi_transaction_t t = {
+ .flags = SPI_TRANS_CS_KEEP_ACTIVE,
+ .cmd = 0,
+ .addr = 0,
+ .length = spiLen,
+ .rxlength = spiLen,
+ .user = NULL,
+ .tx_buffer = data,
+ .rx_buffer = data
+ };
+ ESP_ERROR_CHECK(spi_device_polling_transmit(spi, &t));
+ gpio_set_level(mPinDc, HIGH);
+
+ if(isPGM) {
+ for (uint16_t i = 0; i < n; i++) {
+ data[i] = pgm_read_byte(&*buf++);
+ }
+ } else
+ std::copy(&buf[1], &buf[n], &data[0]);
+
+ spiLen = static_cast(n-1) << 3;
+ spi_transaction_t t1 = {
+ .flags = SPI_TRANS_CS_KEEP_ACTIVE,
+ .cmd = 0,
+ .addr = 0,
+ .length = spiLen,
+ .rxlength = spiLen,
+ .user = NULL,
+ .tx_buffer = data,
+ .rx_buffer = data
+ };
+ ESP_ERROR_CHECK(spi_device_polling_transmit(spi, &t1));
+ spi_device_release_bus(spi);
+
+ release_spi();
+ }
+
+ void startTransfer(void) override {
+ request_spi();
+ }
+
+ void endTransfer(void) override {
+ release_spi();
+ }
+
+ void transfer(const uint8_t val) override {
+ uint8_t data[1];
+ data[0] = val;
+
+ size_t spiLen = static_cast(1u) << 3;
+ spi_transaction_t t = {
+ .flags = 0,
+ .cmd = 0,
+ .addr = 0,
+ .length = spiLen,
+ .rxlength = spiLen,
+ .user = NULL,
+ .tx_buffer = data,
+ .rx_buffer = data
+ };
+ ESP_ERROR_CHECK(spi_device_polling_transmit(spi, &t));
+ }
+
+ private:
+ inline void request_spi() {
+ mSpiPatcher->request(this);
+ }
+
+ inline void release_spi() {
+ mSpiPatcher->release();
+ }
+
+ private:
+ gpio_num_t mPinMosi = GPIO_NUM_NC;
+ gpio_num_t mPinDc = GPIO_NUM_NC;
+ gpio_num_t mPinClk = GPIO_NUM_NC;
+ gpio_num_t mPinCs = GPIO_NUM_NC;
+ gpio_num_t mPinRst = GPIO_NUM_NC;
+ gpio_num_t mPinBusy = GPIO_NUM_NC;
+ int32_t mSpiSpeed = EPD_DEFAULT_SPI_SPEED;
+
+ spi_host_device_t mHostDevice;
+ spi_device_handle_t spi;
+ SpiPatcher *mSpiPatcher;
+};
+
+#endif /*__EPD_HAL_H__*/
diff --git a/src/plugins/MaxPower.h b/src/plugins/MaxPower.h
new file mode 100644
index 00000000..a8db6909
--- /dev/null
+++ b/src/plugins/MaxPower.h
@@ -0,0 +1,67 @@
+//-----------------------------------------------------------------------------
+// 2024 Ahoy, https://github.com/lumpapu/ahoy
+// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/4.0/deed
+//-----------------------------------------------------------------------------
+
+#ifndef __MAX_VALUE__
+#define __MAX_VALUE__
+#pragma once
+
+#include
+#include
+#include "../hm/hmDefines.h"
+
+template
+class MaxPower {
+ public:
+ MaxPower() {
+ mTs = nullptr;
+ mMaxDiff = 60;
+ reset();
+ }
+
+ void setup(uint32_t *ts, uint16_t interval) {
+ mTs = ts;
+ mMaxDiff = interval * 4;
+ }
+
+ void reset(void) {
+ mValues.fill(std::make_pair(0, 0.0));
+ mLast = 0.0;
+ }
+
+ void payloadEvent(uint8_t cmd, Inverter<> *iv) {
+ if(RealTimeRunData_Debug != cmd)
+ return;
+
+ if(nullptr == iv)
+ return;
+
+ if(iv->id >= MAX_NUM_INVERTERS)
+ return;
+
+ record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
+ mValues[iv->id] = std::make_pair(*mTs, iv->getChannelFieldValue(CH0, FLD_PAC, rec));
+ }
+
+ T getTotalMaxPower(void) {
+ T val = 0;
+ for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
+ if((mValues[i].first + mMaxDiff) >= *mTs)
+ val += mValues[i].second;
+ else if(mValues[i].first > 0)
+ return mLast; // old data
+ }
+ if(val > mLast)
+ mLast = val;
+ return mLast;
+ }
+
+ private:
+ uint32_t *mTs;
+ uint32_t mMaxDiff;
+ float mLast;
+ std::array, MAX_NUM_INVERTERS> mValues;
+};
+
+#endif
diff --git a/src/plugins/history.h b/src/plugins/history.h
index 7d7be57c..bffbc6d5 100644
--- a/src/plugins/history.h
+++ b/src/plugins/history.h
@@ -57,17 +57,15 @@ class HistoryData {
void tickerSecond() {
float curPwr = 0;
- //float maxPwr = 0;
float yldDay = -0.1;
uint32_t ts = 0;
for (uint8_t i = 0; i < mSys->getNumInverters(); i++) {
Inverter<> *iv = mSys->getInverterByPos(i);
- record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
if (iv == NULL)
continue;
+ record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
curPwr += iv->getChannelFieldValue(CH0, FLD_PAC, rec);
- //maxPwr += iv->getChannelFieldValue(CH0, FLD_MP, rec);
yldDay += iv->getChannelFieldValue(CH0, FLD_YD, rec);
if (rec->ts > ts)
ts = rec->ts;
@@ -81,8 +79,6 @@ class HistoryData {
if (curPwr > mMaximumDay)
mMaximumDay = roundf(curPwr);
}
- //if (maxPwr > 0)
- // mMaximumDay = roundf(maxPwr);
}
if ((++mCurPwrDay.loopCnt % mCurPwrDay.refreshCycle) == 0) {
diff --git a/src/publisher/pubMqtt.h b/src/publisher/pubMqtt.h
index 6c038360..520cf0d5 100644
--- a/src/publisher/pubMqtt.h
+++ b/src/publisher/pubMqtt.h
@@ -63,7 +63,7 @@ class PubMqtt {
mUptime = uptime;
mIntervalTimeout = 1;
- SendIvData.setup(sys, utcTs, &mSendList);
+ SendIvData.setup(app, sys, cfg_mqtt, utcTs, &mSendList);
SendIvData.setPublishFunc([this](const char *subTopic, const char *payload, bool retained, uint8_t qos) {
publish(subTopic, payload, retained, true, qos);
});
@@ -206,6 +206,9 @@ class PubMqtt {
else
snprintf(mTopic.data(), mTopic.size(), "%s", subTopic);
+ if(!mCfgMqtt->enableRetain)
+ retained = false;
+
mClient.publish(mTopic.data(), qos, retained, payload);
yield();
mTxCnt++;
@@ -254,7 +257,8 @@ class PubMqtt {
void setPowerLimitAck(Inverter<> *iv) {
if (NULL != iv) {
snprintf(mSubTopic.data(), mSubTopic.size(), "%s/%s", iv->config->name, subtopics[MQTT_ACK_PWR_LMT]);
- publish(mSubTopic.data(), "true", true, true, QOS_2);
+ snprintf(mVal.data(), mVal.size(), "%.1f", iv->powerLimit[0]/10.0);
+ publish(mSubTopic.data(), mVal.data(), true, true, QOS_2);
}
}
@@ -457,7 +461,8 @@ class PubMqtt {
snprintf(topic.data(), topic.size(), "%s/sensor/%s/total_%s/config", MQTT_DISCOVERY_PREFIX, node_id.c_str(), fields[fldTotal[mDiscovery.sub]]);
size_t size = measureJson(doc2) + 1;
serializeJson(doc2, buf.data(), size);
- publish(topic.data(), buf.data(), true, false);
+ if(FLD_EVT != rec->assign[mDiscovery.sub].fieldId)
+ publish(topic.data(), buf.data(), true, false);
if(++mDiscovery.sub == ((!total) ? (rec->length) : 4)) {
mDiscovery.sub = 0;
@@ -577,6 +582,9 @@ class PubMqtt {
}
void sendData(Inverter<> *iv, uint8_t curInfoCmd) {
+ if (mCfgMqtt->json)
+ return;
+
record_t<> *rec = iv->getRecordStruct(curInfoCmd);
uint32_t lastTs = iv->getLastTs(rec);
@@ -620,6 +628,10 @@ class PubMqtt {
mLastAnyAvail = anyAvail;
}
+ private:
+ enum {MQTT_STATUS_OFFLINE = 0, MQTT_STATUS_PARTIAL, MQTT_STATUS_ONLINE};
+
+ private:
espMqttClient mClient;
cfgMqtt_t *mCfgMqtt = nullptr;
IApp *mApp;
diff --git a/src/publisher/pubMqttIvData.h b/src/publisher/pubMqttIvData.h
index cd212aa4..3f12afc6 100644
--- a/src/publisher/pubMqttIvData.h
+++ b/src/publisher/pubMqttIvData.h
@@ -24,8 +24,10 @@ class PubMqttIvData {
public:
PubMqttIvData() : mTotal{}, mSubTopic{}, mVal{} {}
- void setup(HMSYSTEM *sys, uint32_t *utcTs, std::queue *sendList) {
+ void setup(IApp *app, HMSYSTEM *sys, cfgMqtt_t *cfg_mqtt, uint32_t *utcTs, std::queue *sendList) {
+ mApp = app;
mSys = sys;
+ mCfg = cfg_mqtt;
mUtcTimestamp = utcTs;
mSendList = sendList;
mState = IDLE;
@@ -114,7 +116,7 @@ class PubMqttIvData {
mPublish(mSubTopic.data(), mVal.data(), true, QOS_0);
if((mIv->ivGen == IV_HMS) || (mIv->ivGen == IV_HMT)) {
- snprintf(mSubTopic.data(), mSubTopic.size(), "%s/ch0/rssi", mIv->config->name);
+ snprintf(mSubTopic.data(), mSubTopic.size(), "%s/rssi", mIv->config->name);
snprintf(mVal.data(), mVal.size(), "%d", mIv->rssi);
mPublish(mSubTopic.data(), mVal.data(), false, QOS_0);
}
@@ -168,9 +170,6 @@ class PubMqttIvData {
case FLD_PDC:
mTotal[3] += mIv->getValue(mPos, rec);
break;
- case FLD_MP:
- mTotal[4] += mIv->getValue(mPos, rec);
- break;
}
} else
mAllTotalFound = false;
@@ -195,18 +194,45 @@ class PubMqttIvData {
static_cast(mIv->getChannelFieldValue(CH0, FLD_GRID_PROFILE_CODE, rec)),
static_cast(mIv->getChannelFieldValue(CH0, FLD_GRID_PROFILE_VERSION, rec)));
} else {
- snprintf(mSubTopic.data(), mSubTopic.size(), "%s/ch%d/%s", mIv->config->name, rec->assign[mPos].ch, fields[rec->assign[mPos].fieldId]);
- snprintf(mVal.data(), mVal.size(), "%g", ah::round3(mIv->getValue(mPos, rec)));
+ if (!mCfg->json) {
+ snprintf(mSubTopic.data(), mSubTopic.size(), "%s/ch%d/%s", mIv->config->name, rec->assign[mPos].ch, fields[rec->assign[mPos].fieldId]);
+ snprintf(mVal.data(), mVal.size(), "%g", ah::round3(mIv->getValue(mPos, rec)));
+ }
}
- uint8_t qos = (FLD_ACT_ACTIVE_PWR_LIMIT == rec->assign[mPos].fieldId) ? QOS_2 : QOS_0;
- if((FLD_EVT != rec->assign[mPos].fieldId)
- && (FLD_LAST_ALARM_CODE != rec->assign[mPos].fieldId))
- mPublish(mSubTopic.data(), mVal.data(), retained, qos);
+ if ((InverterDevInform_All == mCmd) || (InverterDevInform_Simple == mCmd) || !mCfg->json) {
+ uint8_t qos = (FLD_ACT_ACTIVE_PWR_LIMIT == rec->assign[mPos].fieldId) ? QOS_2 : QOS_0;
+ if((FLD_EVT != rec->assign[mPos].fieldId)
+ && (FLD_LAST_ALARM_CODE != rec->assign[mPos].fieldId))
+ mPublish(mSubTopic.data(), mVal.data(), retained, qos);
+ }
}
mPos++;
} else {
if (MqttSentStatus::LAST_SUCCESS_SENT == rec->mqttSentStatus) {
+ if (mCfg->json && (RealTimeRunData_Debug == mCmd)) {
+ DynamicJsonDocument doc(300);
+
+ for (mPos = 0; mPos < rec->length; mPos++) {
+ doc[fields[rec->assign[mPos].fieldId]] = ah::round3(mIv->getValue(mPos, rec));
+
+ bool publish = false;
+ if (mPos != (rec->length - 1)) { // not last one
+ if (rec->assign[mPos].ch != rec->assign[mPos+1].ch)
+ publish = true;
+ } else
+ publish = true;
+
+ if (publish) {
+ // if next channel or end->publish
+ serializeJson(doc, mVal.data(), mVal.size());
+ snprintf(mSubTopic.data(), mSubTopic.size(), "%s/ch%d", mIv->config->name, rec->assign[mPos].ch);
+ mPublish(mSubTopic.data(), mVal.data(), false, QOS_0);
+ doc.clear();
+ }
+ }
+ }
+
sendRadioStat(rec->length);
rec->mqttSentStatus = MqttSentStatus::DATA_SENT;
}
@@ -261,19 +287,40 @@ class PubMqttIvData {
case 4:
fieldId = FLD_MP;
retained = false;
+ mTotal[4] = mApp->getTotalMaxPower();
break;
}
- snprintf(mSubTopic.data(), mSubTopic.size(), "total/%s", fields[fieldId]);
- snprintf(mVal.data(), mVal.size(), "%g", ah::round3(mTotal[mPos]));
- mPublish(mSubTopic.data(), mVal.data(), retained, QOS_0);
+ if (!mCfg->json) {
+ snprintf(mSubTopic.data(), mSubTopic.size(), "total/%s", fields[fieldId]);
+ snprintf(mVal.data(), mVal.size(), "%g", ah::round3(mTotal[mPos]));
+ mPublish(mSubTopic.data(), mVal.data(), retained, QOS_0);
+ }
mPos++;
} else {
+ if (mCfg->json) {
+ int type[5] = {FLD_PAC, FLD_YT, FLD_YD, FLD_PDC, FLD_MP};
+ snprintf(mVal.data(), mVal.size(), "{");
+
+ for (mPos = 0; mPos < 5; mPos++) {
+ snprintf(mSubTopic.data(), mSubTopic.size(), "\"%s\":%g", fields[type[mPos]], ah::round3(mTotal[mPos]));
+ strcat(mVal.data(), mSubTopic.data());
+ if (mPos < 4)
+ strcat(mVal.data(), ",");
+ else
+ strcat(mVal.data(), "}");
+ }
+ mPublish("total", mVal.data(), true, QOS_0);
+ }
mSendList->pop();
mSendTotals = false;
mState = IDLE;
}
}
+ private:
+ IApp *mApp = nullptr;
+ cfgMqtt_t *mCfg = nullptr;
+
HMSYSTEM *mSys = nullptr;
uint32_t *mUtcTimestamp = nullptr;
pubMqttPublisherType mPublish;
@@ -291,7 +338,7 @@ class PubMqttIvData {
bool mRTRDataHasBeenSent = false;
std::array mSubTopic;
- std::array mVal;
+ std::array mVal;
std::queue *mSendList = nullptr;
};
diff --git a/src/utils/dbg.h b/src/utils/dbg.h
index 9e754ba6..f6dd8012 100644
--- a/src/utils/dbg.h
+++ b/src/utils/dbg.h
@@ -110,7 +110,7 @@
#if DEBUG_LEVEL >= DBG_ERROR
#define PERR(str) DBGPRINT(F("E: ")); DBGPRINT(str);
- #define PERRLN(str) DBGPRINT(F("E: ")); DBGPRINTLN(str);
+ #define PERRLN(str) DBGPRINT(F("E: ")); DBGPRINTLN(str); DSERIAL.flush();
#else
#define PERR(str)
#define PERRLN(str)
diff --git a/src/utils/spiPatcher.cpp b/src/utils/spiPatcher.cpp
index 3b7b5681..b3d27482 100644
--- a/src/utils/spiPatcher.cpp
+++ b/src/utils/spiPatcher.cpp
@@ -5,5 +5,6 @@
#if defined(ESP32)
#include "spiPatcher.h"
-SpiPatcher *SpiPatcher::mInstance = nullptr;
+SpiPatcher *SpiPatcher::InstanceHost2 = nullptr;
+SpiPatcher *SpiPatcher::InstanceHost3 = nullptr;
#endif
diff --git a/src/utils/spiPatcher.h b/src/utils/spiPatcher.h
index 210b2a09..c8f0ba3c 100644
--- a/src/utils/spiPatcher.h
+++ b/src/utils/spiPatcher.h
@@ -9,23 +9,38 @@
#if defined(ESP32)
+#include "dbg.h"
#include "spiPatcherHandle.h"
#include
#include
+#if (SOC_SPI_PERIPH_NUM > 2)
+ #define SPI_HOST_OTHER SPI3_HOST
+#else
+ #define SPI_HOST_OTHER SPI2_HOST
+#endif
+
class SpiPatcher {
protected:
explicit SpiPatcher(spi_host_device_t dev) :
- mHostDevice(dev), mCurHandle(nullptr) {
+ mCurHandle(nullptr) {
// Use binary semaphore instead of mutex for performance reasons
mutex = xSemaphoreCreateBinaryStatic(&mutex_buffer);
xSemaphoreGive(mutex);
+ mDev = dev;
+ mBusState = ESP_FAIL;
+ }
- spi_bus_config_t buscfg = {
- .mosi_io_num = -1,
- .miso_io_num = -1,
- .sclk_io_num = -1,
+ public:
+ SpiPatcher(const SpiPatcher &other) = delete;
+ void operator=(const SpiPatcher &) = delete;
+
+ esp_err_t initBus(int mosi = -1, int miso = -1, int sclk = -1, spi_common_dma_t dmaType = SPI_DMA_DISABLED) {
+ mBusConfig = spi_bus_config_t {
+ .mosi_io_num = mosi,
+ .miso_io_num = miso,
+ .sclk_io_num = sclk,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.data4_io_num = -1,
@@ -36,26 +51,48 @@ class SpiPatcher {
.flags = 0,
.intr_flags = 0
};
- ESP_ERROR_CHECK(spi_bus_initialize(mHostDevice, &buscfg, SPI_DMA_DISABLED));
- }
+ ESP_ERROR_CHECK((mBusState = spi_bus_initialize(mDev, &mBusConfig, dmaType)));
- public:
- SpiPatcher(SpiPatcher &other) = delete;
- void operator=(const SpiPatcher &) = delete;
+ return mBusState;
+ }
- static SpiPatcher* getInstance(spi_host_device_t dev) {
- if(nullptr == mInstance)
- mInstance = new SpiPatcher(dev);
- return mInstance;
+ static SpiPatcher* getInstance(spi_host_device_t dev, bool initialize = true) {
+ if(SPI2_HOST == dev) {
+ if(nullptr == InstanceHost2) {
+ InstanceHost2 = new SpiPatcher(dev);
+ if(initialize)
+ InstanceHost2->initBus();
+ }
+ return InstanceHost2;
+ } else { // SPI3_HOST
+ if(nullptr == InstanceHost3) {
+ InstanceHost3 = new SpiPatcher(dev);
+ if(initialize)
+ InstanceHost3->initBus();
+ }
+ return InstanceHost3;
+ }
}
~SpiPatcher() { vSemaphoreDelete(mutex); }
- spi_host_device_t getDevice() {
- return mHostDevice;
+ inline void addDevice(spi_host_device_t host_id, const spi_device_interface_config_t *dev_config, spi_device_handle_t *handle) {
+ assert(mBusState == ESP_OK);
+ if(SPI2_HOST == host_id)
+ mHost2Cnt++;
+ #if (SOC_SPI_PERIPH_NUM > 2)
+ if(SPI3_HOST == host_id)
+ mHost3Cnt++;
+ #endif
+
+ if((mHost2Cnt > 3) || (mHost3Cnt > 3))
+ DPRINTLN(DBG_ERROR, F("maximum number of SPI devices reached (3)"));
+
+ ESP_ERROR_CHECK(spi_bus_add_device(host_id, dev_config, handle));
}
inline void request(SpiPatcherHandle* handle) {
+ assert(mBusState == ESP_OK);
xSemaphoreTake(mutex, portMAX_DELAY);
if (mCurHandle != handle) {
@@ -70,17 +107,22 @@ class SpiPatcher {
}
inline void release() {
+ assert(mBusState == ESP_OK);
xSemaphoreGive(mutex);
}
protected:
- static SpiPatcher *mInstance;
+ static SpiPatcher *InstanceHost2;
+ static SpiPatcher *InstanceHost3;
private:
- const spi_host_device_t mHostDevice;
SpiPatcherHandle* mCurHandle;
SemaphoreHandle_t mutex;
StaticSemaphore_t mutex_buffer;
+ uint8_t mHost2Cnt = 0, mHost3Cnt = 0;
+ spi_host_device_t mDev = SPI2_HOST;
+ esp_err_t mBusState = ESP_FAIL;
+ spi_bus_config_t mBusConfig;
};
#endif /*ESP32*/
diff --git a/src/web/Protection.h b/src/web/Protection.h
index 74f04b52..e41249ac 100644
--- a/src/web/Protection.h
+++ b/src/web/Protection.h
@@ -24,7 +24,7 @@ class Protection {
}
public:
- Protection(Protection &other) = delete;
+ Protection(const Protection &other) = delete;
void operator=(const Protection &) = delete;
static Protection* getInstance(const char *pwd) {
diff --git a/src/web/RestApi.h b/src/web/RestApi.h
index 37749779..fde72193 100644
--- a/src/web/RestApi.h
+++ b/src/web/RestApi.h
@@ -41,7 +41,7 @@ class RestApi {
mApp = app;
mSrv = srv;
mSys = sys;
- mRadioNrf = (HmRadio<>*)mApp->getRadioObj(true);
+ mRadioNrf = (NrfRadio<>*)mApp->getRadioObj(true);
#if defined(ESP32)
mRadioCmt = (CmtRadio<>*)mApp->getRadioObj(false);
#endif
@@ -56,6 +56,9 @@ class RestApi {
mSrv->on("/api", HTTP_GET, std::bind(&RestApi::onApi, this, std::placeholders::_1));
mSrv->on("/get_setup", HTTP_GET, std::bind(&RestApi::onDwnldSetup, this, std::placeholders::_1));
+ #if defined(ESP32)
+ mSrv->on("/coredump", HTTP_GET, std::bind(&RestApi::getCoreDump, this, std::placeholders::_1));
+ #endif
}
uint32_t getTimezoneOffset(void) {
@@ -104,9 +107,10 @@ class RestApi {
else if(path == "setup/getip") getIp(root);
#endif /* !defined(ETHERNET) */
else if(path == "live") getLive(request,root);
- else if (path == "powerHistory") getPowerHistory(request, root);
- else if (path == "powerHistoryDay") getPowerHistoryDay(request, root);
- else if (path == "yieldDayHistory") getYieldDayHistory(request, root);
+ #if defined(ENABLE_HISTORY)
+ else if (path == "powerHistory") getPowerHistory(request, root, HistoryStorageType::POWER);
+ else if (path == "powerHistoryDay") getPowerHistory(request, root, HistoryStorageType::POWER_DAY);
+ #endif /*ENABLE_HISTORY*/
else {
if(path.substring(0, 12) == "inverter/id/")
getInverter(root, request->url().substring(17).toInt());
@@ -299,7 +303,6 @@ class RestApi {
#if defined(ENABLE_HISTORY)
ep[F("powerHistory")] = url + F("powerHistory");
ep[F("powerHistoryDay")] = url + F("powerHistoryDay");
- ep[F("yieldDayHistory")] = url + F("yieldDayHistory");
#endif
}
@@ -349,6 +352,36 @@ class RestApi {
fp.close();
}
+ #if defined(ESP32)
+ void getCoreDump(AsyncWebServerRequest *request) {
+ const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_COREDUMP, "coredump");
+ if (partition != NULL) {
+ size_t size = partition->size;
+
+ AsyncWebServerResponse *response = request->beginResponse("application/octet-stream", size, [size, partition](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
+ if((index + maxLen) > size)
+ maxLen = size - index;
+
+ if (ESP_OK != esp_partition_read(partition, index, buffer, maxLen))
+ DPRINTLN(DBG_ERROR, F("can't read partition"));
+
+ return maxLen;
+ });
+
+ String filename = ah::getDateTimeStrFile(gTimezone.toLocal(mApp->getTimestamp()));
+ filename += "_v" + String(mApp->getVersion());
+ filename += "_" + String(ENV_NAME);
+
+ response->addHeader("Content-Description", "File Transfer");
+ response->addHeader("Content-Disposition", "attachment; filename=" + filename + "_coredump.bin");
+ request->send(response);
+ } else {
+ AsyncWebServerResponse *response = request->beginResponse(200, F("application/json; charset=utf-8"), "{}");
+ request->send(response);
+ }
+ }
+ #endif
+
void getGeneric(AsyncWebServerRequest *request, JsonObject obj) {
mApp->resetLockTimeout();
#if !defined(ETHERNET)
@@ -360,6 +393,7 @@ class RestApi {
obj[F("modules")] = String(mApp->getVersionModules());
obj[F("build")] = String(AUTO_GIT_HASH);
obj[F("env")] = String(ENV_NAME);
+ obj[F("host")] = mConfig->sys.deviceName;
obj[F("menu_prot")] = mApp->isProtected(request->client()->remoteIP().toString().c_str(), "", true);
obj[F("menu_mask")] = (uint16_t)(mConfig->sys.protectionMask );
obj[F("menu_protEn")] = (bool) (mConfig->sys.adminPwd[0] != '\0');
@@ -387,7 +421,6 @@ class RestApi {
obj[F("dark_mode")] = (bool)mConfig->sys.darkMode;
obj[F("sched_reboot")] = (bool)mConfig->sys.schedReboot;
- obj[F("hostname")] = mConfig->sys.deviceName;
obj[F("pwd_set")] = (strlen(mConfig->sys.adminPwd) > 0);
obj[F("prot_mask")] = mConfig->sys.protectionMask;
@@ -436,8 +469,13 @@ class RestApi {
void getHtmlSystem(AsyncWebServerRequest *request, JsonObject obj) {
getSysInfo(request, obj.createNestedObject(F("system")));
getGeneric(request, obj.createNestedObject(F("generic")));
+ #if defined(ESP32)
+ char tmp[300];
+ snprintf(tmp, 300, "%s
%s
%s", FACTORY_RESET, BTN_REBOOT, BTN_COREDUMP);
+ #else
char tmp[200];
snprintf(tmp, 200, "%s
%s", FACTORY_RESET, BTN_REBOOT);
+ #endif
obj[F("html")] = String(tmp);
}
@@ -490,7 +528,9 @@ class RestApi {
void getHtmlFactory(AsyncWebServerRequest *request, JsonObject obj) {
getGeneric(request, obj.createNestedObject(F("generic")));
- obj[F("html")] = F("Factory reset? yes no");
+ char tmp[200];
+ snprintf(tmp, 200, "%s %s %s", FACTORY_RESET, BTN_YES, BTN_NO);
+ obj[F("html")] = tmp;
}
void getHtmlFactoryTrue(AsyncWebServerRequest *request, JsonObject obj) {
@@ -573,12 +613,13 @@ class RestApi {
}
obj[F("interval")] = String(mConfig->inst.sendInterval);
obj[F("max_num_inverters")] = MAX_NUM_INVERTERS;
- obj[F("rstMid")] = (bool)mConfig->inst.rstYieldMidNight;
+ obj[F("rstMid")] = (bool)mConfig->inst.rstValsAtMidNight;
obj[F("rstNotAvail")] = (bool)mConfig->inst.rstValsNotAvail;
obj[F("rstComStop")] = (bool)mConfig->inst.rstValsCommStop;
+ obj[F("rstComStart")] = (bool)mConfig->inst.rstValsCommStart;
obj[F("strtWthtTm")] = (bool)mConfig->inst.startWithoutTime;
obj[F("rdGrid")] = (bool)mConfig->inst.readGrid;
- obj[F("rstMaxMid")] = (bool)mConfig->inst.rstMaxValsMidNight;
+ obj[F("rstMaxMid")] = (bool)mConfig->inst.rstIncludeMaxVals;
}
void getInverter(JsonObject obj, uint8_t id) {
@@ -603,6 +644,7 @@ class RestApi {
obj[F("alarm_cnt")] = iv->alarmCnt;
obj[F("rssi")] = iv->rssi;
obj[F("ts_max_ac_pwr")] = iv->tsMaxAcPower;
+ obj[F("ts_max_temp")] = iv->tsMaxTemperature;
JsonArray ch = obj.createNestedArray("ch");
@@ -710,7 +752,9 @@ class RestApi {
obj[F("user")] = String(mConfig->mqtt.user);
obj[F("pwd")] = (strlen(mConfig->mqtt.pwd) > 0) ? F("{PWD}") : String("");
obj[F("topic")] = String(mConfig->mqtt.topic);
+ obj[F("json")] = (bool) mConfig->mqtt.json;
obj[F("interval")] = String(mConfig->mqtt.interval);
+ obj[F("retain")] = (bool)mConfig->mqtt.enableRetain;
}
void getNtp(JsonObject obj) {
@@ -958,6 +1002,7 @@ class RestApi {
#if !defined(ETHERNET)
void getNetworks(JsonObject obj) {
obj[F("success")] = mApp->getAvailNetworks(obj);
+ obj[F("ip")] = mApp->getIp();
}
#endif /* !defined(ETHERNET) */
@@ -968,6 +1013,7 @@ class RestApi {
void getLive(AsyncWebServerRequest *request, JsonObject obj) {
getGeneric(request, obj.createNestedObject(F("generic")));
obj[F("refresh")] = mConfig->inst.sendInterval;
+ obj[F("max_total_pwr")] = ah::round3(mApp->getTotalMaxPower());
for (uint8_t fld = 0; fld < sizeof(acList); fld++) {
obj[F("ch0_fld_units")][fld] = String(units[fieldUnits[acList[fld]]]);
@@ -988,42 +1034,39 @@ class RestApi {
}
}
- void getPowerHistory(AsyncWebServerRequest *request, JsonObject obj) {
+ #if defined(ENABLE_HISTORY)
+ void getPowerHistory(AsyncWebServerRequest *request, JsonObject obj, HistoryStorageType type) {
getGeneric(request, obj.createNestedObject(F("generic")));
- #if defined(ENABLE_HISTORY)
- obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::POWER);
+ obj[F("refresh")] = mApp->getHistoryPeriod(static_cast(type));
+
uint16_t max = 0;
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
- uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::POWER, fld);
+ uint16_t value = mApp->getHistoryValue(static_cast(type), fld);
obj[F("value")][fld] = value;
if (value > max)
max = value;
}
obj[F("max")] = max;
- obj[F("lastValueTs")] = mApp->getHistoryLastValueTs((uint8_t)HistoryStorageType::POWER);
- #endif /*ENABLE_HISTORY*/
- }
- void getPowerHistoryDay(AsyncWebServerRequest *request, JsonObject obj){
- //getGeneric(request, obj.createNestedObject(F("generic")));
- #if defined(ENABLE_HISTORY)
- obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::POWER_DAY);
- uint16_t max = 0;
- for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
- uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::POWER_DAY, fld);
- obj[F("value")][fld] = value;
- if (value > max)
- max = value;
+ if(HistoryStorageType::POWER_DAY == type) {
+ float yldDay = 0;
+ for (uint8_t i = 0; i < mSys->getNumInverters(); i++) {
+ Inverter<> *iv = mSys->getInverterByPos(i);
+ if (iv == NULL)
+ continue;
+ record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
+ yldDay += iv->getChannelFieldValue(CH0, FLD_YD, rec);
+ }
+ obj[F("yld")] = ah::round3(yldDay / 1000.0);
}
- obj[F("max")] = max;
- obj[F("lastValueTs")] = mApp->getHistoryLastValueTs((uint8_t)HistoryStorageType::POWER_DAY);
- #endif /*ENABLE_HISTORY*/
+
+ obj[F("lastValueTs")] = mApp->getHistoryLastValueTs(static_cast(type));
}
+ #endif /*ENABLE_HISTORY*/
+ #if defined(ENABLE_HISTORY_YIELD_PER_DAY)
void getYieldDayHistory(AsyncWebServerRequest *request, JsonObject obj) {
- //getGeneric(request, obj.createNestedObject(F("generic")));
- #if defined(ENABLE_HISTORY) && defined(ENABLE_HISTORY_YIELD_PER_DAY)
obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::YIELD);
uint16_t max = 0;
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
@@ -1033,8 +1076,8 @@ class RestApi {
max = value;
}
obj[F("max")] = max;
- #endif /*ENABLE_HISTORY*/
}
+ #endif /*ENABLE_HISTORY_YIELD_PER_DAY*/
bool setCtrl(JsonObject jsonIn, JsonObject jsonOut, const char *clientIP) {
if(jsonIn.containsKey(F("auth"))) {
@@ -1076,8 +1119,6 @@ class RestApi {
iv->powerLimit[1] = AbsolutNonPersistent;
accepted = iv->setDevControlRequest(ActivePowerContr);
- if(accepted)
- mApp->triggerTickSend(iv->id);
} else if(F("dev") == jsonIn[F("cmd")]) {
DPRINTLN(DBG_INFO, F("dev cmd"));
iv->setDevCommand(jsonIn[F("val")].as());
@@ -1223,15 +1264,15 @@ class RestApi {
private:
constexpr static uint8_t acList[] = {FLD_UAC, FLD_IAC, FLD_PAC, FLD_F, FLD_PF, FLD_T, FLD_YT,
- FLD_YD, FLD_PDC, FLD_EFF, FLD_Q, FLD_MP};
+ FLD_YD, FLD_PDC, FLD_EFF, FLD_Q, FLD_MP, FLD_MT};
constexpr static uint8_t acListHmt[] = {FLD_UAC_1N, FLD_IAC_1, FLD_PAC, FLD_F, FLD_PF, FLD_T,
- FLD_YT, FLD_YD, FLD_PDC, FLD_EFF, FLD_Q, FLD_MP};
+ FLD_YT, FLD_YD, FLD_PDC, FLD_EFF, FLD_Q, FLD_MP, FLD_MT};
constexpr static uint8_t dcList[] = {FLD_UDC, FLD_IDC, FLD_PDC, FLD_YD, FLD_YT, FLD_IRR, FLD_MP};
private:
IApp *mApp = nullptr;
HMSYSTEM *mSys = nullptr;
- HmRadio<> *mRadioNrf = nullptr;
+ NrfRadio<> *mRadioNrf = nullptr;
#if defined(ESP32)
CmtRadio<> *mRadioCmt = nullptr;
#endif
diff --git a/src/web/html/about.html b/src/web/html/about.html
index c0eb8c5e..1b27ac9d 100644
--- a/src/web/html/about.html
+++ b/src/web/html/about.html
@@ -14,7 +14,7 @@
Used Libraries
-
+
diff --git a/src/web/html/api.js b/src/web/html/api.js
index 6c2ccec2..4930ce17 100644
--- a/src/web/html/api.js
+++ b/src/web/html/api.js
@@ -143,7 +143,7 @@ function parseVersion(obj) {
function parseESP(obj) {
document.getElementById("esp_type").replaceChildren(
- document.createTextNode("Board: " + obj["esp_type"])
+ document.createTextNode("Board: " + obj.esp_type)
);
}
@@ -153,7 +153,11 @@ function parseRssi(obj) {
icon = iconWifi1;
else if(obj["wifi_rssi"] <= -70)
icon = iconWifi2;
- document.getElementById("wifiicon").replaceChildren(svg(icon, 32, 32, "icon-fg2", obj["wifi_rssi"]));
+ document.getElementById("wifiicon").replaceChildren(svg(icon, 32, 32, "icon-fg2", obj.wifi_rssi));
+}
+
+function parseTitle(obj) {
+ document.title = obj.host + " - " + document.title
}
function toIsoDateStr(d) {
diff --git a/src/web/html/colorBright.css b/src/web/html/colorBright.css
index aedd05d4..ebf4f12a 100644
--- a/src/web/html/colorBright.css
+++ b/src/web/html/colorBright.css
@@ -12,6 +12,7 @@
--nav-bg: #333;
--primary: #006ec0;
+ --primary-disabled: #ccc;
--primary-hover: #044e86;
--secondary: #0072c8;
--nav-active: #555;
diff --git a/src/web/html/colorDark.css b/src/web/html/colorDark.css
index b5b1a72b..23e7a2cf 100644
--- a/src/web/html/colorDark.css
+++ b/src/web/html/colorDark.css
@@ -12,6 +12,7 @@
--nav-bg: #333;
--primary: #004d87;
+ --primary-disabled: #ccc;
--primary-hover: #023155;
--secondary: #0072c8;
--nav-active: #555;
diff --git a/src/web/html/history.html b/src/web/html/history.html
index d21e6b96..8b3b63c7 100644
--- a/src/web/html/history.html
+++ b/src/web/html/history.html
@@ -43,14 +43,10 @@
function calcScale(obj) {
let s = {}
s.x_mul = 60
- s.ts_start = obj.lastValueTs - (obj.refresh * obj.value.length)
- s.ts_dur = obj.lastValueTs - s.ts_start
- s.ts_pad = (s.ts_dur < 1800) ? s.ts_start % 300 : s.ts_start % 1800
- s.ts_dur -= s.ts_pad
+ s.ts_dur = obj.refresh * obj.value.length
+ s.ts_start = obj.lastValueTs - s.ts_dur
while(s.x_mul * 10 <= s.ts_dur)
s.x_mul += (s.x_mul == 60) ? 240 : ((s.x_mul < 1800) ? 300 : 1800)
- s.x_step = Math.ceil(s.ts_dur / s.x_mul)
- s.x_max = s.x_mul * s.x_step
s.y_mul = 10
while(s.y_mul * 10 <= obj.max)
@@ -79,7 +75,7 @@
...gridText(n*2, scale),
mlNs("g", {transform: "translate(30, 5)"}, [
...grid(n*2, scale),
- ...poly(obj, scale)
+ ...poly(n*2, obj, scale)
])
])
}
@@ -90,9 +86,9 @@
for(let i = 0; i <= scale.y_max; i += scale.y_mul) {
g.push(mlNs("text", {x: 0, y: height-(i*div)+9}, String(i)))
}
- div = x2 / scale.x_max
- for(let i = 0; i < scale.x_max; i++) {
- if((i + scale.ts_pad) % scale.x_mul == 0) {
+ div = x2 / scale.ts_dur
+ for(let i = 0; i < scale.ts_dur; i++) {
+ if((i + scale.ts_start) % scale.x_mul == 0) {
let d = new Date((scale.ts_start + i) * 1000)
g.push(mlNs("text", {x: (i*div)+17, y: height+20}, ("0"+d.getHours()).slice(-2) + ":" + ("0"+d.getMinutes()).slice(-2)))
}
@@ -106,16 +102,16 @@
for(let i = 0; i <= scale.y_max; i += scale.y_mul) {
g.push(mlNs("line", {x1: 0, x2: x2, y1: height-i*div, y2: height-i*div, "stroke-width": 1, "stroke-dasharray": "1,3", stroke: "#aaa"}))
}
- div = x2 / scale.x_max
- for(let i = 0; i <= scale.x_max; i++) {
- if((i + scale.ts_pad) % scale.x_mul == 0) {
+ div = x2 / scale.ts_dur
+ for(let i = 0; i <= scale.ts_dur; i++) {
+ if((i + scale.ts_start) % scale.x_mul == 0) {
g.push(mlNs("line", {x1: (i*div), x2: (i*div), y1: 0, y2: height, "stroke-width": 1, "stroke-dasharray": "1,3", stroke: "#aaa"}))
}
}
return g
}
- function poly(obj, scale) {
+ function poly(x2, obj, scale) {
let pts = ""
let i = 0, first = -1, last = -1, lastVal = 0
let div = scale.y_max / height
@@ -133,12 +129,17 @@
}
let pts2 = pts + " " + String(last) + "," + String(height)
pts2 += " " + String(first) + "," + String(height)
- return [
+ elm = [
mlNs("polyline", {stroke: "url(#gLine)", fill: "none", points: pts}),
mlNs("polyline", {stroke: "none", fill: "url(#gFill)", points: pts2}),
mlNs("text", {x: i*.8, y: 10}, "{#MAXIMUM}: " + String(obj.max) + "W"),
mlNs("text", {x: i*.8, y: 25}, "{#LAST_VALUE}: " + String(lastVal) + "W")
]
+
+ if(undefined !== obj.yld)
+ elm.push(mlNs("text", {x: i*.8, y: 40}, "{#YIELD_DAY}: " + String(obj.yld) + "kWh"))
+
+ return elm;
}
@@ -148,6 +149,7 @@
parseNav(obj.generic)
parseESP(obj.generic)
parseRssi(obj.generic)
+ parseTitle(obj.generic)
window.setInterval("getAjax('/api/powerHistory', parsePowerHistory)", obj.refresh * 1000)
setTimeout(() => {
window.setInterval("getAjax('/api/powerHistoryDay', parsePowerHistoryDay)", obj.refresh * 1000)
diff --git a/src/web/html/index.html b/src/web/html/index.html
index 954ee012..442160d4 100644
--- a/src/web/html/index.html
+++ b/src/web/html/index.html
@@ -14,6 +14,7 @@
System Infos:
+
@@ -23,9 +24,9 @@
{#SUPPORT}:
@@ -56,8 +57,10 @@
}
function parseGeneric(obj) {
- if(exeOnce)
+ if(exeOnce) {
parseESP(obj)
+ parseTitle(obj)
+ }
parseRssi(obj)
}
@@ -111,6 +114,8 @@
function parseIv(obj, ts) {
var p = div(["none"]);
+ var total = 0;
+ var count = 0;
for(var i of obj) {
var icon = iconSuccess;
var cl = "icon-success";
@@ -131,7 +136,9 @@
avail += "{#NOT_PRODUCING}";
else {
icon = iconSuccessFull;
- avail += "{#PRODUCING} " + i.cur_pwr + "W";
+ avail += "{#PRODUCING} " + i.cur_pwr + " W";
+ total += i.cur_pwr;
+ count += 1;
}
}
@@ -149,6 +156,13 @@
}
}
document.getElementById("iv").replaceChildren(p);
+
+ if (count > 1) {
+ var t = div(["none"]);
+ t.append(svg(iconInfo, 30, 30, "icon icon-info"), span("Total: " + Math.round(total).toLocaleString() + " W"), br());
+ document.getElementById("total").replaceChildren(t);
+ document.getElementById("total").appendChild(div(["hr"]));
+ }
}
function parseWarn(warn) {
@@ -165,7 +179,7 @@
p.append(svg(iconInfo, 30, 30, "icon icon-info"), span("{#UPDATE_AVAIL}: " + release), br());
else if(getVerInt("{#VERSION}") > getVerInt(release))
p.append(svg(iconInfo, 30, 30, "icon icon-info"), span("{#USING_DEV_VERSION} {#VERSION}. {#DEV_ISSUE_RELEASE_VERSION}: " + release), br());
- else
+ else
p.append(svg(iconInfo, 30, 30, "icon icon-info"), span("{#RELEASE_INSTALLED}: " + release), br());
}
diff --git a/src/web/html/serial.html b/src/web/html/serial.html
index 835f1766..39ba0ac2 100644
--- a/src/web/html/serial.html
+++ b/src/web/html/serial.html
@@ -40,10 +40,11 @@
+ ("0"+min).substr(-2) + ":"
+ ("0"+sec).substr(-2);
- parseRssi(obj);
+ parseRssi(obj)
if(true == exeOnce) {
- parseNav(obj);
- parseESP(obj);
+ parseNav(obj)
+ parseESP(obj)
+ parseTitle(obj)
window.setInterval("getAjax('/api/generic', parseGeneric)", 5000);
exeOnce = false;
setTimeOffset();
diff --git a/src/web/html/setup.html b/src/web/html/setup.html
index 2d625d4f..486cf284 100644
--- a/src/web/html/setup.html
+++ b/src/web/html/setup.html
@@ -52,14 +52,18 @@
-
{#INV_PAUSE_SUNSET}
+
{#INV_RESET_SUNRISE}
+
+
+
-
{#INV_RESET_MAX_MIDNIGHT}
+
{#INV_RESET_MAX_VALUES}
@@ -231,6 +240,10 @@
Topic
+
{#MQTT_NOTE}
{#INTERVAL}
@@ -243,6 +256,10 @@
+
@@ -279,7 +296,7 @@
{#DISP_PINOUT}
@@ -288,7 +305,7 @@
{#GRAPH_OPTIONS}
@@ -335,8 +352,8 @@
@@ -627,6 +644,22 @@
getAjax("/api/setup", apiCbMqtt, "POST", JSON.stringify(obj));
}
+ document.addEventListener('DOMContentLoaded', () => {
+ const fileInput = document.querySelector('#importFileInput');
+ const button = document.querySelector('#importButton');
+ button.disabled = true;
+ button.title = "Please select a file first";
+ fileInput.addEventListener('change', () => {
+ if (fileInput.value) {
+ button.disabled = false;
+ button.title = "";
+ } else {
+ button.disabled = true;
+ button.title = "Please select a file first";
+ }
+ });
+ });
+
function hide() {
document.getElementById("form").submit();
var e = document.getElementById("content");
@@ -668,16 +701,21 @@
function ivGlob(obj) {
for(var i of [["invInterval", "interval"]])
document.getElementsByName(i[0])[0].value = obj[i[1]];
- for(var i of ["Mid", "ComStop", "NotAvail", "MaxMid"])
+ for(var i of ["Mid", "ComStop", "ComStart", "NotAvail", "MaxMid"])
document.getElementsByName("invRst"+i)[0].checked = obj["rst" + i];
document.getElementsByName("strtWthtTm")[0].checked = obj["strtWthtTm"];
document.getElementsByName("rdGrid")[0].checked = obj["rdGrid"];
}
function parseSys(obj) {
+ /*IF_ETHERNET*/
+ for(var i of [["device", "device_name"], ["ap_pwd", "ap_pwd"]])
+ document.getElementsByName(i[0])[0].value = obj[i[1]];
+ /*ELSE*/
for(var i of [["device", "device_name"], ["ssid", "ssid"], ["ap_pwd", "ap_pwd"]])
document.getElementsByName(i[0])[0].value = obj[i[1]];
document.getElementsByName("hidd")[0].checked = obj["hidd"];
+ /*ENDIF_ETHERNET*/
document.getElementsByName("darkMode")[0].checked = obj["dark_mode"];
document.getElementsByName("schedReboot")[0].checked = obj["sched_reboot"];
e = document.getElementsByName("adminpwd")[0];
@@ -702,9 +740,10 @@
}
function parseGeneric(obj) {
- parseNav(obj);
- parseESP(obj);
- parseRssi(obj);
+ parseNav(obj)
+ parseESP(obj)
+ parseRssi(obj)
+ parseTitle(obj)
if(0 != obj.cst_lnk.length) {
document.getElementsByName("cstLnk")[0].value = obj.cst_lnk
@@ -935,6 +974,8 @@
function parseMqtt(obj) {
for(var i of [["Addr", "broker"], ["Port", "port"], ["ClientId", "clientId"], ["User", "user"], ["Pwd", "pwd"], ["Topic", "topic"], ["Interval", "interval"]])
document.getElementsByName("mqtt"+i[0])[0].value = obj[i[1]];
+ document.getElementsByName("mqttJson")[0].checked = obj["json"];
+ document.getElementsByName("retain")[0].checked = obj.retain
}
function parseNtp(obj) {
@@ -1859,18 +1900,6 @@
}
}
- function listNetworks(root) {
- var s = document.getElementById("networks");
- selDelAllOpt(s);
- if(root["networks"].length > 0) {
- s.appendChild(opt("-1", "{#NETWORK_PLEASE_SELECT}"));
- for(i = 0; i < root["networks"].length; i++) {
- s.appendChild(opt(root["networks"][i]["ssid"], root["networks"][i]["ssid"] + " (" + root["networks"][i]["rssi"] + " dBm)"));
- }
- } else
- s.appendChild(opt("-1", "{#NO_NETWORK_FOUND}"));
- }
-
getAjax("/api/setup", parse);