Skip to content

Commit e7cdcd9

Browse files
committed
Initial support for ESP32 Ethernet connection over TLS
1 parent 1415f90 commit e7cdcd9

File tree

4 files changed

+51
-25
lines changed

4 files changed

+51
-25
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.28.0
2+
3+
- Initial support for ESP32 Ethernet connection over TLS
4+
15
2.27.0
26

37
- Fix compiling issues for AVR

examples/ESP32/ESP32Eth/ESP32Eth.ino

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,44 @@
1010
//#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
1111

1212
// enable debug output over serial
13-
#define THINGER_SERIAL_DEBUG
13+
#define THINGER_SERIAL_DEBUG
14+
15+
// define private server instance
16+
//#define THINGER_SERVER "acme.aws.thinger.io"
17+
18+
// TLS connection requires SSLClientESP32 library from
19+
// https://github.com/alkonosst/SSLClientESP32
20+
21+
// disable TLS connection by default
22+
#define _DISABLE_TLS_
1423

1524
#include <ThingerESP32Eth.h>
1625
#include "arduino_secrets.h"
1726

1827
ThingerESP32Eth thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
1928

2029
void setup() {
21-
22-
// enable serial for debugging
23-
Serial.begin(115200);
24-
25-
// example of fixed ip address (dhcp is used by default)
26-
//thing.set_address("192.168.1.55", "192.168.1.1", "255.255.255.0", "8.8.8.8", "8.8.4.4");
27-
28-
// set desired hostname
29-
thing.set_hostname("ESP32Eth");
30-
31-
// resource output example (i.e. reading a sensor value)
32-
thing["eth"] >> [](pson& out){
33-
out["hostname"] = ETH.getHostname();
34-
out["mac"] = ETH.macAddress();
35-
out["ip"] = ETH.localIP().toString();
36-
out["link"] = ETH.linkSpeed();
37-
};
38-
39-
// more details at http://docs.thinger.io/arduino/
30+
31+
// enable serial for debugging
32+
Serial.begin(115200);
33+
34+
// example of fixed ip address (dhcp is used by default)
35+
//thing.set_address("192.168.1.55", "192.168.1.1", "255.255.255.0", "8.8.8.8", "8.8.4.4");
36+
37+
// set desired hostname
38+
thing.set_hostname("ESP32Eth");
39+
40+
// resource output example (i.e. reading a sensor value)
41+
thing["eth"] >> [](pson& out){
42+
out["hostname"] = ETH.getHostname();
43+
out["mac"] = ETH.macAddress();
44+
out["ip"] = ETH.localIP().toString();
45+
out["link"] = ETH.linkSpeed();
46+
};
47+
48+
// more details at http://docs.thinger.io/arduino/
4049
}
4150

4251
void loop() {
43-
thing.handle();
52+
thing.handle();
4453
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=thinger.io
2-
version=2.27.0
2+
version=2.28.0
33
author=Alvaro Luis Bustamante <alvarolb@thinger.io>
44
maintainer=Thinger.io <admin@thinger.io>
55
sentence=Arduino library for IOTMP protocol used on Thinger.io IOT Platform.

src/ThingerESP32Eth.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#ifndef THINGER_ESP32ETH_H
22
#define THINGER_ESP32ETH_H
33

4-
// TODO ESP32 TROUGHT ETHERNET DOES NOT SUPPORT SSL/TLS CONNECTIONS
5-
#define _DISABLE_TLS_
6-
74
#ifdef THINGER_FREE_RTOS
85
#include "ThingerESP32FreeRTOS.h"
96
#endif
@@ -12,6 +9,10 @@
129
#include <ThingerClient.h>
1310
#include <functional>
1411

12+
#ifndef _DISABLE_TLS_
13+
#include <SSLClientESP32.h>
14+
#endif
15+
1516
class ThingerESP32Eth : public ThingerClient
1617

1718
#ifdef THINGER_FREE_RTOS
@@ -24,9 +25,16 @@ class ThingerESP32Eth : public ThingerClient
2425
ThingerClient(client_, user, device, device_credential)
2526
#ifdef THINGER_FREE_RTOS
2627
,ThingerESP32FreeRTOS(static_cast<ThingerClient&>(*this))
28+
#endif,
29+
#ifndef _DISABLE_TLS_
30+
,client_(&base_client_)
2731
#endif
2832
{
2933

34+
#ifndef _DISABLE_TLS_
35+
client_.setCACert(CA_ROOT_CERTIFICATE);
36+
#endif
37+
3038
WiFi.onEvent([](WiFiEvent_t event){
3139
switch (event) {
3240
case SYSTEM_EVENT_ETH_START:
@@ -100,7 +108,12 @@ class ThingerESP32Eth : public ThingerClient
100108
return network_connected();
101109
}
102110

111+
#ifndef _DISABLE_TLS_
112+
WiFiClient base_client_;
113+
SSLClientESP32 client_;
114+
#else
103115
WiFiClient client_;
116+
#endif
104117
bool initialized_ = false;
105118
const char* hostname_ = "esp32-thinger";
106119
const char* ip_ = nullptr;

0 commit comments

Comments
 (0)