Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to new OpenDTU Version #1924

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ struct CONFIG_T {
bool Enabled;
} Mdns;

struct {
bool Fronius_SM_Simulation_Enabled;
} Fronius;

struct {
char Server[NTP_MAX_SERVER_STRLEN + 1];
char Timezone[NTP_MAX_TIMEZONE_STRLEN + 1];
Expand Down
18 changes: 18 additions & 0 deletions include/ModbusDtu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <cstdint>
#include "Configuration.h"
#include <ModbusIP_ESP8266.h>
#include <Hoymiles.h>

class ModbusDtuClass {
public:
void init();
void loop();

private:
uint32_t _lastPublish = 0;
bool _isstarted = false;
};

extern ModbusDtuClass ModbusDtu;
2 changes: 1 addition & 1 deletion include/MqttHandleDtu.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MqttHandleDtuClass {

private:
void loop();

uint32_t _lastPublish = 0;
Task _loopTask;
};

Expand Down
1 change: 1 addition & 0 deletions include/MqttHandleInverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MqttHandleInverterClass {
Task _loopTask;

uint32_t _lastPublishStats[INV_MAX_COUNT] = { 0 };
uint32_t _lastPublish = 0;

FieldId_t _publishFields[14] = {
FLD_UDC,
Expand Down
1 change: 1 addition & 0 deletions include/WebApi.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include "ModbusDtu.h"
#include "WebApi_config.h"
#include "WebApi_device.h"
#include "WebApi_devinfo.h"
Expand Down
5 changes: 3 additions & 2 deletions include/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

#define MDNS_ENABLED false

#define NTP_SERVER_OLD "pool.ntp.org"
#define NTP_SERVER "opendtu.pool.ntp.org"
#define FRONIUS_SM_SIMULATION_ENABLED false

#define NTP_SERVER "pool.ntp.org"
#define NTP_TIMEZONE "CET-1CEST,M3.5.0,M10.5.0/3"
#define NTP_TIMEZONEDESCR "Europe/Berlin"
#define NTP_LONGITUDE 10.4515f
Expand Down
188 changes: 86 additions & 102 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
[platformio]
default_envs = generic_esp32
extra_configs =
platformio_override.ini
platformio_override.ini

[env]
; Make sure to NOT add any spaces in the custom_ci_action property
; (also the position in the file is important)
custom_ci_action = generic,generic_esp32,generic_esp32s3,generic_esp32s3_usb

framework = arduino
platform = [email protected]

Expand All @@ -34,8 +31,7 @@ build_flags =
-std=c++17
-std=gnu++17
build_unflags =
-std=gnu++11

-std=gnu++11
lib_deps =
mathieucarbou/ESP Async WebServer @ 2.9.0
bblanchon/ArduinoJson @ ^7.0.4
Expand All @@ -44,7 +40,7 @@ lib_deps =
olikraus/U8g2 @ ^2.35.15
buelowp/sunset @ ^1.1.7
https://github.com/arkhipenko/TaskScheduler#testing

https://github.com/ArekKubacki/modbus-esp8266#4.1.2
extra_scripts =
pre:pio-scripts/auto_firmware_version.py
pre:pio-scripts/patch_apply.py
Expand All @@ -66,11 +62,6 @@ monitor_filters = esp32_exception_decoder, time, log2file, colorize
monitor_speed = 115200
upload_protocol = esptool

; Specify port in platformio_override.ini. Comment out (add ; in front of line) to use auto detection.
; monitor_port = COM4
; upload_port = COM4


[env:generic_esp32]
board = esp32dev
build_flags = ${env.build_flags}
Expand All @@ -96,8 +87,8 @@ build_flags = ${env.build_flags}
board = esp32-c3-devkitc-02
custom_patches = ${env.custom_patches}
build_flags = ${env.build_flags}
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1


[env:generic_esp32s3]
Expand All @@ -109,142 +100,135 @@ build_flags = ${env.build_flags}
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
build_flags = ${env.build_flags}
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1

-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1

[env:generic]
board = esp32dev
build_flags = ${env.build_flags}
-DHOYMILES_PIN_MISO=19
-DHOYMILES_PIN_MOSI=23
-DHOYMILES_PIN_SCLK=18
-DHOYMILES_PIN_IRQ=16
-DHOYMILES_PIN_CE=4
-DHOYMILES_PIN_CS=5
-DHOYMILES_PIN_MISO=19
-DHOYMILES_PIN_MOSI=23
-DHOYMILES_PIN_SCLK=18
-DHOYMILES_PIN_IRQ=16
-DHOYMILES_PIN_CE=4
-DHOYMILES_PIN_CS=5


[env:olimex_esp32_poe]
; https://www.olimex.com/Products/IoT/ESP32/ESP32-POE/open-source-hardware
board = esp32-poe
build_flags = ${env.build_flags}
-DHOYMILES_PIN_MISO=15
-DHOYMILES_PIN_MOSI=2
-DHOYMILES_PIN_SCLK=14
-DHOYMILES_PIN_IRQ=13
-DHOYMILES_PIN_CE=16
-DHOYMILES_PIN_CS=5
-DOPENDTU_ETHERNET
-DHOYMILES_PIN_MISO=15
-DHOYMILES_PIN_MOSI=2
-DHOYMILES_PIN_SCLK=14
-DHOYMILES_PIN_IRQ=13
-DHOYMILES_PIN_CE=16
-DHOYMILES_PIN_CS=5
-DOPENDTU_ETHERNET


[env:olimex_esp32_evb]
; https://www.olimex.com/Products/IoT/ESP32/ESP32-EVB/open-source-hardware
board = esp32-evb
build_flags = ${env.build_flags}
-DHOYMILES_PIN_MISO=15
-DHOYMILES_PIN_MOSI=2
-DHOYMILES_PIN_SCLK=14
-DHOYMILES_PIN_IRQ=13
-DHOYMILES_PIN_CE=16
-DHOYMILES_PIN_CS=17
-DOPENDTU_ETHERNET
-DHOYMILES_PIN_MISO=15
-DHOYMILES_PIN_MOSI=2
-DHOYMILES_PIN_SCLK=14
-DHOYMILES_PIN_IRQ=13
-DHOYMILES_PIN_CE=16
-DHOYMILES_PIN_CS=17
-DOPENDTU_ETHERNET


[env:d1_mini_esp32]
board = wemos_d1_mini32
build_flags =
${env.build_flags}
-DHOYMILES_PIN_MISO=19
-DHOYMILES_PIN_MOSI=23
-DHOYMILES_PIN_SCLK=18
-DHOYMILES_PIN_IRQ=16
-DHOYMILES_PIN_CE=17
-DHOYMILES_PIN_CS=5
${env.build_flags}
-DHOYMILES_PIN_MISO=19
-DHOYMILES_PIN_MOSI=23
-DHOYMILES_PIN_SCLK=18
-DHOYMILES_PIN_IRQ=16
-DHOYMILES_PIN_CE=17
-DHOYMILES_PIN_CS=5


[env:wt32_eth01]
; http://www.wireless-tag.com/portfolio/wt32-eth01/
board = wt32-eth01
build_flags = ${env.build_flags}
-DHOYMILES_PIN_MISO=4
-DHOYMILES_PIN_MOSI=2
-DHOYMILES_PIN_SCLK=32
-DHOYMILES_PIN_IRQ=33
-DHOYMILES_PIN_CE=14
-DHOYMILES_PIN_CS=15
-DOPENDTU_ETHERNET
-DHOYMILES_PIN_MISO=4
-DHOYMILES_PIN_MOSI=2
-DHOYMILES_PIN_SCLK=32
-DHOYMILES_PIN_IRQ=33
-DHOYMILES_PIN_CE=14
-DHOYMILES_PIN_CS=15
-DOPENDTU_ETHERNET


[env:esp_s3_12k_kit]
; https://www.waveshare.com/wiki/NodeMCU-ESP-S3-12K-Kit
board = esp32-s3-devkitc-1
build_flags = ${env.build_flags}
-DHOYMILES_PIN_MISO=16
-DHOYMILES_PIN_MOSI=17
-DHOYMILES_PIN_SCLK=18
-DHOYMILES_PIN_IRQ=3
-DHOYMILES_PIN_CE=4
-DHOYMILES_PIN_CS=5

-DHOYMILES_PIN_MISO=16
-DHOYMILES_PIN_MOSI=17
-DHOYMILES_PIN_SCLK=18
-DHOYMILES_PIN_IRQ=3
-DHOYMILES_PIN_CE=4
-DHOYMILES_PIN_CS=5

[env:lolin32_lite]
; https://www.makershop.de/plattformen/esp8266/wemos-lolin32/
; https://www.az-delivery.de/products/esp32-lolin-lolin32
board = lolin32_lite
build_flags = ${env.build_flags}
-DHOYMILES_PIN_MISO=19
-DHOYMILES_PIN_MOSI=23
-DHOYMILES_PIN_SCLK=18
-DHOYMILES_PIN_IRQ=16
-DHOYMILES_PIN_CE=17
-DHOYMILES_PIN_CS=5
-DHOYMILES_PIN_MISO=19
-DHOYMILES_PIN_MOSI=23
-DHOYMILES_PIN_SCLK=18
-DHOYMILES_PIN_IRQ=16
-DHOYMILES_PIN_CE=17
-DHOYMILES_PIN_CS=5


[env:lolin_s2_mini]
board = lolin_s2_mini
build_flags = ${env.build_flags}
-DHOYMILES_PIN_MISO=13
-DHOYMILES_PIN_MOSI=11
-DHOYMILES_PIN_SCLK=12
-DHOYMILES_PIN_CS=10
-DHOYMILES_PIN_IRQ=4
-DHOYMILES_PIN_CE=5

-DHOYMILES_PIN_MISO=13
-DHOYMILES_PIN_MOSI=11
-DHOYMILES_PIN_SCLK=12
-DHOYMILES_PIN_CS=10
-DHOYMILES_PIN_IRQ=4
-DHOYMILES_PIN_CE=5

[env:opendtufusionv1]
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
debug_tool = esp-builtin
debug_speed = 12000
build_flags = ${env.build_flags}
-DHOYMILES_PIN_MISO=48
-DHOYMILES_PIN_MOSI=35
-DHOYMILES_PIN_SCLK=36
-DHOYMILES_PIN_IRQ=47
-DHOYMILES_PIN_CE=38
-DHOYMILES_PIN_CS=37
-DLED0=17
-DLED1=18
-DARDUINO_USB_MODE=1
-DHOYMILES_PIN_MISO=48
-DHOYMILES_PIN_MOSI=35
-DHOYMILES_PIN_SCLK=36
-DHOYMILES_PIN_IRQ=47
-DHOYMILES_PIN_CE=38
-DHOYMILES_PIN_CS=37
-DLED0=17
-DLED1=18
-DARDUINO_USB_MODE=1

[env:opendtufusionv2]
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
debug_tool = esp-builtin
debug_speed = 12000
build_flags = ${env.build_flags}
-DHOYMILES_PIN_MISO=48
-DHOYMILES_PIN_MOSI=35
-DHOYMILES_PIN_SCLK=36
-DHOYMILES_PIN_IRQ=47
-DHOYMILES_PIN_CE=38
-DHOYMILES_PIN_CS=37
-DLED0=17
-DLED1=18
-DCMT_CLK=6
-DCMT_CS=4
-DCMT_FCS=21
-DCMT_GPIO2=3
-DCMT_GPIO3=8
-DCMT_SDIO=5
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1
-DHOYMILES_PIN_MISO=48
-DHOYMILES_PIN_MOSI=35
-DHOYMILES_PIN_SCLK=36
-DHOYMILES_PIN_IRQ=47
-DHOYMILES_PIN_CE=38
-DHOYMILES_PIN_CS=37
-DLED0=17
-DLED1=18
-DCMT_CLK=6
-DCMT_CS=4
-DCMT_FCS=21
-DCMT_GPIO2=3
-DCMT_GPIO3=8
-DCMT_SDIO=5
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1

12 changes: 6 additions & 6 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ bool ConfigurationClass::write()
JsonObject mdns = doc["mdns"].to<JsonObject>();
mdns["enabled"] = config.Mdns.Enabled;

JsonObject modbus = doc["modbus"].to<JsonObject>();
modbus["enabled"] = config.Fronius.Fronius_SM_Simulation_Enabled;

JsonObject ntp = doc["ntp"].to<JsonObject>();
ntp["server"] = config.Ntp.Server;
ntp["timezone"] = config.Ntp.Timezone;
Expand Down Expand Up @@ -219,6 +222,9 @@ bool ConfigurationClass::read()
JsonObject mdns = doc["mdns"];
config.Mdns.Enabled = mdns["enabled"] | MDNS_ENABLED;

JsonObject modbus = doc["modbus"];
config.Fronius.Fronius_SM_Simulation_Enabled = modbus["enabled"] | FRONIUS_SM_SIMULATION_ENABLED;

JsonObject ntp = doc["ntp"];
strlcpy(config.Ntp.Server, ntp["server"] | NTP_SERVER, sizeof(config.Ntp.Server));
strlcpy(config.Ntp.Timezone, ntp["timezone"] | NTP_TIMEZONE, sizeof(config.Ntp.Timezone));
Expand Down Expand Up @@ -372,12 +378,6 @@ void ConfigurationClass::migrate()
config.Dtu.Cmt.Frequency *= 1000;
}

if (config.Cfg.Version < 0x00011c00) {
if (!strcmp(config.Ntp.Server, NTP_SERVER_OLD)) {
strlcpy(config.Ntp.Server, NTP_SERVER, sizeof(config.Ntp.Server));
}
}

f.close();

config.Cfg.Version = CONFIG_VERSION;
Expand Down
Loading