7
7
8
8
#include < ETH.h>
9
9
#include < ThingerClient.h>
10
- #include < functional>
11
10
12
- #ifndef _DISABLE_TLS_
13
- #include < SSLClientESP32.h>
14
- #endif
11
+ #ifdef _DISABLE_TLS_
12
+ typedef WiFiClient ESP32Client;
13
+ #else
14
+ #include < WiFiClientSecure.h>
15
+ typedef WiFiClientSecure ESP32Client;
16
+ #endif
15
17
16
18
class ThingerESP32Eth : public ThingerClient
17
19
@@ -25,15 +27,8 @@ class ThingerESP32Eth : public ThingerClient
25
27
ThingerClient (client_, user, device, device_credential)
26
28
#ifdef THINGER_FREE_RTOS
27
29
,ThingerESP32FreeRTOS(static_cast <ThingerClient&>(*this ))
28
- #endif ,
29
- #ifndef _DISABLE_TLS_
30
- ,client_(&base_client_)
31
30
#endif
32
31
{
33
-
34
- #ifndef _DISABLE_TLS_
35
- client_.setCACert (CA_ROOT_CERTIFICATE);
36
- #endif
37
32
38
33
WiFi.onEvent ([](WiFiEvent_t event){
39
34
switch (event) {
@@ -79,10 +74,6 @@ class ThingerESP32Eth : public ThingerClient
79
74
80
75
protected:
81
76
82
- virtual bool network_connected (){
83
- return initialized_ ? ETH.linkUp () : false ;
84
- }
85
-
86
77
bool init_address (){
87
78
if (ip_==nullptr ) return true ;
88
79
bool result = true ;
@@ -93,9 +84,30 @@ class ThingerESP32Eth : public ThingerClient
93
84
result &= dns1.fromString (dns1_);
94
85
result &= dns2.fromString (dns2_);
95
86
return result && ETH.config (ip, gateway, subnet, dns1, dns2);
96
- }
87
+ }
88
+
89
+ virtual bool network_connected () override {
90
+ return initialized_ ? ETH.linkUp () : false ;
91
+ }
97
92
98
- virtual bool connect_network (){
93
+ #ifndef _DISABLE_TLS_
94
+ bool connect_socket () override {
95
+
96
+ #ifdef THINGER_INSECURE_SSL
97
+ client_.setInsecure ();
98
+ THINGER_DEBUG (" SSL/TLS" , " Warning: TLS/SSL certificate will not be checked!" )
99
+ #else
100
+ client_.setCACert (get_root_ca ());
101
+ #endif
102
+ return client_.connect (get_host (), THINGER_SSL_PORT);
103
+ }
104
+
105
+ bool secure_connection () override {
106
+ return true ;
107
+ }
108
+ #endif
109
+
110
+ bool connect_network () override {
99
111
if (!initialized_){
100
112
initialized_ = ETH.begin ();
101
113
if (initialized_){
@@ -108,20 +120,14 @@ class ThingerESP32Eth : public ThingerClient
108
120
return network_connected ();
109
121
}
110
122
111
- #ifndef _DISABLE_TLS_
112
- WiFiClient base_client_;
113
- SSLClientESP32 client_;
114
- #else
115
- WiFiClient client_;
116
- #endif
123
+ ESP32Client client_;
117
124
bool initialized_ = false ;
118
125
const char * hostname_ = " esp32-thinger" ;
119
126
const char * ip_ = nullptr ;
120
127
const char * gateway_ = nullptr ;
121
128
const char * subnet_ = nullptr ;
122
129
const char * dns1_ = nullptr ;
123
130
const char * dns2_ = nullptr ;
124
-
125
131
};
126
132
127
133
#endif
0 commit comments