* Optimize Sun data calculation * Remove not required enum * Split config struct into different sub structs * Feature: Allow configuration of LWT QoS * Made resetreason methods static * Feature: Implement offset cache for "YieldDay" Thanks to @broth-itk for the idea! Fix: #1258 #1397 * Add Esp32-Stick-PoE-A * remove broken LilyGO_T_ETH_POE config, use device profile instead * Feature: High resolution Icon and PWA (Progressive Web App) functionality Fix: #1289 * webapp: Update dependencies * Initialize TaskScheduler * Migrate SunPosition to TaskScheduler * Migrate Datastore to TaskScheduler * Migrate MqttHandleInverterTotal to TaskSchedule * Migrate MqttHandleHass to TaskScheduler * Migrate MqttHandleDtu to TaskScheduler * Migrate MqttHandleInverter to TaskScheduler * Migrate LedSingle to TaskScheduler * Migrate NetworkSettings to TaskScheduler * Migrate InverterSettings to TaskScheduler * Migrate MessageOutput to TaskScheduler * Migrate Display_Graphic to TaskScheduler * Migrate WebApi to TaskScheduler * Split InverterSettings into multiple tasks * Calculate SunPosition only every 5 seconds * Split LedSingle into multiple tasks * Upgrade espMqttClient from 1.4.5 to 1.5.0 * Doc: Correct amount of MPP-Tracker * Added HMT-1600-4T and HMT-1800-4T to DevInfoParser Fix #1524 * Adjusted inverter names for HMS-1600/1800/2000-4T * Add channel count to description of detected inverter type (DevInfoParser) * Adjust device web api endpoint for dynamic led count * Feature: Added ability to change the brightness of the LEDs Based on the idea of @moritzlerch with several modifications like pwmTable and structure * webapp: Update dependencies * Update olikraus/U8g2 from 2.35.7 to 2.35.8 * Remove not required onWebsocketEvent * Remove code nesting * Introduce several const statements * Remove not required AsyncEventSource * Doc: Added byte specification to each command * Feature: Added basic Grid Profile parser which shows the used profile and version Other values are still outstanding. * Optimize AlarmLogParser to save memory * Add libfrozen to project to create constexpr maps * Feature: First version of GridProfile Parser which shows all values contained in the profile. * webapp: Update dependencies * Apply better variable names * Remove not required casts * Add additional compiler flags to prevent errors * Add const statement to several variables * Replace NULL by nullptr * Update bblanchon/ArduinoJson from 6.21.3 to 6.21.4 * Add const keyword to method parameters * Add const keyword to methods * Use references instead of pointers whenver possible * Adjust member variable names in MqttSettings * Adjust member variable names in NetworkSettings * webapp: Update timezone database to latest version * webapp: Beautify and unify form footers * Feature: Allow setting of an inverter limit of 0% and 0W Thanks to @madmartin in #1270 * Feature: Allow links in device profiles These links will be shown on the hardware settings page. * Doc: Added hint regarding HMS-xxxx-xT-NA inverters * Feature: Added DeviceProfile for CASmo-DTU Based on #1565 * Upgrade actions/upload-artifact from v3 to v4 * Upgrade actions/download-artifact from v3 to v4 * webapp: add app.js.gz * Gridprofileparser: Added latest known values Thanks to @stefan123t and @noone2k * webapp: Fix lint errors * Feature: Add DTU to Home Assistant Auto Discovery This is based on PR 1365 from @CFenner with several fixes and optimizations * Fix: Remove debug output as it floods the console * Fix: Gridprofileparser: Add additional error handling if profile is unknown * webapp: add app.js.gz * Fix: Offset cache for "YieldDay" did not work correctly * webapp: update dependencies * webapp: add app.js.gz * Fix: yarn.lock was outdated * Fix: yarn build error * Fix: Reset Yield day correction in combination with Zero Yield Day on Midnight lead to wrong values. * Fix: Allow negative values in GridProfileParser * Correct variable name * Fix #1579: Static IP in Ethernet mode did not work correctly * Feature: Added diagram to display This is based on the idea of @Henrik-Ingenieur and was discussed in #1504 * webapp: update dependencies * webapp: add app.js.gz --------- Co-authored-by: Thomas Basler <thomas@familie-basler.net> Co-authored-by: Pierre Kancir <pierre.kancir.emn@gmail.com>
193 lines
6.0 KiB
C++
193 lines
6.0 KiB
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* Copyright (C) 2022-2023 Thomas Basler and others
|
|
*/
|
|
#include "Configuration.h"
|
|
#include "Datastore.h"
|
|
#include "Display_Graphic.h"
|
|
#include "InverterSettings.h"
|
|
#include "Led_Single.h"
|
|
#include "MessageOutput.h"
|
|
#include "VictronMppt.h"
|
|
#include "Battery.h"
|
|
#include "Huawei_can.h"
|
|
#include "MqttHandleDtu.h"
|
|
#include "MqttHandleHass.h"
|
|
#include "MqttHandleVedirectHass.h"
|
|
#include "MqttHandlePylontechHass.h"
|
|
#include "MqttHandleInverter.h"
|
|
#include "MqttHandleInverterTotal.h"
|
|
#include "MqttHandleVedirect.h"
|
|
#include "MqttHandleHuawei.h"
|
|
#include "MqttHandlePowerLimiter.h"
|
|
#include "MqttSettings.h"
|
|
#include "NetworkSettings.h"
|
|
#include "NtpSettings.h"
|
|
#include "PinMapping.h"
|
|
#include "Scheduler.h"
|
|
#include "SunPosition.h"
|
|
#include "Utils.h"
|
|
#include "WebApi.h"
|
|
#include "PowerMeter.h"
|
|
#include "PowerLimiter.h"
|
|
#include "defaults.h"
|
|
#include <Arduino.h>
|
|
#include <LittleFS.h>
|
|
#include <TaskScheduler.h>
|
|
|
|
void setup()
|
|
{
|
|
// Initialize serial output
|
|
Serial.begin(SERIAL_BAUDRATE);
|
|
#if ARDUINO_USB_CDC_ON_BOOT
|
|
Serial.setTxTimeoutMs(0);
|
|
delay(100);
|
|
#else
|
|
while (!Serial)
|
|
yield();
|
|
#endif
|
|
MessageOutput.init(scheduler);
|
|
MessageOutput.println();
|
|
MessageOutput.println("Starting OpenDTU");
|
|
|
|
// Initialize file system
|
|
MessageOutput.print("Initialize FS... ");
|
|
if (!LittleFS.begin(false)) { // Do not format if mount failed
|
|
MessageOutput.print("failed... trying to format...");
|
|
if (!LittleFS.begin(true)) {
|
|
MessageOutput.print("success");
|
|
} else {
|
|
MessageOutput.print("failed");
|
|
}
|
|
} else {
|
|
MessageOutput.println("done");
|
|
}
|
|
|
|
// Read configuration values
|
|
MessageOutput.print("Reading configuration... ");
|
|
if (!Configuration.read()) {
|
|
MessageOutput.print("initializing... ");
|
|
Configuration.init();
|
|
if (Configuration.write()) {
|
|
MessageOutput.print("written... ");
|
|
} else {
|
|
MessageOutput.print("failed... ");
|
|
}
|
|
}
|
|
if (Configuration.get().Cfg.Version != CONFIG_VERSION) {
|
|
MessageOutput.print("migrated... ");
|
|
Configuration.migrate();
|
|
}
|
|
auto& config = Configuration.get();
|
|
MessageOutput.println("done");
|
|
|
|
// Load PinMapping
|
|
MessageOutput.print("Reading PinMapping... ");
|
|
if (PinMapping.init(String(Configuration.get().Dev_PinMapping))) {
|
|
MessageOutput.print("found valid mapping ");
|
|
} else {
|
|
MessageOutput.print("using default config ");
|
|
}
|
|
const auto& pin = PinMapping.get();
|
|
MessageOutput.println("done");
|
|
|
|
// Initialize WiFi
|
|
MessageOutput.print("Initialize Network... ");
|
|
NetworkSettings.init(scheduler);
|
|
MessageOutput.println("done");
|
|
NetworkSettings.applyConfig();
|
|
|
|
// Initialize NTP
|
|
MessageOutput.print("Initialize NTP... ");
|
|
NtpSettings.init();
|
|
MessageOutput.println("done");
|
|
|
|
// Initialize SunPosition
|
|
MessageOutput.print("Initialize SunPosition... ");
|
|
SunPosition.init(scheduler);
|
|
MessageOutput.println("done");
|
|
|
|
// Initialize MqTT
|
|
MessageOutput.print("Initialize MqTT... ");
|
|
MqttSettings.init();
|
|
MqttHandleDtu.init(scheduler);
|
|
MqttHandleInverter.init(scheduler);
|
|
MqttHandleInverterTotal.init(scheduler);
|
|
MqttHandleVedirect.init(scheduler);
|
|
MqttHandleHass.init(scheduler);
|
|
MqttHandleVedirectHass.init(scheduler);
|
|
MqttHandleHuawei.init(scheduler);
|
|
MqttHandlePowerLimiter.init(scheduler);
|
|
MessageOutput.println("done");
|
|
|
|
// Initialize WebApi
|
|
MessageOutput.print("Initialize WebApi... ");
|
|
WebApi.init(scheduler);
|
|
MessageOutput.println("done");
|
|
|
|
// Initialize Display
|
|
MessageOutput.print("Initialize Display... ");
|
|
Display.init(
|
|
scheduler,
|
|
static_cast<DisplayType_t>(pin.display_type),
|
|
pin.display_data,
|
|
pin.display_clk,
|
|
pin.display_cs,
|
|
pin.display_reset);
|
|
Display.setOrientation(config.Display.Rotation);
|
|
Display.enablePowerSafe = config.Display.PowerSafe;
|
|
Display.enableScreensaver = config.Display.ScreenSaver;
|
|
Display.setContrast(config.Display.Contrast);
|
|
Display.setLanguage(config.Display.Language);
|
|
Display.setStartupDisplay();
|
|
MessageOutput.println("done");
|
|
|
|
// Initialize Single LEDs
|
|
MessageOutput.print("Initialize LEDs... ");
|
|
LedSingle.init(scheduler);
|
|
MessageOutput.println("done");
|
|
|
|
// Check for default DTU serial
|
|
MessageOutput.print("Check for default DTU serial... ");
|
|
if (config.Dtu.Serial == DTU_SERIAL) {
|
|
MessageOutput.print("generate serial based on ESP chip id: ");
|
|
const uint64_t dtuId = Utils::generateDtuSerial();
|
|
MessageOutput.printf("%0x%08x... ",
|
|
((uint32_t)((dtuId >> 32) & 0xFFFFFFFF)),
|
|
((uint32_t)(dtuId & 0xFFFFFFFF)));
|
|
config.Dtu.Serial = dtuId;
|
|
Configuration.write();
|
|
}
|
|
MessageOutput.println("done");
|
|
MessageOutput.println("done");
|
|
|
|
InverterSettings.init(scheduler);
|
|
|
|
Datastore.init(scheduler);
|
|
|
|
VictronMppt.init(scheduler);
|
|
|
|
// Power meter
|
|
PowerMeter.init(scheduler);
|
|
|
|
// Dynamic power limiter
|
|
PowerLimiter.init(scheduler);
|
|
|
|
// Initialize Huawei AC-charger PSU / CAN bus
|
|
MessageOutput.println("Initialize Huawei AC charger interface... ");
|
|
if (PinMapping.isValidHuaweiConfig()) {
|
|
MessageOutput.printf("Huawei AC-charger miso = %d, mosi = %d, clk = %d, irq = %d, cs = %d, power_pin = %d\r\n", pin.huawei_miso, pin.huawei_mosi, pin.huawei_clk, pin.huawei_irq, pin.huawei_cs, pin.huawei_power);
|
|
HuaweiCan.init(scheduler, pin.huawei_miso, pin.huawei_mosi, pin.huawei_clk, pin.huawei_irq, pin.huawei_cs, pin.huawei_power);
|
|
MessageOutput.println("done");
|
|
} else {
|
|
MessageOutput.println("Invalid pin config");
|
|
}
|
|
|
|
Battery.init(scheduler);
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
scheduler.execute();
|
|
}
|