Skip to content

Commit a038e53

Browse files
committed
Ethernet support
1 parent 380a04e commit a038e53

File tree

10 files changed

+350
-170
lines changed

10 files changed

+350
-170
lines changed

.github/workflows/ci.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/esphome-AsyncTCP#v2.1.1
7676

7777
- name: Install ESP Async WebServer
78-
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/ESPAsyncWebServer
78+
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/ESPAsyncWebServer#v2.7.0
7979

8080
- name: Build BlockingCaptivePortal
8181
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/BlockingCaptivePortal/BlockingCaptivePortal.ino"
@@ -98,6 +98,10 @@ jobs:
9898
board: esp32dev
9999
eeprom: true
100100
softwareserial: false
101+
- platform: espressif32
102+
board: wt32-eth01
103+
eeprom: true
104+
softwareserial: false
101105

102106
steps:
103107
- name: Checkout

README.md

+25-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
[![Continuous Integration](https://github.com/mathieucarbou/MycilaESPConnect/actions/workflows/ci.yml/badge.svg)](https://github.com/mathieucarbou/MycilaESPConnect/actions/workflows/ci.yml)
55
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/mathieucarbou/library/MycilaESPConnect.svg)](https://registry.platformio.org/libraries/mathieucarbou/MycilaESPConnect)
66

7-
-----
7+
---
88

99
Simple & Easy WiFi Manager with Captive Portal for ESP32
1010

1111
A simplistic approach to a WiFi Manager on ESP32 MCUs. Comes with captive portal to configure modules without any hassle.
1212

13-
-----
13+
---
1414

1515
> This fork is based on [https://github.com/ayushsharma82/ESPConnect](https://github.com/ayushsharma82/ESPConnect).
1616
> I highly recommend looking at all OSS projects (and products) from [@ayushsharma82](https://github.com/ayushsharma82).
@@ -34,4 +34,26 @@ A simplistic approach to a WiFi Manager on ESP32 MCUs. Comes with captive portal
3434

3535
- **mDNS / DNS Support**
3636

37-
See the examples and API for more !
37+
- **Ethernet support**
38+
39+
## Ethernet Support
40+
41+
Compile with `-D CONFIG_ETH_ENABLED` ([ref](https://community.platformio.org/t/please-help-me-fix-error-wifi-h-when-build-project-ethernet-testing-use-esp32-eth01/37573/3))
42+
43+
For wt32-eth01, alo use the following flags:
44+
45+
```cpp
46+
-D ESPCONNECT_ETH_RESET_ON_START
47+
-D ETH_PHY_TYPE=ETH_PHY_LAN8720
48+
-D ETH_PHY_ADDR=1
49+
-D ETH_PHY_MDC=23
50+
-D ETH_PHY_MDIO=18
51+
-D ETH_CLK_MODE=ETH_CLOCK_GPIO0_IN
52+
-D ETH_PHY_POWER=16
53+
```
54+
55+
In your application, if Ethernet is allowed, call `ESPConnect.allowEthernet()`.
56+
57+
- Ethernet takes precedence over WiFi, but you can have both connected at the same time
58+
- Ethernet takes precedence over Captive Portal: if it is running and you connect an Ethernet cable, the Captive Portal will be closed
59+
- Ethernet _does not_ take precedence over AP Mode: if AP mode is configured, then Ethernet won't be started even if a cable is connected

docs/index.md

+25-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
[![Continuous Integration](https://github.com/mathieucarbou/MycilaESPConnect/actions/workflows/ci.yml/badge.svg)](https://github.com/mathieucarbou/MycilaESPConnect/actions/workflows/ci.yml)
55
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/mathieucarbou/library/MycilaESPConnect.svg)](https://registry.platformio.org/libraries/mathieucarbou/MycilaESPConnect)
66

7-
-----
7+
---
88

99
Simple & Easy WiFi Manager with Captive Portal for ESP32
1010

1111
A simplistic approach to a WiFi Manager on ESP32 MCUs. Comes with captive portal to configure modules without any hassle.
1212

13-
-----
13+
---
1414

1515
> This fork is based on [https://github.com/ayushsharma82/ESPConnect](https://github.com/ayushsharma82/ESPConnect).
1616
> I highly recommend looking at all OSS projects (and products) from [@ayushsharma82](https://github.com/ayushsharma82).
@@ -34,4 +34,26 @@ A simplistic approach to a WiFi Manager on ESP32 MCUs. Comes with captive portal
3434

3535
- **mDNS / DNS Support**
3636

37-
See the examples and API for more !
37+
- **Ethernet support**
38+
39+
## Ethernet Support
40+
41+
Compile with `-D CONFIG_ETH_ENABLED` ([ref](https://community.platformio.org/t/please-help-me-fix-error-wifi-h-when-build-project-ethernet-testing-use-esp32-eth01/37573/3))
42+
43+
For wt32-eth01, alo use the following flags:
44+
45+
```cpp
46+
-D ESPCONNECT_ETH_RESET_ON_START
47+
-D ETH_PHY_TYPE=ETH_PHY_LAN8720
48+
-D ETH_PHY_ADDR=1
49+
-D ETH_PHY_MDC=23
50+
-D ETH_PHY_MDIO=18
51+
-D ETH_CLK_MODE=ETH_CLOCK_GPIO0_IN
52+
-D ETH_PHY_POWER=16
53+
```
54+
55+
In your application, if Ethernet is allowed, call `ESPConnect.allowEthernet()`.
56+
57+
- Ethernet takes precedence over WiFi, but you can have both connected at the same time
58+
- Ethernet takes precedence over Captive Portal: if it is running and you connect an Ethernet cable, the Captive Portal will be closed
59+
- Ethernet _does not_ take precedence over AP Mode: if AP mode is configured, then Ethernet won't be started even if a cable is connected

examples/AdvancedCaptivePortal/AdvancedCaptivePortal.ino

+9-10
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,31 @@ void setup() {
3737

3838
// network state listener is required here in async mode
3939
ESPConnect.listen([](ESPConnectState previous, ESPConnectState state) {
40-
Serial.printf("NetworkState: %s => %s\n", ESPConnect.getStateName(previous), ESPConnect.getStateName(state));
41-
4240
JsonDocument doc;
4341
ESPConnect.toJson(doc.to<JsonObject>());
44-
serializeJson(doc, Serial);
42+
serializeJsonPretty(doc, Serial);
4543
Serial.println();
4644

4745
switch (state) {
48-
case ESPConnectState::STA_CONNECTED:
49-
case ESPConnectState::AP_CONNECTED:
46+
case ESPConnectState::NETWORK_CONNECTED:
47+
case ESPConnectState::AP_STARTED:
5048
server.begin();
5149
MDNS.addService("http", "tcp", 80);
5250
break;
5351

54-
case ESPConnectState::STA_DISCONNECTED:
52+
case ESPConnectState::NETWORK_DISCONNECTED:
5553
server.end();
5654
mdns_service_remove("_http", "_tcp");
5755
break;
5856

5957
case ESPConnectState::PORTAL_COMPLETE:
60-
config.apMode = ESPConnect.isAPMode();
58+
config.apMode = ESPConnect.hasConfiguredAPMode();
6159
if (config.apMode) {
6260
Serial.println("====> Captive Portal: Access Point configured");
6361
} else {
6462
Serial.println("====> Captive Portal: WiFi configured");
65-
config.wifiSSID = ESPConnect.getWiFiSSIDConfigured();
66-
config.wifiPassword = ESPConnect.getWiFiPassword();
63+
config.wifiSSID = ESPConnect.getConfiguredWiFiSSID();
64+
config.wifiPassword = ESPConnect.getConfiguredWiFiPassword();
6765
}
6866
// SAVE config somewhere
6967
break;
@@ -73,10 +71,11 @@ void setup() {
7371
}
7472
});
7573

74+
ESPConnect.allowEthernet();
7675
ESPConnect.setAutoRestart(true);
7776
ESPConnect.setBlocking(false);
7877
ESPConnect.setCaptivePortalTimeout(180);
79-
ESPConnect.setWiFiConnectTimeout(10);
78+
ESPConnect.setConnectTimeout(10);
8079

8180
Serial.println("====> Load config from elsewhere...");
8281
config.wifiSSID = "arduino";

examples/BlockingCaptivePortal/BlockingCaptivePortal.ino

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <MycilaESPConnect.h>
22

33
AsyncWebServer server(80);
4+
uint32_t lastLog = 0;
45

56
void setup() {
67
Serial.begin(115200);
@@ -32,17 +33,17 @@ void setup() {
3233

3334
// network state listener
3435
ESPConnect.listen([](ESPConnectState previous, ESPConnectState state) {
35-
Serial.printf("NetworkState: %s => %s\n", ESPConnect.getStateName(previous), ESPConnect.getStateName(state));
3636
JsonDocument doc;
3737
ESPConnect.toJson(doc.to<JsonObject>());
38-
serializeJson(doc, Serial);
38+
serializeJsonPretty(doc, Serial);
3939
Serial.println();
4040
});
4141

42+
ESPConnect.allowEthernet();
4243
ESPConnect.setAutoRestart(true);
4344
ESPConnect.setBlocking(true);
4445
ESPConnect.setCaptivePortalTimeout(180);
45-
ESPConnect.setWiFiConnectTimeout(10);
46+
ESPConnect.setConnectTimeout(10);
4647

4748
Serial.println("Trying to connect to saved WiFi or will start portal...");
4849

@@ -55,4 +56,12 @@ void setup() {
5556

5657
void loop() {
5758
ESPConnect.loop();
59+
60+
if (millis() - lastLog > 5000) {
61+
JsonDocument doc;
62+
ESPConnect.toJson(doc.to<JsonObject>());
63+
serializeJson(doc, Serial);
64+
Serial.println();
65+
lastLog = millis();
66+
}
5867
}

examples/NonBlockingCaptivePortal/NonBlockingCaptivePortal.ino

+15-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <MycilaESPConnect.h>
33

44
AsyncWebServer server(80);
5+
uint32_t lastLog = 0;
56

67
void setup() {
78
Serial.begin(115200);
@@ -34,32 +35,31 @@ void setup() {
3435

3536
// network state listener is required here in async mode
3637
ESPConnect.listen([](ESPConnectState previous, ESPConnectState state) {
37-
Serial.printf("NetworkState: %s => %s\n", ESPConnect.getStateName(previous), ESPConnect.getStateName(state));
3838
JsonDocument doc;
3939
ESPConnect.toJson(doc.to<JsonObject>());
40-
serializeJson(doc, Serial);
40+
serializeJsonPretty(doc, Serial);
4141
Serial.println();
4242

4343
switch (state) {
44-
case ESPConnectState::STA_CONNECTED:
45-
case ESPConnectState::AP_CONNECTED:
44+
case ESPConnectState::NETWORK_CONNECTED:
45+
case ESPConnectState::AP_STARTED:
4646
server.begin();
4747
MDNS.addService("http", "tcp", 80);
4848
break;
4949

50-
case ESPConnectState::STA_DISCONNECTED:
50+
case ESPConnectState::NETWORK_DISCONNECTED:
5151
server.end();
5252
mdns_service_remove("_http", "_tcp");
53-
5453
default:
5554
break;
5655
}
5756
});
5857

58+
ESPConnect.allowEthernet();
5959
ESPConnect.setAutoRestart(true);
6060
ESPConnect.setBlocking(false);
6161
ESPConnect.setCaptivePortalTimeout(180);
62-
ESPConnect.setWiFiConnectTimeout(10);
62+
ESPConnect.setConnectTimeout(10);
6363

6464
Serial.println("====> Trying to connect to saved WiFi or will start portal in the background...");
6565

@@ -70,4 +70,12 @@ void setup() {
7070

7171
void loop() {
7272
ESPConnect.loop();
73+
74+
if (millis() - lastLog > 5000) {
75+
JsonDocument doc;
76+
ESPConnect.toJson(doc.to<JsonObject>());
77+
serializeJson(doc, Serial);
78+
Serial.println();
79+
lastLog = millis();
80+
}
7381
}

library.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
{
3030
"owner": "mathieucarbou",
3131
"name": "ESP Async WebServer",
32-
"version": "^2.4.4",
32+
"version": "^2.7.0",
3333
"platforms": "espressif32"
3434
},
3535
{
3636
"owner": "bblanchon",
3737
"name": "ArduinoJson",
38-
"version": "^7.0.2",
38+
"version": "^7.0.3",
3939
"platforms": [
4040
"espressif32"
4141
]

platformio.ini

+28-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,44 @@
1+
12
[env]
3+
4+
framework = arduino
5+
26
lib_deps =
3-
bblanchon/ArduinoJson @ 7.0.2
7+
bblanchon/ArduinoJson @ 7.0.3
48
mathieucarbou/ESP Async WebServer @ 2.4.4
59

6-
build_flags = -Wall -Wextra
10+
build_flags =
11+
-Wall
12+
-Wextra
13+
-D CONFIG_ARDUHAL_LOG_COLORS
14+
-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
715

816
upload_protocol = esptool
9-
upload_port = /dev/cu.usbserial-0001
17+
; upload_port = /dev/cu.usbserial-0001
18+
; upload_port = /dev/cu.usbserial-10
1019

11-
monitor_port = /dev/cu.usbserial-0001
20+
; monitor_port = /dev/cu.usbserial-0001
21+
; monitor_port = /dev/cu.usbserial-10
1222
monitor_speed = 115200
1323
monitor_filters = esp32_exception_decoder, log2file
1424

1525
[platformio]
26+
default_envs = wt32-eth01
1627
lib_dir = .
17-
; src_dir = examples/BlockingCaptivePortal
28+
src_dir = examples/BlockingCaptivePortal
1829
; src_dir = examples/NonBlockingCaptivePortal
19-
src_dir = examples/AdvancedCaptivePortal
20-
30+
; src_dir = examples/AdvancedCaptivePortal
2131

2232
[env:esp32]
23-
2433
board = esp32dev
25-
framework = arduino
34+
35+
[env:wt32-eth01]
36+
board = wt32-eth01
37+
build_flags = ${env.build_flags}
38+
-D ESPCONNECT_ETH_RESET_ON_START
39+
-D ETH_PHY_TYPE=ETH_PHY_LAN8720
40+
-D ETH_PHY_ADDR=1
41+
-D ETH_PHY_MDC=23
42+
-D ETH_PHY_MDIO=18
43+
-D ETH_CLK_MODE=ETH_CLOCK_GPIO0_IN
44+
-D ETH_PHY_POWER=16

0 commit comments

Comments
 (0)