mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-02 03:36:22 +02:00
merge development03
This commit is contained in:
parent
1af142c46e
commit
aa9da851a1
67 changed files with 2607 additions and 967 deletions
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
patches/GxEPD2_HAL.patch eol=lf
|
33
.github/workflows/compile_development.yml
vendored
33
.github/workflows/compile_development.yml
vendored
|
@ -70,6 +70,11 @@ jobs:
|
||||||
- name: Run PlatformIO
|
- name: Run PlatformIO
|
||||||
run: pio run -d src -e ${{ matrix.variant }}
|
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
|
- name: Rename Firmware
|
||||||
run: python scripts/getVersion.py ${{ matrix.variant }} >> $GITHUB_OUTPUT
|
run: python scripts/getVersion.py ${{ matrix.variant }} >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
@ -132,6 +137,11 @@ jobs:
|
||||||
- name: Run PlatformIO
|
- name: Run PlatformIO
|
||||||
run: pio run -d src -e ${{ matrix.variant }}
|
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
|
- name: Rename Firmware
|
||||||
run: python scripts/getVersion.py ${{ matrix.variant }} >> $GITHUB_OUTPUT
|
run: python scripts/getVersion.py ${{ matrix.variant }} >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
@ -188,15 +198,6 @@ jobs:
|
||||||
with:
|
with:
|
||||||
name: dev-*
|
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
|
- name: Deploy
|
||||||
uses: nogsantos/scp-deploy@master
|
uses: nogsantos/scp-deploy@master
|
||||||
with:
|
with:
|
||||||
|
@ -206,3 +207,17 @@ jobs:
|
||||||
port: ${{ secrets.FW_SSH_PORT }}
|
port: ${{ secrets.FW_SSH_PORT }}
|
||||||
user: ${{ secrets.FW_SSH_USER }}
|
user: ${{ secrets.FW_SSH_USER }}
|
||||||
key: ${{ secrets.FW_SSH_KEY }}
|
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
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,6 +7,7 @@
|
||||||
src/config/config_override.h
|
src/config/config_override.h
|
||||||
src/web/html/h/*
|
src/web/html/h/*
|
||||||
src/web/html/tmp/*
|
src/web/html/tmp/*
|
||||||
|
src/data/*
|
||||||
/**/Debug
|
/**/Debug
|
||||||
/**/v16/*
|
/**/v16/*
|
||||||
*.db
|
*.db
|
||||||
|
|
56
manual/factory_firmware.md
Normal file
56
manual/factory_firmware.md
Normal file
|
@ -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
|
392
patches/GxEPD2_HAL.patch
Normal file
392
patches/GxEPD2_HAL.patch
Normal file
|
@ -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 <avr/pgmspace.h>
|
||||||
|
#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 <Arduino.h>
|
||||||
|
-#include <SPI.h>
|
||||||
|
|
||||||
|
#include <GxEPD2.h>
|
||||||
|
+#include <GxEPD2_Hal.h>
|
||||||
|
|
||||||
|
#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)
|
|
@ -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;
|
|
||||||
};
|
|
||||||
|
|
BIN
scripts/__pycache__/htmlPreprocessorDefines.cpython-311.pyc
Normal file
BIN
scripts/__pycache__/htmlPreprocessorDefines.cpython-311.pyc
Normal file
Binary file not shown.
79
scripts/add_littlefs_binary.py
Normal file
79
scripts/add_littlefs_binary.py
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
from SCons.Script import DefaultEnvironment
|
||||||
|
Import("env")
|
||||||
|
|
||||||
|
|
||||||
|
def build_littlefs():
|
||||||
|
if os.path.isfile('data/settings.json') == False:
|
||||||
|
return # nothing to do
|
||||||
|
|
||||||
|
result = subprocess.run(["pio", "run", "--target", "buildfs", "--environment", env['PIOENV']])
|
||||||
|
if result.returncode != 0:
|
||||||
|
print("Error building LittleFS:")
|
||||||
|
exit(1)
|
||||||
|
else:
|
||||||
|
print("LittleFS build successful")
|
||||||
|
|
||||||
|
def merge_bins():
|
||||||
|
if os.path.isfile('data/settings.json') == False:
|
||||||
|
return # nothing to do
|
||||||
|
|
||||||
|
BOOTLOADER_OFFSET = 0x0000
|
||||||
|
PARTITIONS_OFFSET = 0x8000
|
||||||
|
FIRMWARE_OFFSET = 0x10000
|
||||||
|
|
||||||
|
if env['PIOENV'][:13] == "esp32-wroom32":
|
||||||
|
BOOTLOADER_OFFSET = 0x1000
|
||||||
|
|
||||||
|
flash_size = int(env.BoardConfig().get("upload.maximum_size", "1310720")) # 0x140000
|
||||||
|
app0_offset = 0x10000
|
||||||
|
if env['PIOENV'][:7] == "esp8266":
|
||||||
|
app0_offset = 0
|
||||||
|
elif env['PIOENV'][:7] == "esp8285":
|
||||||
|
app0_offset = 0
|
||||||
|
|
||||||
|
littlefs_offset = 0x290000
|
||||||
|
if flash_size == 0x330000:
|
||||||
|
littlefs_offset = 0x670000
|
||||||
|
elif flash_size == 0x640000:
|
||||||
|
littlefs_offset = 0xc90000
|
||||||
|
|
||||||
|
# save current wd
|
||||||
|
start = os.getcwd()
|
||||||
|
os.chdir('.pio/build/' + env['PIOENV'] + '/')
|
||||||
|
|
||||||
|
with open("bootloader.bin", "rb") as bootloader_file:
|
||||||
|
bootloader_data = bootloader_file.read()
|
||||||
|
|
||||||
|
with open("partitions.bin", "rb") as partitions_file:
|
||||||
|
partitions_data = partitions_file.read()
|
||||||
|
|
||||||
|
with open("firmware.bin", "rb") as firmware_file:
|
||||||
|
firmware_data = firmware_file.read()
|
||||||
|
|
||||||
|
with open("littlefs.bin", "rb") as littlefs_file:
|
||||||
|
littlefs_data = littlefs_file.read()
|
||||||
|
|
||||||
|
with open("firmware.factory.bin", "wb") as merged_file:
|
||||||
|
merged_file.write(b'\xFF' * BOOTLOADER_OFFSET)
|
||||||
|
merged_file.write(bootloader_data)
|
||||||
|
|
||||||
|
merged_file.write(b'\xFF' * (PARTITIONS_OFFSET - (BOOTLOADER_OFFSET + len(bootloader_data))))
|
||||||
|
merged_file.write(partitions_data)
|
||||||
|
|
||||||
|
merged_file.write(b'\xFF' * (FIRMWARE_OFFSET - (PARTITIONS_OFFSET + len(partitions_data))))
|
||||||
|
merged_file.write(firmware_data)
|
||||||
|
|
||||||
|
merged_file.write(b'\xFF' * (littlefs_offset - (FIRMWARE_OFFSET + len(firmware_data))))
|
||||||
|
merged_file.write(littlefs_data)
|
||||||
|
|
||||||
|
os.chdir(start)
|
||||||
|
|
||||||
|
def main(target, source, env):
|
||||||
|
build_littlefs()
|
||||||
|
merge_bins()
|
||||||
|
|
||||||
|
# ensure that script is called once firmeware was compiled
|
||||||
|
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", main)
|
|
@ -28,8 +28,8 @@ def applyPatch(libName, patchFile):
|
||||||
# list of patches to apply (relative to /src)
|
# list of patches to apply (relative to /src)
|
||||||
applyPatch("ESPAsyncWebServer-esphome", "../patches/AsyncWeb_Prometheus.patch")
|
applyPatch("ESPAsyncWebServer-esphome", "../patches/AsyncWeb_Prometheus.patch")
|
||||||
|
|
||||||
if env['PIOENV'][:13] == "opendtufusion":
|
if (env['PIOENV'][:5] == "esp32") or (env['PIOENV'][:13] == "opendtufusion"):
|
||||||
applyPatch("GxEPD2", "../patches/GxEPD2_SW_SPI.patch")
|
applyPatch("GxEPD2", "../patches/GxEPD2_HAL.patch")
|
||||||
|
|
||||||
if (env['PIOENV'][:13] == "opendtufusion"): # or (env['PIOENV'][:13] == "esp32-wroom32"):
|
if (env['PIOENV'][:13] == "opendtufusion") or (env['PIOENV'][:5] == "esp32"):
|
||||||
applyPatch("RF24", "../patches/RF24_Hal.patch")
|
applyPatch("RF24", "../patches/RF24_Hal.patch")
|
||||||
|
|
|
@ -27,11 +27,22 @@ def getFlagsOfEnv(env):
|
||||||
elif len(flags[i]) > 0:
|
elif len(flags[i]) > 0:
|
||||||
build_flags = build_flags + [flags[i]]
|
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():
|
def get_build_flags():
|
||||||
getFlagsOfEnv("env:" + env['PIOENV'])
|
getFlagsOfEnv("env:" + env['PIOENV'])
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read('platformio.ini')
|
config.read('platformio.ini')
|
||||||
|
parseDefinesH()
|
||||||
|
|
||||||
# translate board
|
# translate board
|
||||||
board = config["env:" + env['PIOENV']]['board']
|
board = config["env:" + env['PIOENV']]['board']
|
||||||
|
|
|
@ -76,8 +76,9 @@ def renameFw(path_define, env):
|
||||||
fname = version[:-1] + "_" + sha + "_" + env + ".bin"
|
fname = version[:-1] + "_" + sha + "_" + env + ".bin"
|
||||||
|
|
||||||
os.rename("src/.pio/build/" + env + "/firmware.bin", dst + fname)
|
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 + "/bootloader.bin", dst + "bootloader.bin")
|
||||||
os.rename("src/.pio/build/" + env + "/partitions.bin", dst + "partitions.bin")
|
os.rename("src/.pio/build/" + env + "/partitions.bin", dst + "partitions.bin")
|
||||||
genOtaBin(dst)
|
genOtaBin(dst)
|
||||||
|
|
102
src/CHANGES.md
102
src/CHANGES.md
|
@ -1,5 +1,107 @@
|
||||||
# Development Changes
|
# 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
|
## 0.8.103 - 2024-04-02
|
||||||
* merge PR: fix: get refresh property from object #1552
|
* merge PR: fix: get refresh property from object #1552
|
||||||
* merge PR: fix typos and spelling in Github Issue template #1550
|
* merge PR: fix typos and spelling in Github Issue template #1550
|
||||||
|
|
138
src/app.cpp
138
src/app.cpp
|
@ -37,25 +37,16 @@ void app::setup() {
|
||||||
resetSystem();
|
resetSystem();
|
||||||
esp_task_wdt_reset();
|
esp_task_wdt_reset();
|
||||||
|
|
||||||
mSettings.setup();
|
mSettings.setup(mConfig);
|
||||||
mSettings.getPtr(mConfig);
|
|
||||||
ah::Scheduler::setup(mConfig->inst.startWithoutTime);
|
ah::Scheduler::setup(mConfig->inst.startWithoutTime);
|
||||||
DPRINT(DBG_INFO, F("Settings valid: "));
|
DPRINT(DBG_INFO, F("Settings valid: "));
|
||||||
DSERIAL.flush();
|
DBGPRINTLN(mConfig->valid ? F("true") : F("false"));
|
||||||
if (mSettings.getValid())
|
|
||||||
DBGPRINTLN(F("true"));
|
|
||||||
else
|
|
||||||
DBGPRINTLN(F("false"));
|
|
||||||
|
|
||||||
esp_task_wdt_reset();
|
esp_task_wdt_reset();
|
||||||
|
|
||||||
if(mConfig->nrf.enabled) {
|
mNrfRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, &mConfig->nrf);
|
||||||
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);
|
|
||||||
}
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
if(mConfig->cmt.enabled) {
|
mCmtRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, &mConfig->cmt, mConfig->sys.region);
|
||||||
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);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ETHERNET
|
#ifdef ETHERNET
|
||||||
|
@ -63,21 +54,21 @@ void app::setup() {
|
||||||
mNetwork = static_cast<AhoyNetwork*>(new AhoyEthernet());
|
mNetwork = static_cast<AhoyNetwork*>(new AhoyEthernet());
|
||||||
#else
|
#else
|
||||||
mNetwork = static_cast<AhoyNetwork*>(new AhoyWifi());
|
mNetwork = static_cast<AhoyNetwork*>(new AhoyWifi());
|
||||||
#endif // ETHERNET
|
#endif
|
||||||
mNetwork->setup(mConfig, &mTimestamp, [this](bool gotIp) { this->onNetwork(gotIp); }, [this](bool gotTime) { this->onNtpUpdate(gotTime); });
|
mNetwork->setup(mConfig, &mTimestamp, [this](bool gotIp) { this->onNetwork(gotIp); }, [this](bool gotTime) { this->onNtpUpdate(gotTime); });
|
||||||
mNetwork->begin();
|
mNetwork->begin();
|
||||||
|
|
||||||
esp_task_wdt_reset();
|
esp_task_wdt_reset();
|
||||||
|
|
||||||
mCommunication.setup(&mTimestamp, &mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace);
|
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)
|
#if defined(PLUGIN_ZEROEXPORT) || defined(ENABLE_MQTT)
|
||||||
mCommunication.addPowerLimitAckListener([this] (Inverter<> *iv) {
|
mCommunication.addPowerLimitAckListener([this] (Inverter<> *iv) {
|
||||||
#if defined(PLUGIN_ZEROEXPORT)
|
#if defined(PLUGIN_ZEROEXPORT)
|
||||||
mZeroExport.eventAckSetLimit(iv);
|
mZeroExport.eventAckSetLimit(iv);
|
||||||
#endif /*PLUGIN_ZEROEXPORT*/
|
#endif /*PLUGIN_ZEROEXPORT*/
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
mMqtt.setPowerLimitAck(iv);
|
mMqtt.setPowerLimitAck(iv);
|
||||||
#endif
|
#endif
|
||||||
});
|
});
|
||||||
#endif /*defined(PLUGIN_ZEROEXPORT) || defined(ENABLE_MQTT)*/
|
#endif /*defined(PLUGIN_ZEROEXPORT) || defined(ENABLE_MQTT)*/
|
||||||
|
@ -110,7 +101,6 @@ void app::setup() {
|
||||||
esp_task_wdt_reset();
|
esp_task_wdt_reset();
|
||||||
|
|
||||||
// when WiFi is in client mode, then enable mqtt broker
|
// when WiFi is in client mode, then enable mqtt broker
|
||||||
#if !defined(AP_ONLY)
|
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
mMqttEnabled = (mConfig->mqtt.broker[0] > 0);
|
mMqttEnabled = (mConfig->mqtt.broker[0] > 0);
|
||||||
if (mMqttEnabled) {
|
if (mMqttEnabled) {
|
||||||
|
@ -120,7 +110,6 @@ void app::setup() {
|
||||||
mCommunication.addAlarmListener([this](Inverter<> *iv) { mMqtt.alarmEvent(iv); });
|
mCommunication.addAlarmListener([this](Inverter<> *iv) { mMqtt.alarmEvent(iv); });
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
setupLed();
|
setupLed();
|
||||||
|
|
||||||
esp_task_wdt_reset();
|
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)
|
mDbgSyslog.setup(mConfig); // be sure to init after mWeb.setup (webSerial uses also debug callback)
|
||||||
#endif
|
#endif
|
||||||
// Plugins
|
// Plugins
|
||||||
|
mMaxPower.setup(&mTimestamp, mConfig->inst.sendInterval);
|
||||||
#if defined(PLUGIN_DISPLAY)
|
#if defined(PLUGIN_DISPLAY)
|
||||||
if (DISP_TYPE_T0_NONE != mConfig->plugin.display.type)
|
if (DISP_TYPE_T0_NONE != mConfig->plugin.display.type)
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
|
@ -162,9 +152,7 @@ void app::setup() {
|
||||||
|
|
||||||
#if defined(ENABLE_SIMULATOR)
|
#if defined(ENABLE_SIMULATOR)
|
||||||
mSimulator.setup(&mSys, &mTimestamp, 0);
|
mSimulator.setup(&mSys, &mTimestamp, 0);
|
||||||
mSimulator.addPayloadListener([this](uint8_t cmd, Inverter<> *iv) {
|
mSimulator.addPayloadListener([this](uint8_t cmd, Inverter<> *iv) { payloadEventListener(cmd, iv); });
|
||||||
payloadEventListener(cmd, iv);
|
|
||||||
});
|
|
||||||
#endif /*ENABLE_SIMULATOR*/
|
#endif /*ENABLE_SIMULATOR*/
|
||||||
|
|
||||||
esp_task_wdt_reset();
|
esp_task_wdt_reset();
|
||||||
|
@ -175,12 +163,10 @@ void app::setup() {
|
||||||
void app::loop(void) {
|
void app::loop(void) {
|
||||||
esp_task_wdt_reset();
|
esp_task_wdt_reset();
|
||||||
|
|
||||||
if(mConfig->nrf.enabled)
|
mNrfRadio.loop();
|
||||||
mNrfRadio.loop();
|
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
if(mConfig->cmt.enabled)
|
mCmtRadio.loop();
|
||||||
mCmtRadio.loop();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ah::Scheduler::loop();
|
ah::Scheduler::loop();
|
||||||
|
@ -205,12 +191,14 @@ void app::loop(void) {
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::onNetwork(bool gotIp) {
|
void app::onNetwork(bool gotIp) {
|
||||||
mNetworkConnected = gotIp;
|
mNetworkConnected = gotIp;
|
||||||
ah::Scheduler::resetTicker();
|
if(gotIp) {
|
||||||
regularTickers(); //reinstall regular tickers
|
ah::Scheduler::resetTicker();
|
||||||
every(std::bind(&app::tickSend, this), mConfig->inst.sendInterval, "tSend");
|
regularTickers(); //reinstall regular tickers
|
||||||
mMqttReconnect = true;
|
every(std::bind(&app::tickSend, this), mConfig->inst.sendInterval, "tSend");
|
||||||
mSunrise = 0; // needs to be set to 0, to reinstall sunrise and ivComm tickers!
|
mTickerInstallOnce = true;
|
||||||
once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2");
|
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]() { mProtection->tickSecond(); }, "prot");
|
||||||
everySec([this]() {mNetwork->tickNetworkLoop(); }, "net");
|
everySec([this]() {mNetwork->tickNetworkLoop(); }, "net");
|
||||||
|
|
||||||
|
if(mConfig->inst.startWithoutTime && !mNetworkConnected)
|
||||||
|
every(std::bind(&app::tickSend, this), mConfig->inst.sendInterval, "tSend");
|
||||||
|
|
||||||
// Plugins
|
// Plugins
|
||||||
#if defined(PLUGIN_DISPLAY)
|
#if defined(PLUGIN_DISPLAY)
|
||||||
if (DISP_TYPE_T0_NONE != mConfig->plugin.display.type)
|
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;
|
mCalculatedTimezoneOffset = (int8_t)((mConfig->sun.lon >= 0 ? mConfig->sun.lon + 7.5 : mConfig->sun.lon - 7.5) / 15) * 3600;
|
||||||
tickCalcSunrise();
|
tickCalcSunrise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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*/
|
||||||
|
|
||||||
|
if (mConfig->inst.rstValsNotAvail)
|
||||||
|
everyMin(std::bind(&app::tickMinute, this), "tMin");
|
||||||
|
|
||||||
|
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
|
||||||
|
onceAt(std::bind(&app::tickReboot, this), rebootTrig, "midRe");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::updateNtp(void) {
|
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*/
|
|
||||||
|
|
||||||
// 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 (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;
|
|
||||||
}
|
|
||||||
onceAt(std::bind(&app::tickReboot, this), rebootTrig, "midRe");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mNtpReceived)
|
if(mNtpReceived)
|
||||||
onNtpUpdate(true);
|
onNtpUpdate(true);
|
||||||
|
|
||||||
mMqttReconnect = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -302,8 +290,6 @@ void app::tickNtpUpdate(void) {
|
||||||
|
|
||||||
updateNtp();
|
updateNtp();
|
||||||
|
|
||||||
mMqttReconnect = false;
|
|
||||||
|
|
||||||
once(std::bind(&app::tickNtpUpdate, this), nxtTrig, "ntp");
|
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
|
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;
|
nxtTrig = 0;
|
||||||
} else { // current time lies within communication start/stop time, set next trigger to communication stop
|
} 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;
|
iv->commEnabled = true;
|
||||||
nxtTrig = mSunset + mConfig->sun.offsetSecEvening;
|
nxtTrig = mSunset + mConfig->sun.offsetSecEvening;
|
||||||
}
|
}
|
||||||
|
@ -417,18 +405,9 @@ void app::tickMidnight(void) {
|
||||||
// reset alarms
|
// reset alarms
|
||||||
if(InverterStatus::OFF == iv->getStatus())
|
if(InverterStatus::OFF == iv->getStatus())
|
||||||
iv->resetAlarms();
|
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);
|
zeroIvValues(!CHECK_AVAIL, !SKIP_YIELD_DAY);
|
||||||
|
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
|
@ -512,6 +491,9 @@ bool app::sendIv(Inverter<> *iv) {
|
||||||
void app:: zeroIvValues(bool checkAvail, bool skipYieldDay) {
|
void app:: zeroIvValues(bool checkAvail, bool skipYieldDay) {
|
||||||
Inverter<> *iv;
|
Inverter<> *iv;
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
|
mMaxPower.reset();
|
||||||
|
|
||||||
// set values to zero, except yields
|
// set values to zero, except yields
|
||||||
for (uint8_t id = 0; id < mSys.getNumInverters(); id++) {
|
for (uint8_t id = 0; id < mSys.getNumInverters(); id++) {
|
||||||
iv = mSys.getInverterByPos(id);
|
iv = mSys.getInverterByPos(id);
|
||||||
|
@ -542,18 +524,21 @@ void app:: zeroIvValues(bool checkAvail, bool skipYieldDay) {
|
||||||
pos = iv->getPosByChFld(ch, fld, rec);
|
pos = iv->getPosByChFld(ch, fld, rec);
|
||||||
iv->setValue(pos, rec, 0.0f);
|
iv->setValue(pos, rec, 0.0f);
|
||||||
}
|
}
|
||||||
// zero max power
|
// zero max power and max temperature
|
||||||
if(!skipYieldDay) {
|
if(mConfig->inst.rstIncludeMaxVals) {
|
||||||
pos = iv->getPosByChFld(ch, FLD_MP, rec);
|
pos = iv->getPosByChFld(ch, FLD_MP, rec);
|
||||||
iv->setValue(pos, rec, 0.0f);
|
iv->setValue(pos, rec, 0.0f);
|
||||||
}
|
pos = iv->getPosByChFld(ch, FLD_MT, rec);
|
||||||
iv->resetAlarms();
|
iv->setValue(pos, rec, 0.0f);
|
||||||
|
iv->resetAlarms(true);
|
||||||
|
} else
|
||||||
|
iv->resetAlarms();
|
||||||
iv->doCalculations();
|
iv->doCalculations();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(changed)
|
if(changed)
|
||||||
payloadEventListener(RealTimeRunData_Debug, NULL);
|
payloadEventListener(RealTimeRunData_Debug, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -618,6 +603,7 @@ void app::resetSystem(void) {
|
||||||
|
|
||||||
mNetworkConnected = false;
|
mNetworkConnected = false;
|
||||||
mNtpReceived = false;
|
mNtpReceived = false;
|
||||||
|
mTickerInstallOnce = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
39
src/app.h
39
src/app.h
|
@ -17,9 +17,9 @@
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "appInterface.h"
|
#include "appInterface.h"
|
||||||
#include "hm/hmSystem.h"
|
#include "hm/hmSystem.h"
|
||||||
#include "hm/hmRadio.h"
|
#include "hm/NrfRadio.h"
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
#include "hms/hmsRadio.h"
|
#include "hms/CmtRadio.h"
|
||||||
#endif
|
#endif
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
#include "publisher/pubMqtt.h"
|
#include "publisher/pubMqtt.h"
|
||||||
|
@ -31,6 +31,7 @@
|
||||||
#include "utils/syslog.h"
|
#include "utils/syslog.h"
|
||||||
#include "web/RestApi.h"
|
#include "web/RestApi.h"
|
||||||
#include "web/Protection.h"
|
#include "web/Protection.h"
|
||||||
|
#include "plugins/MaxPower.h"
|
||||||
#if defined(ENABLE_HISTORY)
|
#if defined(ENABLE_HISTORY)
|
||||||
#include "plugins/history.h"
|
#include "plugins/history.h"
|
||||||
#endif /*ENABLE_HISTORY*/
|
#endif /*ENABLE_HISTORY*/
|
||||||
|
@ -175,7 +176,7 @@ class app : public IApp, public ah::Scheduler {
|
||||||
|
|
||||||
#if !defined(ETHERNET)
|
#if !defined(ETHERNET)
|
||||||
bool getAvailNetworks(JsonObject obj) override {
|
bool getAvailNetworks(JsonObject obj) override {
|
||||||
return mNetwork->getAvailNetworks(obj);
|
return mNetwork->getAvailNetworks(obj, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupStation(void) override {
|
void setupStation(void) override {
|
||||||
|
@ -211,6 +212,10 @@ class app : public IApp, public ah::Scheduler {
|
||||||
return mVersionModules;
|
return mVersionModules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addOnce(ah::scdCb c, uint32_t timeout, const char *name) override {
|
||||||
|
once(c, timeout, name);
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t getSunrise() override {
|
uint32_t getSunrise() override {
|
||||||
return mSunrise;
|
return mSunrise;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +225,7 @@ class app : public IApp, public ah::Scheduler {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getSettingsValid() override {
|
bool getSettingsValid() override {
|
||||||
return mSettings.getValid();
|
return mConfig->valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getRebootRequestState() override {
|
bool getRebootRequestState() override {
|
||||||
|
@ -306,8 +311,14 @@ class app : public IApp, public ah::Scheduler {
|
||||||
DBGPRINTLN(String(newTime));
|
DBGPRINTLN(String(newTime));
|
||||||
if(0 == newTime)
|
if(0 == newTime)
|
||||||
mNetwork->updateNtpTime();
|
mNetwork->updateNtpTime();
|
||||||
else
|
else {
|
||||||
Scheduler::setTimestamp(newTime);
|
Scheduler::setTimestamp(newTime);
|
||||||
|
onNtpUpdate(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float getTotalMaxPower(void) override {
|
||||||
|
return mMaxPower.getTotalMaxPower();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t getHistoryValue(uint8_t type, uint16_t i) override {
|
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 zeroIvValues(bool checkAvail = false, bool skipYieldDay = true);
|
||||||
|
|
||||||
void payloadEventListener(uint8_t cmd, Inverter<> *iv) {
|
void payloadEventListener(uint8_t cmd, Inverter<> *iv) {
|
||||||
#if !defined(AP_ONLY)
|
mMaxPower.payloadEvent(cmd, iv);
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
if (mMqttEnabled)
|
if (mMqttEnabled)
|
||||||
mMqtt.payloadEventListener(cmd, iv);
|
mMqtt.payloadEventListener(cmd, iv);
|
||||||
#endif /*ENABLE_MQTT*/
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(PLUGIN_DISPLAY)
|
#if defined(PLUGIN_DISPLAY)
|
||||||
if(DISP_TYPE_T0_NONE != mConfig->plugin.display.type)
|
if(DISP_TYPE_T0_NONE != mConfig->plugin.display.type)
|
||||||
mDisplay.payloadEventListener(cmd);
|
mDisplay.payloadEventListener(cmd);
|
||||||
#endif
|
#endif
|
||||||
updateLed();
|
updateLed();
|
||||||
}
|
}
|
||||||
|
@ -417,7 +427,7 @@ class app : public IApp, public ah::Scheduler {
|
||||||
void notAvailChanged(void);
|
void notAvailChanged(void);
|
||||||
|
|
||||||
HmSystemType mSys;
|
HmSystemType mSys;
|
||||||
HmRadio<> mNrfRadio;
|
NrfRadio<> mNrfRadio;
|
||||||
Communication mCommunication;
|
Communication mCommunication;
|
||||||
|
|
||||||
bool mShowRebootRequest = false;
|
bool mShowRebootRequest = false;
|
||||||
|
@ -429,8 +439,7 @@ class app : public IApp, public ah::Scheduler {
|
||||||
#ifdef ENABLE_SYSLOG
|
#ifdef ENABLE_SYSLOG
|
||||||
DbgSyslog mDbgSyslog;
|
DbgSyslog mDbgSyslog;
|
||||||
#endif
|
#endif
|
||||||
//PayloadType mPayload;
|
|
||||||
//MiPayloadType mMiPayload;
|
|
||||||
PubSerialType mPubSerial;
|
PubSerialType mPubSerial;
|
||||||
#if !defined(ETHERNET)
|
#if !defined(ETHERNET)
|
||||||
//Improv mImprov;
|
//Improv mImprov;
|
||||||
|
@ -455,11 +464,10 @@ class app : public IApp, public ah::Scheduler {
|
||||||
|
|
||||||
bool mNetworkConnected = false;
|
bool mNetworkConnected = false;
|
||||||
|
|
||||||
// mqtt
|
|
||||||
#if defined(ENABLE_MQTT)
|
#if defined(ENABLE_MQTT)
|
||||||
PubMqttType mMqtt;
|
PubMqttType mMqtt;
|
||||||
#endif /*ENABLE_MQTT*/
|
#endif
|
||||||
bool mMqttReconnect = false;
|
bool mTickerInstallOnce = false;
|
||||||
bool mMqttEnabled = false;
|
bool mMqttEnabled = false;
|
||||||
|
|
||||||
// sun
|
// sun
|
||||||
|
@ -467,6 +475,7 @@ class app : public IApp, public ah::Scheduler {
|
||||||
uint32_t mSunrise = 0, mSunset = 0;
|
uint32_t mSunrise = 0, mSunset = 0;
|
||||||
|
|
||||||
// plugins
|
// plugins
|
||||||
|
MaxPower<float> mMaxPower;
|
||||||
#if defined(PLUGIN_DISPLAY)
|
#if defined(PLUGIN_DISPLAY)
|
||||||
DisplayType mDisplay;
|
DisplayType mDisplay;
|
||||||
DisplayData mDispData;
|
DisplayData mDispData;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "ESPAsyncWebServer.h"
|
#include "ESPAsyncWebServer.h"
|
||||||
|
#include "utils/scheduler.h"
|
||||||
|
|
||||||
// abstract interface to App. Make members of App accessible from child class
|
// abstract interface to App. Make members of App accessible from child class
|
||||||
// like web or API without forward declaration
|
// like web or API without forward declaration
|
||||||
|
@ -25,6 +26,8 @@ class IApp {
|
||||||
virtual const char *getVersion() = 0;
|
virtual const char *getVersion() = 0;
|
||||||
virtual const char *getVersionModules() = 0;
|
virtual const char *getVersionModules() = 0;
|
||||||
|
|
||||||
|
virtual void addOnce(ah::scdCb c, uint32_t timeout, const char *name) = 0;
|
||||||
|
|
||||||
#if !defined(ETHERNET)
|
#if !defined(ETHERNET)
|
||||||
virtual bool getAvailNetworks(JsonObject obj) = 0;
|
virtual bool getAvailNetworks(JsonObject obj) = 0;
|
||||||
virtual void setupStation(void) = 0;
|
virtual void setupStation(void) = 0;
|
||||||
|
@ -61,6 +64,7 @@ class IApp {
|
||||||
virtual void resetLockTimeout(void) = 0;
|
virtual void resetLockTimeout(void) = 0;
|
||||||
virtual bool isProtected(const char *clientIp, const char *token, bool askedFromWeb) const = 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 uint16_t getHistoryValue(uint8_t type, uint16_t i) = 0;
|
||||||
virtual uint32_t getHistoryPeriod(uint8_t type) = 0;
|
virtual uint32_t getHistoryPeriod(uint8_t type) = 0;
|
||||||
virtual uint16_t getHistoryMaxDay() = 0;
|
virtual uint16_t getHistoryMaxDay() = 0;
|
||||||
|
|
|
@ -28,6 +28,11 @@
|
||||||
|
|
||||||
// If the next line is uncommented, Ahoy will stay in access point mode all the time
|
// If the next line is uncommented, Ahoy will stay in access point mode all the time
|
||||||
//#define AP_ONLY
|
//#define AP_ONLY
|
||||||
|
#if defined(AP_ONLY)
|
||||||
|
#if defined(ENABLE_MQTT)
|
||||||
|
#undef ENABLE_MQTT
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
// timeout for automatic logoff (20 minutes)
|
// timeout for automatic logoff (20 minutes)
|
||||||
#define LOGOUT_TIMEOUT (20 * 60)
|
#define LOGOUT_TIMEOUT (20 * 60)
|
||||||
|
@ -145,7 +150,7 @@
|
||||||
#ifndef DEF_MOTION_SENSOR_PIN
|
#ifndef DEF_MOTION_SENSOR_PIN
|
||||||
#define DEF_MOTION_SENSOR_PIN DEF_PIN_OFF
|
#define DEF_MOTION_SENSOR_PIN DEF_PIN_OFF
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else // ESP8266
|
||||||
#ifndef DEF_NRF_CS_PIN
|
#ifndef DEF_NRF_CS_PIN
|
||||||
#define DEF_NRF_CS_PIN 15
|
#define DEF_NRF_CS_PIN 15
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
|
|
||||||
#define CONFIG_VERSION 11
|
#define CONFIG_VERSION 11
|
||||||
|
|
||||||
|
|
||||||
#define PROT_MASK_INDEX 0x0001
|
#define PROT_MASK_INDEX 0x0001
|
||||||
#define PROT_MASK_LIVE 0x0002
|
#define PROT_MASK_LIVE 0x0002
|
||||||
#define PROT_MASK_SERIAL 0x0004
|
#define PROT_MASK_SERIAL 0x0004
|
||||||
|
@ -55,6 +54,20 @@
|
||||||
#define DEF_PROT_MQTT 0x0000
|
#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 {
|
typedef struct {
|
||||||
uint8_t ip[4]; // ip address
|
uint8_t ip[4]; // ip address
|
||||||
uint8_t mask[4]; // sub mask
|
uint8_t mask[4]; // sub mask
|
||||||
|
@ -151,7 +164,9 @@ typedef struct {
|
||||||
char user[MQTT_USER_LEN];
|
char user[MQTT_USER_LEN];
|
||||||
char pwd[MQTT_PWD_LEN];
|
char pwd[MQTT_PWD_LEN];
|
||||||
char topic[MQTT_TOPIC_LEN];
|
char topic[MQTT_TOPIC_LEN];
|
||||||
|
bool json;
|
||||||
uint16_t interval;
|
uint16_t interval;
|
||||||
|
bool enableRetain;
|
||||||
} cfgMqtt_t;
|
} cfgMqtt_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -171,10 +186,11 @@ typedef struct {
|
||||||
cfgIv_t iv[MAX_NUM_INVERTERS];
|
cfgIv_t iv[MAX_NUM_INVERTERS];
|
||||||
|
|
||||||
uint16_t sendInterval;
|
uint16_t sendInterval;
|
||||||
bool rstYieldMidNight;
|
bool rstValsAtMidNight;
|
||||||
bool rstValsNotAvail;
|
bool rstValsNotAvail;
|
||||||
bool rstValsCommStop;
|
bool rstValsCommStop;
|
||||||
bool rstMaxValsMidNight;
|
bool rstValsCommStart;
|
||||||
|
bool rstIncludeMaxVals;
|
||||||
bool startWithoutTime;
|
bool startWithoutTime;
|
||||||
bool readGrid;
|
bool readGrid;
|
||||||
} cfgInst_t;
|
} cfgInst_t;
|
||||||
|
@ -369,8 +385,9 @@ class settings {
|
||||||
std::fill(reinterpret_cast<char*>(&mCfg), reinterpret_cast<char*>(&mCfg) + sizeof(mCfg), 0);
|
std::fill(reinterpret_cast<char*>(&mCfg), reinterpret_cast<char*>(&mCfg) + sizeof(mCfg), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup(settings_t *&c) {
|
||||||
DPRINTLN(DBG_INFO, F("Initializing FS .."));
|
DPRINTLN(DBG_INFO, F("Initializing FS .."));
|
||||||
|
c = &mCfg;
|
||||||
|
|
||||||
mCfg.valid = false;
|
mCfg.valid = false;
|
||||||
#if !defined(ESP32)
|
#if !defined(ESP32)
|
||||||
|
@ -406,14 +423,6 @@ class settings {
|
||||||
DPRINTLN(DBG_INFO, F("FS stopped"));
|
DPRINTLN(DBG_INFO, F("FS stopped"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void getPtr(settings_t *&cfg) {
|
|
||||||
cfg = &mCfg;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool getValid(void) {
|
|
||||||
return mCfg.valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool getLastSaveSucceed() {
|
inline bool getLastSaveSucceed() {
|
||||||
return mLastSaveSucceed;
|
return mLastSaveSucceed;
|
||||||
}
|
}
|
||||||
|
@ -622,14 +631,17 @@ class settings {
|
||||||
snprintf(mCfg.mqtt.pwd, MQTT_PWD_LEN, "%s", DEF_MQTT_PWD);
|
snprintf(mCfg.mqtt.pwd, MQTT_PWD_LEN, "%s", DEF_MQTT_PWD);
|
||||||
snprintf(mCfg.mqtt.topic, MQTT_TOPIC_LEN, "%s", DEF_MQTT_TOPIC);
|
snprintf(mCfg.mqtt.topic, MQTT_TOPIC_LEN, "%s", DEF_MQTT_TOPIC);
|
||||||
mCfg.mqtt.interval = 0; // off
|
mCfg.mqtt.interval = 0; // off
|
||||||
|
mCfg.mqtt.json = false; // off
|
||||||
|
mCfg.mqtt.enableRetain = true;
|
||||||
|
|
||||||
mCfg.inst.sendInterval = SEND_INTERVAL;
|
mCfg.inst.sendInterval = SEND_INTERVAL;
|
||||||
mCfg.inst.rstYieldMidNight = false;
|
mCfg.inst.rstValsAtMidNight = false;
|
||||||
mCfg.inst.rstValsNotAvail = false;
|
mCfg.inst.rstValsNotAvail = false;
|
||||||
mCfg.inst.rstValsCommStop = false;
|
mCfg.inst.rstValsCommStop = false;
|
||||||
mCfg.inst.startWithoutTime = false;
|
mCfg.inst.rstValsCommStart = false;
|
||||||
mCfg.inst.rstMaxValsMidNight = false;
|
mCfg.inst.startWithoutTime = false;
|
||||||
mCfg.inst.readGrid = true;
|
mCfg.inst.rstIncludeMaxVals = false;
|
||||||
|
mCfg.inst.readGrid = true;
|
||||||
|
|
||||||
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
|
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
|
||||||
mCfg.inst.iv[i].powerLevel = 0xff; // impossible high value
|
mCfg.inst.iv[i].powerLevel = 0xff; // impossible high value
|
||||||
|
@ -974,16 +986,20 @@ class settings {
|
||||||
obj[F("user")] = mCfg.mqtt.user;
|
obj[F("user")] = mCfg.mqtt.user;
|
||||||
obj[F("pwd")] = mCfg.mqtt.pwd;
|
obj[F("pwd")] = mCfg.mqtt.pwd;
|
||||||
obj[F("topic")] = mCfg.mqtt.topic;
|
obj[F("topic")] = mCfg.mqtt.topic;
|
||||||
|
obj[F("json")] = mCfg.mqtt.json;
|
||||||
obj[F("intvl")] = mCfg.mqtt.interval;
|
obj[F("intvl")] = mCfg.mqtt.interval;
|
||||||
|
obj[F("retain")] = mCfg.mqtt.enableRetain;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
getVal<uint16_t>(obj, F("port"), &mCfg.mqtt.port);
|
getVal<uint16_t>(obj, F("port"), &mCfg.mqtt.port);
|
||||||
getVal<uint16_t>(obj, F("intvl"), &mCfg.mqtt.interval);
|
getVal<uint16_t>(obj, F("intvl"), &mCfg.mqtt.interval);
|
||||||
|
getVal<bool>(obj, F("json"), &mCfg.mqtt.json);
|
||||||
getChar(obj, F("broker"), mCfg.mqtt.broker, MQTT_ADDR_LEN);
|
getChar(obj, F("broker"), mCfg.mqtt.broker, MQTT_ADDR_LEN);
|
||||||
getChar(obj, F("user"), mCfg.mqtt.user, MQTT_USER_LEN);
|
getChar(obj, F("user"), mCfg.mqtt.user, MQTT_USER_LEN);
|
||||||
getChar(obj, F("clientId"), mCfg.mqtt.clientId, MQTT_CLIENTID_LEN);
|
getChar(obj, F("clientId"), mCfg.mqtt.clientId, MQTT_CLIENTID_LEN);
|
||||||
getChar(obj, F("pwd"), mCfg.mqtt.pwd, MQTT_PWD_LEN);
|
getChar(obj, F("pwd"), mCfg.mqtt.pwd, MQTT_PWD_LEN);
|
||||||
getChar(obj, F("topic"), mCfg.mqtt.topic, MQTT_TOPIC_LEN);
|
getChar(obj, F("topic"), mCfg.mqtt.topic, MQTT_TOPIC_LEN);
|
||||||
|
getVal<bool>(obj, F("retain"), &mCfg.mqtt.enableRetain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1205,21 +1221,23 @@ class settings {
|
||||||
if(set) {
|
if(set) {
|
||||||
obj[F("intvl")] = mCfg.inst.sendInterval;
|
obj[F("intvl")] = mCfg.inst.sendInterval;
|
||||||
// obj[F("en")] = (bool)mCfg.inst.enabled;
|
// 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("rstNotAvail")] = (bool)mCfg.inst.rstValsNotAvail;
|
||||||
obj[F("rstComStop")] = (bool)mCfg.inst.rstValsCommStop;
|
obj[F("rstComStop")] = (bool)mCfg.inst.rstValsCommStop;
|
||||||
|
obj[F("rstComStart")] = (bool)mCfg.inst.rstValsCommStart;
|
||||||
obj[F("strtWthtTime")] = (bool)mCfg.inst.startWithoutTime;
|
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;
|
obj[F("rdGrid")] = (bool)mCfg.inst.readGrid;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getVal<uint16_t>(obj, F("intvl"), &mCfg.inst.sendInterval);
|
getVal<uint16_t>(obj, F("intvl"), &mCfg.inst.sendInterval);
|
||||||
// getVal<bool>(obj, F("en"), &mCfg.inst.enabled);
|
// getVal<bool>(obj, F("en"), &mCfg.inst.enabled);
|
||||||
getVal<bool>(obj, F("rstMidNight"), &mCfg.inst.rstYieldMidNight);
|
getVal<bool>(obj, F("rstMidNight"), &mCfg.inst.rstValsAtMidNight);
|
||||||
getVal<bool>(obj, F("rstNotAvail"), &mCfg.inst.rstValsNotAvail);
|
getVal<bool>(obj, F("rstNotAvail"), &mCfg.inst.rstValsNotAvail);
|
||||||
getVal<bool>(obj, F("rstComStop"), &mCfg.inst.rstValsCommStop);
|
getVal<bool>(obj, F("rstComStop"), &mCfg.inst.rstValsCommStop);
|
||||||
|
getVal<bool>(obj, F("rstComStart"), &mCfg.inst.rstValsCommStart);
|
||||||
getVal<bool>(obj, F("strtWthtTime"), &mCfg.inst.startWithoutTime);
|
getVal<bool>(obj, F("strtWthtTime"), &mCfg.inst.startWithoutTime);
|
||||||
getVal<bool>(obj, F("rstMaxMidNight"), &mCfg.inst.rstMaxValsMidNight);
|
getVal<bool>(obj, F("rstMaxMidNight"), &mCfg.inst.rstIncludeMaxVals);
|
||||||
getVal<bool>(obj, F("rdGrid"), &mCfg.inst.readGrid);
|
getVal<bool>(obj, F("rdGrid"), &mCfg.inst.readGrid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1294,6 +1312,7 @@ class settings {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
settings_t mCfg;
|
settings_t mCfg;
|
||||||
bool mLastSaveSucceed = 0;
|
bool mLastSaveSucceed = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 8
|
#define VERSION_MINOR 8
|
||||||
#define VERSION_PATCH 1030020
|
#define VERSION_PATCH 1230001
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t ch;
|
uint8_t ch;
|
||||||
|
@ -23,41 +23,6 @@ typedef struct {
|
||||||
uint16_t millis;
|
uint16_t millis;
|
||||||
} packet_t;
|
} 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 {
|
typedef enum {
|
||||||
AbsolutNonPersistent = 0UL, // 0x0000
|
AbsolutNonPersistent = 0UL, // 0x0000
|
||||||
RelativNonPersistent = 1UL, // 0x0001
|
RelativNonPersistent = 1UL, // 0x0001
|
||||||
|
@ -70,13 +35,6 @@ union serial_u {
|
||||||
uint8_t b[8];
|
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 {
|
enum {
|
||||||
DISP_TYPE_T0_NONE = 0,
|
DISP_TYPE_T0_NONE = 0,
|
||||||
DISP_TYPE_T1_SSD1306_128X64 = 1,
|
DISP_TYPE_T1_SSD1306_128X64 = 1,
|
||||||
|
@ -88,27 +46,6 @@ enum {
|
||||||
DISP_TYPE_T10_EPAPER = 10
|
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 {
|
typedef struct {
|
||||||
uint32_t rxFail;
|
uint32_t rxFail;
|
||||||
uint32_t rxFailNoAnswer;
|
uint32_t rxFailNoAnswer;
|
||||||
|
|
|
@ -19,13 +19,19 @@ template <uint8_t N=100>
|
||||||
class CommQueue {
|
class CommQueue {
|
||||||
public:
|
public:
|
||||||
void addImportant(Inverter<> *iv, uint8_t cmd) {
|
void addImportant(Inverter<> *iv, uint8_t cmd) {
|
||||||
dec(&mRdPtr);
|
queue_s q(iv, cmd, true);
|
||||||
mQueue[mRdPtr] = queue_s(iv, cmd, true);
|
if(!isIncluded(&q)) {
|
||||||
|
dec(&mRdPtr);
|
||||||
|
mQueue[mRdPtr] = q;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(Inverter<> *iv, uint8_t cmd) {
|
void add(Inverter<> *iv, uint8_t cmd) {
|
||||||
mQueue[mWrPtr] = queue_s(iv, cmd, false);
|
queue_s q(iv, cmd, false);
|
||||||
inc(&mWrPtr);
|
if(!isIncluded(&q)) {
|
||||||
|
mQueue[mWrPtr] = q;
|
||||||
|
inc(&mWrPtr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void chgCmd(Inverter<> *iv, uint8_t cmd) {
|
void chgCmd(Inverter<> *iv, uint8_t cmd) {
|
||||||
|
@ -117,6 +123,19 @@ class CommQueue {
|
||||||
--(*ptr);
|
--(*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:
|
protected:
|
||||||
std::array<queue_s, N> mQueue;
|
std::array<queue_s, N> mQueue;
|
||||||
uint8_t mWrPtr = 0;
|
uint8_t mWrPtr = 0;
|
||||||
|
|
|
@ -174,8 +174,6 @@ class Communication : public CommQueue<> {
|
||||||
mFirstTry = false;
|
mFirstTry = false;
|
||||||
mHeu.evalTxChQuality(q->iv, false, 0, 0);
|
mHeu.evalTxChQuality(q->iv, false, 0, 0);
|
||||||
mHeu.getTxCh(q->iv);
|
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->radioStatistics.retransmits++;
|
||||||
q->iv->radio->mRadioWaitTime.stopTimeMonitor();
|
q->iv->radio->mRadioWaitTime.stopTimeMonitor();
|
||||||
mState = States::START;
|
mState = States::START;
|
||||||
|
@ -927,7 +925,7 @@ class Communication : public CommQueue<> {
|
||||||
uint8_t oldState = rec->record[q->iv->getPosByChFld(0, FLD_EVT, rec)];
|
uint8_t oldState = rec->record[q->iv->getPosByChFld(0, FLD_EVT, rec)];
|
||||||
if ( prntsts != oldState ) { // sth.'s changed?
|
if ( prntsts != oldState ) { // sth.'s changed?
|
||||||
stsok = false;
|
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;
|
changedStatus = true;
|
||||||
q->iv->alarmCnt = 1; // minimum...
|
q->iv->alarmCnt = 1; // minimum...
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -8,9 +8,10 @@
|
||||||
|
|
||||||
#include <RF24.h>
|
#include <RF24.h>
|
||||||
#include "SPI.h"
|
#include "SPI.h"
|
||||||
#include "radio.h"
|
#include "Radio.h"
|
||||||
#include "../config/config.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"
|
#include "nrfHal.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -28,24 +29,30 @@ const char* const rf24AmpPowerNames[] = {"MIN", "LOW", "HIGH", "MAX"};
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// HM Radio class
|
// HM Radio class
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template <uint8_t IRQ_PIN = DEF_NRF_IRQ_PIN, uint8_t CE_PIN = DEF_NRF_CE_PIN, uint8_t CS_PIN = DEF_NRF_CS_PIN, uint8_t AMP_PWR = RF24_PA_LOW, uint8_t SCLK_PIN = DEF_NRF_SCLK_PIN, uint8_t MOSI_PIN = DEF_NRF_MOSI_PIN, uint8_t MISO_PIN = DEF_NRF_MISO_PIN, uint32_t DTU_SN = 0x81001765>
|
template <uint32_t DTU_SN = 0x81001765>
|
||||||
class HmRadio : public Radio {
|
class NrfRadio : public Radio {
|
||||||
public:
|
public:
|
||||||
HmRadio() {
|
NrfRadio() {
|
||||||
mDtuSn = DTU_SN;
|
mDtuSn = DTU_SN;
|
||||||
mIrqRcvd = false;
|
mIrqRcvd = false;
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL)
|
#if defined(SPI_HAL)
|
||||||
//mNrf24.reset(new RF24());
|
//mNrf24.reset(new RF24());
|
||||||
#else
|
#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
|
#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) {
|
void setup(bool *serialDebug, bool *privacyMode, bool *printWholeTrace, cfgNrf24_t *cfg) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setup"));
|
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;
|
mSerialDebug = serialDebug;
|
||||||
mPrivacyMode = privacyMode;
|
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;
|
mDtuRadioId = ((uint64_t)(((mDtuSn >> 24) & 0xFF) | ((mDtuSn >> 8) & 0xFF00) | ((mDtuSn << 8) & 0xFF0000) | ((mDtuSn << 24) & 0xFF000000)) << 8) | 0x01;
|
||||||
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL)
|
#if defined(SPI_HAL)
|
||||||
mNrfHal.init(mosi, miso, sclk, cs, ce, SPI_SPEED);
|
mNrfHal.init(mCfg->pinMosi, mCfg->pinMiso, mCfg->pinSclk, mCfg->pinCs, mCfg->pinCe, SPI_SPEED);
|
||||||
mNrf24.reset(new RF24(&mNrfHal));
|
mNrf24.reset(new RF24(&mNrfHal));
|
||||||
#else
|
#else
|
||||||
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||||
|
@ -64,7 +71,7 @@ class HmRadio : public Radio {
|
||||||
#else
|
#else
|
||||||
mSpi.reset(new SPIClass(VSPI));
|
mSpi.reset(new SPIClass(VSPI));
|
||||||
#endif
|
#endif
|
||||||
mSpi->begin(sclk, miso, mosi, cs);
|
mSpi->begin(mCfg->pinSclk, mCfg->pinMiso, mCfg->pinMosi, mCfg->pinCs);
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
//the old ESP82xx cannot freely place their SPI pins
|
//the old ESP82xx cannot freely place their SPI pins
|
||||||
|
@ -72,10 +79,10 @@ class HmRadio : public Radio {
|
||||||
mSpi->begin();
|
mSpi->begin();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL)
|
#if defined(SPI_HAL)
|
||||||
mNrf24->begin();
|
mNrf24->begin();
|
||||||
#else
|
#else
|
||||||
mNrf24->begin(mSpi.get(), ce, cs);
|
mNrf24->begin(mSpi.get(), mCfg->pinCe, mCfg->pinCs);
|
||||||
#endif
|
#endif
|
||||||
mNrf24->setRetries(3, 15); // wait 3*250 = 750us, 16 * 250us -> 4000us = 4ms
|
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
|
// returns true if communication is active
|
||||||
bool loop(void) override {
|
void loop(void) {
|
||||||
|
if(!mCfg->enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!mIrqRcvd && !mNRFisInRX)
|
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!
|
if(NULL == mLastIv) // prevent reading on NULL object!
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
if(!mIrqRcvd) { // no news from nRF, check timers
|
if(!mIrqRcvd) { // no news from nRF, check timers
|
||||||
if ((millis() - mTimeslotStart) < innerLoopTimeout)
|
if ((millis() - mTimeslotStart) < innerLoopTimeout)
|
||||||
return true; // nothing to do, still waiting
|
return; // nothing to do, still waiting
|
||||||
|
|
||||||
if (mRadioWaitTime.isTimeout()) { // timeout reached!
|
if (mRadioWaitTime.isTimeout()) { // timeout reached!
|
||||||
mNRFisInRX = false;
|
mNRFisInRX = false;
|
||||||
rx_ready = false;
|
rx_ready = false;
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise switch to next RX channel
|
// otherwise switch to next RX channel
|
||||||
|
@ -132,7 +142,7 @@ class HmRadio : public Radio {
|
||||||
mNrf24->setChannel(mRfChLst[tempRxChIdx]);
|
mNrf24->setChannel(mRfChLst[tempRxChIdx]);
|
||||||
isRxInit = false;
|
isRxInit = false;
|
||||||
|
|
||||||
return true; // communicating, but changed RX channel
|
return; // communicating, but changed RX channel
|
||||||
} else {
|
} else {
|
||||||
// here we got news from the nRF
|
// here we got news from the nRF
|
||||||
mIrqRcvd = false;
|
mIrqRcvd = false;
|
||||||
|
@ -145,7 +155,7 @@ class HmRadio : public Radio {
|
||||||
|
|
||||||
if(mNRFisInRX) {
|
if(mNRFisInRX) {
|
||||||
DPRINTLN(DBG_WARN, F("unexpected tx irq!"));
|
DPRINTLN(DBG_WARN, F("unexpected tx irq!"));
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mNRFisInRX = true;
|
mNRFisInRX = true;
|
||||||
|
@ -181,18 +191,23 @@ class HmRadio : public Radio {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rx_ready = false; // reset
|
rx_ready = false; // reset
|
||||||
return mNRFisInRX;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isChipConnected(void) const override {
|
bool isChipConnected(void) const override {
|
||||||
|
if(!mCfg->enabled)
|
||||||
|
return false;
|
||||||
return mNrf24->isChipConnected();
|
return mNrf24->isChipConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendControlPacket(Inverter<> *iv, uint8_t cmd, uint16_t *data, bool isRetransmit) override {
|
void sendControlPacket(Inverter<> *iv, uint8_t cmd, uint16_t *data, bool isRetransmit) override {
|
||||||
|
if(!mCfg->enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
DPRINT_IVID(DBG_INFO, iv->id);
|
DPRINT_IVID(DBG_INFO, iv->id);
|
||||||
DBGPRINT(F("sendControlPacket cmd: "));
|
DBGPRINT(F("sendControlPacket cmd: "));
|
||||||
DBGHEXLN(cmd);
|
DBGHEXLN(cmd);
|
||||||
|
@ -279,13 +294,14 @@ class HmRadio : public Radio {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getDataRate(void) const {
|
uint8_t getDataRate(void) const {
|
||||||
if(!mNrf24->isChipConnected())
|
if(!isChipConnected())
|
||||||
return 3; // unknown
|
return 3; // unknown
|
||||||
return mNrf24->getDataRate();
|
return mNrf24->getDataRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isPVariant(void) const {
|
bool isPVariant(void) const {
|
||||||
return mNrf24->isPVariant();
|
if(!isChipConnected())
|
||||||
|
return mNrf24->isPVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -413,6 +429,7 @@ class HmRadio : public Radio {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t mDtuRadioId = 0ULL;
|
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
|
const uint8_t mRfChLst[RF_CHANNELS] = {03, 23, 40, 61, 75}; // channel List:2403, 2423, 2440, 2461, 2475MHz
|
||||||
uint8_t mTxChIdx = 0;
|
uint8_t mTxChIdx = 0;
|
||||||
uint8_t mRxChIdx = 0;
|
uint8_t mRxChIdx = 0;
|
||||||
|
@ -432,7 +449,7 @@ class HmRadio : public Radio {
|
||||||
|
|
||||||
std::unique_ptr<SPIClass> mSpi;
|
std::unique_ptr<SPIClass> mSpi;
|
||||||
std::unique_ptr<RF24> mNrf24;
|
std::unique_ptr<RF24> mNrf24;
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL)
|
#if defined(SPI_HAL)
|
||||||
nrfHal mNrfHal;
|
nrfHal mNrfHal;
|
||||||
#endif
|
#endif
|
||||||
Inverter<> *mLastIv = NULL;
|
Inverter<> *mLastIv = NULL;
|
|
@ -33,7 +33,7 @@ class Radio {
|
||||||
virtual uint16_t getBaseFreqMhz() { return 0; }
|
virtual uint16_t getBaseFreqMhz() { return 0; }
|
||||||
virtual uint16_t getBootFreqMhz() { return 0; }
|
virtual uint16_t getBootFreqMhz() { return 0; }
|
||||||
virtual std::pair<uint16_t,uint16_t> getFreqRangeMhz(void) { return std::make_pair(0, 0); }
|
virtual std::pair<uint16_t,uint16_t> getFreqRangeMhz(void) { return std::make_pair(0, 0); }
|
||||||
virtual bool loop(void) = 0;
|
virtual void loop(void) = 0;
|
||||||
|
|
||||||
Radio() : mTxBuf{} {}
|
Radio() : mTxBuf{} {}
|
||||||
|
|
|
@ -9,6 +9,41 @@
|
||||||
#include "../utils/dbg.h"
|
#include "../utils/dbg.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
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
|
// inverter generations
|
||||||
enum {IV_MI = 0, IV_HM, IV_HMS, IV_HMT, IV_UNKNOWN};
|
enum {IV_MI = 0, IV_HM, IV_HMS, IV_HMT, IV_UNKNOWN};
|
||||||
const char* const generationNames[] = {"MI", "HM", "HMS", "HMT", "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_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_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_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",
|
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",
|
"U_AC", "U_AC_1N", "U_AC_2N", "U_AC_3N", "U_AC_12", "U_AC_23", "U_AC_31", "I_AC",
|
||||||
"IAC_1", "I_AC_2", "I_AC_3", "P_AC", "F_AC", "Temp", "PF_AC", "Efficiency", "Irradiation","Q_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",
|
"ALARM_MES_ID","FWVersion","FWBuildYear","FWBuildMonthDay","FWBuildHourMinute","BootloaderVersion",
|
||||||
"active_PowerLimit", "HWPartNumber", "HWVersion", "GridProfileCode",
|
"active_PowerLimit", "HWPartNumber", "HWVersion", "GridProfileCode",
|
||||||
"GridProfileVersion", /*"reactivePowerLimit","Powerfactor",*/ "LastAlarmCode", "MaxPower"};
|
"GridProfileVersion", /*"reactivePowerLimit","Powerfactor",*/ "LastAlarmCode", "MaxPower", "MaxTemp"};
|
||||||
const char* const notAvail = "n/a";
|
const char* const notAvail = "n/a";
|
||||||
|
|
||||||
const uint8_t fieldUnits[] = {UNIT_V, UNIT_A, UNIT_W, UNIT_WH, UNIT_KWH, UNIT_KWH,
|
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_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_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
|
// 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};
|
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))
|
#define DEVICE_CLS_ASSIGN_LIST_LEN (sizeof(deviceFieldAssignment) / sizeof(byteAssign_fieldDeviceClass))
|
||||||
|
|
||||||
// indices to calculation functions, defined in hmInverter.h
|
// 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};
|
enum {CMD_CALC = 0xffff};
|
||||||
|
|
||||||
|
|
||||||
|
@ -173,7 +208,8 @@ const byteAssign_t hm1chAssignment[] = {
|
||||||
{ FLD_YT, UNIT_KWH, CH0, CALC_YT_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_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC },
|
||||||
{ FLD_EFF, UNIT_PCT, CH0, CALC_EFF_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_LIST_LEN (sizeof(hm1chAssignment) / sizeof(byteAssign_t))
|
||||||
#define HM1CH_PAYLOAD_LEN 30
|
#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_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC },
|
||||||
{ FLD_PDC, UNIT_W, CH0, CALC_PDC_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_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))
|
#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_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC },
|
||||||
{ FLD_PDC, UNIT_W, CH0, CALC_PDC_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_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_LIST_LEN (sizeof(hm4chAssignment) / sizeof(byteAssign_t))
|
||||||
#define HM4CH_PAYLOAD_LEN 62
|
#define HM4CH_PAYLOAD_LEN 62
|
||||||
|
@ -351,8 +389,11 @@ const devInfo_t devInfo[] = {
|
||||||
{ 0x102271, 2000 }, // v2 black backplane, 16A
|
{ 0x102271, 2000 }, // v2 black backplane, 16A
|
||||||
|
|
||||||
// HMT
|
// HMT
|
||||||
{ 0x103311, 1800 },
|
{ 0x103241, 1600 }, // -4T
|
||||||
{ 0x103331, 2250 }
|
{ 0x103251, 1800 }, // -4T
|
||||||
|
{ 0x103271, 2000 }, // -4T
|
||||||
|
{ 0x103311, 1800 }, // -6T
|
||||||
|
{ 0x103331, 2250 } // -6T
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MI_REQ_CH1 0x09
|
#define MI_REQ_CH1 0x09
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "../config/settings.h"
|
#include "../config/settings.h"
|
||||||
|
|
||||||
#include "radio.h"
|
#include "Radio.h"
|
||||||
/**
|
/**
|
||||||
* For values which are of interest and not transmitted by the inverter can be
|
* For values which are of interest and not transmitted by the inverter can be
|
||||||
* calculated automatically.
|
* calculated automatically.
|
||||||
|
@ -33,28 +33,31 @@
|
||||||
|
|
||||||
// prototypes
|
// prototypes
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0);
|
T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0);
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0);
|
T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0);
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcUdcCh(Inverter<> *iv, uint8_t arg0);
|
T calcUdcCh(Inverter<> *iv, uint8_t arg0);
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0);
|
T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0);
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0);
|
T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0);
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcIrradiation(Inverter<> *iv, uint8_t arg0);
|
T calcIrradiation(Inverter<> *iv, uint8_t arg0);
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0);
|
T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0);
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcMaxPowerDc(Inverter<> *iv, uint8_t arg0);
|
T calcMaxPowerDc(Inverter<> *iv, uint8_t arg0);
|
||||||
|
|
||||||
|
template<class T=float>
|
||||||
|
T calcMaxTemperature(Inverter<> *iv, uint8_t arg0);
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
using func_t = T (Inverter<> *, uint8_t);
|
using func_t = T (Inverter<> *, uint8_t);
|
||||||
|
@ -84,7 +87,7 @@ struct record_t {
|
||||||
byteAssign_t* assign = nullptr; // assignment of bytes in payload
|
byteAssign_t* assign = nullptr; // assignment of bytes in payload
|
||||||
uint8_t length = 0; // length of the assignment list
|
uint8_t length = 0; // length of the assignment list
|
||||||
T *record = nullptr; // data pointer
|
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
|
uint8_t pyldLen = 0; // expected payload length for plausibility check
|
||||||
MqttSentStatus mqttSentStatus = MqttSentStatus:: NEW_DATA; // indicates the current MqTT sent status
|
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
|
// list of all available functions, mapped in hmDefines.h
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
const calcFunc_t<T> calcFunctions[] = {
|
const calcFunc_t<T> calcFunctions[] = {
|
||||||
{ CALC_YT_CH0, &calcYieldTotalCh0 },
|
{ CALC_YT_CH0, &calcYieldTotalCh0 },
|
||||||
{ CALC_YD_CH0, &calcYieldDayCh0 },
|
{ CALC_YD_CH0, &calcYieldDayCh0 },
|
||||||
{ CALC_UDC_CH, &calcUdcCh },
|
{ CALC_UDC_CH, &calcUdcCh },
|
||||||
{ CALC_PDC_CH0, &calcPowerDcCh0 },
|
{ CALC_PDC_CH0, &calcPowerDcCh0 },
|
||||||
{ CALC_EFF_CH0, &calcEffiencyCh0 },
|
{ CALC_EFF_CH0, &calcEffiencyCh0 },
|
||||||
{ CALC_IRR_CH, &calcIrradiation },
|
{ CALC_IRR_CH, &calcIrradiation },
|
||||||
{ CALC_MPAC_CH0, &calcMaxPowerAcCh0 },
|
{ CALC_MPAC_CH0, &calcMaxPowerAcCh0 },
|
||||||
{ CALC_MPDC_CH, &calcMaxPowerDc }
|
{ CALC_MPDC_CH, &calcMaxPowerDc },
|
||||||
|
{ CALC_MT_CH0, &calcMaxTemperature }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class REC_TYP>
|
template <class REC_TYP>
|
||||||
|
@ -146,7 +150,8 @@ class Inverter {
|
||||||
statistics_t radioStatistics; // information about transmitted, failed, ... packets
|
statistics_t radioStatistics; // information about transmitted, failed, ... packets
|
||||||
HeuristicInv heuristics; // heuristic information / logic
|
HeuristicInv heuristics; // heuristic information / logic
|
||||||
uint8_t curCmtFreq = 0; // current used CMT frequency, used to check if freq. was changed during runtime
|
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
|
bool commEnabled = true; // 'pause night communication' sets this field to false
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -189,7 +194,7 @@ class Inverter {
|
||||||
cb(InverterDevInform_Simple, false); // get hardware version
|
cb(InverterDevInform_Simple, false); // get hardware version
|
||||||
} else if((alarmLastId != alarmMesIndex) && (alarmMesIndex != 0)) {
|
} else if((alarmLastId != alarmMesIndex) && (alarmMesIndex != 0)) {
|
||||||
cb(AlarmData, false); // get last alarms
|
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);
|
cb(GridOnProFilePara, false);
|
||||||
} else if (mGetLossInterval > AHOY_GET_LOSS_INTERVAL) { // get loss rate
|
} else if (mGetLossInterval > AHOY_GET_LOSS_INTERVAL) { // get loss rate
|
||||||
mGetLossInterval = 1;
|
mGetLossInterval = 1;
|
||||||
|
@ -213,7 +218,7 @@ class Inverter {
|
||||||
if (getChannelFieldValue(CH0, FLD_PART_NUM, rec) == 0) {
|
if (getChannelFieldValue(CH0, FLD_PART_NUM, rec) == 0) {
|
||||||
cb(0x0f, false); // hard- and firmware version for missing HW part nr, delivered by frame 1
|
cb(0x0f, false); // hard- and firmware version for missing HW part nr, delivered by frame 1
|
||||||
mIvRxCnt +=2;
|
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
|
cb(0x10, false); // legacy GPF command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,19 +234,20 @@ class Inverter {
|
||||||
initAssignment(&recordAlarm, AlarmData);
|
initAssignment(&recordAlarm, AlarmData);
|
||||||
toRadioId();
|
toRadioId();
|
||||||
curCmtFreq = this->config->frequency; // update to frequency read from settings
|
curCmtFreq = this->config->frequency; // update to frequency read from settings
|
||||||
|
resetAlarms(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId, record_t<> *rec) {
|
uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId, record_t<> *rec) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getPosByChFld"));
|
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getPosByChFld"));
|
||||||
if(NULL != rec) {
|
if(nullptr == 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
|
|
||||||
return 0xff;
|
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) {
|
byteAssign_t *getByteAssign(uint8_t pos, record_t<> *rec) {
|
||||||
|
@ -270,15 +276,18 @@ class Inverter {
|
||||||
if(InverterStatus::OFF != status) {
|
if(InverterStatus::OFF != status) {
|
||||||
mDevControlRequest = true;
|
mDevControlRequest = true;
|
||||||
devControlCmd = cmd;
|
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) {
|
bool setDevCommand(uint8_t cmd) {
|
||||||
if(InverterStatus::OFF != status)
|
bool retval = (InverterStatus::OFF != status);
|
||||||
|
if(retval)
|
||||||
devControlCmd = cmd;
|
devControlCmd = cmd;
|
||||||
return (InverterStatus::OFF != status);
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addValue(uint8_t pos, const uint8_t buf[], record_t<> *rec) {
|
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) {
|
bool setValue(uint8_t pos, record_t<> *rec, REC_TYP val) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:setValue"));
|
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:setValue"));
|
||||||
if(NULL == rec)
|
if(nullptr == rec)
|
||||||
return false;
|
return false;
|
||||||
if(pos > rec->length)
|
if(pos > rec->length)
|
||||||
return false;
|
return false;
|
||||||
|
@ -408,14 +417,14 @@ class Inverter {
|
||||||
if(recordMeas.ts == 0)
|
if(recordMeas.ts == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(((*timestamp) - recordMeas.ts) < INVERTER_INACT_THRES_SEC)
|
if(((*Timestamp) - recordMeas.ts) < INVERTER_INACT_THRES_SEC)
|
||||||
avail = true;
|
avail = true;
|
||||||
|
|
||||||
if(avail) {
|
if(avail) {
|
||||||
if(status < InverterStatus::PRODUCING)
|
if(status < InverterStatus::PRODUCING)
|
||||||
status = InverterStatus::STARTING;
|
status = InverterStatus::STARTING;
|
||||||
} else {
|
} else {
|
||||||
if(((*timestamp) - recordMeas.ts) > INVERTER_OFF_THRES_SEC) {
|
if(((*Timestamp) - recordMeas.ts) > INVERTER_OFF_THRES_SEC) {
|
||||||
if(status != InverterStatus::OFF) {
|
if(status != InverterStatus::OFF) {
|
||||||
status = InverterStatus::OFF;
|
status = InverterStatus::OFF;
|
||||||
actPowerLimit = 0xffff; // power limit will be read once inverter becomes available
|
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->length = (uint8_t)(HMS4CH_LIST_LEN);
|
||||||
rec->assign = reinterpret_cast<byteAssign_t*>(const_cast<byteAssign_t*>(hms4chAssignment));
|
rec->assign = reinterpret_cast<byteAssign_t*>(const_cast<byteAssign_t*>(hms4chAssignment));
|
||||||
rec->pyldLen = HMS4CH_PAYLOAD_LEN;
|
rec->pyldLen = HMS4CH_PAYLOAD_LEN;
|
||||||
|
} else if(IV_HMT == ivGen){
|
||||||
|
rec->length = (uint8_t)(HMT4CH_LIST_LEN);
|
||||||
|
rec->assign = reinterpret_cast<byteAssign_t*>(const_cast<byteAssign_t*>(hmt4chAssignment));
|
||||||
|
rec->pyldLen = HMT4CH_PAYLOAD_LEN;
|
||||||
}
|
}
|
||||||
channels = 4;
|
channels = 4;
|
||||||
}
|
}
|
||||||
|
@ -576,7 +589,7 @@ class Inverter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetAlarms() {
|
void resetAlarms(bool clearTs = false) {
|
||||||
lastAlarm.fill({0, 0, 0});
|
lastAlarm.fill({0, 0, 0});
|
||||||
mAlarmNxtWrPos = 0;
|
mAlarmNxtWrPos = 0;
|
||||||
alarmCnt = 0;
|
alarmCnt = 0;
|
||||||
|
@ -584,6 +597,11 @@ class Inverter {
|
||||||
|
|
||||||
memset(mOffYD, 0, sizeof(float) * 6);
|
memset(mOffYD, 0, sizeof(float) * 6);
|
||||||
memset(mLastYD, 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) {
|
bool parseGetLossRate(const uint8_t pyld[], uint8_t len) {
|
||||||
|
@ -816,8 +834,9 @@ class Inverter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static uint32_t *timestamp; // system timestamp
|
static uint32_t *Timestamp; // system timestamp
|
||||||
static cfgInst_t *generalConfig; // general inverter configuration from setup
|
static cfgInst_t *GeneralConfig; // general inverter configuration from setup
|
||||||
|
static IApp *App;
|
||||||
|
|
||||||
uint16_t mDtuRxCnt = 0;
|
uint16_t mDtuRxCnt = 0;
|
||||||
uint16_t mDtuTxCnt = 0;
|
uint16_t mDtuTxCnt = 0;
|
||||||
|
@ -835,9 +854,11 @@ class Inverter {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class REC_TYP>
|
template <class REC_TYP>
|
||||||
uint32_t *Inverter<REC_TYP>::timestamp {0};
|
uint32_t *Inverter<REC_TYP>::Timestamp {0};
|
||||||
template <class REC_TYP>
|
template <class REC_TYP>
|
||||||
cfgInst_t *Inverter<REC_TYP>::generalConfig {0};
|
cfgInst_t *Inverter<REC_TYP>::GeneralConfig {0};
|
||||||
|
template <class REC_TYP>
|
||||||
|
IApp *Inverter<REC_TYP>::App {nullptr};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -847,7 +868,7 @@ cfgInst_t *Inverter<REC_TYP>::generalConfig {0};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
|
T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcYieldTotalCh0"));
|
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcYieldTotalCh0"));
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
||||||
|
@ -861,7 +882,7 @@ static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
|
T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcYieldDayCh0"));
|
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcYieldDayCh0"));
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
||||||
|
@ -875,7 +896,7 @@ static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
|
T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcUdcCh"));
|
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcUdcCh"));
|
||||||
// arg0 = channel of source
|
// arg0 = channel of source
|
||||||
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
||||||
|
@ -889,7 +910,7 @@ static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
|
T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcPowerDcCh0"));
|
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcPowerDcCh0"));
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
||||||
|
@ -903,7 +924,7 @@ static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
|
T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcEfficiencyCh0"));
|
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcEfficiencyCh0"));
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
||||||
|
@ -919,7 +940,7 @@ static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcIrradiation(Inverter<> *iv, uint8_t arg0) {
|
T calcIrradiation(Inverter<> *iv, uint8_t arg0) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcIrradiation"));
|
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcIrradiation"));
|
||||||
// arg0 = channel
|
// arg0 = channel
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
|
@ -931,7 +952,7 @@ static T calcIrradiation(Inverter<> *iv, uint8_t arg0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0) {
|
T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcMaxPowerAcCh0"));
|
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcMaxPowerAcCh0"));
|
||||||
T acMaxPower = 0.0;
|
T acMaxPower = 0.0;
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
|
@ -944,7 +965,7 @@ static T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(acPower > acMaxPower) {
|
if(acPower > acMaxPower) {
|
||||||
iv->tsMaxAcPower = *iv->timestamp;
|
iv->tsMaxAcPower = *iv->Timestamp;
|
||||||
return acPower;
|
return acPower;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -952,7 +973,7 @@ static T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcMaxPowerDc(Inverter<> *iv, uint8_t arg0) {
|
T calcMaxPowerDc(Inverter<> *iv, uint8_t arg0) {
|
||||||
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcMaxPowerDc"));
|
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:calcMaxPowerDc"));
|
||||||
// arg0 = channel
|
// arg0 = channel
|
||||||
T dcMaxPower = 0.0;
|
T dcMaxPower = 0.0;
|
||||||
|
@ -971,4 +992,22 @@ static T calcMaxPowerDc(Inverter<> *iv, uint8_t arg0) {
|
||||||
return dcMaxPower;
|
return dcMaxPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T=float>
|
||||||
|
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__*/
|
#endif /*__HM_INVERTER_H__*/
|
||||||
|
|
|
@ -16,8 +16,9 @@ class HmSystem {
|
||||||
HmSystem() {}
|
HmSystem() {}
|
||||||
|
|
||||||
void setup(uint32_t *timestamp, cfgInst_t *config, IApp *app) {
|
void setup(uint32_t *timestamp, cfgInst_t *config, IApp *app) {
|
||||||
INVERTERTYPE::timestamp = timestamp;
|
INVERTERTYPE::Timestamp = timestamp;
|
||||||
INVERTERTYPE::generalConfig = config;
|
INVERTERTYPE::GeneralConfig = config;
|
||||||
|
INVERTERTYPE::App = app;
|
||||||
//mInverter[0].app = app;
|
//mInverter[0].app = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ class HmSystem {
|
||||||
DPRINTLN(DBG_VERBOSE, F("hmSystem.h:addInverter"));
|
DPRINTLN(DBG_VERBOSE, F("hmSystem.h:addInverter"));
|
||||||
INVERTERTYPE *iv = &mInverter[id];
|
INVERTERTYPE *iv = &mInverter[id];
|
||||||
iv->id = 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));
|
DPRINT(DBG_VERBOSE, "SERIAL: " + String(iv->config->serial.b[5], HEX));
|
||||||
DPRINTLN(DBG_VERBOSE, " " + String(iv->config->serial.b[4], HEX));
|
DPRINTLN(DBG_VERBOSE, " " + String(iv->config->serial.b[4], HEX));
|
||||||
if((iv->config->serial.b[5] == 0x11) || (iv->config->serial.b[5] == 0x10)) {
|
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;
|
iv->ivRadioType = INV_RADIO_TYPE_NRF;
|
||||||
}
|
}
|
||||||
} else if(iv->config->serial.b[5] == 0x13) {
|
} 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->type = INV_TYPE_6CH;
|
||||||
iv->ivRadioType = INV_RADIO_TYPE_CMT;
|
|
||||||
|
iv->ivRadioType = INV_RADIO_TYPE_CMT;
|
||||||
} else if(iv->config->serial.u64 != 0ULL) {
|
} else if(iv->config->serial.u64 != 0ULL) {
|
||||||
DPRINTLN(DBG_ERROR, F("inverter type can't be detected!"));
|
DPRINTLN(DBG_ERROR, F("inverter type can't be detected!"));
|
||||||
|
iv->config->enabled = false;
|
||||||
return;
|
return;
|
||||||
} else
|
} else
|
||||||
iv->ivGen = IV_UNKNOWN;
|
iv->ivGen = IV_UNKNOWN;
|
||||||
|
@ -115,6 +121,8 @@ class HmSystem {
|
||||||
DPRINTLN(DBG_VERBOSE, F("hmSystem.h:getInverterByPos"));
|
DPRINTLN(DBG_VERBOSE, F("hmSystem.h:getInverterByPos"));
|
||||||
if(pos >= MAX_INVERTER)
|
if(pos >= MAX_INVERTER)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
else if(nullptr == mInverter[pos].config)
|
||||||
|
return nullptr;
|
||||||
else if((mInverter[pos].config->serial.u64 != 0ULL) || (false == check))
|
else if((mInverter[pos].config->serial.u64 != 0ULL) || (false == check))
|
||||||
return &mInverter[pos];
|
return &mInverter[pos];
|
||||||
else
|
else
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../utils/spiPatcher.h"
|
#include "../utils/spiPatcher.h"
|
||||||
|
|
||||||
#include <esp_rom_gpio.h>
|
#include <esp_rom_gpio.h>
|
||||||
#include <RF24.h>
|
#include <RF24.h>
|
||||||
|
|
||||||
|
@ -18,9 +17,7 @@
|
||||||
|
|
||||||
class nrfHal: public RF24_hal, public SpiPatcherHandle {
|
class nrfHal: public RF24_hal, public SpiPatcherHandle {
|
||||||
public:
|
public:
|
||||||
nrfHal() {
|
nrfHal() {}
|
||||||
mSpiPatcher = SpiPatcher::getInstance(SPI2_HOST);
|
|
||||||
}
|
|
||||||
|
|
||||||
void patch() override {
|
void patch() override {
|
||||||
esp_rom_gpio_connect_out_signal(mPinMosi, spi_periph_signal[mHostDevice].spid_out, false, false);
|
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<gpio_num_t>(en);
|
mPinEn = static_cast<gpio_num_t>(en);
|
||||||
mSpiSpeed = speed;
|
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_reset_pin(mPinMosi);
|
||||||
gpio_set_direction(mPinMosi, GPIO_MODE_OUTPUT);
|
gpio_set_direction(mPinMosi, GPIO_MODE_OUTPUT);
|
||||||
|
@ -56,6 +59,7 @@ class nrfHal: public RF24_hal, public SpiPatcherHandle {
|
||||||
gpio_set_level(mPinClk, 0);
|
gpio_set_level(mPinClk, 0);
|
||||||
|
|
||||||
gpio_reset_pin(mPinCs);
|
gpio_reset_pin(mPinCs);
|
||||||
|
request_spi();
|
||||||
spi_device_interface_config_t devcfg = {
|
spi_device_interface_config_t devcfg = {
|
||||||
.command_bits = 0,
|
.command_bits = 0,
|
||||||
.address_bits = 0,
|
.address_bits = 0,
|
||||||
|
@ -72,14 +76,14 @@ class nrfHal: public RF24_hal, public SpiPatcherHandle {
|
||||||
.pre_cb = nullptr,
|
.pre_cb = nullptr,
|
||||||
.post_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_reset_pin(mPinEn);
|
||||||
gpio_set_direction(mPinEn, GPIO_MODE_OUTPUT);
|
gpio_set_direction(mPinEn, GPIO_MODE_OUTPUT);
|
||||||
gpio_set_level(mPinEn, 0);
|
gpio_set_level(mPinEn, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool begin() override {
|
bool begin() override {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#define __HMS_RADIO_H__
|
#define __HMS_RADIO_H__
|
||||||
|
|
||||||
#include "cmt2300a.h"
|
#include "cmt2300a.h"
|
||||||
#include "../hm/radio.h"
|
#include "../hm/Radio.h"
|
||||||
|
|
||||||
//#define CMT_SWITCH_CHANNEL_CYCLE 5
|
//#define CMT_SWITCH_CHANNEL_CYCLE 5
|
||||||
|
|
||||||
|
@ -15,25 +15,34 @@ template<uint32_t DTU_SN = 0x81001765>
|
||||||
class CmtRadio : public Radio {
|
class CmtRadio : public Radio {
|
||||||
typedef Cmt2300a CmtType;
|
typedef Cmt2300a CmtType;
|
||||||
public:
|
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) {
|
void setup(bool *serialDebug, bool *privacyMode, bool *printWholeTrace, cfgCmt_t *cfg, uint8_t region = 0, bool genDtuSn = true) {
|
||||||
mCmt.setup(pinSclk, pinSdio, pinCsb, pinFcsb);
|
mCfg = cfg;
|
||||||
reset(genDtuSn, static_cast<RegionCfg>(region));
|
|
||||||
|
if(!cfg->enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
mPrivacyMode = privacyMode;
|
mPrivacyMode = privacyMode;
|
||||||
mSerialDebug = serialDebug;
|
mSerialDebug = serialDebug;
|
||||||
mPrintWholeTrace = printWholeTrace;
|
mPrintWholeTrace = printWholeTrace;
|
||||||
mTxBuf.fill(0);
|
mTxBuf.fill(0);
|
||||||
|
|
||||||
|
mCmt.setup(cfg->pinSclk, cfg->pinSdio, cfg->pinCsb, cfg->pinFcsb);
|
||||||
|
reset(genDtuSn, static_cast<RegionCfg>(region));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool loop() override {
|
void loop() override {
|
||||||
|
if(!mCfg->enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
mCmt.loop();
|
mCmt.loop();
|
||||||
if((!mIrqRcvd) && (!mRqstGetRx))
|
if((!mIrqRcvd) && (!mRqstGetRx))
|
||||||
return false;
|
return;
|
||||||
getRx();
|
getRx();
|
||||||
if(CmtStatus::SUCCESS == mCmt.goRx()) {
|
if(CmtStatus::SUCCESS == mCmt.goRx()) {
|
||||||
mIrqRcvd = false;
|
mIrqRcvd = false;
|
||||||
mRqstGetRx = false;
|
mRqstGetRx = false;
|
||||||
}
|
}
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isChipConnected(void) const override {
|
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 {
|
void sendControlPacket(Inverter<> *iv, uint8_t cmd, uint16_t *data, bool isRetransmit) override {
|
||||||
|
if(!mCfg->enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
DPRINT(DBG_INFO, F("sendControlPacket cmd: "));
|
DPRINT(DBG_INFO, F("sendControlPacket cmd: "));
|
||||||
DBGHEXLN(cmd);
|
DBGHEXLN(cmd);
|
||||||
initPacket(iv->radioId.u64, TX_REQ_DEVCONTROL, SINGLE_FRAME);
|
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 {
|
bool switchFrequency(Inverter<> *iv, uint32_t fromkHz, uint32_t tokHz) override {
|
||||||
|
if(!isChipConnected())
|
||||||
|
return false;
|
||||||
|
|
||||||
uint8_t fromCh = mCmt.freq2Chan(fromkHz);
|
uint8_t fromCh = mCmt.freq2Chan(fromkHz);
|
||||||
uint8_t toCh = mCmt.freq2Chan(tokHz);
|
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 {
|
bool switchFrequencyCh(Inverter<> *iv, uint8_t fromCh, uint8_t toCh) override {
|
||||||
if((0xff == fromCh) || (0xff == toCh))
|
if((0xff == fromCh) || (0xff == toCh))
|
||||||
return false;
|
return false;
|
||||||
|
if(!isChipConnected())
|
||||||
|
return false;
|
||||||
|
|
||||||
mCmt.switchChannel(fromCh);
|
mCmt.switchChannel(fromCh);
|
||||||
sendSwitchChCmd(iv, toCh);
|
sendSwitchChCmd(iv, toCh);
|
||||||
|
@ -188,6 +205,7 @@ class CmtRadio : public Radio {
|
||||||
}
|
}
|
||||||
|
|
||||||
CmtType mCmt;
|
CmtType mCmt;
|
||||||
|
cfgCmt_t *mCfg = nullptr;
|
||||||
bool mCmtAvail = false;
|
bool mCmtAvail = false;
|
||||||
bool mRqstGetRx = false;
|
bool mRqstGetRx = false;
|
||||||
uint32_t mMillis = 0;
|
uint32_t mMillis = 0;
|
|
@ -6,7 +6,7 @@
|
||||||
#ifndef __CMT2300A_H__
|
#ifndef __CMT2300A_H__
|
||||||
#define __CMT2300A_H__
|
#define __CMT2300A_H__
|
||||||
|
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL)
|
#if defined(SPI_HAL)
|
||||||
#include "cmtHal.h"
|
#include "cmtHal.h"
|
||||||
#else
|
#else
|
||||||
#include "esp32_3wSpi.h"
|
#include "esp32_3wSpi.h"
|
||||||
|
@ -545,7 +545,7 @@ class Cmt2300a {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(SPI_HAL)
|
#if defined(SPI_HAL)
|
||||||
cmtHal mSpi;
|
cmtHal mSpi;
|
||||||
#else
|
#else
|
||||||
esp32_3wSpi mSpi;
|
esp32_3wSpi mSpi;
|
||||||
|
|
|
@ -16,9 +16,7 @@
|
||||||
|
|
||||||
class cmtHal : public SpiPatcherHandle {
|
class cmtHal : public SpiPatcherHandle {
|
||||||
public:
|
public:
|
||||||
cmtHal() {
|
cmtHal() {}
|
||||||
mSpiPatcher = SpiPatcher::getInstance(DEF_CMT_SPI_HOST);
|
|
||||||
}
|
|
||||||
|
|
||||||
void patch() override {
|
void patch() override {
|
||||||
esp_rom_gpio_connect_out_signal(mPinSdio, spi_periph_signal[mHostDevice].spid_out, false, false);
|
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<gpio_num_t>(fcs);
|
mPinFcs = static_cast<gpio_num_t>(fcs);
|
||||||
mSpiSpeed = speed;
|
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_reset_pin(mPinSdio);
|
||||||
gpio_set_direction(mPinSdio, GPIO_MODE_INPUT_OUTPUT);
|
gpio_set_direction(mPinSdio, GPIO_MODE_INPUT_OUTPUT);
|
||||||
|
@ -50,6 +54,7 @@ class cmtHal : public SpiPatcherHandle {
|
||||||
gpio_set_level(mPinClk, 0);
|
gpio_set_level(mPinClk, 0);
|
||||||
|
|
||||||
gpio_reset_pin(mPinCs);
|
gpio_reset_pin(mPinCs);
|
||||||
|
request_spi();
|
||||||
spi_device_interface_config_t devcfg_reg = {
|
spi_device_interface_config_t devcfg_reg = {
|
||||||
.command_bits = 1,
|
.command_bits = 1,
|
||||||
.address_bits = 7,
|
.address_bits = 7,
|
||||||
|
@ -66,7 +71,8 @@ class cmtHal : public SpiPatcherHandle {
|
||||||
.pre_cb = nullptr,
|
.pre_cb = nullptr,
|
||||||
.post_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);
|
gpio_reset_pin(mPinFcs);
|
||||||
spi_device_interface_config_t devcfg_fifo = {
|
spi_device_interface_config_t devcfg_fifo = {
|
||||||
|
|
|
@ -33,7 +33,8 @@ const byteAssign_t hms1chAssignment[] = {
|
||||||
{ FLD_YT, UNIT_KWH, CH0, CALC_YT_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_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC },
|
||||||
{ FLD_EFF, UNIT_PCT, CH0, CALC_EFF_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_LIST_LEN (sizeof(hms1chAssignment) / sizeof(byteAssign_t))
|
||||||
#define HMS1CH_PAYLOAD_LEN 30
|
#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_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC },
|
||||||
{ FLD_PDC, UNIT_W, CH0, CALC_PDC_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_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_LIST_LEN (sizeof(hms2chAssignment) / sizeof(byteAssign_t))
|
||||||
#define HMS2CH_PAYLOAD_LEN 42
|
#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_YT, UNIT_KWH, CH0, CALC_YT_CH0, 0, CMD_CALC },
|
||||||
{ FLD_PDC, UNIT_W, CH0, CALC_PDC_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_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_LIST_LEN (sizeof(hms4chAssignment) / sizeof(byteAssign_t))
|
||||||
#define HMS4CH_PAYLOAD_LEN 66
|
#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
|
// HMT-1800, HMT-2250
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
|
@ -199,7 +263,8 @@ const byteAssign_t hmt6chAssignment[] = {
|
||||||
{ FLD_YT, UNIT_KWH, CH0, CALC_YT_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_PDC, UNIT_W, CH0, CALC_PDC_CH0, 0, CMD_CALC },
|
||||||
{ FLD_EFF, UNIT_PCT, CH0, CALC_EFF_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_LIST_LEN (sizeof(hmt6chAssignment) / sizeof(byteAssign_t))
|
||||||
#define HMT6CH_PAYLOAD_LEN 98
|
#define HMT6CH_PAYLOAD_LEN 98
|
||||||
|
|
|
@ -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);
|
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);
|
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 {
|
void OnEvent(WiFiEvent_t event) override {
|
||||||
if(mAp.isEnabled())
|
switch(event) {
|
||||||
mAp.tickLoop();
|
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||||
|
if(NetworkState::CONNECTED != mStatus) {
|
||||||
switch(mStatus) {
|
mStatus = NetworkState::CONNECTED;
|
||||||
case NetworkState::DISCONNECTED:
|
DPRINTLN(DBG_INFO, F("Network connected"));
|
||||||
if(mConnected) {
|
setStaticIp();
|
||||||
mConnected = false;
|
|
||||||
mOnNetworkCB(false);
|
|
||||||
mAp.enable();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NetworkState::CONNECTED:
|
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||||
break;
|
mStatus = NetworkState::GOT_IP;
|
||||||
|
|
||||||
case NetworkState::GOT_IP:
|
|
||||||
if(!mConnected) {
|
if(!mConnected) {
|
||||||
mAp.disable();
|
mAp.disable();
|
||||||
mConnected = true;
|
mConnected = true;
|
||||||
|
@ -55,13 +45,39 @@ class AhoyEthernet : public AhoyNetwork {
|
||||||
mOnNetworkCB(true);
|
mOnNetworkCB(true);
|
||||||
}
|
}
|
||||||
break;
|
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 {
|
String getIp(void) override {
|
||||||
return ETH.localIP().toString();
|
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:
|
private:
|
||||||
AhoyEthernetSpi mEthSpi;
|
AhoyEthernetSpi mEthSpi;
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <esp_netif.h>
|
#include <esp_netif.h>
|
||||||
#include <WiFiGeneric.h>
|
#include <WiFiGeneric.h>
|
||||||
#include <driver/spi_master.h>
|
#include "../utils/spiPatcher.h"
|
||||||
|
|
||||||
// Functions from WiFiGeneric
|
// Functions from WiFiGeneric
|
||||||
void tcpipInit();
|
void tcpipInit();
|
||||||
|
@ -44,23 +44,14 @@ class AhoyEthernetSpi {
|
||||||
gpio_reset_pin(static_cast<gpio_num_t>(pin_int));
|
gpio_reset_pin(static_cast<gpio_num_t>(pin_int));
|
||||||
gpio_set_pull_mode(static_cast<gpio_num_t>(pin_int), GPIO_PULLUP_ONLY);
|
gpio_set_pull_mode(static_cast<gpio_num_t>(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 = {
|
mSpiPatcher = SpiPatcher::getInstance(mHostDevice, false);
|
||||||
.mosi_io_num = pin_mosi,
|
mSpiPatcher->initBus(pin_mosi, pin_miso, pin_sclk, SPI_DMA_CH_AUTO);
|
||||||
.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));
|
|
||||||
|
|
||||||
spi_device_interface_config_t devcfg = {
|
spi_device_interface_config_t devcfg = {
|
||||||
.command_bits = 16, // actually address phase
|
.command_bits = 16, // actually address phase
|
||||||
|
@ -79,8 +70,7 @@ class AhoyEthernetSpi {
|
||||||
.post_cb = nullptr
|
.post_cb = nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
spi_device_handle_t spi;
|
mSpiPatcher->addDevice(mHostDevice, &devcfg, &spi);
|
||||||
ESP_ERROR_CHECK(spi_bus_add_device(SPI3_HOST, &devcfg, &spi));
|
|
||||||
|
|
||||||
// Reset sequence
|
// Reset sequence
|
||||||
if(-1 != pin_rst) {
|
if(-1 != pin_rst) {
|
||||||
|
@ -137,6 +127,9 @@ class AhoyEthernetSpi {
|
||||||
private:
|
private:
|
||||||
esp_eth_handle_t eth_handle;
|
esp_eth_handle_t eth_handle;
|
||||||
esp_netif_t *eth_netif;
|
esp_netif_t *eth_netif;
|
||||||
|
spi_host_device_t mHostDevice;
|
||||||
|
spi_device_handle_t spi;
|
||||||
|
SpiPatcher *mSpiPatcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*__ETH_SPI_H__*/
|
#endif /*__ETH_SPI_H__*/
|
||||||
|
|
|
@ -28,7 +28,6 @@ class AhoyNetwork {
|
||||||
|
|
||||||
if('\0' == mConfig->sys.deviceName[0])
|
if('\0' == mConfig->sys.deviceName[0])
|
||||||
snprintf(mConfig->sys.deviceName, DEVNAME_LEN, "%s", DEF_DEVICE_NAME);
|
snprintf(mConfig->sys.deviceName, DEVNAME_LEN, "%s", DEF_DEVICE_NAME);
|
||||||
WiFi.hostname(mConfig->sys.deviceName);
|
|
||||||
|
|
||||||
mAp.setup(&mConfig->sys);
|
mAp.setup(&mConfig->sys);
|
||||||
|
|
||||||
|
@ -90,14 +89,9 @@ class AhoyNetwork {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(ETHERNET)
|
#if !defined(ETHERNET)
|
||||||
bool getAvailNetworks(JsonObject obj) {
|
bool getAvailNetworks(JsonObject obj, IApp *app) {
|
||||||
JsonArray nets = obj.createNestedArray(F("networks"));
|
|
||||||
|
|
||||||
if(!mScanActive) {
|
if(!mScanActive) {
|
||||||
mScanActive = true;
|
app->addOnce([this]() {scan();}, 1, "scan");
|
||||||
if(NetworkState::GOT_IP != mStatus)
|
|
||||||
WiFi.disconnect();
|
|
||||||
WiFi.scanNetworks(true, true);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +100,7 @@ class AhoyNetwork {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(n > 0) {
|
if(n > 0) {
|
||||||
|
JsonArray nets = obj.createNestedArray(F("networks"));
|
||||||
int sort[n];
|
int sort[n];
|
||||||
sortRSSI(&sort[0], n);
|
sortRSSI(&sort[0], n);
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
|
@ -118,9 +113,20 @@ class AhoyNetwork {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scan(void) {
|
||||||
|
mScanActive = true;
|
||||||
|
if(mWifiConnecting) {
|
||||||
|
mWifiConnecting = false;
|
||||||
|
WiFi.disconnect();
|
||||||
|
}
|
||||||
|
WiFi.scanNetworks(true, true);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void setStaticIp() = 0;
|
||||||
|
|
||||||
void setupIp(std::function<bool(IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2)> cb) {
|
void setupIp(std::function<bool(IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2)> cb) {
|
||||||
if(mConfig->sys.ip.ip[0] != 0) {
|
if(mConfig->sys.ip.ip[0] != 0) {
|
||||||
IPAddress ip(mConfig->sys.ip.ip);
|
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) {
|
switch(event) {
|
||||||
case SYSTEM_EVENT_STA_CONNECTED:
|
case SYSTEM_EVENT_STA_CONNECTED:
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
|
@ -228,6 +234,9 @@ class AhoyNetwork {
|
||||||
uint32_t *mUtcTimestamp = nullptr;
|
uint32_t *mUtcTimestamp = nullptr;
|
||||||
bool mConnected = false;
|
bool mConnected = false;
|
||||||
bool mScanActive = false;
|
bool mScanActive = false;
|
||||||
|
#if !defined(ETHERNET)
|
||||||
|
bool mWifiConnecting = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
OnNetworkCB mOnNetworkCB;
|
OnNetworkCB mOnNetworkCB;
|
||||||
OnTimeCB mOnTimeCB;
|
OnTimeCB mOnTimeCB;
|
||||||
|
|
|
@ -44,6 +44,7 @@ class AhoyWifiAp {
|
||||||
WiFi.softAPConfig(mIp, mIp, IPAddress(255, 255, 255, 0));
|
WiFi.softAPConfig(mIp, mIp, IPAddress(255, 255, 255, 0));
|
||||||
WiFi.softAP(WIFI_AP_SSID, mCfg->apPwd);
|
WiFi.softAP(WIFI_AP_SSID, mCfg->apPwd);
|
||||||
|
|
||||||
|
mDns.setErrorReplyCode(DNSReplyCode::NoError);
|
||||||
mDns.start(53, "*", mIp);
|
mDns.start(53, "*", mIp);
|
||||||
|
|
||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
|
@ -62,6 +63,7 @@ class AhoyWifiAp {
|
||||||
#if defined(ETHERNET)
|
#if defined(ETHERNET)
|
||||||
WiFi.mode(WIFI_OFF);
|
WiFi.mode(WIFI_OFF);
|
||||||
#else
|
#else
|
||||||
|
WiFi.scanDelete();
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -17,40 +17,36 @@ class AhoyWifi : public AhoyNetwork {
|
||||||
void begin() override {
|
void begin() override {
|
||||||
mAp.enable();
|
mAp.enable();
|
||||||
|
|
||||||
// static IP
|
if(String(FB_WIFI_SSID) == mConfig->sys.stationSsid)
|
||||||
setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
|
return; // no station wifi defined
|
||||||
return WiFi.config(ip, gateway, mask, dns1, dns2);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
WiFi.disconnect(); // clean up
|
||||||
WiFi.setHostname(mConfig->sys.deviceName);
|
WiFi.setHostname(mConfig->sys.deviceName);
|
||||||
#if !defined(AP_ONLY)
|
#if !defined(AP_ONLY)
|
||||||
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
|
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
|
||||||
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
|
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
|
||||||
|
setStaticIp();
|
||||||
WiFi.begin(mConfig->sys.stationSsid, mConfig->sys.stationPwd, WIFI_ALL_CHANNEL_SCAN);
|
WiFi.begin(mConfig->sys.stationSsid, mConfig->sys.stationPwd, WIFI_ALL_CHANNEL_SCAN);
|
||||||
|
mWifiConnecting = true;
|
||||||
|
|
||||||
DBGPRINT(F("connect to network '"));
|
DBGPRINT(F("connect to network '"));
|
||||||
DBGPRINT(mConfig->sys.stationSsid);
|
DBGPRINT(mConfig->sys.stationSsid);
|
||||||
|
DBGPRINTLN(F("'"));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void tickNetworkLoop() override {
|
void OnEvent(WiFiEvent_t event) override {
|
||||||
if(mAp.isEnabled())
|
switch(event) {
|
||||||
mAp.tickLoop();
|
case SYSTEM_EVENT_STA_CONNECTED:
|
||||||
|
if(NetworkState::CONNECTED != mStatus) {
|
||||||
switch(mStatus) {
|
mStatus = NetworkState::CONNECTED;
|
||||||
case NetworkState::DISCONNECTED:
|
mWifiConnecting = false;
|
||||||
if(mConnected) {
|
DPRINTLN(DBG_INFO, F("Network connected"));
|
||||||
mConnected = false;
|
|
||||||
mOnNetworkCB(false);
|
|
||||||
mAp.enable();
|
|
||||||
MDNS.end();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NetworkState::CONNECTED:
|
case SYSTEM_EVENT_STA_GOT_IP:
|
||||||
break;
|
mStatus = NetworkState::GOT_IP;
|
||||||
|
|
||||||
case NetworkState::GOT_IP:
|
|
||||||
if(mAp.isEnabled())
|
if(mAp.isEnabled())
|
||||||
mAp.disable();
|
mAp.disable();
|
||||||
|
|
||||||
|
@ -58,16 +54,44 @@ class AhoyWifi : public AhoyNetwork {
|
||||||
mConnected = true;
|
mConnected = true;
|
||||||
ah::welcome(WiFi.localIP().toString(), F("Station"));
|
ah::welcome(WiFi.localIP().toString(), F("Station"));
|
||||||
MDNS.begin(mConfig->sys.deviceName);
|
MDNS.begin(mConfig->sys.deviceName);
|
||||||
MDNS.addServiceTxt("http", "tcp", "path", "/");
|
|
||||||
mOnNetworkCB(true);
|
mOnNetworkCB(true);
|
||||||
}
|
}
|
||||||
break;
|
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 {
|
String getIp(void) override {
|
||||||
return WiFi.localIP().toString();
|
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*/
|
#endif /*ESP32 & !ETHERNET*/
|
||||||
|
|
|
@ -18,11 +18,6 @@ class AhoyWifi : public AhoyNetwork {
|
||||||
void begin() override {
|
void begin() override {
|
||||||
mAp.enable();
|
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);
|
WiFi.setHostname(mConfig->sys.deviceName);
|
||||||
mBSSIDList.clear();
|
mBSSIDList.clear();
|
||||||
}
|
}
|
||||||
|
@ -37,6 +32,7 @@ class AhoyWifi : public AhoyNetwork {
|
||||||
case NetworkState::DISCONNECTED:
|
case NetworkState::DISCONNECTED:
|
||||||
if(mConnected) {
|
if(mConnected) {
|
||||||
mConnected = false;
|
mConnected = false;
|
||||||
|
mWifiConnecting = false;
|
||||||
mOnNetworkCB(false);
|
mOnNetworkCB(false);
|
||||||
mAp.enable();
|
mAp.enable();
|
||||||
MDNS.end();
|
MDNS.end();
|
||||||
|
@ -75,12 +71,15 @@ class AhoyWifi : public AhoyNetwork {
|
||||||
DBGPRINT(" " + String(bssid[j], HEX));
|
DBGPRINT(" " + String(bssid[j], HEX));
|
||||||
}
|
}
|
||||||
DBGPRINTLN("");
|
DBGPRINTLN("");
|
||||||
|
setStaticIp();
|
||||||
WiFi.begin(mConfig->sys.stationSsid, mConfig->sys.stationPwd, 0, &bssid[0]);
|
WiFi.begin(mConfig->sys.stationSsid, mConfig->sys.stationPwd, 0, &bssid[0]);
|
||||||
|
mWifiConnecting = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NetworkState::CONNECTING:
|
case NetworkState::CONNECTING:
|
||||||
if (isTimeout(TIMEOUT)) {
|
if (isTimeout(TIMEOUT)) {
|
||||||
WiFi.disconnect();
|
WiFi.disconnect();
|
||||||
|
mWifiConnecting = false;
|
||||||
mStatus = mBSSIDList.empty() ? NetworkState::DISCONNECTED : NetworkState::SCAN_READY;
|
mStatus = mBSSIDList.empty() ? NetworkState::DISCONNECTED : NetworkState::SCAN_READY;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -117,6 +116,12 @@ class AhoyWifi : public AhoyNetwork {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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 getBSSIDs() {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
int n = WiFi.scanComplete();
|
int n = WiFi.scanComplete();
|
||||||
|
|
|
@ -23,7 +23,7 @@ extra_scripts =
|
||||||
pre:../scripts/convertHtml.py
|
pre:../scripts/convertHtml.py
|
||||||
pre:../scripts/applyPatches.py
|
pre:../scripts/applyPatches.py
|
||||||
pre:../scripts/reduceGxEPD2.py
|
pre:../scripts/reduceGxEPD2.py
|
||||||
;;post:../scripts/add_littlefs_binary.py
|
post:../scripts/add_littlefs_binary.py
|
||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
https://github.com/esphome/ESPAsyncWebServer @ ^3.2.2
|
https://github.com/esphome/ESPAsyncWebServer @ ^3.2.2
|
||||||
|
@ -155,7 +155,7 @@ monitor_filters =
|
||||||
platform = espressif32@6.6.0
|
platform = espressif32@6.6.0
|
||||||
board = lolin_d32
|
board = lolin_d32
|
||||||
build_flags = ${env.build_flags}
|
build_flags = ${env.build_flags}
|
||||||
;;-DSPI_HAL
|
-DSPI_HAL
|
||||||
monitor_filters =
|
monitor_filters =
|
||||||
esp32_exception_decoder
|
esp32_exception_decoder
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ platform = espressif32@6.6.0
|
||||||
board = lolin_s2_mini
|
board = lolin_s2_mini
|
||||||
build_flags = ${env.build_flags}
|
build_flags = ${env.build_flags}
|
||||||
-DUSE_HSPI_FOR_EPD
|
-DUSE_HSPI_FOR_EPD
|
||||||
;;-DSPI_HAL
|
-DSPI_HAL
|
||||||
-DENABLE_MQTT
|
-DENABLE_MQTT
|
||||||
-DPLUGIN_DISPLAY
|
-DPLUGIN_DISPLAY
|
||||||
-DENABLE_HISTORY
|
-DENABLE_HISTORY
|
||||||
|
@ -262,7 +262,7 @@ platform = espressif32@6.6.0
|
||||||
board = lolin_c3_mini
|
board = lolin_c3_mini
|
||||||
build_flags = ${env.build_flags}
|
build_flags = ${env.build_flags}
|
||||||
-DUSE_HSPI_FOR_EPD
|
-DUSE_HSPI_FOR_EPD
|
||||||
;;-DSPI_HAL
|
-DSPI_HAL
|
||||||
-DENABLE_MQTT
|
-DENABLE_MQTT
|
||||||
-DPLUGIN_DISPLAY
|
-DPLUGIN_DISPLAY
|
||||||
-DENABLE_HISTORY
|
-DENABLE_HISTORY
|
||||||
|
@ -353,6 +353,7 @@ build_flags = ${env:opendtufusion-zero_export.build_flags}
|
||||||
|
|
||||||
[env:opendtufusion-ethernet]
|
[env:opendtufusion-ethernet]
|
||||||
platform = espressif32@6.6.0
|
platform = espressif32@6.6.0
|
||||||
|
platform = espressif32@6.6.0
|
||||||
board = esp32-s3-devkitc-1
|
board = esp32-s3-devkitc-1
|
||||||
upload_protocol = esp-builtin
|
upload_protocol = esp-builtin
|
||||||
build_flags = ${env:opendtufusion-minimal.build_flags}
|
build_flags = ${env:opendtufusion-minimal.build_flags}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include <U8g2lib.h>
|
#include <U8g2lib.h>
|
||||||
|
|
||||||
#include "../../hm/hmSystem.h"
|
#include "../../hm/hmSystem.h"
|
||||||
#include "../../hm/hmRadio.h"
|
#include "../../hm/NrfRadio.h"
|
||||||
#include "../../utils/helper.h"
|
#include "../../utils/helper.h"
|
||||||
#include "../plugin_lang.h"
|
#include "../plugin_lang.h"
|
||||||
#include "Display_Mono.h"
|
#include "Display_Mono.h"
|
||||||
|
@ -25,9 +25,9 @@ class Display {
|
||||||
mMono = NULL;
|
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;
|
mApp = app;
|
||||||
mHmRadio = hmradio;
|
mNrfRadio = nrfRadio;
|
||||||
mHmsRadio = hmsradio;
|
mHmsRadio = hmsradio;
|
||||||
mCfg = cfg;
|
mCfg = cfg;
|
||||||
mSys = sys;
|
mSys = sys;
|
||||||
|
@ -149,7 +149,7 @@ class Display {
|
||||||
mDisplayData.totalYieldDay = totalYieldDay;
|
mDisplayData.totalYieldDay = totalYieldDay;
|
||||||
mDisplayData.totalYieldTotal = totalYieldTotal;
|
mDisplayData.totalYieldTotal = totalYieldTotal;
|
||||||
bool nrf_en = mApp->getNrfEnabled();
|
bool nrf_en = mApp->getNrfEnabled();
|
||||||
bool nrf_ok = nrf_en && mHmRadio->isChipConnected();
|
bool nrf_ok = nrf_en && mNrfRadio->isChipConnected();
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
bool cmt_en = mApp->getCmtEnabled();
|
bool cmt_en = mApp->getCmtEnabled();
|
||||||
bool cmt_ok = cmt_en && mHmsRadio->isChipConnected();
|
bool cmt_ok = cmt_en && mHmsRadio->isChipConnected();
|
||||||
|
@ -231,7 +231,7 @@ class Display {
|
||||||
uint32_t *mUtcTs = nullptr;
|
uint32_t *mUtcTs = nullptr;
|
||||||
display_t *mCfg = nullptr;
|
display_t *mCfg = nullptr;
|
||||||
HMSYSTEM *mSys = nullptr;
|
HMSYSTEM *mSys = nullptr;
|
||||||
RADIO *mHmRadio = nullptr;
|
RADIO *mNrfRadio = nullptr;
|
||||||
RADIO *mHmsRadio = nullptr;
|
RADIO *mHmsRadio = nullptr;
|
||||||
uint16_t mRefreshCycle = 0;
|
uint16_t mRefreshCycle = 0;
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,12 @@
|
||||||
#include "Display_ePaper.h"
|
#include "Display_ePaper.h"
|
||||||
|
|
||||||
#ifdef ESP8266
|
#if defined(ESP32)
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#elif defined(ESP32)
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#endif
|
|
||||||
#include "../../utils/helper.h"
|
#include "../../utils/helper.h"
|
||||||
#include "imagedata.h"
|
#include "imagedata.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "../plugin_lang.h"
|
#include "../plugin_lang.h"
|
||||||
|
|
||||||
#if defined(ESP32)
|
|
||||||
|
|
||||||
static const uint32_t spiClk = 4000000; // 4 MHz
|
static const uint32_t spiClk = 4000000; // 4 MHz
|
||||||
|
|
||||||
#if defined(ESP32) && defined(USE_HSPI_FOR_EPD)
|
#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) {
|
if (DISP_TYPE_T10_EPAPER == type) {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
_display = new GxEPD2_BW<GxEPD2_150_BN, GxEPD2_150_BN::HEIGHT>(GxEPD2_150_BN(_CS, _DC, _RST, _BUSY));
|
|
||||||
|
|
||||||
#if defined(ESP32) && defined(USE_HSPI_FOR_EPD)
|
#if defined(SPI_HAL)
|
||||||
hspi.begin(_SCK, _BUSY, _MOSI, _CS);
|
hal.init(_MOSI, _DC, _SCK, _CS, _RST, _BUSY);
|
||||||
_display->epd2.selectSPI(hspi, SPISettings(spiClk, MSBFIRST, SPI_MODE0));
|
_display = new GxEPD2_BW<GxEPD2_150_BN, GxEPD2_150_BN::HEIGHT>(GxEPD2_150_BN(&hal));
|
||||||
#elif defined(ESP32)
|
#else
|
||||||
_display->epd2.init(_SCK, _MOSI, 115200, true, 20, false);
|
_display = new GxEPD2_BW<GxEPD2_150_BN, GxEPD2_150_BN::HEIGHT>(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
|
#endif
|
||||||
_display->init(115200, true, 20, false);
|
_display->init(115200, true, 20, false);
|
||||||
_display->setRotation(mDisplayRotation);
|
_display->setRotation(mDisplayRotation);
|
||||||
|
|
|
@ -12,7 +12,11 @@
|
||||||
#define EPAPER_MAX_TEXT_LEN 35
|
#define EPAPER_MAX_TEXT_LEN 35
|
||||||
|
|
||||||
#include <GxEPD2_BW.h>
|
#include <GxEPD2_BW.h>
|
||||||
|
#if defined(SPI_HAL)
|
||||||
|
#include "epdHal.h"
|
||||||
|
#else
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// FreeFonts from Adafruit_GFX
|
// FreeFonts from Adafruit_GFX
|
||||||
#include <Fonts/FreeSans12pt7b.h>
|
#include <Fonts/FreeSans12pt7b.h>
|
||||||
|
@ -60,6 +64,9 @@ class DisplayEPaper {
|
||||||
const char* _version;
|
const char* _version;
|
||||||
RefreshStatus mRefreshState, mNextRefreshState;
|
RefreshStatus mRefreshState, mNextRefreshState;
|
||||||
uint8_t mSecondCnt;
|
uint8_t mSecondCnt;
|
||||||
|
#if defined(SPI_HAL)
|
||||||
|
epdHal hal;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ESP32
|
#endif // ESP32
|
||||||
|
|
304
src/plugins/Display/epdHal.h
Normal file
304
src/plugins/Display/epdHal.h
Normal file
|
@ -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 <esp_rom_gpio.h>
|
||||||
|
#include <GxEPD2_BW.h>
|
||||||
|
|
||||||
|
|
||||||
|
#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<gpio_num_t>(mosi);
|
||||||
|
mPinDc = static_cast<gpio_num_t>(dc);
|
||||||
|
mPinClk = static_cast<gpio_num_t>(sclk);
|
||||||
|
mPinCs = static_cast<gpio_num_t>(cs);
|
||||||
|
mPinRst = static_cast<gpio_num_t>(rst);
|
||||||
|
mPinBusy = static_cast<gpio_num_t>(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<gpio_mode_t>(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<size_t>(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<size_t>(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<size_t>(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<size_t>(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<size_t>(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<size_t>(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__*/
|
67
src/plugins/MaxPower.h
Normal file
67
src/plugins/MaxPower.h
Normal file
|
@ -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 <array>
|
||||||
|
#include <utility>
|
||||||
|
#include "../hm/hmDefines.h"
|
||||||
|
|
||||||
|
template<class T=float>
|
||||||
|
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<std::pair<uint32_t, T>, MAX_NUM_INVERTERS> mValues;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -57,17 +57,15 @@ class HistoryData {
|
||||||
|
|
||||||
void tickerSecond() {
|
void tickerSecond() {
|
||||||
float curPwr = 0;
|
float curPwr = 0;
|
||||||
//float maxPwr = 0;
|
|
||||||
float yldDay = -0.1;
|
float yldDay = -0.1;
|
||||||
uint32_t ts = 0;
|
uint32_t ts = 0;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < mSys->getNumInverters(); i++) {
|
for (uint8_t i = 0; i < mSys->getNumInverters(); i++) {
|
||||||
Inverter<> *iv = mSys->getInverterByPos(i);
|
Inverter<> *iv = mSys->getInverterByPos(i);
|
||||||
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
|
||||||
if (iv == NULL)
|
if (iv == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
||||||
curPwr += iv->getChannelFieldValue(CH0, FLD_PAC, rec);
|
curPwr += iv->getChannelFieldValue(CH0, FLD_PAC, rec);
|
||||||
//maxPwr += iv->getChannelFieldValue(CH0, FLD_MP, rec);
|
|
||||||
yldDay += iv->getChannelFieldValue(CH0, FLD_YD, rec);
|
yldDay += iv->getChannelFieldValue(CH0, FLD_YD, rec);
|
||||||
if (rec->ts > ts)
|
if (rec->ts > ts)
|
||||||
ts = rec->ts;
|
ts = rec->ts;
|
||||||
|
@ -81,8 +79,6 @@ class HistoryData {
|
||||||
if (curPwr > mMaximumDay)
|
if (curPwr > mMaximumDay)
|
||||||
mMaximumDay = roundf(curPwr);
|
mMaximumDay = roundf(curPwr);
|
||||||
}
|
}
|
||||||
//if (maxPwr > 0)
|
|
||||||
// mMaximumDay = roundf(maxPwr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((++mCurPwrDay.loopCnt % mCurPwrDay.refreshCycle) == 0) {
|
if ((++mCurPwrDay.loopCnt % mCurPwrDay.refreshCycle) == 0) {
|
||||||
|
|
|
@ -63,7 +63,7 @@ class PubMqtt {
|
||||||
mUptime = uptime;
|
mUptime = uptime;
|
||||||
mIntervalTimeout = 1;
|
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) {
|
SendIvData.setPublishFunc([this](const char *subTopic, const char *payload, bool retained, uint8_t qos) {
|
||||||
publish(subTopic, payload, retained, true, qos);
|
publish(subTopic, payload, retained, true, qos);
|
||||||
});
|
});
|
||||||
|
@ -206,6 +206,9 @@ class PubMqtt {
|
||||||
else
|
else
|
||||||
snprintf(mTopic.data(), mTopic.size(), "%s", subTopic);
|
snprintf(mTopic.data(), mTopic.size(), "%s", subTopic);
|
||||||
|
|
||||||
|
if(!mCfgMqtt->enableRetain)
|
||||||
|
retained = false;
|
||||||
|
|
||||||
mClient.publish(mTopic.data(), qos, retained, payload);
|
mClient.publish(mTopic.data(), qos, retained, payload);
|
||||||
yield();
|
yield();
|
||||||
mTxCnt++;
|
mTxCnt++;
|
||||||
|
@ -254,7 +257,8 @@ class PubMqtt {
|
||||||
void setPowerLimitAck(Inverter<> *iv) {
|
void setPowerLimitAck(Inverter<> *iv) {
|
||||||
if (NULL != iv) {
|
if (NULL != iv) {
|
||||||
snprintf(mSubTopic.data(), mSubTopic.size(), "%s/%s", iv->config->name, subtopics[MQTT_ACK_PWR_LMT]);
|
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]]);
|
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;
|
size_t size = measureJson(doc2) + 1;
|
||||||
serializeJson(doc2, buf.data(), size);
|
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)) {
|
if(++mDiscovery.sub == ((!total) ? (rec->length) : 4)) {
|
||||||
mDiscovery.sub = 0;
|
mDiscovery.sub = 0;
|
||||||
|
@ -577,6 +582,9 @@ class PubMqtt {
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendData(Inverter<> *iv, uint8_t curInfoCmd) {
|
void sendData(Inverter<> *iv, uint8_t curInfoCmd) {
|
||||||
|
if (mCfgMqtt->json)
|
||||||
|
return;
|
||||||
|
|
||||||
record_t<> *rec = iv->getRecordStruct(curInfoCmd);
|
record_t<> *rec = iv->getRecordStruct(curInfoCmd);
|
||||||
|
|
||||||
uint32_t lastTs = iv->getLastTs(rec);
|
uint32_t lastTs = iv->getLastTs(rec);
|
||||||
|
@ -620,6 +628,10 @@ class PubMqtt {
|
||||||
mLastAnyAvail = anyAvail;
|
mLastAnyAvail = anyAvail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum {MQTT_STATUS_OFFLINE = 0, MQTT_STATUS_PARTIAL, MQTT_STATUS_ONLINE};
|
||||||
|
|
||||||
|
private:
|
||||||
espMqttClient mClient;
|
espMqttClient mClient;
|
||||||
cfgMqtt_t *mCfgMqtt = nullptr;
|
cfgMqtt_t *mCfgMqtt = nullptr;
|
||||||
IApp *mApp;
|
IApp *mApp;
|
||||||
|
|
|
@ -24,8 +24,10 @@ class PubMqttIvData {
|
||||||
public:
|
public:
|
||||||
PubMqttIvData() : mTotal{}, mSubTopic{}, mVal{} {}
|
PubMqttIvData() : mTotal{}, mSubTopic{}, mVal{} {}
|
||||||
|
|
||||||
void setup(HMSYSTEM *sys, uint32_t *utcTs, std::queue<sendListCmdIv> *sendList) {
|
void setup(IApp *app, HMSYSTEM *sys, cfgMqtt_t *cfg_mqtt, uint32_t *utcTs, std::queue<sendListCmdIv> *sendList) {
|
||||||
|
mApp = app;
|
||||||
mSys = sys;
|
mSys = sys;
|
||||||
|
mCfg = cfg_mqtt;
|
||||||
mUtcTimestamp = utcTs;
|
mUtcTimestamp = utcTs;
|
||||||
mSendList = sendList;
|
mSendList = sendList;
|
||||||
mState = IDLE;
|
mState = IDLE;
|
||||||
|
@ -114,7 +116,7 @@ class PubMqttIvData {
|
||||||
mPublish(mSubTopic.data(), mVal.data(), true, QOS_0);
|
mPublish(mSubTopic.data(), mVal.data(), true, QOS_0);
|
||||||
|
|
||||||
if((mIv->ivGen == IV_HMS) || (mIv->ivGen == IV_HMT)) {
|
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);
|
snprintf(mVal.data(), mVal.size(), "%d", mIv->rssi);
|
||||||
mPublish(mSubTopic.data(), mVal.data(), false, QOS_0);
|
mPublish(mSubTopic.data(), mVal.data(), false, QOS_0);
|
||||||
}
|
}
|
||||||
|
@ -168,9 +170,6 @@ class PubMqttIvData {
|
||||||
case FLD_PDC:
|
case FLD_PDC:
|
||||||
mTotal[3] += mIv->getValue(mPos, rec);
|
mTotal[3] += mIv->getValue(mPos, rec);
|
||||||
break;
|
break;
|
||||||
case FLD_MP:
|
|
||||||
mTotal[4] += mIv->getValue(mPos, rec);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
mAllTotalFound = false;
|
mAllTotalFound = false;
|
||||||
|
@ -195,18 +194,45 @@ class PubMqttIvData {
|
||||||
static_cast<int>(mIv->getChannelFieldValue(CH0, FLD_GRID_PROFILE_CODE, rec)),
|
static_cast<int>(mIv->getChannelFieldValue(CH0, FLD_GRID_PROFILE_CODE, rec)),
|
||||||
static_cast<int>(mIv->getChannelFieldValue(CH0, FLD_GRID_PROFILE_VERSION, rec)));
|
static_cast<int>(mIv->getChannelFieldValue(CH0, FLD_GRID_PROFILE_VERSION, rec)));
|
||||||
} else {
|
} else {
|
||||||
snprintf(mSubTopic.data(), mSubTopic.size(), "%s/ch%d/%s", mIv->config->name, rec->assign[mPos].ch, fields[rec->assign[mPos].fieldId]);
|
if (!mCfg->json) {
|
||||||
snprintf(mVal.data(), mVal.size(), "%g", ah::round3(mIv->getValue(mPos, rec)));
|
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 ((InverterDevInform_All == mCmd) || (InverterDevInform_Simple == mCmd) || !mCfg->json) {
|
||||||
if((FLD_EVT != rec->assign[mPos].fieldId)
|
uint8_t qos = (FLD_ACT_ACTIVE_PWR_LIMIT == rec->assign[mPos].fieldId) ? QOS_2 : QOS_0;
|
||||||
&& (FLD_LAST_ALARM_CODE != rec->assign[mPos].fieldId))
|
if((FLD_EVT != rec->assign[mPos].fieldId)
|
||||||
mPublish(mSubTopic.data(), mVal.data(), retained, qos);
|
&& (FLD_LAST_ALARM_CODE != rec->assign[mPos].fieldId))
|
||||||
|
mPublish(mSubTopic.data(), mVal.data(), retained, qos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mPos++;
|
mPos++;
|
||||||
} else {
|
} else {
|
||||||
if (MqttSentStatus::LAST_SUCCESS_SENT == rec->mqttSentStatus) {
|
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);
|
sendRadioStat(rec->length);
|
||||||
rec->mqttSentStatus = MqttSentStatus::DATA_SENT;
|
rec->mqttSentStatus = MqttSentStatus::DATA_SENT;
|
||||||
}
|
}
|
||||||
|
@ -261,19 +287,40 @@ class PubMqttIvData {
|
||||||
case 4:
|
case 4:
|
||||||
fieldId = FLD_MP;
|
fieldId = FLD_MP;
|
||||||
retained = false;
|
retained = false;
|
||||||
|
mTotal[4] = mApp->getTotalMaxPower();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
snprintf(mSubTopic.data(), mSubTopic.size(), "total/%s", fields[fieldId]);
|
if (!mCfg->json) {
|
||||||
snprintf(mVal.data(), mVal.size(), "%g", ah::round3(mTotal[mPos]));
|
snprintf(mSubTopic.data(), mSubTopic.size(), "total/%s", fields[fieldId]);
|
||||||
mPublish(mSubTopic.data(), mVal.data(), retained, QOS_0);
|
snprintf(mVal.data(), mVal.size(), "%g", ah::round3(mTotal[mPos]));
|
||||||
|
mPublish(mSubTopic.data(), mVal.data(), retained, QOS_0);
|
||||||
|
}
|
||||||
mPos++;
|
mPos++;
|
||||||
} else {
|
} 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();
|
mSendList->pop();
|
||||||
mSendTotals = false;
|
mSendTotals = false;
|
||||||
mState = IDLE;
|
mState = IDLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
IApp *mApp = nullptr;
|
||||||
|
cfgMqtt_t *mCfg = nullptr;
|
||||||
|
|
||||||
HMSYSTEM *mSys = nullptr;
|
HMSYSTEM *mSys = nullptr;
|
||||||
uint32_t *mUtcTimestamp = nullptr;
|
uint32_t *mUtcTimestamp = nullptr;
|
||||||
pubMqttPublisherType mPublish;
|
pubMqttPublisherType mPublish;
|
||||||
|
@ -291,7 +338,7 @@ class PubMqttIvData {
|
||||||
bool mRTRDataHasBeenSent = false;
|
bool mRTRDataHasBeenSent = false;
|
||||||
|
|
||||||
std::array<char, (32 + MAX_NAME_LENGTH + 1)> mSubTopic;
|
std::array<char, (32 + MAX_NAME_LENGTH + 1)> mSubTopic;
|
||||||
std::array<char, 160> mVal;
|
std::array<char, 300> mVal;
|
||||||
|
|
||||||
std::queue<sendListCmdIv> *mSendList = nullptr;
|
std::queue<sendListCmdIv> *mSendList = nullptr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -110,7 +110,7 @@
|
||||||
|
|
||||||
#if DEBUG_LEVEL >= DBG_ERROR
|
#if DEBUG_LEVEL >= DBG_ERROR
|
||||||
#define PERR(str) DBGPRINT(F("E: ")); DBGPRINT(str);
|
#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
|
#else
|
||||||
#define PERR(str)
|
#define PERR(str)
|
||||||
#define PERRLN(str)
|
#define PERRLN(str)
|
||||||
|
|
|
@ -5,5 +5,6 @@
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
#include "spiPatcher.h"
|
#include "spiPatcher.h"
|
||||||
SpiPatcher *SpiPatcher::mInstance = nullptr;
|
SpiPatcher *SpiPatcher::InstanceHost2 = nullptr;
|
||||||
|
SpiPatcher *SpiPatcher::InstanceHost3 = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,23 +9,38 @@
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
|
|
||||||
|
#include "dbg.h"
|
||||||
#include "spiPatcherHandle.h"
|
#include "spiPatcherHandle.h"
|
||||||
|
|
||||||
#include <driver/spi_master.h>
|
#include <driver/spi_master.h>
|
||||||
#include <freertos/semphr.h>
|
#include <freertos/semphr.h>
|
||||||
|
|
||||||
|
#if (SOC_SPI_PERIPH_NUM > 2)
|
||||||
|
#define SPI_HOST_OTHER SPI3_HOST
|
||||||
|
#else
|
||||||
|
#define SPI_HOST_OTHER SPI2_HOST
|
||||||
|
#endif
|
||||||
|
|
||||||
class SpiPatcher {
|
class SpiPatcher {
|
||||||
protected:
|
protected:
|
||||||
explicit SpiPatcher(spi_host_device_t dev) :
|
explicit SpiPatcher(spi_host_device_t dev) :
|
||||||
mHostDevice(dev), mCurHandle(nullptr) {
|
mCurHandle(nullptr) {
|
||||||
// Use binary semaphore instead of mutex for performance reasons
|
// Use binary semaphore instead of mutex for performance reasons
|
||||||
mutex = xSemaphoreCreateBinaryStatic(&mutex_buffer);
|
mutex = xSemaphoreCreateBinaryStatic(&mutex_buffer);
|
||||||
xSemaphoreGive(mutex);
|
xSemaphoreGive(mutex);
|
||||||
|
mDev = dev;
|
||||||
|
mBusState = ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
spi_bus_config_t buscfg = {
|
public:
|
||||||
.mosi_io_num = -1,
|
SpiPatcher(const SpiPatcher &other) = delete;
|
||||||
.miso_io_num = -1,
|
void operator=(const SpiPatcher &) = delete;
|
||||||
.sclk_io_num = -1,
|
|
||||||
|
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,
|
.quadwp_io_num = -1,
|
||||||
.quadhd_io_num = -1,
|
.quadhd_io_num = -1,
|
||||||
.data4_io_num = -1,
|
.data4_io_num = -1,
|
||||||
|
@ -36,26 +51,48 @@ class SpiPatcher {
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.intr_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)));
|
||||||
|
|
||||||
|
return mBusState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
static SpiPatcher* getInstance(spi_host_device_t dev, bool initialize = true) {
|
||||||
SpiPatcher(SpiPatcher &other) = delete;
|
if(SPI2_HOST == dev) {
|
||||||
void operator=(const SpiPatcher &) = delete;
|
if(nullptr == InstanceHost2) {
|
||||||
|
InstanceHost2 = new SpiPatcher(dev);
|
||||||
static SpiPatcher* getInstance(spi_host_device_t dev) {
|
if(initialize)
|
||||||
if(nullptr == mInstance)
|
InstanceHost2->initBus();
|
||||||
mInstance = new SpiPatcher(dev);
|
}
|
||||||
return mInstance;
|
return InstanceHost2;
|
||||||
|
} else { // SPI3_HOST
|
||||||
|
if(nullptr == InstanceHost3) {
|
||||||
|
InstanceHost3 = new SpiPatcher(dev);
|
||||||
|
if(initialize)
|
||||||
|
InstanceHost3->initBus();
|
||||||
|
}
|
||||||
|
return InstanceHost3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~SpiPatcher() { vSemaphoreDelete(mutex); }
|
~SpiPatcher() { vSemaphoreDelete(mutex); }
|
||||||
|
|
||||||
spi_host_device_t getDevice() {
|
inline void addDevice(spi_host_device_t host_id, const spi_device_interface_config_t *dev_config, spi_device_handle_t *handle) {
|
||||||
return mHostDevice;
|
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) {
|
inline void request(SpiPatcherHandle* handle) {
|
||||||
|
assert(mBusState == ESP_OK);
|
||||||
xSemaphoreTake(mutex, portMAX_DELAY);
|
xSemaphoreTake(mutex, portMAX_DELAY);
|
||||||
|
|
||||||
if (mCurHandle != handle) {
|
if (mCurHandle != handle) {
|
||||||
|
@ -70,17 +107,22 @@ class SpiPatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void release() {
|
inline void release() {
|
||||||
|
assert(mBusState == ESP_OK);
|
||||||
xSemaphoreGive(mutex);
|
xSemaphoreGive(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static SpiPatcher *mInstance;
|
static SpiPatcher *InstanceHost2;
|
||||||
|
static SpiPatcher *InstanceHost3;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const spi_host_device_t mHostDevice;
|
|
||||||
SpiPatcherHandle* mCurHandle;
|
SpiPatcherHandle* mCurHandle;
|
||||||
SemaphoreHandle_t mutex;
|
SemaphoreHandle_t mutex;
|
||||||
StaticSemaphore_t mutex_buffer;
|
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*/
|
#endif /*ESP32*/
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Protection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Protection(Protection &other) = delete;
|
Protection(const Protection &other) = delete;
|
||||||
void operator=(const Protection &) = delete;
|
void operator=(const Protection &) = delete;
|
||||||
|
|
||||||
static Protection* getInstance(const char *pwd) {
|
static Protection* getInstance(const char *pwd) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ class RestApi {
|
||||||
mApp = app;
|
mApp = app;
|
||||||
mSrv = srv;
|
mSrv = srv;
|
||||||
mSys = sys;
|
mSys = sys;
|
||||||
mRadioNrf = (HmRadio<>*)mApp->getRadioObj(true);
|
mRadioNrf = (NrfRadio<>*)mApp->getRadioObj(true);
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
mRadioCmt = (CmtRadio<>*)mApp->getRadioObj(false);
|
mRadioCmt = (CmtRadio<>*)mApp->getRadioObj(false);
|
||||||
#endif
|
#endif
|
||||||
|
@ -56,6 +56,9 @@ class RestApi {
|
||||||
mSrv->on("/api", HTTP_GET, std::bind(&RestApi::onApi, this, std::placeholders::_1));
|
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));
|
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) {
|
uint32_t getTimezoneOffset(void) {
|
||||||
|
@ -104,9 +107,10 @@ class RestApi {
|
||||||
else if(path == "setup/getip") getIp(root);
|
else if(path == "setup/getip") getIp(root);
|
||||||
#endif /* !defined(ETHERNET) */
|
#endif /* !defined(ETHERNET) */
|
||||||
else if(path == "live") getLive(request,root);
|
else if(path == "live") getLive(request,root);
|
||||||
else if (path == "powerHistory") getPowerHistory(request, root);
|
#if defined(ENABLE_HISTORY)
|
||||||
else if (path == "powerHistoryDay") getPowerHistoryDay(request, root);
|
else if (path == "powerHistory") getPowerHistory(request, root, HistoryStorageType::POWER);
|
||||||
else if (path == "yieldDayHistory") getYieldDayHistory(request, root);
|
else if (path == "powerHistoryDay") getPowerHistory(request, root, HistoryStorageType::POWER_DAY);
|
||||||
|
#endif /*ENABLE_HISTORY*/
|
||||||
else {
|
else {
|
||||||
if(path.substring(0, 12) == "inverter/id/")
|
if(path.substring(0, 12) == "inverter/id/")
|
||||||
getInverter(root, request->url().substring(17).toInt());
|
getInverter(root, request->url().substring(17).toInt());
|
||||||
|
@ -299,7 +303,6 @@ class RestApi {
|
||||||
#if defined(ENABLE_HISTORY)
|
#if defined(ENABLE_HISTORY)
|
||||||
ep[F("powerHistory")] = url + F("powerHistory");
|
ep[F("powerHistory")] = url + F("powerHistory");
|
||||||
ep[F("powerHistoryDay")] = url + F("powerHistoryDay");
|
ep[F("powerHistoryDay")] = url + F("powerHistoryDay");
|
||||||
ep[F("yieldDayHistory")] = url + F("yieldDayHistory");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,6 +352,36 @@ class RestApi {
|
||||||
fp.close();
|
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) {
|
void getGeneric(AsyncWebServerRequest *request, JsonObject obj) {
|
||||||
mApp->resetLockTimeout();
|
mApp->resetLockTimeout();
|
||||||
#if !defined(ETHERNET)
|
#if !defined(ETHERNET)
|
||||||
|
@ -360,6 +393,7 @@ class RestApi {
|
||||||
obj[F("modules")] = String(mApp->getVersionModules());
|
obj[F("modules")] = String(mApp->getVersionModules());
|
||||||
obj[F("build")] = String(AUTO_GIT_HASH);
|
obj[F("build")] = String(AUTO_GIT_HASH);
|
||||||
obj[F("env")] = String(ENV_NAME);
|
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_prot")] = mApp->isProtected(request->client()->remoteIP().toString().c_str(), "", true);
|
||||||
obj[F("menu_mask")] = (uint16_t)(mConfig->sys.protectionMask );
|
obj[F("menu_mask")] = (uint16_t)(mConfig->sys.protectionMask );
|
||||||
obj[F("menu_protEn")] = (bool) (mConfig->sys.adminPwd[0] != '\0');
|
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("dark_mode")] = (bool)mConfig->sys.darkMode;
|
||||||
obj[F("sched_reboot")] = (bool)mConfig->sys.schedReboot;
|
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("pwd_set")] = (strlen(mConfig->sys.adminPwd) > 0);
|
||||||
obj[F("prot_mask")] = mConfig->sys.protectionMask;
|
obj[F("prot_mask")] = mConfig->sys.protectionMask;
|
||||||
|
|
||||||
|
@ -436,8 +469,13 @@ class RestApi {
|
||||||
void getHtmlSystem(AsyncWebServerRequest *request, JsonObject obj) {
|
void getHtmlSystem(AsyncWebServerRequest *request, JsonObject obj) {
|
||||||
getSysInfo(request, obj.createNestedObject(F("system")));
|
getSysInfo(request, obj.createNestedObject(F("system")));
|
||||||
getGeneric(request, obj.createNestedObject(F("generic")));
|
getGeneric(request, obj.createNestedObject(F("generic")));
|
||||||
|
#if defined(ESP32)
|
||||||
|
char tmp[300];
|
||||||
|
snprintf(tmp, 300, "<a href=\"/factory\" class=\"btn\">%s</a><br/><br/><a href=\"/reboot\" class=\"btn\">%s</a><br/><br/><a href=\"/coredump\" class=\"btn\">%s</a>", FACTORY_RESET, BTN_REBOOT, BTN_COREDUMP);
|
||||||
|
#else
|
||||||
char tmp[200];
|
char tmp[200];
|
||||||
snprintf(tmp, 200, "<a href=\"/factory\" class=\"btn\">%s</a><br/><br/><a href=\"/reboot\" class=\"btn\">%s</a>", FACTORY_RESET, BTN_REBOOT);
|
snprintf(tmp, 200, "<a href=\"/factory\" class=\"btn\">%s</a><br/><br/><a href=\"/reboot\" class=\"btn\">%s</a>", FACTORY_RESET, BTN_REBOOT);
|
||||||
|
#endif
|
||||||
obj[F("html")] = String(tmp);
|
obj[F("html")] = String(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,7 +528,9 @@ class RestApi {
|
||||||
|
|
||||||
void getHtmlFactory(AsyncWebServerRequest *request, JsonObject obj) {
|
void getHtmlFactory(AsyncWebServerRequest *request, JsonObject obj) {
|
||||||
getGeneric(request, obj.createNestedObject(F("generic")));
|
getGeneric(request, obj.createNestedObject(F("generic")));
|
||||||
obj[F("html")] = F("Factory reset? <a class=\"btn\" href=\"/factorytrue\">yes</a> <a class=\"btn\" href=\"/\">no</a>");
|
char tmp[200];
|
||||||
|
snprintf(tmp, 200, "%s <a class=\"btn\" href=\"/factorytrue\">%s</a> <a class=\"btn\" href=\"/\">%s</a>", FACTORY_RESET, BTN_YES, BTN_NO);
|
||||||
|
obj[F("html")] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getHtmlFactoryTrue(AsyncWebServerRequest *request, JsonObject obj) {
|
void getHtmlFactoryTrue(AsyncWebServerRequest *request, JsonObject obj) {
|
||||||
|
@ -573,12 +613,13 @@ class RestApi {
|
||||||
}
|
}
|
||||||
obj[F("interval")] = String(mConfig->inst.sendInterval);
|
obj[F("interval")] = String(mConfig->inst.sendInterval);
|
||||||
obj[F("max_num_inverters")] = MAX_NUM_INVERTERS;
|
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("rstNotAvail")] = (bool)mConfig->inst.rstValsNotAvail;
|
||||||
obj[F("rstComStop")] = (bool)mConfig->inst.rstValsCommStop;
|
obj[F("rstComStop")] = (bool)mConfig->inst.rstValsCommStop;
|
||||||
|
obj[F("rstComStart")] = (bool)mConfig->inst.rstValsCommStart;
|
||||||
obj[F("strtWthtTm")] = (bool)mConfig->inst.startWithoutTime;
|
obj[F("strtWthtTm")] = (bool)mConfig->inst.startWithoutTime;
|
||||||
obj[F("rdGrid")] = (bool)mConfig->inst.readGrid;
|
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) {
|
void getInverter(JsonObject obj, uint8_t id) {
|
||||||
|
@ -603,6 +644,7 @@ class RestApi {
|
||||||
obj[F("alarm_cnt")] = iv->alarmCnt;
|
obj[F("alarm_cnt")] = iv->alarmCnt;
|
||||||
obj[F("rssi")] = iv->rssi;
|
obj[F("rssi")] = iv->rssi;
|
||||||
obj[F("ts_max_ac_pwr")] = iv->tsMaxAcPower;
|
obj[F("ts_max_ac_pwr")] = iv->tsMaxAcPower;
|
||||||
|
obj[F("ts_max_temp")] = iv->tsMaxTemperature;
|
||||||
|
|
||||||
JsonArray ch = obj.createNestedArray("ch");
|
JsonArray ch = obj.createNestedArray("ch");
|
||||||
|
|
||||||
|
@ -710,7 +752,9 @@ class RestApi {
|
||||||
obj[F("user")] = String(mConfig->mqtt.user);
|
obj[F("user")] = String(mConfig->mqtt.user);
|
||||||
obj[F("pwd")] = (strlen(mConfig->mqtt.pwd) > 0) ? F("{PWD}") : String("");
|
obj[F("pwd")] = (strlen(mConfig->mqtt.pwd) > 0) ? F("{PWD}") : String("");
|
||||||
obj[F("topic")] = String(mConfig->mqtt.topic);
|
obj[F("topic")] = String(mConfig->mqtt.topic);
|
||||||
|
obj[F("json")] = (bool) mConfig->mqtt.json;
|
||||||
obj[F("interval")] = String(mConfig->mqtt.interval);
|
obj[F("interval")] = String(mConfig->mqtt.interval);
|
||||||
|
obj[F("retain")] = (bool)mConfig->mqtt.enableRetain;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getNtp(JsonObject obj) {
|
void getNtp(JsonObject obj) {
|
||||||
|
@ -958,6 +1002,7 @@ class RestApi {
|
||||||
#if !defined(ETHERNET)
|
#if !defined(ETHERNET)
|
||||||
void getNetworks(JsonObject obj) {
|
void getNetworks(JsonObject obj) {
|
||||||
obj[F("success")] = mApp->getAvailNetworks(obj);
|
obj[F("success")] = mApp->getAvailNetworks(obj);
|
||||||
|
obj[F("ip")] = mApp->getIp();
|
||||||
}
|
}
|
||||||
#endif /* !defined(ETHERNET) */
|
#endif /* !defined(ETHERNET) */
|
||||||
|
|
||||||
|
@ -968,6 +1013,7 @@ class RestApi {
|
||||||
void getLive(AsyncWebServerRequest *request, JsonObject obj) {
|
void getLive(AsyncWebServerRequest *request, JsonObject obj) {
|
||||||
getGeneric(request, obj.createNestedObject(F("generic")));
|
getGeneric(request, obj.createNestedObject(F("generic")));
|
||||||
obj[F("refresh")] = mConfig->inst.sendInterval;
|
obj[F("refresh")] = mConfig->inst.sendInterval;
|
||||||
|
obj[F("max_total_pwr")] = ah::round3(mApp->getTotalMaxPower());
|
||||||
|
|
||||||
for (uint8_t fld = 0; fld < sizeof(acList); fld++) {
|
for (uint8_t fld = 0; fld < sizeof(acList); fld++) {
|
||||||
obj[F("ch0_fld_units")][fld] = String(units[fieldUnits[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")));
|
getGeneric(request, obj.createNestedObject(F("generic")));
|
||||||
#if defined(ENABLE_HISTORY)
|
obj[F("refresh")] = mApp->getHistoryPeriod(static_cast<uint8_t>(type));
|
||||||
obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::POWER);
|
|
||||||
uint16_t max = 0;
|
uint16_t max = 0;
|
||||||
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
|
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<uint8_t>(type), fld);
|
||||||
obj[F("value")][fld] = value;
|
obj[F("value")][fld] = value;
|
||||||
if (value > max)
|
if (value > max)
|
||||||
max = value;
|
max = value;
|
||||||
}
|
}
|
||||||
obj[F("max")] = max;
|
obj[F("max")] = max;
|
||||||
obj[F("lastValueTs")] = mApp->getHistoryLastValueTs((uint8_t)HistoryStorageType::POWER);
|
|
||||||
#endif /*ENABLE_HISTORY*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void getPowerHistoryDay(AsyncWebServerRequest *request, JsonObject obj){
|
if(HistoryStorageType::POWER_DAY == type) {
|
||||||
//getGeneric(request, obj.createNestedObject(F("generic")));
|
float yldDay = 0;
|
||||||
#if defined(ENABLE_HISTORY)
|
for (uint8_t i = 0; i < mSys->getNumInverters(); i++) {
|
||||||
obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::POWER_DAY);
|
Inverter<> *iv = mSys->getInverterByPos(i);
|
||||||
uint16_t max = 0;
|
if (iv == NULL)
|
||||||
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
|
continue;
|
||||||
uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::POWER_DAY, fld);
|
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
||||||
obj[F("value")][fld] = value;
|
yldDay += iv->getChannelFieldValue(CH0, FLD_YD, rec);
|
||||||
if (value > max)
|
}
|
||||||
max = value;
|
obj[F("yld")] = ah::round3(yldDay / 1000.0);
|
||||||
}
|
}
|
||||||
obj[F("max")] = max;
|
|
||||||
obj[F("lastValueTs")] = mApp->getHistoryLastValueTs((uint8_t)HistoryStorageType::POWER_DAY);
|
obj[F("lastValueTs")] = mApp->getHistoryLastValueTs(static_cast<uint8_t>(type));
|
||||||
#endif /*ENABLE_HISTORY*/
|
|
||||||
}
|
}
|
||||||
|
#endif /*ENABLE_HISTORY*/
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(ENABLE_HISTORY_YIELD_PER_DAY)
|
||||||
void getYieldDayHistory(AsyncWebServerRequest *request, JsonObject obj) {
|
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);
|
obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::YIELD);
|
||||||
uint16_t max = 0;
|
uint16_t max = 0;
|
||||||
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
|
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
|
||||||
|
@ -1033,8 +1076,8 @@ class RestApi {
|
||||||
max = value;
|
max = value;
|
||||||
}
|
}
|
||||||
obj[F("max")] = max;
|
obj[F("max")] = max;
|
||||||
#endif /*ENABLE_HISTORY*/
|
|
||||||
}
|
}
|
||||||
|
#endif /*ENABLE_HISTORY_YIELD_PER_DAY*/
|
||||||
|
|
||||||
bool setCtrl(JsonObject jsonIn, JsonObject jsonOut, const char *clientIP) {
|
bool setCtrl(JsonObject jsonIn, JsonObject jsonOut, const char *clientIP) {
|
||||||
if(jsonIn.containsKey(F("auth"))) {
|
if(jsonIn.containsKey(F("auth"))) {
|
||||||
|
@ -1076,8 +1119,6 @@ class RestApi {
|
||||||
iv->powerLimit[1] = AbsolutNonPersistent;
|
iv->powerLimit[1] = AbsolutNonPersistent;
|
||||||
|
|
||||||
accepted = iv->setDevControlRequest(ActivePowerContr);
|
accepted = iv->setDevControlRequest(ActivePowerContr);
|
||||||
if(accepted)
|
|
||||||
mApp->triggerTickSend(iv->id);
|
|
||||||
} else if(F("dev") == jsonIn[F("cmd")]) {
|
} else if(F("dev") == jsonIn[F("cmd")]) {
|
||||||
DPRINTLN(DBG_INFO, F("dev cmd"));
|
DPRINTLN(DBG_INFO, F("dev cmd"));
|
||||||
iv->setDevCommand(jsonIn[F("val")].as<int>());
|
iv->setDevCommand(jsonIn[F("val")].as<int>());
|
||||||
|
@ -1223,15 +1264,15 @@ class RestApi {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
constexpr static uint8_t acList[] = {FLD_UAC, FLD_IAC, FLD_PAC, FLD_F, FLD_PF, FLD_T, FLD_YT,
|
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,
|
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};
|
constexpr static uint8_t dcList[] = {FLD_UDC, FLD_IDC, FLD_PDC, FLD_YD, FLD_YT, FLD_IRR, FLD_MP};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IApp *mApp = nullptr;
|
IApp *mApp = nullptr;
|
||||||
HMSYSTEM *mSys = nullptr;
|
HMSYSTEM *mSys = nullptr;
|
||||||
HmRadio<> *mRadioNrf = nullptr;
|
NrfRadio<> *mRadioNrf = nullptr;
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
CmtRadio<> *mRadioCmt = nullptr;
|
CmtRadio<> *mRadioCmt = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<div class="p-2">Used Libraries</div>
|
<div class="p-2">Used Libraries</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row"><a href="https://github.com/bertmelis/espMqttClient" target="_blank">bertmelis/espMqttClient</a></div>
|
<div class="row"><a href="https://github.com/bertmelis/espMqttClient" target="_blank">bertmelis/espMqttClient</a></div>
|
||||||
<div class="row"><a href="https://github.com/yubox-node-org/ESPAsyncWebServer" target="_blank">yubox-node-org/ESPAsyncWebServer</a></div>
|
<div class="row"><a href="https://github.com/esphome/ESPAsyncWebServer" target="_blank">esphome/ESPAsyncWebServer</a></div>
|
||||||
<div class="row"><a href="https://github.com/bblanchon/ArduinoJson" target="_blank">bblanchon/ArduinoJson</a></div>
|
<div class="row"><a href="https://github.com/bblanchon/ArduinoJson" target="_blank">bblanchon/ArduinoJson</a></div>
|
||||||
<div class="row"><a href="https://github.com/nrf24/RF24" target="_blank">nrf24/RF24</a></div>
|
<div class="row"><a href="https://github.com/nrf24/RF24" target="_blank">nrf24/RF24</a></div>
|
||||||
<div class="row"><a href="https://github.com/paulstoffregen/Time" target="_blank">paulstoffregen/Time</a></div>
|
<div class="row"><a href="https://github.com/paulstoffregen/Time" target="_blank">paulstoffregen/Time</a></div>
|
||||||
|
|
|
@ -143,7 +143,7 @@ function parseVersion(obj) {
|
||||||
|
|
||||||
function parseESP(obj) {
|
function parseESP(obj) {
|
||||||
document.getElementById("esp_type").replaceChildren(
|
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;
|
icon = iconWifi1;
|
||||||
else if(obj["wifi_rssi"] <= -70)
|
else if(obj["wifi_rssi"] <= -70)
|
||||||
icon = iconWifi2;
|
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) {
|
function toIsoDateStr(d) {
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
--nav-bg: #333;
|
--nav-bg: #333;
|
||||||
--primary: #006ec0;
|
--primary: #006ec0;
|
||||||
|
--primary-disabled: #ccc;
|
||||||
--primary-hover: #044e86;
|
--primary-hover: #044e86;
|
||||||
--secondary: #0072c8;
|
--secondary: #0072c8;
|
||||||
--nav-active: #555;
|
--nav-active: #555;
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
--nav-bg: #333;
|
--nav-bg: #333;
|
||||||
--primary: #004d87;
|
--primary: #004d87;
|
||||||
|
--primary-disabled: #ccc;
|
||||||
--primary-hover: #023155;
|
--primary-hover: #023155;
|
||||||
--secondary: #0072c8;
|
--secondary: #0072c8;
|
||||||
--nav-active: #555;
|
--nav-active: #555;
|
||||||
|
|
|
@ -43,14 +43,10 @@
|
||||||
function calcScale(obj) {
|
function calcScale(obj) {
|
||||||
let s = {}
|
let s = {}
|
||||||
s.x_mul = 60
|
s.x_mul = 60
|
||||||
s.ts_start = obj.lastValueTs - (obj.refresh * obj.value.length)
|
s.ts_dur = obj.refresh * obj.value.length
|
||||||
s.ts_dur = obj.lastValueTs - s.ts_start
|
s.ts_start = obj.lastValueTs - s.ts_dur
|
||||||
s.ts_pad = (s.ts_dur < 1800) ? s.ts_start % 300 : s.ts_start % 1800
|
|
||||||
s.ts_dur -= s.ts_pad
|
|
||||||
while(s.x_mul * 10 <= 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_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
|
s.y_mul = 10
|
||||||
while(s.y_mul * 10 <= obj.max)
|
while(s.y_mul * 10 <= obj.max)
|
||||||
|
@ -79,7 +75,7 @@
|
||||||
...gridText(n*2, scale),
|
...gridText(n*2, scale),
|
||||||
mlNs("g", {transform: "translate(30, 5)"}, [
|
mlNs("g", {transform: "translate(30, 5)"}, [
|
||||||
...grid(n*2, scale),
|
...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) {
|
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)))
|
g.push(mlNs("text", {x: 0, y: height-(i*div)+9}, String(i)))
|
||||||
}
|
}
|
||||||
div = x2 / scale.x_max
|
div = x2 / scale.ts_dur
|
||||||
for(let i = 0; i < scale.x_max; i++) {
|
for(let i = 0; i < scale.ts_dur; i++) {
|
||||||
if((i + scale.ts_pad) % scale.x_mul == 0) {
|
if((i + scale.ts_start) % scale.x_mul == 0) {
|
||||||
let d = new Date((scale.ts_start + i) * 1000)
|
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)))
|
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) {
|
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"}))
|
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
|
div = x2 / scale.ts_dur
|
||||||
for(let i = 0; i <= scale.x_max; i++) {
|
for(let i = 0; i <= scale.ts_dur; i++) {
|
||||||
if((i + scale.ts_pad) % scale.x_mul == 0) {
|
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"}))
|
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
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
function poly(obj, scale) {
|
function poly(x2, obj, scale) {
|
||||||
let pts = ""
|
let pts = ""
|
||||||
let i = 0, first = -1, last = -1, lastVal = 0
|
let i = 0, first = -1, last = -1, lastVal = 0
|
||||||
let div = scale.y_max / height
|
let div = scale.y_max / height
|
||||||
|
@ -133,12 +129,17 @@
|
||||||
}
|
}
|
||||||
let pts2 = pts + " " + String(last) + "," + String(height)
|
let pts2 = pts + " " + String(last) + "," + String(height)
|
||||||
pts2 += " " + String(first) + "," + String(height)
|
pts2 += " " + String(first) + "," + String(height)
|
||||||
return [
|
elm = [
|
||||||
mlNs("polyline", {stroke: "url(#gLine)", fill: "none", points: pts}),
|
mlNs("polyline", {stroke: "url(#gLine)", fill: "none", points: pts}),
|
||||||
mlNs("polyline", {stroke: "none", fill: "url(#gFill)", points: pts2}),
|
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: 10}, "{#MAXIMUM}: " + String(obj.max) + "W"),
|
||||||
mlNs("text", {x: i*.8, y: 25}, "{#LAST_VALUE}: " + String(lastVal) + "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)
|
parseNav(obj.generic)
|
||||||
parseESP(obj.generic)
|
parseESP(obj.generic)
|
||||||
parseRssi(obj.generic)
|
parseRssi(obj.generic)
|
||||||
|
parseTitle(obj.generic)
|
||||||
window.setInterval("getAjax('/api/powerHistory', parsePowerHistory)", obj.refresh * 1000)
|
window.setInterval("getAjax('/api/powerHistory', parsePowerHistory)", obj.refresh * 1000)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.setInterval("getAjax('/api/powerHistoryDay', parsePowerHistoryDay)", obj.refresh * 1000)
|
window.setInterval("getAjax('/api/powerHistoryDay', parsePowerHistoryDay)", obj.refresh * 1000)
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<span class="des">System Infos:</span>
|
<span class="des">System Infos:</span>
|
||||||
|
<div id="total"></div>
|
||||||
<div id="iv"></div>
|
<div id="iv"></div>
|
||||||
<div class="hr"></div>
|
<div class="hr"></div>
|
||||||
<div id="warn_info"></div>
|
<div id="warn_info"></div>
|
||||||
|
@ -23,9 +24,9 @@
|
||||||
<h3>{#SUPPORT}:</h3>
|
<h3>{#SUPPORT}:</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="https://github.com/lumapu/ahoy/blob/main/src/CHANGES.md" target="_blank">{#CHANGELOG}</a></li>
|
<li><a href="https://github.com/lumapu/ahoy/blob/main/src/CHANGES.md" target="_blank">{#CHANGELOG}</a></li>
|
||||||
<li>{#DISCUSS} <a href="https://discord.gg/WzhxEY62mB">Discord</a></li>
|
<li>{#DISCUSS} <a href="https://discord.gg/WzhxEY62mB" target="_blank">Discord</a></li>
|
||||||
<li>{#REPORT} <a href="https://github.com/lumapu/ahoy/issues" target="_blank">{#ISSUES}</a></li>
|
<li>{#REPORT} <a href="https://github.com/lumapu/ahoy/issues" target="_blank">{#ISSUES}</a></li>
|
||||||
<li>{#CONTRIBUTE} <a href="https://github.com/lumapu/ahoy/blob/main/User_Manual.md" target="_blank">{#DOCUMENTATION}</a></li>
|
<li>{#CONTRIBUTE} <a href="https://docs.ahoydtu.de" target="_blank">{#DOCUMENTATION}</a></li>
|
||||||
<li><a href="https://fw.ahoydtu.de/fw/dev/" target="_blank">Download</a> & Test {#DEV_FIRMWARE}, <a href="https://github.com/lumapu/ahoy/blob/development03/src/CHANGES.md" target="_blank">{#DEV_CHANGELOG}</a></li>
|
<li><a href="https://fw.ahoydtu.de/fw/dev/" target="_blank">Download</a> & Test {#DEV_FIRMWARE}, <a href="https://github.com/lumapu/ahoy/blob/development03/src/CHANGES.md" target="_blank">{#DEV_CHANGELOG}</a></li>
|
||||||
<li>{#DON_MAKE} <a href="https://paypal.me/lupusch" target="_blank">{#DONATION}</a></li>
|
<li>{#DON_MAKE} <a href="https://paypal.me/lupusch" target="_blank">{#DONATION}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -56,8 +57,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseGeneric(obj) {
|
function parseGeneric(obj) {
|
||||||
if(exeOnce)
|
if(exeOnce) {
|
||||||
parseESP(obj)
|
parseESP(obj)
|
||||||
|
parseTitle(obj)
|
||||||
|
}
|
||||||
parseRssi(obj)
|
parseRssi(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +114,8 @@
|
||||||
|
|
||||||
function parseIv(obj, ts) {
|
function parseIv(obj, ts) {
|
||||||
var p = div(["none"]);
|
var p = div(["none"]);
|
||||||
|
var total = 0;
|
||||||
|
var count = 0;
|
||||||
for(var i of obj) {
|
for(var i of obj) {
|
||||||
var icon = iconSuccess;
|
var icon = iconSuccess;
|
||||||
var cl = "icon-success";
|
var cl = "icon-success";
|
||||||
|
@ -131,7 +136,9 @@
|
||||||
avail += "{#NOT_PRODUCING}";
|
avail += "{#NOT_PRODUCING}";
|
||||||
else {
|
else {
|
||||||
icon = iconSuccessFull;
|
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);
|
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) {
|
function parseWarn(warn) {
|
||||||
|
@ -165,7 +179,7 @@
|
||||||
p.append(svg(iconInfo, 30, 30, "icon icon-info"), span("{#UPDATE_AVAIL}: " + release), br());
|
p.append(svg(iconInfo, 30, 30, "icon icon-info"), span("{#UPDATE_AVAIL}: " + release), br());
|
||||||
else if(getVerInt("{#VERSION}") > getVerInt(release))
|
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());
|
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());
|
p.append(svg(iconInfo, 30, 30, "icon icon-info"), span("{#RELEASE_INSTALLED}: " + release), br());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,10 +40,11 @@
|
||||||
+ ("0"+min).substr(-2) + ":"
|
+ ("0"+min).substr(-2) + ":"
|
||||||
+ ("0"+sec).substr(-2);
|
+ ("0"+sec).substr(-2);
|
||||||
|
|
||||||
parseRssi(obj);
|
parseRssi(obj)
|
||||||
if(true == exeOnce) {
|
if(true == exeOnce) {
|
||||||
parseNav(obj);
|
parseNav(obj)
|
||||||
parseESP(obj);
|
parseESP(obj)
|
||||||
|
parseTitle(obj)
|
||||||
window.setInterval("getAjax('/api/generic', parseGeneric)", 5000);
|
window.setInterval("getAjax('/api/generic', parseGeneric)", 5000);
|
||||||
exeOnce = false;
|
exeOnce = false;
|
||||||
setTimeOffset();
|
setTimeOffset();
|
||||||
|
|
|
@ -52,14 +52,18 @@
|
||||||
<div class="s_content">
|
<div class="s_content">
|
||||||
<fieldset class="mb-2">
|
<fieldset class="mb-2">
|
||||||
<legend class="des">WiFi</legend>
|
<legend class="des">WiFi</legend>
|
||||||
|
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-12 col-sm-3 my-2">{#AP_PWD}</div>
|
<div class="col-12 col-sm-3 my-2">{#AP_PWD}</div>
|
||||||
<div class="col-12 col-sm-9"><input type="text" name="ap_pwd" minlength="8" /></div>
|
<div class="col-12 col-sm-9"><input type="text" name="ap_pwd" minlength="8" /></div>
|
||||||
</div>
|
</div>
|
||||||
|
<!--IF_ETHERNET-->
|
||||||
|
<!--ELSE-->
|
||||||
<div class="row mb-2 mb-sm-3">
|
<div class="row mb-2 mb-sm-3">
|
||||||
<div class="col-12 col-sm-3 my-2">SSID</div>
|
<div class="col-12 col-sm-3 my-2">SSID</div>
|
||||||
<div class="col-12 col-sm-9"><input type="text" name="ssid"/><br/><a href="/wizard">{#SCAN_WIFI}</a></div>
|
<div class="col-12 col-sm-9">
|
||||||
|
<input type="text" name="ssid"/><br/>
|
||||||
|
<a href="/wizard">{#SCAN_WIFI}</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mb-2 mb-sm-3">
|
<div class="row mb-2 mb-sm-3">
|
||||||
<div class="col-12 col-sm-3">{#SSID_HIDDEN}</div>
|
<div class="col-12 col-sm-3">{#SSID_HIDDEN}</div>
|
||||||
|
@ -69,6 +73,7 @@
|
||||||
<div class="col-12 col-sm-3 my-2">{#PASSWORD}</div>
|
<div class="col-12 col-sm-3 my-2">{#PASSWORD}</div>
|
||||||
<div class="col-12 col-sm-9"><input type="password" name="pwd" value="{PWD}"/></div>
|
<div class="col-12 col-sm-9"><input type="password" name="pwd" value="{PWD}"/></div>
|
||||||
</div>
|
</div>
|
||||||
|
<!--ENDIF_ETHERNET-->
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset class="mb-4">
|
<fieldset class="mb-4">
|
||||||
<legend class="des">{#STATIC_IP}</legend>
|
<legend class="des">{#STATIC_IP}</legend>
|
||||||
|
@ -125,7 +130,11 @@
|
||||||
<div class="col-4"><input type="checkbox" name="invRstMid"/></div>
|
<div class="col-4"><input type="checkbox" name="invRstMid"/></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-8 mb-2">{#INV_PAUSE_SUNSET}</div>
|
<div class="col-8 mb-2">{#INV_RESET_SUNRISE}</div>
|
||||||
|
<div class="col-4"><input type="checkbox" name="invRstComStart"/></div>
|
||||||
|
</div>
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-8 mb-2">{#INV_RESET_SUNSET}</div>
|
||||||
<div class="col-4"><input type="checkbox" name="invRstComStop"/></div>
|
<div class="col-4"><input type="checkbox" name="invRstComStop"/></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
|
@ -133,7 +142,7 @@
|
||||||
<div class="col-4"><input type="checkbox" name="invRstNotAvail"/></div>
|
<div class="col-4"><input type="checkbox" name="invRstNotAvail"/></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-8">{#INV_RESET_MAX_MIDNIGHT}</div>
|
<div class="col-8">{#INV_RESET_MAX_VALUES}</div>
|
||||||
<div class="col-4"><input type="checkbox" name="invRstMaxMid"/></div>
|
<div class="col-4"><input type="checkbox" name="invRstMaxMid"/></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
|
@ -231,6 +240,10 @@
|
||||||
<div class="col-12 col-sm-3 my-2">Topic</div>
|
<div class="col-12 col-sm-3 my-2">Topic</div>
|
||||||
<div class="col-12 col-sm-9"><input type="text" name="mqttTopic" pattern="[\-\+A-Za-z0-9\.\/#\$%&=_]+" title="Invalid input" /></div>
|
<div class="col-12 col-sm-9"><input type="text" name="mqttTopic" pattern="[\-\+A-Za-z0-9\.\/#\$%&=_]+" title="Invalid input" /></div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-12 col-sm-3 my-2">{#MQTT_JSON}</div>
|
||||||
|
<div class="col-12 col-sm-9"><input type="checkbox" name="mqttJson" /></div>
|
||||||
|
</div>
|
||||||
<p class="des">{#MQTT_NOTE}</p>
|
<p class="des">{#MQTT_NOTE}</p>
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-12 col-sm-3 my-2">{#INTERVAL}</div>
|
<div class="col-12 col-sm-3 my-2">{#INTERVAL}</div>
|
||||||
|
@ -243,6 +256,10 @@
|
||||||
<span id="apiResultMqtt"></span>
|
<span id="apiResultMqtt"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-8 col-sm-3">{#RETAIN}</div>
|
||||||
|
<div class="col-4 col-sm-9"><input type="checkbox" name="retain"/></div>
|
||||||
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -279,7 +296,7 @@
|
||||||
<div id="screenSaver"></div>
|
<div id="screenSaver"></div>
|
||||||
<div class="row mb-3" id="luminanceOption">
|
<div class="row mb-3" id="luminanceOption">
|
||||||
<div class="col-12 col-sm-3 my-2">{#DISP_LUMINANCE}</div>
|
<div class="col-12 col-sm-3 my-2">{#DISP_LUMINANCE}</div>
|
||||||
<div class="col-12 col-sm-9"><input type="number" name="disp_cont" min="0" max="255"></select></div>
|
<div class="col-12 col-sm-9"><input type="number" name="disp_cont" min="0" max="255"></div>
|
||||||
</div>
|
</div>
|
||||||
<p class="des">{#DISP_PINOUT}</p>
|
<p class="des">{#DISP_PINOUT}</p>
|
||||||
<div id="dispPins"></div>
|
<div id="dispPins"></div>
|
||||||
|
@ -288,7 +305,7 @@
|
||||||
<p class="des">{#GRAPH_OPTIONS}</p>
|
<p class="des">{#GRAPH_OPTIONS}</p>
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-12 col-sm-3 my-2">{#GRAPH_SHOW_RATIO}</div>
|
<div class="col-12 col-sm-3 my-2">{#GRAPH_SHOW_RATIO}</div>
|
||||||
<div class="col-12 col-sm-9"><input type="number" name="disp_graph_ratio" min="0" max="100"></select></div>
|
<div class="col-12 col-sm-9"><input type="number" name="disp_graph_ratio" min="0" max="100"></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="graphSize"></div>
|
<div id="graphSize"></div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -335,8 +352,8 @@
|
||||||
<div class="col-12 col-sm-9">
|
<div class="col-12 col-sm-9">
|
||||||
<form id="form" method="POST" action="/upload" enctype="multipart/form-data" accept-charset="utf-8">
|
<form id="form" method="POST" action="/upload" enctype="multipart/form-data" accept-charset="utf-8">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12 col-sm-8 my-2"><input type="file" name="upload"></div>
|
<div class="col-12 col-sm-8 my-2"><input type="file" id="importFileInput" name="upload"></div>
|
||||||
<div class="col-12 col-sm-4 my-2"><input type="button" class="btn" value="Import" onclick="hide()"></div>
|
<div class="col-12 col-sm-4 my-2"><input type="button" id="importButton" class="btn" value="Import" onclick="hide()"></div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -627,6 +644,22 @@
|
||||||
getAjax("/api/setup", apiCbMqtt, "POST", JSON.stringify(obj));
|
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() {
|
function hide() {
|
||||||
document.getElementById("form").submit();
|
document.getElementById("form").submit();
|
||||||
var e = document.getElementById("content");
|
var e = document.getElementById("content");
|
||||||
|
@ -668,16 +701,21 @@
|
||||||
function ivGlob(obj) {
|
function ivGlob(obj) {
|
||||||
for(var i of [["invInterval", "interval"]])
|
for(var i of [["invInterval", "interval"]])
|
||||||
document.getElementsByName(i[0])[0].value = obj[i[1]];
|
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("invRst"+i)[0].checked = obj["rst" + i];
|
||||||
document.getElementsByName("strtWthtTm")[0].checked = obj["strtWthtTm"];
|
document.getElementsByName("strtWthtTm")[0].checked = obj["strtWthtTm"];
|
||||||
document.getElementsByName("rdGrid")[0].checked = obj["rdGrid"];
|
document.getElementsByName("rdGrid")[0].checked = obj["rdGrid"];
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseSys(obj) {
|
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"]])
|
for(var i of [["device", "device_name"], ["ssid", "ssid"], ["ap_pwd", "ap_pwd"]])
|
||||||
document.getElementsByName(i[0])[0].value = obj[i[1]];
|
document.getElementsByName(i[0])[0].value = obj[i[1]];
|
||||||
document.getElementsByName("hidd")[0].checked = obj["hidd"];
|
document.getElementsByName("hidd")[0].checked = obj["hidd"];
|
||||||
|
/*ENDIF_ETHERNET*/
|
||||||
document.getElementsByName("darkMode")[0].checked = obj["dark_mode"];
|
document.getElementsByName("darkMode")[0].checked = obj["dark_mode"];
|
||||||
document.getElementsByName("schedReboot")[0].checked = obj["sched_reboot"];
|
document.getElementsByName("schedReboot")[0].checked = obj["sched_reboot"];
|
||||||
e = document.getElementsByName("adminpwd")[0];
|
e = document.getElementsByName("adminpwd")[0];
|
||||||
|
@ -702,9 +740,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseGeneric(obj) {
|
function parseGeneric(obj) {
|
||||||
parseNav(obj);
|
parseNav(obj)
|
||||||
parseESP(obj);
|
parseESP(obj)
|
||||||
parseRssi(obj);
|
parseRssi(obj)
|
||||||
|
parseTitle(obj)
|
||||||
|
|
||||||
if(0 != obj.cst_lnk.length) {
|
if(0 != obj.cst_lnk.length) {
|
||||||
document.getElementsByName("cstLnk")[0].value = obj.cst_lnk
|
document.getElementsByName("cstLnk")[0].value = obj.cst_lnk
|
||||||
|
@ -935,6 +974,8 @@
|
||||||
function parseMqtt(obj) {
|
function parseMqtt(obj) {
|
||||||
for(var i of [["Addr", "broker"], ["Port", "port"], ["ClientId", "clientId"], ["User", "user"], ["Pwd", "pwd"], ["Topic", "topic"], ["Interval", "interval"]])
|
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("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) {
|
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);
|
getAjax("/api/setup", parse);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -567,7 +567,13 @@ input.btn {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
input.btn:hover {
|
input.btn:disabled {
|
||||||
|
background-color: var(--primary-disabled);
|
||||||
|
color: #888;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
input.btn:not(:disabled):hover {
|
||||||
background-color: #044e86;
|
background-color: #044e86;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -685,7 +691,7 @@ div.hr {
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
transform: translate(-50%,-100%);
|
transform: translate(-50%,-50%);
|
||||||
margin:0 auto;
|
margin:0 auto;
|
||||||
color: var(--fg2);
|
color: var(--fg2);
|
||||||
min-width: 100px;
|
min-width: 100px;
|
||||||
|
@ -756,6 +762,7 @@ div.hr {
|
||||||
font-family: inherit;
|
font-family: inherit;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
color: var(--fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
button.close {
|
button.close {
|
||||||
|
|
|
@ -15,9 +15,10 @@
|
||||||
{#HTML_FOOTER}
|
{#HTML_FOOTER}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function parseGeneric(obj) {
|
function parseGeneric(obj) {
|
||||||
parseNav(obj);
|
parseNav(obj)
|
||||||
parseESP(obj);
|
parseESP(obj)
|
||||||
parseRssi(obj);
|
parseRssi(obj)
|
||||||
|
parseTitle(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseSysInfo(obj) {
|
function parseSysInfo(obj) {
|
||||||
|
|
|
@ -12,22 +12,39 @@
|
||||||
<legend class="des">{#SELECT_FILE} (*.bin)</legend>
|
<legend class="des">{#SELECT_FILE} (*.bin)</legend>
|
||||||
<p>{#INSTALLED_VERSION}:<br/><span id="version" style="background-color: var(--input-bg); padding: 7px; display: block; margin: 3px;"></span></p>
|
<p>{#INSTALLED_VERSION}:<br/><span id="version" style="background-color: var(--input-bg); padding: 7px; display: block; margin: 3px;"></span></p>
|
||||||
<form id="form" method="POST" action="/update" enctype="multipart/form-data" accept-charset="utf-8">
|
<form id="form" method="POST" action="/update" enctype="multipart/form-data" accept-charset="utf-8">
|
||||||
<input type="file" name="update">
|
<input type="file" id="uploadFileInput" name="update">
|
||||||
<input type="button" class="btn my-4" value="{#BTN_UPDATE}" onclick="hide()">
|
<input type="button" id="uploadButton" class="btn my-4" value="{#BTN_UPDATE}" onclick="hide()">
|
||||||
</form>
|
</form>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<div class="row mt-4">
|
<div class="row mt-4">
|
||||||
<a href="https://fw.ahoydtu.de" target="_blank">{#DOWNLOADS}<a/>
|
<a href="https://fw.ahoydtu.de" target="_blank">{#DOWNLOADS}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{#HTML_FOOTER}
|
{#HTML_FOOTER}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const fileInput = document.querySelector('#uploadFileInput');
|
||||||
|
const button = document.querySelector('#uploadButton');
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var env;
|
var env;
|
||||||
function parseGeneric(obj) {
|
function parseGeneric(obj) {
|
||||||
parseNav(obj)
|
parseNav(obj)
|
||||||
parseESP(obj)
|
parseESP(obj)
|
||||||
parseRssi(obj)
|
parseRssi(obj)
|
||||||
|
parseTitle(obj)
|
||||||
env = obj.env
|
env = obj.env
|
||||||
document.getElementById("version").innerHTML = "{#VERSION_FULL}_" + obj.env + ".bin"
|
document.getElementById("version").innerHTML = "{#VERSION_FULL}_" + obj.env + ".bin"
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
var mNum = 0;
|
var mNum = 0;
|
||||||
var total = Array(6).fill(0);
|
var total = Array(6).fill(0);
|
||||||
var tPwrAck;
|
var tPwrAck;
|
||||||
|
var totalsRendered = false
|
||||||
|
|
||||||
function getErrStr(code) {
|
function getErrStr(code) {
|
||||||
if("ERR_AUTH") return "{#ERR_AUTH}"
|
if("ERR_AUTH") return "{#ERR_AUTH}"
|
||||||
|
@ -35,10 +36,11 @@
|
||||||
|
|
||||||
function parseGeneric(obj) {
|
function parseGeneric(obj) {
|
||||||
if(true == exeOnce){
|
if(true == exeOnce){
|
||||||
parseNav(obj);
|
parseNav(obj)
|
||||||
parseESP(obj);
|
parseESP(obj)
|
||||||
|
parseTitle(obj)
|
||||||
}
|
}
|
||||||
parseRssi(obj);
|
parseRssi(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
function numBig(val, unit, des) {
|
function numBig(val, unit, des) {
|
||||||
|
@ -56,11 +58,11 @@
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function numMid(val, unit, des, opt={class: "fs-6"}) {
|
function numMid(val, unit, des, opt={class: "row"}) {
|
||||||
return ml("div", {class: "col-6 col-sm-4 col-md-3 mb-2"}, [
|
return ml("div", {class: "col-6 col-sm-4 col-md-3 mb-2"}, [
|
||||||
ml("div", {class: "row"},
|
ml("div", opt,
|
||||||
ml("div", {class: "col"}, [
|
ml("div", {class: "col"}, [
|
||||||
ml("span", opt, String(Math.round(val * 100) / 100)),
|
ml("span", {class: "fs-6"}, String(Math.round(val * 100) / 100)),
|
||||||
ml("span", {class: "fs-8 mx-1"}, unit)
|
ml("span", {class: "fs-8 mx-1"}, unit)
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
|
@ -76,6 +78,7 @@
|
||||||
for(var i = 0; i < 6; i++) {
|
for(var i = 0; i < 6; i++) {
|
||||||
total[i] = Math.round(total[i] * 100) / 100;
|
total[i] = Math.round(total[i] * 100) / 100;
|
||||||
}
|
}
|
||||||
|
totalsRendered = true
|
||||||
|
|
||||||
return ml("div", {class: "row mt-3 mb-5"},
|
return ml("div", {class: "row mt-3 mb-5"},
|
||||||
ml("div", {class: "col"}, [
|
ml("div", {class: "col"}, [
|
||||||
|
@ -106,7 +109,6 @@
|
||||||
total[4] += obj.ch[0][8]; // P_DC
|
total[4] += obj.ch[0][8]; // P_DC
|
||||||
total[5] += obj.ch[0][10]; // Q_AC
|
total[5] += obj.ch[0][10]; // Q_AC
|
||||||
}
|
}
|
||||||
total[3] += obj.ch[0][11]; // MAX P_AC
|
|
||||||
total[1] += obj.ch[0][7]; // YieldDay
|
total[1] += obj.ch[0][7]; // YieldDay
|
||||||
total[2] += obj.ch[0][6]; // YieldTotal
|
total[2] += obj.ch[0][6]; // YieldTotal
|
||||||
|
|
||||||
|
@ -121,7 +123,8 @@
|
||||||
pwrLimit += ", " + (obj.max_pwr * obj.power_limit_read / 100).toFixed(1) + " W";
|
pwrLimit += ", " + (obj.max_pwr * obj.power_limit_read / 100).toFixed(1) + " W";
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxAcPwr = toIsoDateStr(new Date(obj.ts_max_ac_pwr * 1000));
|
var maxAcPwrDate = toIsoDateStr(new Date(obj.ts_max_ac_pwr * 1000))
|
||||||
|
var maxTempDate = toIsoDateStr(new Date(obj.ts_max_temp * 1000))
|
||||||
return ml("div", {class: "row mt-2"},
|
return ml("div", {class: "row mt-2"},
|
||||||
ml("div", {class: "col"}, [
|
ml("div", {class: "col"}, [
|
||||||
ml("div", {class: "p-2 " + clh},
|
ml("div", {class: "p-2 " + clh},
|
||||||
|
@ -136,7 +139,7 @@
|
||||||
ml("div", {class: "col a-c"}, ml("span", { class: "pointer", onclick: function() {
|
ml("div", {class: "col a-c"}, ml("span", { class: "pointer", onclick: function() {
|
||||||
getAjax("/api/inverter/alarm/" + obj.id, parseIvAlarm);
|
getAjax("/api/inverter/alarm/" + obj.id, parseIvAlarm);
|
||||||
}}, ("{#ALARMS}: " + obj.alarm_cnt))),
|
}}, ("{#ALARMS}: " + obj.alarm_cnt))),
|
||||||
ml("div", {class: "col a-r mx-2 mx-md-1"}, String(obj.ch[0][5].toFixed(1)) + t.innerText)
|
ml("div", {class: "col a-r mx-2 mx-md-1 tooltip", data: (obj.ch[0][12] + t.innerText + "\n" + maxTempDate)}, String(obj.ch[0][5].toFixed(1)) + t.innerText)
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
ml("div", {class: "p-2 " + clbg}, [
|
ml("div", {class: "p-2 " + clbg}, [
|
||||||
|
@ -147,7 +150,7 @@
|
||||||
]),
|
]),
|
||||||
ml("div", {class: "hr"}),
|
ml("div", {class: "hr"}),
|
||||||
ml("div", {class: "row mt-2"},[
|
ml("div", {class: "row mt-2"},[
|
||||||
numMid(obj.ch[0][11], "W", "{#MAX_AC_POWER}", {class: "fs-6 tooltip", data: maxAcPwr}),
|
numMid(obj.ch[0][11], "W", "{#MAX_AC_POWER}", {class: "row tooltip", data: maxAcPwrDate}),
|
||||||
numMid(obj.ch[0][8], "W", "{#DC_POWER}"),
|
numMid(obj.ch[0][8], "W", "{#DC_POWER}"),
|
||||||
numMid(obj.ch[0][0], "V", "{#AC_VOLTAGE}"),
|
numMid(obj.ch[0][0], "V", "{#AC_VOLTAGE}"),
|
||||||
numMid(obj.ch[0][1], "A", "{#AC_CURRENT}"),
|
numMid(obj.ch[0][1], "A", "{#AC_CURRENT}"),
|
||||||
|
@ -242,20 +245,18 @@
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
var last = true;
|
|
||||||
for(var i = obj.id + 1; i < ivEn.length; i++) {
|
for(var i = obj.id + 1; i < ivEn.length; i++) {
|
||||||
if((i != ivEn.length) && ivEn[i]) {
|
if((i != ivEn.length) && ivEn[i]) {
|
||||||
last = false;
|
|
||||||
getAjax("/api/inverter/id/" + i, parseIv);
|
getAjax("/api/inverter/id/" + i, parseIv);
|
||||||
break;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(last) {
|
|
||||||
if(mNum > 1)
|
if(mNum > 1) {
|
||||||
|
if(!totalsRendered)
|
||||||
mIvHtml.unshift(totals());
|
mIvHtml.unshift(totals());
|
||||||
document.getElementById("live").replaceChildren(...mIvHtml);
|
|
||||||
}
|
}
|
||||||
|
document.getElementById("live").replaceChildren(...mIvHtml);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseIvAlarm(obj) {
|
function parseIvAlarm(obj) {
|
||||||
|
@ -516,7 +517,9 @@
|
||||||
ivEn = Object.values(Object.assign({}, obj["iv"]));
|
ivEn = Object.values(Object.assign({}, obj["iv"]));
|
||||||
mIvHtml = [];
|
mIvHtml = [];
|
||||||
mNum = 0;
|
mNum = 0;
|
||||||
|
totalsRendered = false
|
||||||
total.fill(0);
|
total.fill(0);
|
||||||
|
total[3] = obj.max_total_pwr
|
||||||
for(var i = 0; i < obj.iv.length; i++) {
|
for(var i = 0; i < obj.iv.length; i++) {
|
||||||
if(obj.iv[i]) {
|
if(obj.iv[i]) {
|
||||||
getAjax("/api/inverter/id/" + i, parseIv);
|
getAjax("/api/inverter/id/" + i, parseIv);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<title>{#NAV_WIZARD}</title>
|
<title>{#NAV_WIZARD}</title>
|
||||||
{#HTML_HEADER}
|
{#HTML_HEADER}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body onload="init()">
|
||||||
<div id="wrapper">
|
<div id="wrapper">
|
||||||
<div class="container d-flex aic jc">
|
<div class="container d-flex aic jc">
|
||||||
<div id="con"></div>
|
<div id="con"></div>
|
||||||
|
@ -14,6 +14,7 @@
|
||||||
var v;
|
var v;
|
||||||
var found = false;
|
var found = false;
|
||||||
var c = document.getElementById("con");
|
var c = document.getElementById("con");
|
||||||
|
var redirIp = "http://192.168.4.1/index"
|
||||||
|
|
||||||
/*IF_ESP32*/
|
/*IF_ESP32*/
|
||||||
var pinList = [
|
var pinList = [
|
||||||
|
@ -206,7 +207,7 @@
|
||||||
]),
|
]),
|
||||||
...lst,
|
...lst,
|
||||||
ml("div", {class: "row my-4"}, ml("div", {class: "col a-r"}, ml("input", {type: "button", class:"btn", value: "{#BTN_REBOOT}", onclick: () => {saveEth()}}, null))),
|
ml("div", {class: "row my-4"}, ml("div", {class: "col a-r"}, ml("input", {type: "button", class:"btn", value: "{#BTN_REBOOT}", onclick: () => {saveEth()}}, null))),
|
||||||
ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {href: "http://192.168.4.1/"}, "{#STOP_WIZARD}")))
|
ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {onclick: () => {redirect()}}, "{#STOP_WIZARD}")))
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
/*ELSE*/
|
/*ELSE*/
|
||||||
|
@ -218,7 +219,7 @@
|
||||||
sect("{#WIFI_MANUAL}", ml("input", {id: "man", type: "text"})),
|
sect("{#WIFI_MANUAL}", ml("input", {id: "man", type: "text"})),
|
||||||
sect("{#WIFI_PASSWORD}", ml("input", {id: "pwd", type: "password"})),
|
sect("{#WIFI_PASSWORD}", ml("input", {id: "pwd", type: "password"})),
|
||||||
ml("div", {class: "row my-4"}, ml("div", {class: "col a-r"}, ml("input", {type: "button", class:"btn", value: "{#BTN_NEXT}", onclick: () => {saveWifi()}}, null))),
|
ml("div", {class: "row my-4"}, ml("div", {class: "col a-r"}, ml("input", {type: "button", class:"btn", value: "{#BTN_NEXT}", onclick: () => {saveWifi()}}, null))),
|
||||||
ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {href: "http://192.168.4.1/index"}, "{#STOP_WIZARD}")))
|
ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {onclick: () => {redirect()}}, "{#STOP_WIZARD}")))
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
/*ENDIF_ETHERNET*/
|
/*ENDIF_ETHERNET*/
|
||||||
|
@ -229,17 +230,17 @@
|
||||||
ml("div", {class: "row"}, ml("div", {class: "col"}, ml("span", {class: "fs-5"}, "{#TEST_CONNECTION}"))),
|
ml("div", {class: "row"}, ml("div", {class: "col"}, ml("span", {class: "fs-5"}, "{#TEST_CONNECTION}"))),
|
||||||
sect("{#TRY_TO_CONNECT}", ml("span", {id: "state"}, "{#CONNECTING}")),
|
sect("{#TRY_TO_CONNECT}", ml("span", {id: "state"}, "{#CONNECTING}")),
|
||||||
ml("div", {class: "row my-4"}, ml("div", {class: "col a-r"}, ml("input", {type: "button", class:"btn hide", id: "btn", value: "{#BTN_FINISH}", onclick: () => {redirect()}}, null))),
|
ml("div", {class: "row my-4"}, ml("div", {class: "col a-r"}, ml("input", {type: "button", class:"btn hide", id: "btn", value: "{#BTN_FINISH}", onclick: () => {redirect()}}, null))),
|
||||||
ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {href: "http://192.168.4.1/index"}, "{#STOP_WIZARD}")))
|
ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {onclick: () => {redirect()}}, "{#STOP_WIZARD}")))
|
||||||
)
|
)
|
||||||
v = setInterval(() => {getAjax('/api/setup/getip', printIp)}, 300);
|
v = setInterval(() => {getAjax('/api/setup/getip', printIp)}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirect() {
|
function redirect() {
|
||||||
window.location.replace("http://192.168.4.1/")
|
window.location.replace(redirIp)
|
||||||
}
|
}
|
||||||
|
|
||||||
function printIp(obj) {
|
function printIp(obj) {
|
||||||
if("0.0.0.0" != obj["ip"]) {
|
if("0.0.0.0" != obj.ip) {
|
||||||
clearInterval(v)
|
clearInterval(v)
|
||||||
setHide("btn", false)
|
setHide("btn", false)
|
||||||
document.getElementById("state").innerHTML = "{#NETWORK_SUCCESS}" + obj.ip
|
document.getElementById("state").innerHTML = "{#NETWORK_SUCCESS}" + obj.ip
|
||||||
|
@ -266,29 +267,36 @@
|
||||||
}
|
}
|
||||||
/*ENDIF_ETHERNET*/
|
/*ENDIF_ETHERNET*/
|
||||||
|
|
||||||
/*IF_ETHERNET*/
|
function init() {
|
||||||
getAjax("/api/setup", ((o) => c.append(step1(o.eth))));
|
/*IF_ETHERNET*/
|
||||||
/*ELSE*/
|
getAjax("/api/setup", ((o) => c.append(step1(o.eth))));
|
||||||
function nets(obj) {
|
/*ELSE*/
|
||||||
if(!obj.success)
|
function nets(obj) {
|
||||||
return;
|
clearInterval(v)
|
||||||
|
v = setInterval(() => {getAjax('/api/setup/networks', nets)}, 4000)
|
||||||
|
|
||||||
var e = document.getElementById("net");
|
if(!obj.success)
|
||||||
if(obj.networks.length > 0) {
|
return;
|
||||||
var a = []
|
|
||||||
a.push(ml("option", {value: -1}, obj.networks.length + " {#NUM_NETWORKS_FOUND}"))
|
var e = document.getElementById("net");
|
||||||
for(n of obj.networks) {
|
if(obj.networks.length > 0) {
|
||||||
a.push(ml("option", {value: n.ssid}, n.ssid + " (" + n.rssi + "dBm)"))
|
var a = []
|
||||||
found = true;
|
a.push(ml("option", {value: -1}, obj.networks.length + " {#NUM_NETWORKS_FOUND}"))
|
||||||
|
for(n of obj.networks) {
|
||||||
|
a.push(ml("option", {value: n.ssid}, n.ssid + " (" + n.rssi + "dBm)"))
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
e.replaceChildren(...a)
|
||||||
}
|
}
|
||||||
e.replaceChildren(...a)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
c.append(step1())
|
if("0.0.0.0" != obj.ip)
|
||||||
getAjax('/api/setup/networks', nets)
|
redirIp = "http://" + obj.ip + "/index"
|
||||||
v = setInterval(() => {getAjax('/api/setup/networks', nets)}, 1000)
|
}
|
||||||
/*ENDIF_ETHERNET*/
|
|
||||||
|
c.append(step1())
|
||||||
|
getAjax('/api/setup/networks', nets)
|
||||||
|
/*ENDIF_ETHERNET*/
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -72,4 +72,28 @@
|
||||||
#define BTN_REBOOT "Reboot"
|
#define BTN_REBOOT "Reboot"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef LANG_DE
|
||||||
|
#define BTN_REBOOT "Ahoy neustarten"
|
||||||
|
#else /*LANG_EN*/
|
||||||
|
#define BTN_REBOOT "Reboot"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LANG_DE
|
||||||
|
#define BTN_YES "ja"
|
||||||
|
#else /*LANG_EN*/
|
||||||
|
#define BTN_YES "yes"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LANG_DE
|
||||||
|
#define BTN_NO "nein"
|
||||||
|
#else /*LANG_EN*/
|
||||||
|
#define BTN_NO "no"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LANG_DE
|
||||||
|
#define BTN_COREDUMP "CoreDump herunterladen"
|
||||||
|
#else /*LANG_EN*/
|
||||||
|
#define BTN_COREDUMP "download CoreDump"
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /*__LANG_H__*/
|
#endif /*__LANG_H__*/
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
{
|
{
|
||||||
"token": "NAV_WIZARD",
|
"token": "NAV_WIZARD",
|
||||||
"en": "Setup Wizard",
|
"en": "Setup Wizard",
|
||||||
"de": "Daten"
|
"de": "Einrichtungsassitent"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"token": "NAV_LIVE",
|
"token": "NAV_LIVE",
|
||||||
|
@ -81,7 +81,7 @@
|
||||||
{
|
{
|
||||||
"token": "BTN_NEXT",
|
"token": "BTN_NEXT",
|
||||||
"en": "next >>",
|
"en": "next >>",
|
||||||
"de": "prüfen >>"
|
"de": "speichern >>"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"token": "BTN_REBOOT",
|
"token": "BTN_REBOOT",
|
||||||
|
@ -96,7 +96,7 @@
|
||||||
{
|
{
|
||||||
"token": "TRY_TO_CONNECT",
|
"token": "TRY_TO_CONNECT",
|
||||||
"en": "AhoyDTU is trying to connect to your WiFi",
|
"en": "AhoyDTU is trying to connect to your WiFi",
|
||||||
"de": "AhoyDTU versucht eine Verindung mit deinem Netzwerk herzustellen"
|
"de": "AhoyDTU versucht eine Verbindung mit Deinem Netzwerk herzustellen"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"token": "CONNECTING",
|
"token": "CONNECTING",
|
||||||
|
@ -106,7 +106,7 @@
|
||||||
{
|
{
|
||||||
"token": "NETWORK_SUCCESS",
|
"token": "NETWORK_SUCCESS",
|
||||||
"en": "success, got following IP in your network: ",
|
"en": "success, got following IP in your network: ",
|
||||||
"de": "Verindung erfolgreich. AhoyDTU hat die folgende IP bekommen: "
|
"de": "Verbindung erfolgreich. AhoyDTU hat die folgende IP bekommen: "
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"token": "BTN_FINISH",
|
"token": "BTN_FINISH",
|
||||||
|
@ -324,19 +324,24 @@
|
||||||
"de": "Werte und Gesamtertrag um Mitternacht zurücksetzen"
|
"de": "Werte und Gesamtertrag um Mitternacht zurücksetzen"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"token": "INV_PAUSE_SUNSET",
|
"token": "INV_RESET_SUNSET",
|
||||||
"en": "Reset values at sunset",
|
"en": "Reset values at sunset",
|
||||||
"de": "Werte bei Sonnenuntergang zurücksetzen"
|
"de": "Werte bei Sonnenuntergang zurücksetzen"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"token": "INV_RESET_SUNRISE",
|
||||||
|
"en": "Reset values at sunrise",
|
||||||
|
"de": "Werte bei Sonnenaufgang zurücksetzen"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"token": "INV_RESET_NOT_AVAIL",
|
"token": "INV_RESET_NOT_AVAIL",
|
||||||
"en": "Reset values when inverter status is 'not available'",
|
"en": "Reset values when inverter status is 'not available'",
|
||||||
"de": "Werte zurücksetzen, sobald der Wechselrichter nicht erreichbar ist"
|
"de": "Werte zurücksetzen, sobald der Wechselrichter nicht erreichbar ist"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"token": "INV_RESET_MAX_MIDNIGHT",
|
"token": "INV_RESET_MAX_VALUES",
|
||||||
"en": "Reset 'max' values at midnight",
|
"en": "Include reset 'max' values",
|
||||||
"de": "Maximalwerte mitternachts zurücksetzen"
|
"de": "Maximalwerte auch zurücksetzen"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"token": "INV_START_WITHOUT_TIME",
|
"token": "INV_START_WITHOUT_TIME",
|
||||||
|
@ -408,11 +413,21 @@
|
||||||
"en": "Password (optional)",
|
"en": "Password (optional)",
|
||||||
"de": "Passwort (optional)"
|
"de": "Passwort (optional)"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"token": "MQTT_JSON",
|
||||||
|
"en": "Payload as JSON",
|
||||||
|
"de": "Ausgabe als JSON"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"token": "MQTT_NOTE",
|
"token": "MQTT_NOTE",
|
||||||
"en": "Send Inverter data in a fixed interval, even if there is no change. A value of '0' disables the fixed interval. The data is published once it was successfully received from inverter. (default: 0)",
|
"en": "Send Inverter data in a fixed interval, even if there is no change. A value of '0' disables the fixed interval. The data is published once it was successfully received from inverter. (default: 0)",
|
||||||
"de": "Wechselrichterdaten in fixem Intervall schicken, auch wenn es keine Änderung gab. Ein Wert von '0' deaktiviert das fixe Intervall, die Wechselrichterdaten werden übertragen, sobald neue zur Verfügung stehen. (Standard: 0)"
|
"de": "Wechselrichterdaten in fixem Intervall schicken, auch wenn es keine Änderung gab. Ein Wert von '0' deaktiviert das fixe Intervall, die Wechselrichterdaten werden übertragen, sobald neue zur Verfügung stehen. (Standard: 0)"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"token": "RETAIN",
|
||||||
|
"en": "enable retain flag",
|
||||||
|
"de": "'Retain Flag' aktivieren"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"token": "DISPLAY_CONFIG",
|
"token": "DISPLAY_CONFIG",
|
||||||
"en": "Display Config",
|
"en": "Display Config",
|
||||||
|
@ -1827,6 +1842,11 @@
|
||||||
"token": "LAST_VALUE",
|
"token": "LAST_VALUE",
|
||||||
"en": "Last value",
|
"en": "Last value",
|
||||||
"de": "Letzter Wert"
|
"de": "Letzter Wert"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"token": "YIELD_DAY",
|
||||||
|
"en": "Yield day",
|
||||||
|
"de": "Tagesertrag"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,7 @@ class Web {
|
||||||
|
|
||||||
mWeb.on("/setup", HTTP_GET, std::bind(&Web::onSetup, this, std::placeholders::_1));
|
mWeb.on("/setup", HTTP_GET, std::bind(&Web::onSetup, this, std::placeholders::_1));
|
||||||
mWeb.on("/wizard", HTTP_GET, std::bind(&Web::onWizard, this, std::placeholders::_1));
|
mWeb.on("/wizard", HTTP_GET, std::bind(&Web::onWizard, this, std::placeholders::_1));
|
||||||
|
mWeb.on("/generate_204", HTTP_GET, std::bind(&Web::onWizard, this, std::placeholders::_1)); //Android captive portal
|
||||||
mWeb.on("/save", HTTP_POST, std::bind(&Web::showSave, this, std::placeholders::_1));
|
mWeb.on("/save", HTTP_POST, std::bind(&Web::showSave, this, std::placeholders::_1));
|
||||||
|
|
||||||
mWeb.on("/live", HTTP_ANY, std::bind(&Web::onLive, this, std::placeholders::_1));
|
mWeb.on("/live", HTTP_ANY, std::bind(&Web::onLive, this, std::placeholders::_1));
|
||||||
|
@ -501,12 +502,13 @@ class Web {
|
||||||
|
|
||||||
if (request->arg("invInterval") != "")
|
if (request->arg("invInterval") != "")
|
||||||
mConfig->inst.sendInterval = request->arg("invInterval").toInt();
|
mConfig->inst.sendInterval = request->arg("invInterval").toInt();
|
||||||
mConfig->inst.rstYieldMidNight = (request->arg("invRstMid") == "on");
|
mConfig->inst.rstValsAtMidNight = (request->arg("invRstMid") == "on");
|
||||||
mConfig->inst.rstValsCommStop = (request->arg("invRstComStop") == "on");
|
mConfig->inst.rstValsCommStop = (request->arg("invRstComStop") == "on");
|
||||||
|
mConfig->inst.rstValsCommStart = (request->arg("invRstComStart") == "on");
|
||||||
mConfig->inst.rstValsNotAvail = (request->arg("invRstNotAvail") == "on");
|
mConfig->inst.rstValsNotAvail = (request->arg("invRstNotAvail") == "on");
|
||||||
mConfig->inst.startWithoutTime = (request->arg("strtWthtTm") == "on");
|
mConfig->inst.startWithoutTime = (request->arg("strtWthtTm") == "on");
|
||||||
mConfig->inst.readGrid = (request->arg("rdGrid") == "on");
|
mConfig->inst.readGrid = (request->arg("rdGrid") == "on");
|
||||||
mConfig->inst.rstMaxValsMidNight = (request->arg("invRstMaxMid") == "on");
|
mConfig->inst.rstIncludeMaxVals = (request->arg("invRstMaxMid") == "on");
|
||||||
|
|
||||||
|
|
||||||
// pinout
|
// pinout
|
||||||
|
@ -584,8 +586,10 @@ class Web {
|
||||||
if (request->arg("mqttPwd") != "{PWD}")
|
if (request->arg("mqttPwd") != "{PWD}")
|
||||||
request->arg("mqttPwd").toCharArray(mConfig->mqtt.pwd, MQTT_PWD_LEN);
|
request->arg("mqttPwd").toCharArray(mConfig->mqtt.pwd, MQTT_PWD_LEN);
|
||||||
request->arg("mqttTopic").toCharArray(mConfig->mqtt.topic, MQTT_TOPIC_LEN);
|
request->arg("mqttTopic").toCharArray(mConfig->mqtt.topic, MQTT_TOPIC_LEN);
|
||||||
|
mConfig->mqtt.json = (request->arg("mqttJson") == "on");
|
||||||
mConfig->mqtt.port = request->arg("mqttPort").toInt();
|
mConfig->mqtt.port = request->arg("mqttPort").toInt();
|
||||||
mConfig->mqtt.interval = request->arg("mqttInterval").toInt();
|
mConfig->mqtt.interval = request->arg("mqttInterval").toInt();
|
||||||
|
mConfig->mqtt.enableRetain = (request->arg("retain") == "on");
|
||||||
|
|
||||||
// serial console
|
// serial console
|
||||||
mConfig->serial.debug = (request->arg("serDbg") == "on");
|
mConfig->serial.debug = (request->arg("serDbg") == "on");
|
||||||
|
|
466
tools/NodeRED/flows-mqtt-json-example.json
Normal file
466
tools/NodeRED/flows-mqtt-json-example.json
Normal file
|
@ -0,0 +1,466 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "67bced2c4e728783",
|
||||||
|
"type": "mqtt in",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "",
|
||||||
|
"topic": "hoymiles/+",
|
||||||
|
"qos": "0",
|
||||||
|
"datatype": "auto-detect",
|
||||||
|
"broker": "319864a4e0fd913f",
|
||||||
|
"nl": false,
|
||||||
|
"rap": true,
|
||||||
|
"rh": 0,
|
||||||
|
"inputs": 0,
|
||||||
|
"x": 80,
|
||||||
|
"y": 2100,
|
||||||
|
"wires": [
|
||||||
|
[
|
||||||
|
"a55632ad0dff0b69"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "a7f0d307d7cf77e2",
|
||||||
|
"type": "mqtt in",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "",
|
||||||
|
"topic": "hoymiles/X/#",
|
||||||
|
"qos": "0",
|
||||||
|
"datatype": "auto-detect",
|
||||||
|
"broker": "319864a4e0fd913f",
|
||||||
|
"nl": false,
|
||||||
|
"rap": true,
|
||||||
|
"rh": 0,
|
||||||
|
"inputs": 0,
|
||||||
|
"x": 90,
|
||||||
|
"y": 2260,
|
||||||
|
"wires": [
|
||||||
|
[
|
||||||
|
"7e17e5a3f4df3011",
|
||||||
|
"1a8cca488d53394a"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "7e17e5a3f4df3011",
|
||||||
|
"type": "debug",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "Inverter X",
|
||||||
|
"active": false,
|
||||||
|
"tosidebar": true,
|
||||||
|
"console": false,
|
||||||
|
"tostatus": false,
|
||||||
|
"complete": "payload",
|
||||||
|
"targetType": "msg",
|
||||||
|
"statusVal": "",
|
||||||
|
"statusType": "auto",
|
||||||
|
"x": 340,
|
||||||
|
"y": 2260,
|
||||||
|
"wires": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "fb7357db50501627",
|
||||||
|
"type": "change",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "Tags setzen",
|
||||||
|
"rules": [
|
||||||
|
{
|
||||||
|
"t": "set",
|
||||||
|
"p": "payload",
|
||||||
|
"pt": "msg",
|
||||||
|
"to": "(\t $a := $split(topic, '/');\t [\t payload,\t {\t \"device\":$a[0],\t \"name\":$a[1],\t \"channel\":$a[2]\t }\t ]\t)\t",
|
||||||
|
"tot": "jsonata"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"t": "delete",
|
||||||
|
"p": "topic",
|
||||||
|
"pt": "msg"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"action": "",
|
||||||
|
"property": "",
|
||||||
|
"from": "",
|
||||||
|
"to": "",
|
||||||
|
"reg": false,
|
||||||
|
"x": 610,
|
||||||
|
"y": 2360,
|
||||||
|
"wires": [
|
||||||
|
[
|
||||||
|
"91a4607dfda84b67"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "670eb9fbb5c31b2c",
|
||||||
|
"type": "debug",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "InfluxDB",
|
||||||
|
"active": false,
|
||||||
|
"tosidebar": true,
|
||||||
|
"console": false,
|
||||||
|
"tostatus": false,
|
||||||
|
"complete": "payload",
|
||||||
|
"targetType": "msg",
|
||||||
|
"statusVal": "",
|
||||||
|
"statusType": "auto",
|
||||||
|
"x": 940,
|
||||||
|
"y": 2360,
|
||||||
|
"wires": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1a8cca488d53394a",
|
||||||
|
"type": "switch",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "",
|
||||||
|
"property": "$split(topic, '/')[2]",
|
||||||
|
"propertyType": "jsonata",
|
||||||
|
"rules": [
|
||||||
|
{
|
||||||
|
"t": "eq",
|
||||||
|
"v": "available",
|
||||||
|
"vt": "str"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"t": "eq",
|
||||||
|
"v": "last_success",
|
||||||
|
"vt": "str"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"t": "regex",
|
||||||
|
"v": "(ch[0-6])\\b",
|
||||||
|
"vt": "str",
|
||||||
|
"case": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"t": "eq",
|
||||||
|
"v": "radio_stat",
|
||||||
|
"vt": "str"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"t": "eq",
|
||||||
|
"v": "firmware",
|
||||||
|
"vt": "str"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"t": "eq",
|
||||||
|
"v": "hardware",
|
||||||
|
"vt": "str"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"t": "eq",
|
||||||
|
"v": "alarm",
|
||||||
|
"vt": "str"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"checkall": "true",
|
||||||
|
"repair": false,
|
||||||
|
"outputs": 7,
|
||||||
|
"x": 330,
|
||||||
|
"y": 2380,
|
||||||
|
"wires": [
|
||||||
|
[
|
||||||
|
"845aeb93e39092c5"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"241a8e70e9fde93c"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"fb7357db50501627"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"9d38f021308664c1"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"a508355f0cc87966"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"d2c9aa1a8978aca6"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"b27032beb597d5a7"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "845aeb93e39092c5",
|
||||||
|
"type": "debug",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "available",
|
||||||
|
"active": true,
|
||||||
|
"tosidebar": false,
|
||||||
|
"console": false,
|
||||||
|
"tostatus": true,
|
||||||
|
"complete": "payload",
|
||||||
|
"targetType": "msg",
|
||||||
|
"statusVal": "payload",
|
||||||
|
"statusType": "auto",
|
||||||
|
"x": 600,
|
||||||
|
"y": 2240,
|
||||||
|
"wires": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "241a8e70e9fde93c",
|
||||||
|
"type": "debug",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "last_success",
|
||||||
|
"active": true,
|
||||||
|
"tosidebar": false,
|
||||||
|
"console": false,
|
||||||
|
"tostatus": true,
|
||||||
|
"complete": "payload",
|
||||||
|
"targetType": "msg",
|
||||||
|
"statusVal": "payload",
|
||||||
|
"statusType": "auto",
|
||||||
|
"x": 610,
|
||||||
|
"y": 2300,
|
||||||
|
"wires": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "9d38f021308664c1",
|
||||||
|
"type": "debug",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "radio_stat",
|
||||||
|
"active": false,
|
||||||
|
"tosidebar": true,
|
||||||
|
"console": false,
|
||||||
|
"tostatus": false,
|
||||||
|
"complete": "payload",
|
||||||
|
"targetType": "msg",
|
||||||
|
"statusVal": "",
|
||||||
|
"statusType": "auto",
|
||||||
|
"x": 600,
|
||||||
|
"y": 2400,
|
||||||
|
"wires": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "a508355f0cc87966",
|
||||||
|
"type": "debug",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "firmware",
|
||||||
|
"active": false,
|
||||||
|
"tosidebar": true,
|
||||||
|
"console": false,
|
||||||
|
"tostatus": false,
|
||||||
|
"complete": "payload",
|
||||||
|
"targetType": "msg",
|
||||||
|
"statusVal": "",
|
||||||
|
"statusType": "auto",
|
||||||
|
"x": 600,
|
||||||
|
"y": 2440,
|
||||||
|
"wires": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "d2c9aa1a8978aca6",
|
||||||
|
"type": "debug",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "hardware",
|
||||||
|
"active": false,
|
||||||
|
"tosidebar": true,
|
||||||
|
"console": false,
|
||||||
|
"tostatus": false,
|
||||||
|
"complete": "payload",
|
||||||
|
"targetType": "msg",
|
||||||
|
"statusVal": "",
|
||||||
|
"statusType": "auto",
|
||||||
|
"x": 600,
|
||||||
|
"y": 2480,
|
||||||
|
"wires": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "b27032beb597d5a7",
|
||||||
|
"type": "debug",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "alarm",
|
||||||
|
"active": false,
|
||||||
|
"tosidebar": true,
|
||||||
|
"console": false,
|
||||||
|
"tostatus": false,
|
||||||
|
"complete": "payload",
|
||||||
|
"targetType": "msg",
|
||||||
|
"statusVal": "",
|
||||||
|
"statusType": "auto",
|
||||||
|
"x": 590,
|
||||||
|
"y": 2520,
|
||||||
|
"wires": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "d814738cf55ad663",
|
||||||
|
"type": "debug",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "total",
|
||||||
|
"active": false,
|
||||||
|
"tosidebar": true,
|
||||||
|
"console": false,
|
||||||
|
"tostatus": false,
|
||||||
|
"complete": "payload",
|
||||||
|
"targetType": "msg",
|
||||||
|
"statusVal": "",
|
||||||
|
"statusType": "auto",
|
||||||
|
"x": 590,
|
||||||
|
"y": 2160,
|
||||||
|
"wires": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "a55632ad0dff0b69",
|
||||||
|
"type": "switch",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "",
|
||||||
|
"property": "$split(topic, '/')[1]",
|
||||||
|
"propertyType": "jsonata",
|
||||||
|
"rules": [
|
||||||
|
{
|
||||||
|
"t": "eq",
|
||||||
|
"v": "uptime",
|
||||||
|
"vt": "str"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"t": "eq",
|
||||||
|
"v": "wifi_rssi",
|
||||||
|
"vt": "str"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"t": "eq",
|
||||||
|
"v": "status",
|
||||||
|
"vt": "str"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"t": "eq",
|
||||||
|
"v": "total",
|
||||||
|
"vt": "str"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"checkall": "true",
|
||||||
|
"repair": false,
|
||||||
|
"outputs": 4,
|
||||||
|
"x": 330,
|
||||||
|
"y": 2100,
|
||||||
|
"wires": [
|
||||||
|
[
|
||||||
|
"1fbb0674d2576ee7"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"e6be1c98ac55f511"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"f9c2d3b30e34fdda"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"d814738cf55ad663"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "f9c2d3b30e34fdda",
|
||||||
|
"type": "debug",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "status",
|
||||||
|
"active": false,
|
||||||
|
"tosidebar": false,
|
||||||
|
"console": false,
|
||||||
|
"tostatus": true,
|
||||||
|
"complete": "payload",
|
||||||
|
"targetType": "msg",
|
||||||
|
"statusVal": "payload",
|
||||||
|
"statusType": "auto",
|
||||||
|
"x": 590,
|
||||||
|
"y": 2100,
|
||||||
|
"wires": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "e6be1c98ac55f511",
|
||||||
|
"type": "debug",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "wifi_rssi",
|
||||||
|
"active": false,
|
||||||
|
"tosidebar": false,
|
||||||
|
"console": false,
|
||||||
|
"tostatus": true,
|
||||||
|
"complete": "payload",
|
||||||
|
"targetType": "msg",
|
||||||
|
"statusVal": "payload",
|
||||||
|
"statusType": "auto",
|
||||||
|
"x": 600,
|
||||||
|
"y": 2040,
|
||||||
|
"wires": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1fbb0674d2576ee7",
|
||||||
|
"type": "debug",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "uptime",
|
||||||
|
"active": false,
|
||||||
|
"tosidebar": false,
|
||||||
|
"console": false,
|
||||||
|
"tostatus": true,
|
||||||
|
"complete": "payload",
|
||||||
|
"targetType": "msg",
|
||||||
|
"statusVal": "payload",
|
||||||
|
"statusType": "auto",
|
||||||
|
"x": 590,
|
||||||
|
"y": 1980,
|
||||||
|
"wires": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "91a4607dfda84b67",
|
||||||
|
"type": "change",
|
||||||
|
"z": "5de5756d190f9086",
|
||||||
|
"name": "Lösche",
|
||||||
|
"rules": [
|
||||||
|
{
|
||||||
|
"t": "delete",
|
||||||
|
"p": "payload[0].YieldDay",
|
||||||
|
"pt": "msg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"t": "delete",
|
||||||
|
"p": "payload[0].MaxPower",
|
||||||
|
"pt": "msg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"t": "delete",
|
||||||
|
"p": "payload[0].ALARM_MES_ID",
|
||||||
|
"pt": "msg"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"action": "",
|
||||||
|
"property": "",
|
||||||
|
"from": "",
|
||||||
|
"to": "",
|
||||||
|
"reg": false,
|
||||||
|
"x": 780,
|
||||||
|
"y": 2360,
|
||||||
|
"wires": [
|
||||||
|
[
|
||||||
|
"670eb9fbb5c31b2c"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "319864a4e0fd913f",
|
||||||
|
"type": "mqtt-broker",
|
||||||
|
"name": "broker",
|
||||||
|
"broker": "localhost",
|
||||||
|
"port": "1883",
|
||||||
|
"clientid": "",
|
||||||
|
"autoConnect": true,
|
||||||
|
"usetls": false,
|
||||||
|
"protocolVersion": "4",
|
||||||
|
"keepalive": "60",
|
||||||
|
"cleansession": true,
|
||||||
|
"birthTopic": "",
|
||||||
|
"birthQos": "0",
|
||||||
|
"birthPayload": "",
|
||||||
|
"birthMsg": {},
|
||||||
|
"closeTopic": "",
|
||||||
|
"closeQos": "0",
|
||||||
|
"closePayload": "",
|
||||||
|
"closeMsg": {},
|
||||||
|
"willTopic": "",
|
||||||
|
"willQos": "0",
|
||||||
|
"willPayload": "",
|
||||||
|
"willMsg": {},
|
||||||
|
"userProps": "",
|
||||||
|
"sessionExpiry": ""
|
||||||
|
}
|
||||||
|
]
|
Loading…
Add table
Reference in a new issue