Replace all Serial by MessageOutput
This commit is contained in:
parent
cd5d5edd5f
commit
8b60c29667
@ -3,6 +3,7 @@
|
||||
* Copyright (C) 2022 Thomas Basler and others
|
||||
*/
|
||||
#include "Configuration.h"
|
||||
#include "MessageOutput.h"
|
||||
#include "defaults.h"
|
||||
#include <ArduinoJson.h>
|
||||
#include <LittleFS.h>
|
||||
@ -95,7 +96,7 @@ bool ConfigurationClass::write()
|
||||
|
||||
// Serialize JSON to file
|
||||
if (serializeJson(doc, f) == 0) {
|
||||
Serial.println("Failed to write file");
|
||||
MessageOutput.println("Failed to write file");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -111,7 +112,7 @@ bool ConfigurationClass::read()
|
||||
// Deserialize the JSON document
|
||||
DeserializationError error = deserializeJson(doc, f);
|
||||
if (error) {
|
||||
Serial.println(F("Failed to read file, using default configuration"));
|
||||
MessageOutput.println(F("Failed to read file, using default configuration"));
|
||||
}
|
||||
|
||||
JsonObject cfg = doc["cfg"];
|
||||
@ -222,7 +223,7 @@ void ConfigurationClass::migrate()
|
||||
if (config.Cfg_Version < 0x00011700) {
|
||||
File f = LittleFS.open(CONFIG_FILENAME, "r", false);
|
||||
if (!f) {
|
||||
Serial.println(F("Failed to open file, cancel migration"));
|
||||
MessageOutput.println(F("Failed to open file, cancel migration"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -230,7 +231,7 @@ void ConfigurationClass::migrate()
|
||||
// Deserialize the JSON document
|
||||
DeserializationError error = deserializeJson(doc, f);
|
||||
if (error) {
|
||||
Serial.println(F("Failed to read file, cancel migration"));
|
||||
MessageOutput.println(F("Failed to read file, cancel migration"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
* Copyright (C) 2022 Thomas Basler and others
|
||||
*/
|
||||
#include "MqttHandleInverter.h"
|
||||
#include "MessageOutput.h"
|
||||
#include "MqttSettings.h"
|
||||
#include <ctime>
|
||||
|
||||
@ -168,7 +169,7 @@ void MqttHandleInverterClass::onMqttMessage(const espMqttClientTypes::MessagePro
|
||||
auto inv = Hoymiles.getInverterBySerial(serial);
|
||||
|
||||
if (inv == nullptr) {
|
||||
Serial.println(F("Inverter not found"));
|
||||
MessageOutput.println(F("Inverter not found"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -185,44 +186,44 @@ void MqttHandleInverterClass::onMqttMessage(const espMqttClientTypes::MessagePro
|
||||
|
||||
if (!strcmp(setting, TOPIC_SUB_LIMIT_PERSISTENT_RELATIVE)) {
|
||||
// Set inverter limit relative persistent
|
||||
Serial.printf("Limit Persistent: %d %%\n", payload_val);
|
||||
MessageOutput.printf("Limit Persistent: %d %%\n", payload_val);
|
||||
inv->sendActivePowerControlRequest(Hoymiles.getRadio(), payload_val, PowerLimitControlType::RelativPersistent);
|
||||
|
||||
} else if (!strcmp(setting, TOPIC_SUB_LIMIT_PERSISTENT_ABSOLUTE)) {
|
||||
// Set inverter limit absolute persistent
|
||||
Serial.printf("Limit Persistent: %d W\n", payload_val);
|
||||
MessageOutput.printf("Limit Persistent: %d W\n", payload_val);
|
||||
inv->sendActivePowerControlRequest(Hoymiles.getRadio(), payload_val, PowerLimitControlType::AbsolutPersistent);
|
||||
|
||||
} else if (!strcmp(setting, TOPIC_SUB_LIMIT_NONPERSISTENT_RELATIVE)) {
|
||||
// Set inverter limit relative non persistent
|
||||
Serial.printf("Limit Non-Persistent: %d %%\n", payload_val);
|
||||
MessageOutput.printf("Limit Non-Persistent: %d %%\n", payload_val);
|
||||
if (!properties.retain) {
|
||||
inv->sendActivePowerControlRequest(Hoymiles.getRadio(), payload_val, PowerLimitControlType::RelativNonPersistent);
|
||||
} else {
|
||||
Serial.println("Ignored because retained");
|
||||
MessageOutput.println("Ignored because retained");
|
||||
}
|
||||
|
||||
} else if (!strcmp(setting, TOPIC_SUB_LIMIT_NONPERSISTENT_ABSOLUTE)) {
|
||||
// Set inverter limit absolute non persistent
|
||||
Serial.printf("Limit Non-Persistent: %d W\n", payload_val);
|
||||
MessageOutput.printf("Limit Non-Persistent: %d W\n", payload_val);
|
||||
if (!properties.retain) {
|
||||
inv->sendActivePowerControlRequest(Hoymiles.getRadio(), payload_val, PowerLimitControlType::AbsolutNonPersistent);
|
||||
} else {
|
||||
Serial.println("Ignored because retained");
|
||||
MessageOutput.println("Ignored because retained");
|
||||
}
|
||||
|
||||
} else if (!strcmp(setting, TOPIC_SUB_POWER)) {
|
||||
// Turn inverter on or off
|
||||
Serial.printf("Set inverter power to: %d\n", payload_val);
|
||||
MessageOutput.printf("Set inverter power to: %d\n", payload_val);
|
||||
inv->sendPowerControlRequest(Hoymiles.getRadio(), payload_val > 0);
|
||||
|
||||
} else if (!strcmp(setting, TOPIC_SUB_RESTART)) {
|
||||
// Restart inverter
|
||||
Serial.printf("Restart inverter\n");
|
||||
MessageOutput.printf("Restart inverter\n");
|
||||
if (!properties.retain && payload_val == 1) {
|
||||
inv->sendRestartControlRequest(Hoymiles.getRadio());
|
||||
} else {
|
||||
Serial.println("Ignored because retained");
|
||||
MessageOutput.println("Ignored because retained");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
* Copyright (C) 2022 Thomas Basler and others
|
||||
*/
|
||||
#include "MqttSettings.h"
|
||||
#include "MessageOutput.h"
|
||||
#include "Configuration.h"
|
||||
|
||||
MqttSettingsClass::MqttSettingsClass()
|
||||
@ -13,11 +14,11 @@ void MqttSettingsClass::NetworkEvent(network_event event)
|
||||
{
|
||||
switch (event) {
|
||||
case network_event::NETWORK_GOT_IP:
|
||||
Serial.println(F("Network connected"));
|
||||
MessageOutput.println(F("Network connected"));
|
||||
performConnect();
|
||||
break;
|
||||
case network_event::NETWORK_DISCONNECTED:
|
||||
Serial.println(F("Network lost connection"));
|
||||
MessageOutput.println(F("Network lost connection"));
|
||||
mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
|
||||
break;
|
||||
default:
|
||||
@ -27,7 +28,7 @@ void MqttSettingsClass::NetworkEvent(network_event event)
|
||||
|
||||
void MqttSettingsClass::onMqttConnect(bool sessionPresent)
|
||||
{
|
||||
Serial.println(F("Connected to MQTT."));
|
||||
MessageOutput.println(F("Connected to MQTT."));
|
||||
const CONFIG_T& config = Configuration.get();
|
||||
publish(config.Mqtt_LwtTopic, config.Mqtt_LwtValue_Online);
|
||||
|
||||
@ -50,30 +51,30 @@ void MqttSettingsClass::unsubscribe(const String& topic)
|
||||
|
||||
void MqttSettingsClass::onMqttDisconnect(espMqttClientTypes::DisconnectReason reason)
|
||||
{
|
||||
Serial.println(F("Disconnected from MQTT."));
|
||||
MessageOutput.println(F("Disconnected from MQTT."));
|
||||
|
||||
Serial.print(F("Disconnect reason:"));
|
||||
MessageOutput.print(F("Disconnect reason:"));
|
||||
switch (reason) {
|
||||
case espMqttClientTypes::DisconnectReason::TCP_DISCONNECTED:
|
||||
Serial.println(F("TCP_DISCONNECTED"));
|
||||
MessageOutput.println(F("TCP_DISCONNECTED"));
|
||||
break;
|
||||
case espMqttClientTypes::DisconnectReason::MQTT_UNACCEPTABLE_PROTOCOL_VERSION:
|
||||
Serial.println(F("MQTT_UNACCEPTABLE_PROTOCOL_VERSION"));
|
||||
MessageOutput.println(F("MQTT_UNACCEPTABLE_PROTOCOL_VERSION"));
|
||||
break;
|
||||
case espMqttClientTypes::DisconnectReason::MQTT_IDENTIFIER_REJECTED:
|
||||
Serial.println(F("MQTT_IDENTIFIER_REJECTED"));
|
||||
MessageOutput.println(F("MQTT_IDENTIFIER_REJECTED"));
|
||||
break;
|
||||
case espMqttClientTypes::DisconnectReason::MQTT_SERVER_UNAVAILABLE:
|
||||
Serial.println(F("MQTT_SERVER_UNAVAILABLE"));
|
||||
MessageOutput.println(F("MQTT_SERVER_UNAVAILABLE"));
|
||||
break;
|
||||
case espMqttClientTypes::DisconnectReason::MQTT_MALFORMED_CREDENTIALS:
|
||||
Serial.println(F("MQTT_MALFORMED_CREDENTIALS"));
|
||||
MessageOutput.println(F("MQTT_MALFORMED_CREDENTIALS"));
|
||||
break;
|
||||
case espMqttClientTypes::DisconnectReason::MQTT_NOT_AUTHORIZED:
|
||||
Serial.println(F("MQTT_NOT_AUTHORIZED"));
|
||||
MessageOutput.println(F("MQTT_NOT_AUTHORIZED"));
|
||||
break;
|
||||
default:
|
||||
Serial.println(F("Unknown"));
|
||||
MessageOutput.println(F("Unknown"));
|
||||
}
|
||||
mqttReconnectTimer.once(
|
||||
2, +[](MqttSettingsClass* instance) { instance->performConnect(); }, this);
|
||||
@ -81,8 +82,8 @@ void MqttSettingsClass::onMqttDisconnect(espMqttClientTypes::DisconnectReason re
|
||||
|
||||
void MqttSettingsClass::onMqttMessage(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total)
|
||||
{
|
||||
Serial.print(F("Received MQTT message on topic: "));
|
||||
Serial.println(topic);
|
||||
MessageOutput.print(F("Received MQTT message on topic: "));
|
||||
MessageOutput.println(topic);
|
||||
|
||||
_mqttSubscribeParser.handle_message(properties, topic, payload, len, index, total);
|
||||
}
|
||||
@ -96,7 +97,7 @@ void MqttSettingsClass::performConnect()
|
||||
using std::placeholders::_4;
|
||||
using std::placeholders::_5;
|
||||
using std::placeholders::_6;
|
||||
Serial.println(F("Connecting to MQTT..."));
|
||||
MessageOutput.println(F("Connecting to MQTT..."));
|
||||
const CONFIG_T& config = Configuration.get();
|
||||
willTopic = getPrefix() + config.Mqtt_LwtTopic;
|
||||
clientId = NetworkSettings.getApName();
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
*/
|
||||
#include "NetworkSettings.h"
|
||||
#include "Configuration.h"
|
||||
#include "MessageOutput.h"
|
||||
#include "Utils.h"
|
||||
#include "defaults.h"
|
||||
#ifdef OPENDTU_ETHERNET
|
||||
@ -30,30 +31,30 @@ void NetworkSettingsClass::NetworkEvent(WiFiEvent_t event)
|
||||
switch (event) {
|
||||
#ifdef OPENDTU_ETHERNET
|
||||
case ARDUINO_EVENT_ETH_START:
|
||||
Serial.println(F("ETH start"));
|
||||
MessageOutput.println(F("ETH start"));
|
||||
if (_networkMode == network_mode::Ethernet) {
|
||||
raiseEvent(network_event::NETWORK_START);
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_STOP:
|
||||
Serial.println(F("ETH stop"));
|
||||
MessageOutput.println(F("ETH stop"));
|
||||
if (_networkMode == network_mode::Ethernet) {
|
||||
raiseEvent(network_event::NETWORK_STOP);
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||
Serial.println(F("ETH connected"));
|
||||
MessageOutput.println(F("ETH connected"));
|
||||
_ethConnected = true;
|
||||
raiseEvent(network_event::NETWORK_CONNECTED);
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||
Serial.printf("ETH got IP: %s\n", ETH.localIP().toString().c_str());
|
||||
MessageOutput.printf("ETH got IP: %s\n", ETH.localIP().toString().c_str());
|
||||
if (_networkMode == network_mode::Ethernet) {
|
||||
raiseEvent(network_event::NETWORK_GOT_IP);
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
||||
Serial.println(F("ETH disconnected"));
|
||||
MessageOutput.println(F("ETH disconnected"));
|
||||
_ethConnected = false;
|
||||
if (_networkMode == network_mode::Ethernet) {
|
||||
raiseEvent(network_event::NETWORK_DISCONNECTED);
|
||||
@ -61,21 +62,21 @@ void NetworkSettingsClass::NetworkEvent(WiFiEvent_t event)
|
||||
break;
|
||||
#endif
|
||||
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
||||
Serial.println(F("WiFi connected"));
|
||||
MessageOutput.println(F("WiFi connected"));
|
||||
if (_networkMode == network_mode::WiFi) {
|
||||
raiseEvent(network_event::NETWORK_CONNECTED);
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
||||
Serial.println(F("WiFi disconnected"));
|
||||
MessageOutput.println(F("WiFi disconnected"));
|
||||
if (_networkMode == network_mode::WiFi) {
|
||||
Serial.println(F("Try reconnecting"));
|
||||
MessageOutput.println(F("Try reconnecting"));
|
||||
WiFi.reconnect();
|
||||
raiseEvent(network_event::NETWORK_DISCONNECTED);
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
||||
Serial.printf("WiFi got ip: %s\n", WiFi.localIP().toString().c_str());
|
||||
MessageOutput.printf("WiFi got ip: %s\n", WiFi.localIP().toString().c_str());
|
||||
if (_networkMode == network_mode::WiFi) {
|
||||
raiseEvent(network_event::NETWORK_GOT_IP);
|
||||
}
|
||||
@ -151,7 +152,7 @@ void NetworkSettingsClass::loop()
|
||||
if (_ethConnected) {
|
||||
if (_networkMode != network_mode::Ethernet) {
|
||||
// Do stuff when switching to Ethernet mode
|
||||
Serial.println(F("Switch to Ethernet mode"));
|
||||
MessageOutput.println(F("Switch to Ethernet mode"));
|
||||
_networkMode = network_mode::Ethernet;
|
||||
WiFi.mode(WIFI_MODE_NULL);
|
||||
setStaticIp();
|
||||
@ -161,7 +162,7 @@ void NetworkSettingsClass::loop()
|
||||
#endif
|
||||
if (_networkMode != network_mode::WiFi) {
|
||||
// Do stuff when switching to Ethernet mode
|
||||
Serial.println(F("Switch to WiFi mode"));
|
||||
MessageOutput.println(F("Switch to WiFi mode"));
|
||||
_networkMode = network_mode::WiFi;
|
||||
enableAdminMode();
|
||||
applyConfig();
|
||||
@ -182,7 +183,7 @@ void NetworkSettingsClass::loop()
|
||||
// seconds, disable the internal Access Point
|
||||
if (adminTimeoutCounter > ADMIN_TIMEOUT) {
|
||||
adminEnabled = false;
|
||||
Serial.println(F("Admin mode disabled"));
|
||||
MessageOutput.println(F("Admin mode disabled"));
|
||||
setupMode();
|
||||
}
|
||||
// It's nearly not possible to use the internal AP if the
|
||||
@ -193,16 +194,16 @@ void NetworkSettingsClass::loop()
|
||||
connectRedoTimer = 0;
|
||||
} else {
|
||||
if (connectTimeoutTimer > WIFI_RECONNECT_TIMEOUT && !forceDisconnection) {
|
||||
Serial.print(F("Disable search for AP... "));
|
||||
MessageOutput.print(F("Disable search for AP... "));
|
||||
WiFi.mode(WIFI_AP);
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
connectRedoTimer = 0;
|
||||
forceDisconnection = true;
|
||||
}
|
||||
if (connectRedoTimer > WIFI_RECONNECT_REDO_TIMEOUT && forceDisconnection) {
|
||||
Serial.print(F("Enable search for AP... "));
|
||||
MessageOutput.print(F("Enable search for AP... "));
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
applyConfig();
|
||||
connectTimeoutTimer = 0;
|
||||
forceDisconnection = false;
|
||||
@ -220,28 +221,28 @@ void NetworkSettingsClass::applyConfig()
|
||||
if (!strcmp(Configuration.get().WiFi_Ssid, "")) {
|
||||
return;
|
||||
}
|
||||
Serial.print(F("Configuring WiFi STA using "));
|
||||
MessageOutput.print(F("Configuring WiFi STA using "));
|
||||
if (strcmp(WiFi.SSID().c_str(), Configuration.get().WiFi_Ssid) || strcmp(WiFi.psk().c_str(), Configuration.get().WiFi_Password)) {
|
||||
Serial.print(F("new credentials... "));
|
||||
MessageOutput.print(F("new credentials... "));
|
||||
WiFi.begin(
|
||||
Configuration.get().WiFi_Ssid,
|
||||
Configuration.get().WiFi_Password);
|
||||
} else {
|
||||
Serial.print(F("existing credentials... "));
|
||||
MessageOutput.print(F("existing credentials... "));
|
||||
WiFi.begin();
|
||||
}
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
setStaticIp();
|
||||
}
|
||||
|
||||
void NetworkSettingsClass::setHostname()
|
||||
{
|
||||
Serial.print(F("Setting Hostname... "));
|
||||
MessageOutput.print(F("Setting Hostname... "));
|
||||
if (_networkMode == network_mode::WiFi) {
|
||||
if (WiFi.hostname(getHostname())) {
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
} else {
|
||||
Serial.println(F("failed"));
|
||||
MessageOutput.println(F("failed"));
|
||||
}
|
||||
|
||||
// Evil bad hack to get the hostname set up correctly
|
||||
@ -252,9 +253,9 @@ void NetworkSettingsClass::setHostname()
|
||||
#ifdef OPENDTU_ETHERNET
|
||||
else if (_networkMode == network_mode::Ethernet) {
|
||||
if (ETH.setHostname(getHostname().c_str())) {
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
} else {
|
||||
Serial.println(F("failed"));
|
||||
MessageOutput.println(F("failed"));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -264,35 +265,35 @@ void NetworkSettingsClass::setStaticIp()
|
||||
{
|
||||
if (_networkMode == network_mode::WiFi) {
|
||||
if (Configuration.get().WiFi_Dhcp) {
|
||||
Serial.print(F("Configuring WiFi STA DHCP IP... "));
|
||||
MessageOutput.print(F("Configuring WiFi STA DHCP IP... "));
|
||||
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
} else {
|
||||
Serial.print(F("Configuring WiFi STA static IP... "));
|
||||
MessageOutput.print(F("Configuring WiFi STA static IP... "));
|
||||
WiFi.config(
|
||||
IPAddress(Configuration.get().WiFi_Ip),
|
||||
IPAddress(Configuration.get().WiFi_Gateway),
|
||||
IPAddress(Configuration.get().WiFi_Netmask),
|
||||
IPAddress(Configuration.get().WiFi_Dns1),
|
||||
IPAddress(Configuration.get().WiFi_Dns2));
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
}
|
||||
}
|
||||
#ifdef OPENDTU_ETHERNET
|
||||
else if (_networkMode == network_mode::Ethernet) {
|
||||
if (Configuration.get().WiFi_Dhcp) {
|
||||
Serial.print(F("Configuring Ethernet DHCP IP... "));
|
||||
MessageOutput.print(F("Configuring Ethernet DHCP IP... "));
|
||||
ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
} else {
|
||||
Serial.print(F("Configuring Ethernet static IP... "));
|
||||
MessageOutput.print(F("Configuring Ethernet static IP... "));
|
||||
ETH.config(
|
||||
IPAddress(Configuration.get().WiFi_Ip),
|
||||
IPAddress(Configuration.get().WiFi_Gateway),
|
||||
IPAddress(Configuration.get().WiFi_Netmask),
|
||||
IPAddress(Configuration.get().WiFi_Dns1),
|
||||
IPAddress(Configuration.get().WiFi_Dns2));
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
*/
|
||||
#include "WebApi_ws_live.h"
|
||||
#include "Configuration.h"
|
||||
#include "MessageOutput.h"
|
||||
#include "WebApi.h"
|
||||
#include "defaults.h"
|
||||
#include <AsyncJson.h>
|
||||
@ -198,11 +199,11 @@ void WebApiWsLiveClass::onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketC
|
||||
if (type == WS_EVT_CONNECT) {
|
||||
char str[64];
|
||||
snprintf(str, sizeof(str), "Websocket: [%s][%u] connect", server->url(), client->id());
|
||||
Serial.println(str);
|
||||
MessageOutput.println(str);
|
||||
} else if (type == WS_EVT_DISCONNECT) {
|
||||
char str[64];
|
||||
snprintf(str, sizeof(str), "Websocket: [%s][%u] disconnect", server->url(), client->id());
|
||||
Serial.println(str);
|
||||
MessageOutput.println(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
74
src/main.cpp
74
src/main.cpp
@ -3,6 +3,7 @@
|
||||
* Copyright (C) 2022 Thomas Basler and others
|
||||
*/
|
||||
#include "Configuration.h"
|
||||
#include "MessageOutput.h"
|
||||
#include "MqttHandleDtu.h"
|
||||
#include "MqttHandleHass.h"
|
||||
#include "MqttHandleInverter.h"
|
||||
@ -22,98 +23,99 @@ void setup()
|
||||
Serial.begin(SERIAL_BAUDRATE);
|
||||
while (!Serial)
|
||||
yield();
|
||||
Serial.println();
|
||||
Serial.println(F("Starting OpenDTU"));
|
||||
MessageOutput.println();
|
||||
MessageOutput.println(F("Starting OpenDTU"));
|
||||
|
||||
// Initialize file system
|
||||
Serial.print(F("Initialize FS... "));
|
||||
MessageOutput.print(F("Initialize FS... "));
|
||||
if (!LittleFS.begin(false)) { // Do not format if mount failed
|
||||
Serial.print(F("failed... trying to format..."));
|
||||
MessageOutput.print(F("failed... trying to format..."));
|
||||
if (!LittleFS.begin(true)) {
|
||||
Serial.print("success");
|
||||
MessageOutput.print("success");
|
||||
} else {
|
||||
Serial.print("failed");
|
||||
MessageOutput.print("failed");
|
||||
}
|
||||
} else {
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
}
|
||||
|
||||
// Read configuration values
|
||||
Serial.print(F("Reading configuration... "));
|
||||
MessageOutput.print(F("Reading configuration... "));
|
||||
if (!Configuration.read()) {
|
||||
Serial.print(F("initializing... "));
|
||||
MessageOutput.print(F("initializing... "));
|
||||
Configuration.init();
|
||||
if (Configuration.write()) {
|
||||
Serial.print(F("written... "));
|
||||
MessageOutput.print(F("written... "));
|
||||
} else {
|
||||
Serial.print(F("failed... "));
|
||||
MessageOutput.print(F("failed... "));
|
||||
}
|
||||
}
|
||||
if (Configuration.get().Cfg_Version != CONFIG_VERSION) {
|
||||
Serial.print(F("migrated... "));
|
||||
MessageOutput.print(F("migrated... "));
|
||||
Configuration.migrate();
|
||||
}
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
|
||||
// Initialize WiFi
|
||||
Serial.print(F("Initialize Network... "));
|
||||
MessageOutput.print(F("Initialize Network... "));
|
||||
NetworkSettings.init();
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
NetworkSettings.applyConfig();
|
||||
|
||||
// Initialize NTP
|
||||
Serial.print(F("Initialize NTP... "));
|
||||
MessageOutput.print(F("Initialize NTP... "));
|
||||
NtpSettings.init();
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
|
||||
// Initialize MqTT
|
||||
Serial.print(F("Initialize MqTT... "));
|
||||
MessageOutput.print(F("Initialize MqTT... "));
|
||||
MqttSettings.init();
|
||||
MqttHandleDtu.init();
|
||||
MqttHandleInverter.init();
|
||||
MqttHandleHass.init();
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
|
||||
// Initialize WebApi
|
||||
Serial.print(F("Initialize WebApi... "));
|
||||
MessageOutput.print(F("Initialize WebApi... "));
|
||||
WebApi.init();
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
|
||||
// Check for default DTU serial
|
||||
Serial.print(F("Check for default DTU serial... "));
|
||||
MessageOutput.print(F("Check for default DTU serial... "));
|
||||
CONFIG_T& config = Configuration.get();
|
||||
if (config.Dtu_Serial == DTU_SERIAL) {
|
||||
Serial.print(F("generate serial based on ESP chip id: "));
|
||||
MessageOutput.print(F("generate serial based on ESP chip id: "));
|
||||
uint64_t dtuId = Utils::generateDtuSerial();
|
||||
Serial.printf("%0x%08x... ",
|
||||
MessageOutput.printf("%0x%08x... ",
|
||||
((uint32_t)((dtuId >> 32) & 0xFFFFFFFF)),
|
||||
((uint32_t)(dtuId & 0xFFFFFFFF)));
|
||||
config.Dtu_Serial = dtuId;
|
||||
Configuration.write();
|
||||
}
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
|
||||
// Initialize inverter communication
|
||||
Serial.print(F("Initialize Hoymiles interface... "));
|
||||
MessageOutput.print(F("Initialize Hoymiles interface... "));
|
||||
SPIClass* spiClass = new SPIClass(HSPI);
|
||||
spiClass->begin(HOYMILES_PIN_SCLK, HOYMILES_PIN_MISO, HOYMILES_PIN_MOSI, HOYMILES_PIN_CS);
|
||||
Hoymiles.setMessageOutput(&MessageOutput);
|
||||
Hoymiles.init(spiClass, HOYMILES_PIN_CE, HOYMILES_PIN_IRQ);
|
||||
|
||||
Serial.println(F(" Setting radio PA level... "));
|
||||
MessageOutput.println(F(" Setting radio PA level... "));
|
||||
Hoymiles.getRadio()->setPALevel((rf24_pa_dbm_e)config.Dtu_PaLevel);
|
||||
|
||||
Serial.println(F(" Setting DTU serial... "));
|
||||
MessageOutput.println(F(" Setting DTU serial... "));
|
||||
Hoymiles.getRadio()->setDtuSerial(config.Dtu_Serial);
|
||||
|
||||
Serial.println(F(" Setting poll interval... "));
|
||||
MessageOutput.println(F(" Setting poll interval... "));
|
||||
Hoymiles.setPollInterval(config.Dtu_PollInterval);
|
||||
|
||||
for (uint8_t i = 0; i < INV_MAX_COUNT; i++) {
|
||||
if (config.Inverter[i].Serial > 0) {
|
||||
Serial.print(F(" Adding inverter: "));
|
||||
Serial.print(config.Inverter[i].Serial, HEX);
|
||||
Serial.print(F(" - "));
|
||||
Serial.print(config.Inverter[i].Name);
|
||||
MessageOutput.print(F(" Adding inverter: "));
|
||||
MessageOutput.print(config.Inverter[i].Serial, HEX);
|
||||
MessageOutput.print(F(" - "));
|
||||
MessageOutput.print(config.Inverter[i].Name);
|
||||
auto inv = Hoymiles.addInverter(
|
||||
config.Inverter[i].Name,
|
||||
config.Inverter[i].Serial);
|
||||
@ -123,10 +125,10 @@ void setup()
|
||||
inv->Statistics()->setChannelMaxPower(c, config.Inverter[i].channel[c].MaxChannelPower);
|
||||
}
|
||||
}
|
||||
Serial.println(F(" done"));
|
||||
MessageOutput.println(F(" done"));
|
||||
}
|
||||
}
|
||||
Serial.println(F("done"));
|
||||
MessageOutput.println(F("done"));
|
||||
}
|
||||
|
||||
void loop()
|
||||
@ -143,4 +145,6 @@ void loop()
|
||||
yield();
|
||||
WebApi.loop();
|
||||
yield();
|
||||
MessageOutput.loop();
|
||||
yield();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user