refactor NetworkDevice interface to work with new esp mqtt lib

This commit is contained in:
technyon
2023-01-28 17:17:46 +01:00
parent a6010a7f49
commit 5853b0dc0e
24 changed files with 493 additions and 287 deletions

View File

@@ -19,64 +19,47 @@ the LICENSE file.
#endif
#include "MqttClientSetup.h"
#include "Transport/ClientSyncEthernet.h"
class espMqttClient : public MqttClientSetup {
public:
class espMqttClient : public MqttClientSetup<espMqttClient> {
public:
#if defined(ARDUINO_ARCH_ESP32)
explicit espMqttClient(WiFiClient* wiFiClient, uint8_t priority = 1, uint8_t core = 1);
explicit espMqttClient(uint8_t priority = 1, uint8_t core = 1);
#else
espMqttClient();
espMqttClient();
#endif
protected:
protected:
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
espMqttClientInternals::ClientSync _client;
espMqttClientInternals::ClientSync _client;
#elif defined(__linux__)
espMqttClientInternals::ClientPosix _client;
espMqttClientInternals::ClientPosix _client;
#endif
};
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
class espMqttClientSecure : public MqttClientSetup {
public:
#if defined(ARDUINO_ARCH_ESP32)
explicit espMqttClientSecure(WiFiClientSecure* wiFiClient, uint8_t priority = 1, uint8_t core = 1);
#else
espMqttClientSecure();
#endif
espMqttClientSecure& setInsecure();
#if defined(ARDUINO_ARCH_ESP32)
espMqttClientSecure& setCACert(const char* rootCA);
espMqttClientSecure& setCertificate(const char* clientCa);
espMqttClientSecure& setPrivateKey(const char* privateKey);
espMqttClientSecure& setPreSharedKey(const char* pskIdent, const char* psKey);
#else
espMqttClientSecure& setFingerprint(const uint8_t fingerprint[20]);
class espMqttClientSecure : public MqttClientSetup<espMqttClientSecure> {
public:
#if defined(ARDUINO_ARCH_ESP32)
explicit espMqttClientSecure(uint8_t priority = 1, uint8_t core = 1);
#else
espMqttClientSecure();
#endif
espMqttClientSecure& setInsecure();
#if defined(ARDUINO_ARCH_ESP32)
espMqttClientSecure& setCACert(const char* rootCA);
espMqttClientSecure& setCertificate(const char* clientCa);
espMqttClientSecure& setPrivateKey(const char* privateKey);
espMqttClientSecure& setPreSharedKey(const char* pskIdent, const char* psKey);
#else
espMqttClientSecure& setFingerprint(const uint8_t fingerprint[20]);
espMqttClientSecure& setTrustAnchors(const X509List *ta);
espMqttClientSecure& setClientRSACert(const X509List *cert, const PrivateKey *sk);
espMqttClientSecure& setClientECCert(const X509List *cert, const PrivateKey *sk, unsigned allowed_usages, unsigned cert_issuer_key_type);
espMqttClientSecure& setCertStore(CertStoreBase *certStore);
#endif
#endif
protected:
espMqttClientInternals::ClientSecureSync _client;
};
class espMqttClientEthernet : public MqttClientSetup {
public:
#if defined(ARDUINO_ARCH_ESP32)
explicit espMqttClientEthernet(EthernetClient* ethernetClient, uint8_t priority = 1, uint8_t core = 1);
#else
espMqttClient();
#endif
protected:
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
espMqttClientInternals::ClientSyncEthernet _client;
#elif defined(__linux__)
espMqttClientInternals::ClientPosix _client;
#endif
protected:
espMqttClientInternals::ClientSecureSync _client;
};
#endif