Skip to content

Commit

Permalink
Merge remote-tracking branch 'tbnobody/OpenDTU/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
helgeerbe committed Dec 5, 2022
2 parents a213082 + e8c517f commit df5cde2
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 240 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ This can be achieved by editing the 'platformio.ini' file and add/change one or
* erase flash: `platformio run -e generic -t erase`

### using the pre-compiled .bin files
The pre-compiled files can be found on the [github page](https://github.com/tbnobody/OpenDTU) in the tab "Actions" and the sub menu "OpenDTU Build". Just choose the latest build from the master branch (blue font). You need to be logged in with your github account to download the files.
The pre-compiled files can be found on the [github page](https://github.com/tbnobody/OpenDTU) in the tab "Actions" and the sub menu "OpenDTU Build". Just choose the latest build from the master branch (search for "master" in the blue font text but click on the white header text!). You need to be logged in with your github account to download the files.
Use a ESP32 flash tool of your choice (see next chapter) and flash the `.bin` files to the right addresses:

| Address | File |
Expand All @@ -184,7 +184,7 @@ Use a ESP32 flash tool of your choice (see next chapter) and flash the `.bin` fi

For further updates you can just use the web interface and upload the `opendtu-*.bin` file.

### Flash with esptool.py (Linux)
#### Flash with esptool.py (Linux)
```
esptool.py --port /dev/ttyUSB0 --chip esp32 --before default_reset --after hard_reset \
write_flash --flash_mode dout --flash_freq 40m --flash_size detect \
Expand All @@ -194,7 +194,7 @@ esptool.py --port /dev/ttyUSB0 --chip esp32 --before default_reset --after hard_
0x10000 opendtu-generic.bin
```

### Flash with Espressif Flash Download Tool (Windows)
#### Flash with Espressif Flash Download Tool (Windows)

[Download link](https://www.espressif.com/en/support/download/other-tools)

Expand All @@ -205,7 +205,7 @@ esptool.py --port /dev/ttyUSB0 --chip esp32 --before default_reset --after hard_
- To program, press "Start" on screen, then the "Boot" button.
- When flashing is complete (FINISH appears) then press the Reset button on the ESP32 board (or powercycle ) to start the OpenDTU application.

### Flash with ESP_Flasher (Windows)
#### Flash with ESP_Flasher (Windows)
Users report that [ESP_Flasher](https://github.com/Jason2866/ESP_Flasher/releases/) is suitable for flashing OpenDTU on Windows.

## First configuration
Expand Down Expand Up @@ -236,6 +236,9 @@ A documentation of the Web API can be found here: [Web-API Documentation](docs/W
## Available cases
* <https://www.thingiverse.com/thing:5435911>
* <https://www.printables.com/model/293003-sol-opendtu-esp32-nrf24l01-case>
* <https://www.thingiverse.com/thing:5661780>
* <https://www.thingiverse.com/thing:5632374>


## Building
* Building the WebApp
Expand Down
4 changes: 2 additions & 2 deletions docs/MQTT_Topics.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ cmd topics are used to set values. Status topics are updated from values set in
| [serial]/status/limit_relative | R | Current applied production limit of the inverter | % of total possible output |
| [serial]/status/limit_absolute | R | Current applied production limit of the inverter | Watt (W) |
| [serial]/cmd/limit_persistent_relative | W | Set the inverter limit as a percentage of total production capability. The value will survive the night without power. The updated value will show up in the web GUI and limit_relative topic immediatly. | % |
| [serial]/cmd/limit_persistent_absolute | W | Set the inverter limit as a absolute value. The value will survive the night without power. The updated value will show up in the web GUI and limit_relative topic after around 4 minutes. | Watt (W) |
| [serial]/cmd/limit_persistent_absolute | W | Set the inverter limit as a absolute value. The value will survive the night without power. The updated value will set immediatly within the inverter but show up in the web GUI and limit_relative topic after around 4 minutes. If you are using a already known inverter (known Hardware ID), the updated value will show up within a few seconds. | Watt (W) |
| [serial]/cmd/limit_nonpersistent_relative | W | Set the inverter limit as a percentage of total production capability. The value will reset to the last persistent value at night without power. The updated value will show up in the web GUI and limit_relative topic immediatly. | % |
| [serial]/cmd/limit_nonpersistent_absolute | W | Set the inverter limit as a absolute value. The value will reset to the last persistent value at night without power. The updated value will show up in the web GUI and limit_relative topic after around 4 minutes. | Watt (W) |
| [serial]/cmd/limit_nonpersistent_absolute | W | Set the inverter limit as a absolute value. The value will reset to the last persistent value at night without power. The updated value will set immediatly within the inverter but show up in the web GUI and limit_relative topic after around 4 minutes. If you are using a already known inverter (known Hardware ID), the updated value will show up within a few seconds. | Watt (W) |
| [serial]/cmd/power | W | Turn the inverter on (1) or off (0) | 0 or 1 |
| [serial]/cmd/restart | W | Restarts the inverters (also resets YieldDay) | 1 |
166 changes: 0 additions & 166 deletions lib/CircularBuffer/CircularBuffer.h

This file was deleted.

4 changes: 2 additions & 2 deletions lib/Hoymiles/src/Hoymiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

HoymilesClass Hoymiles;

void HoymilesClass::init()
void HoymilesClass::init(SPIClass* initialisedSpiBus, uint8_t pinCE, uint8_t pinIRQ)
{
_xSemaphore = xSemaphoreCreateMutex();
HOY_SEMAPHORE_GIVE(); // release before first use

_pollInterval = 0;
_radio.reset(new HoymilesRadio());
_radio->init();
_radio->init(initialisedSpiBus, pinCE, pinIRQ);
}

void HoymilesClass::loop()
Expand Down
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/Hoymiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class HoymilesClass {
public:
void init();
void init(SPIClass* initialisedSpiBus, uint8_t pinCE, uint8_t pinIRQ);
void loop();

std::shared_ptr<InverterAbstract> addInverter(const char* name, uint64_t serial);
Expand Down
45 changes: 21 additions & 24 deletions lib/Hoymiles/src/HoymilesRadio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
#include <Every.h>
#include <FunctionalInterrupt.h>

void HoymilesRadio::init()
void HoymilesRadio::init(SPIClass* initialisedSpiBus, uint8_t pinCE, uint8_t pinIRQ)
{
_dtuSerial.u64 = 0;

_hspi.reset(new SPIClass(HSPI));
_radio.reset(new RF24(HOYMILES_PIN_CE, HOYMILES_PIN_CS));
_spiPtr.reset(initialisedSpiBus);
_radio.reset(new RF24(pinCE, initialisedSpiBus->pinSS()));

_hspi->begin(HOYMILES_PIN_SCLK, HOYMILES_PIN_MISO, HOYMILES_PIN_MOSI, HOYMILES_PIN_CS);
_radio->begin(_hspi.get());
_radio->begin(_spiPtr.get());

_radio->setDataRate(RF24_250KBPS);
_radio->enableDynamicPayloads();
Expand All @@ -27,7 +26,7 @@ void HoymilesRadio::init()
Serial.println(F("Connection error!!"));
}

attachInterrupt(digitalPinToInterrupt(HOYMILES_PIN_IRQ), std::bind(&HoymilesRadio::handleIntr, this), FALLING);
attachInterrupt(digitalPinToInterrupt(pinIRQ), std::bind(&HoymilesRadio::handleIntr, this), FALLING);

openReadingPipe();
_radio->startListening();
Expand All @@ -43,17 +42,15 @@ void HoymilesRadio::loop()
if (_packetReceived) {
Serial.println(F("Interrupt received"));
while (_radio->available()) {
if (!_rxBuffer.full()) {
fragment_t* f;
f = _rxBuffer.getFront();
memset(f->fragment, 0xcc, MAX_RF_PAYLOAD_SIZE);
f->len = _radio->getDynamicPayloadSize();
f->channel = _radio->getChannel();
if (f->len > MAX_RF_PAYLOAD_SIZE)
f->len = MAX_RF_PAYLOAD_SIZE;

_radio->read(f->fragment, f->len);
_rxBuffer.pushFront(f);
if (!(_rxBuffer.size() > FRAGMENT_BUFFER_SIZE)) {
fragment_t f;
memset(f.fragment, 0xcc, MAX_RF_PAYLOAD_SIZE);
f.len = _radio->getDynamicPayloadSize();
f.channel = _radio->getChannel();
if (f.len > MAX_RF_PAYLOAD_SIZE)
f.len = MAX_RF_PAYLOAD_SIZE;
_radio->read(f.fragment, f.len);
_rxBuffer.push(f);
} else {
Serial.println(F("Buffer full"));
_radio->flush_rx();
Expand All @@ -64,16 +61,16 @@ void HoymilesRadio::loop()
} else {
// Perform package parsing only if no packages are received
if (!_rxBuffer.empty()) {
fragment_t* f = _rxBuffer.getBack();
if (checkFragmentCrc(f)) {
std::shared_ptr<InverterAbstract> inv = Hoymiles.getInverterByFragment(f);
fragment_t f = _rxBuffer.back();
if (checkFragmentCrc(&f)) {
std::shared_ptr<InverterAbstract> inv = Hoymiles.getInverterByFragment(&f);

if (nullptr != inv) {
// Save packet in inverter rx buffer
char buf[30];
snprintf(buf, sizeof(buf), "RX Channel: %d --> ", f->channel);
dumpBuf(buf, f->fragment, f->len);
inv->addRxFragment(f->fragment, f->len);
snprintf(buf, sizeof(buf), "RX Channel: %d --> ", f.channel);
dumpBuf(buf, f.fragment, f.len);
inv->addRxFragment(f.fragment, f.len);
} else {
Serial.println(F("Inverter Not found!"));
}
Expand All @@ -83,7 +80,7 @@ void HoymilesRadio::loop()
}

// Remove paket from buffer even it was corrupted
_rxBuffer.popBack();
_rxBuffer.pop();
}
}

Expand Down
31 changes: 3 additions & 28 deletions lib/Hoymiles/src/HoymilesRadio.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "CircularBuffer.h"
#include "TimeoutHelper.h"
#include "commands/CommandAbstract.h"
#include "types.h"
Expand All @@ -12,33 +11,9 @@
// number of fragments hold in buffer
#define FRAGMENT_BUFFER_SIZE 30

#ifndef HOYMILES_PIN_MISO
#define HOYMILES_PIN_MISO 19
#endif

#ifndef HOYMILES_PIN_MOSI
#define HOYMILES_PIN_MOSI 23
#endif

#ifndef HOYMILES_PIN_SCLK
#define HOYMILES_PIN_SCLK 18
#endif

#ifndef HOYMILES_PIN_IRQ
#define HOYMILES_PIN_IRQ 16
#endif

#ifndef HOYMILES_PIN_CE
#define HOYMILES_PIN_CE 4
#endif

#ifndef HOYMILES_PIN_CS
#define HOYMILES_PIN_CS 5
#endif

class HoymilesRadio {
public:
void init();
void init(SPIClass* initialisedSpiBus, uint8_t pinCE, uint8_t pinIRQ);
void loop();
void setPALevel(rf24_pa_dbm_e paLevel);

Expand Down Expand Up @@ -71,7 +46,7 @@ class HoymilesRadio {
void sendRetransmitPacket(uint8_t fragment_id);
void sendLastPacketAgain();

std::unique_ptr<SPIClass> _hspi;
std::unique_ptr<SPIClass> _spiPtr;
std::unique_ptr<RF24> _radio;
uint8_t _rxChLst[5] = { 3, 23, 40, 61, 75 };
uint8_t _rxChIdx = 0;
Expand All @@ -81,7 +56,7 @@ class HoymilesRadio {

volatile bool _packetReceived = false;

CircularBuffer<fragment_t, FRAGMENT_BUFFER_SIZE> _rxBuffer;
std::queue<fragment_t> _rxBuffer;
TimeoutHelper _rxTimeout;

serial_u _dtuSerial;
Expand Down
Loading

0 comments on commit df5cde2

Please sign in to comment.