Arduino Core 3 (#407)

* Add and remove libs and components for Arduino Core 3

* Arduino Core 3

* Add back Solo1

* Change ESP32-S3 to 4MB build

* Update README.md

* Fix retain and number of retries

* Fix rolling log

* Fix defaults

* Fix BleScanner on Solo1

* Export settings

* Import settings

* Fix HA Battery voltage

* Change submodule

* Update espMqttClient and AsyncTCP

* Webserial and MQTT/Network reconnecting

* Update nuki_ble

---------

Co-authored-by: iranl <iranl@github.com>
This commit is contained in:
iranl
2024-07-05 18:45:39 +02:00
committed by GitHub
parent 193ebb5f91
commit 6b0100fd61
236 changed files with 16390 additions and 9740 deletions

View File

@@ -6,8 +6,10 @@
#include "EthLan8720Device.h"
#include "../PreferencesKeys.h"
#include "../Logger.h"
#ifndef NUKI_HUB_UPDATER
#include "../MqttTopics.h"
#include "espMqttClient.h"
#endif
#include "../RestartReason.h"
EthLan8720Device::EthLan8720Device(const String& hostname, Preferences* preferences, const IPConfiguration* ipConfiguration, const std::string& deviceName, uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t ethtype, eth_clock_mode_t clock_mode, bool use_mac_from_efuse)
@@ -23,6 +25,7 @@ EthLan8720Device::EthLan8720Device(const String& hostname, Preferences* preferen
{
_restartOnDisconnect = preferences->getBool(preference_restart_on_disconnect);
#ifndef NUKI_HUB_UPDATER
size_t caLength = preferences->getString(preference_mqtt_ca, _ca, TLS_CA_MAX_SIZE);
size_t crtLength = preferences->getString(preference_mqtt_crt, _cert, TLS_CERT_MAX_SIZE);
size_t keyLength = preferences->getString(preference_mqtt_key, _key, TLS_KEY_MAX_SIZE);
@@ -59,6 +62,7 @@ EthLan8720Device::EthLan8720Device(const String& hostname, Preferences* preferen
strcpy(_path, pathStr.c_str());
Log = new MqttLogger(*getMqttClient(), _path, MqttLoggerMode::MqttAndSerial);
}
#endif
}
const String EthLan8720Device::deviceName() const
@@ -71,23 +75,29 @@ void EthLan8720Device::initialize()
delay(250);
WiFi.setHostname(_hostname.c_str());
#if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0))
_hardwareInitialized = ETH.begin(_phy_addr, _power, _mdc, _mdio, _type, _clock_mode, _use_mac_from_efuse);
#else
#ifdef CONFIG_IDF_TARGET_ESP32
_hardwareInitialized = ETH.begin(_type, _phy_addr, _mdc, _mdio, ETH_RESET_PIN, _clock_mode);
#else
_hardwareInitialized = false;
#endif
#endif
ETH.setHostname(_hostname.c_str());
if(!_ipConfiguration->dhcpEnabled())
{
ETH.config(_ipConfiguration->ipAddress(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet(), _ipConfiguration->dnsServer());
}
if(_restartOnDisconnect)
WiFi.onEvent([&](WiFiEvent_t event, WiFiEventInfo_t info)
{
WiFi.onEvent([&](WiFiEvent_t event, WiFiEventInfo_t info)
if(event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED)
{
if(event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED)
{
onDisconnected();
}
});
}
onDisconnected();
}
});
}
void EthLan8720Device::reconfigure()
@@ -128,10 +138,8 @@ ReconnectStatus EthLan8720Device::reconnect()
void EthLan8720Device::onDisconnected()
{
if(millis() > 60000)
{
restartEsp(RestartReason::RestartOnDisconnectWatchdog);
}
if(_restartOnDisconnect && (millis() > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
reconnect();
}
int8_t EthLan8720Device::signalStrength()

View File

@@ -1,10 +1,38 @@
#pragma once
#if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(5, 0, 0))
#ifndef CONFIG_IDF_TARGET_ESP32
typedef enum {
ETH_CLOCK_GPIO0_IN = 0,
ETH_CLOCK_GPIO16_OUT = 2,
ETH_CLOCK_GPIO17_OUT = 3
} eth_clock_mode_t;
#define ETH_PHY_TYPE ETH_PHY_MAX
#else
#define ETH_PHY_TYPE ETH_PHY_LAN8720
#endif
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
#define ETH_PHY_ADDR 0
#define ETH_PHY_MDC 23
#define ETH_PHY_MDIO 18
#define ETH_PHY_POWER -1
#define ETH_RESET_PIN 1
#endif
#include <WiFiClient.h>
#if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0))
#include <WiFiClientSecure.h>
#else
#include <NetworkClientSecure.h>
#endif
#include <Preferences.h>
#include "NetworkDevice.h"
#ifndef NUKI_HUB_UPDATER
#include "espMqttClient.h"
#endif
#include <ETH.h>
class EthLan8720Device : public NetworkDevice
@@ -54,8 +82,9 @@ private:
eth_phy_type_t _type;
eth_clock_mode_t _clock_mode;
bool _use_mac_from_efuse;
#ifndef NUKI_HUB_UPDATER
char _ca[TLS_CA_MAX_SIZE] = {0};
char _cert[TLS_CERT_MAX_SIZE] = {0};
char _key[TLS_KEY_MAX_SIZE] = {0};
};
#endif
};

View File

@@ -8,6 +8,7 @@ void NetworkDevice::printError()
Log->println(ESP.getFreeHeap());
}
#ifndef NUKI_HUB_UPDATER
void NetworkDevice::update()
{
if (_mqttEnabled)
@@ -40,6 +41,18 @@ void NetworkDevice::mqttSetCleanSession(bool cleanSession)
}
}
void NetworkDevice::mqttSetKeepAlive(uint16_t keepAlive)
{
if (_useEncryption)
{
_mqttClientSecure->setKeepAlive(keepAlive);
}
else
{
_mqttClient->setKeepAlive(keepAlive);
}
}
uint16_t NetworkDevice::mqttPublish(const char *topic, uint8_t qos, bool retain, const char *payload)
{
return getMqttClient()->publish(topic, qos, retain, payload);
@@ -158,4 +171,9 @@ MqttClient *NetworkDevice::getMqttClient() const
{
return _mqttClient;
}
}
}
#else
void NetworkDevice::update()
{
}
#endif

View File

@@ -1,7 +1,9 @@
#pragma once
#ifndef NUKI_HUB_UPDATER
#include "espMqttClient.h"
#include "MqttClientSetup.h"
#endif
#include "IPConfiguration.h"
enum class ReconnectStatus
@@ -35,8 +37,10 @@ public:
virtual String localIP() = 0;
virtual String BSSIDstr() = 0;
#ifndef NUKI_HUB_UPDATER
virtual void mqttSetClientId(const char* clientId);
virtual void mqttSetCleanSession(bool cleanSession);
virtual void mqttSetKeepAlive(uint16_t keepAlive);
virtual uint16_t mqttPublish(const char* topic, uint8_t qos, bool retain, const char* payload);
virtual uint16_t mqttPublish(const char* topic, uint8_t qos, bool retain, const uint8_t* payload, size_t length);
virtual bool mqttConnected() const;
@@ -51,16 +55,19 @@ public:
virtual void disableMqtt();
virtual uint16_t mqttSubscribe(const char* topic, uint8_t qos);
#endif
protected:
#ifndef NUKI_HUB_UPDATER
espMqttClient *_mqttClient = nullptr;
espMqttClientSecure *_mqttClientSecure = nullptr;
bool _useEncryption = false;
bool _mqttEnabled = true;
MqttClient *getMqttClient() const;
#endif
const String _hostname;
const IPConfiguration* _ipConfiguration = nullptr;
MqttClient *getMqttClient() const;
};

View File

@@ -3,7 +3,9 @@
#include "W5500Device.h"
#include "../PreferencesKeys.h"
#include "../Logger.h"
#ifndef NUKI_HUB_UPDATER
#include "../MqttTopics.h"
#endif
#include "sdkconfig.h"
W5500Device::W5500Device(const String &hostname, Preferences* preferences, const IPConfiguration* ipConfiguration, int variant)
@@ -27,8 +29,9 @@ W5500Device::W5500Device(const String &hostname, Preferences* preferences, const
}
}
Log->println();
#ifndef NUKI_HUB_UPDATER
_mqttClient = new espMqttClientW5500();
#endif
}
W5500Device::~W5500Device()
@@ -61,6 +64,7 @@ void W5500Device::initialize()
break;
}
#ifndef NUKI_HUB_UPDATER
if(_preferences->getBool(preference_mqtt_log_enabled))
{
String pathStr = _preferences->getString(preference_mqtt_lock_path);
@@ -70,6 +74,7 @@ void W5500Device::initialize()
strcpy(_path, pathStr.c_str());
Log = new MqttLogger(*getMqttClient(), _path, MqttLoggerMode::MqttAndSerial);
}
#endif
reconnect();
}

View File

@@ -1,8 +1,10 @@
#pragma once
#include "NetworkDevice.h"
#ifndef NUKI_HUB_UPDATER
#include "espMqttClient.h"
#include "espMqttClientW5500.h"
#endif
#include <Ethernet.h>
#include <Preferences.h>

View File

@@ -2,8 +2,10 @@
#include "WifiDevice.h"
#include "../PreferencesKeys.h"
#include "../Logger.h"
#ifndef NUKI_HUB_UPDATER
#include "../MqttTopics.h"
#include "espMqttClient.h"
#endif
#include "../RestartReason.h"
RTC_NOINIT_ATTR char WiFiDevice_reconfdetect[17];
@@ -15,6 +17,7 @@ WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const I
{
_startAp = strcmp(WiFiDevice_reconfdetect, "reconfigure_wifi") == 0;
#ifndef NUKI_HUB_UPDATER
_restartOnDisconnect = preferences->getBool(preference_restart_on_disconnect);
size_t caLength = preferences->getString(preference_mqtt_ca, _ca, TLS_CA_MAX_SIZE);
@@ -53,6 +56,7 @@ WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const I
strcpy(_path, pathStr.c_str());
Log = new MqttLogger(*getMqttClient(), _path, MqttLoggerMode::MqttAndSerial);
}
#endif
}
const String WifiDevice::deviceName() const
@@ -94,9 +98,9 @@ void WifiDevice::initialize()
if(!res)
{
esp_wifi_disconnect ();
esp_wifi_stop ();
esp_wifi_deinit ();
esp_wifi_disconnect();
esp_wifi_stop();
esp_wifi_deinit();
Log->println(F("Failed to connect. Wait for ESP restart."));
delay(1000);
@@ -107,16 +111,17 @@ void WifiDevice::initialize()
Log->println(WiFi.localIP().toString());
}
if(_restartOnDisconnect)
WiFi.onEvent([&](WiFiEvent_t event, WiFiEventInfo_t info)
{
WiFi.onEvent([&](WiFiEvent_t event, WiFiEventInfo_t info)
if(event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED)
{
if(event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED)
{
onDisconnected();
}
});
}
onDisconnected();
}
else if(event == ARDUINO_EVENT_WIFI_STA_GOT_IP)
{
onConnected();
}
});
}
void WifiDevice::reconfigure()
@@ -138,16 +143,30 @@ bool WifiDevice::isConnected()
ReconnectStatus WifiDevice::reconnect()
{
delay(3000);
if(!isConnected() && !_isReconnecting)
{
_isReconnecting = true;
_wm.autoConnect();
delay(10000);
_isReconnecting = false;
}
if(!isConnected() && _disconnectTs > millis() - 120000) _wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled));
return isConnected() ? ReconnectStatus::Success : ReconnectStatus::Failure;
}
void WifiDevice::onConnected()
{
_isReconnecting = false;
_wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled));
}
void WifiDevice::onDisconnected()
{
if(millis() > 60000)
{
restartEsp(RestartReason::RestartOnDisconnectWatchdog);
}
_disconnectTs = millis();
if(_restartOnDisconnect && (millis() > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
_wm.setEnableConfigPortal(false);
reconnect();
}
int8_t WifiDevice::signalStrength()

View File

@@ -1,11 +1,17 @@
#pragma once
#include <WiFiClient.h>
#if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0))
#include <WiFiClientSecure.h>
#else
#include <NetworkClientSecure.h>
#endif
#include <Preferences.h>
#include "NetworkDevice.h"
#include "WiFiManager.h"
#ifndef NUKI_HUB_UPDATER
#include "espMqttClient.h"
#endif
#include "IPConfiguration.h"
class WifiDevice : public NetworkDevice
@@ -31,15 +37,20 @@ private:
static void clearRtcInitVar(WiFiManager*);
void onDisconnected();
void onConnected();
WiFiManager _wm;
Preferences* _preferences = nullptr;
bool _restartOnDisconnect = false;
bool _startAp = false;
bool _isReconnecting = false;
char* _path;
unsigned long _disconnectTs = 0;
#ifndef NUKI_HUB_UPDATER
char _ca[TLS_CA_MAX_SIZE] = {0};
char _cert[TLS_CERT_MAX_SIZE] = {0};
char _key[TLS_KEY_MAX_SIZE] = {0};
#endif
};