Skip to content

Commit

Permalink
Arduino Bootstrapper (v1.17.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
sblantipodi committed Jun 3, 2024
1 parent e741201 commit 1e5e032
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 69 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "git",
"url": "https://github.com/sblantipodi/arduino_bootstrapper.git"
},
"version": "1.16.3",
"version": "1.17.0",
"examples": "examples/*.cpp",
"exclude": "tests",
"frameworks": "arduino",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Bootstrapper
version=1.16.3
version=1.17.0
author=Davide Perini <[email protected]>
maintainer=Davide Perini <[email protected]>
sentence=A client library for MQTT messaging.
Expand Down
9 changes: 7 additions & 2 deletions src/BootstrapManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,25 @@ void BootstrapManager::bootstrapSetup(void (*manageDisconnections)(), void (*man
}

#if defined(ARDUINO_ARCH_ESP32)
void WT32_ETH01_event(WiFiEvent_t event) {
void eth_event(WiFiEvent_t event) {
switch (event) {
case ARDUINO_EVENT_ETH_START:
ethConnected = true;
break;
case ARDUINO_EVENT_ETH_CONNECTED:
MAC = WiFi.macAddress();
ethConnected = true;
break;
case ARDUINO_EVENT_ETH_GOT_IP:
MAC = WiFi.macAddress();
microcontrollerIP = ETH.localIP().toString();
ethConnected = true;
break;
case ARDUINO_EVENT_ETH_DISCONNECTED:
ethConnected = false;
break;
case ARDUINO_EVENT_ETH_STOP:
ethConnected = false;
break;
default:
break;
Expand All @@ -98,7 +103,7 @@ void BootstrapManager::bootstrapSetup(void (*manageDisconnections)(), void (*man
#if defined(ARDUINO_ARCH_ESP32)
isConfigFileOk = true;
ETH.setHostname(Helpers::string2char(deviceName));
WiFi.onEvent(WT32_ETH01_event);
WiFi.onEvent(eth_event);
EthManager::connectToEthernet(ethd);
Serial.println(F("Ethernet connected."));
initMqttOta(callback);
Expand Down
156 changes: 91 additions & 65 deletions src/EthManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,77 +20,103 @@


#if defined(ARDUINO_ARCH_ESP32)
/**
* Supported ethernet devices
*/
const ethernet_config ethernetDevices[] = {
// No Ethernet
{
},
// QuinLed-ESP32-Ethernet
{
0,
5,
23,
18,
ETH_PHY_LAN8720,
ETH_CLOCK_GPIO17_OUT
},
// QuinLed-Dig-Octa Brainboard-32-8L and LilyGO-T-ETH-POE
{
0,
-1,
23,
18,
ETH_PHY_LAN8720,
ETH_CLOCK_GPIO17_OUT
},
// WT32-EHT01
// These pins works well: IO2, IO4, IO12, IO14, IO15
// These not: IO35, IO36, IO39
{
1,
16,
23,
18,
ETH_PHY_LAN8720,
ETH_CLOCK_GPIO0_IN
},
// ESP32-ETHERNET-KIT-VE
{
0,
5,
23,
18,
ETH_PHY_IP101,
ETH_CLOCK_GPIO0_IN
},
// ESP32-POE
{
0,
12,
23,
18,
ETH_PHY_LAN8720,
ETH_CLOCK_GPIO17_OUT
},
// WESP32
{
0,
-1,
16,
17,
ETH_PHY_LAN8720,
ETH_CLOCK_GPIO0_IN
}
// No Ethernet
{
},
// QuinLed-ESP32-Ethernet
{

0,
5,
23,
18,
ETH_PHY_LAN8720,
ETH_CLOCK_GPIO17_OUT
},
// QuinLed-Dig-Octa Brainboard-32-8L and LilyGO-T-ETH-POE
{
0,
-1,
23,
18,
ETH_PHY_LAN8720,
ETH_CLOCK_GPIO17_OUT
},
// WT32-EHT01
// These pins works well: IO2, IO4, IO12, IO14, IO15
// These not: IO35, IO36, IO39
{
1,
16,
23,
18,
ETH_PHY_LAN8720,
ETH_CLOCK_GPIO0_IN
},
// ESP32-ETHERNET-KIT-VE
{
0,
5,
23,
18,
ETH_PHY_IP101,
ETH_CLOCK_GPIO0_IN
},
// ESP32-POE
{
0,
12,
23,
18,
ETH_PHY_LAN8720,
ETH_CLOCK_GPIO17_OUT
},
// WESP32
{
0,
-1,
16,
17,
ETH_PHY_LAN8720,
ETH_CLOCK_GPIO0_IN
}
};

/**
* Connect to ethernet
* @param deviceNumber to use
*/
void EthManager::connectToEthernet(int8_t deviceNumber) {
ETH.begin(
ethernetDevices[deviceNumber].address,
ethernetDevices[deviceNumber].power,
ethernetDevices[deviceNumber].mdc,
ethernetDevices[deviceNumber].mdio,
ethernetDevices[deviceNumber].type,
ethernetDevices[deviceNumber].clk_mode
ethernetDevices[deviceNumber].address,
ethernetDevices[deviceNumber].power,
ethernetDevices[deviceNumber].mdc,
ethernetDevices[deviceNumber].mdio,
ethernetDevices[deviceNumber].type,
ethernetDevices[deviceNumber].clk_mode
);
}

/**
* Deallocate ethernet pins
* @param deviceNumber to deallocate
*/
void EthManager::deallocateEthernetPins(int8_t deviceNumber) {
const uint32_t MATRIX_DETACH_OUT_SIG = 0x100;
gpio_matrix_out(ethernetDevices[deviceNumber].address, MATRIX_DETACH_OUT_SIG, false, false);
gpio_matrix_out(ethernetDevices[deviceNumber].power, MATRIX_DETACH_OUT_SIG, false, false);
gpio_matrix_out(ethernetDevices[deviceNumber].mdc, MATRIX_DETACH_OUT_SIG, false, false);
gpio_matrix_out(ethernetDevices[deviceNumber].mdio, MATRIX_DETACH_OUT_SIG, false, false);
gpio_matrix_out(ethernetDevices[deviceNumber].clk_mode, MATRIX_DETACH_OUT_SIG, false, false);
pinMode(ethernetDevices[deviceNumber].address, INPUT);
pinMode(ethernetDevices[deviceNumber].power, INPUT);
pinMode(ethernetDevices[deviceNumber].mdc, INPUT);
pinMode(ethernetDevices[deviceNumber].mdio, INPUT);
pinMode(ethernetDevices[deviceNumber].clk_mode, INPUT);
}

#endif
1 change: 1 addition & 0 deletions src/EthManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class EthManager {

public:
static void connectToEthernet(int8_t deviceNumber);
static void deallocateEthernetPins(int8_t deviceNumber);
};

#endif
Expand Down
1 change: 1 addition & 0 deletions src/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ int mqttWillQOS = 1;
bool mqttWillRetain = 0;
bool mqttCleanSession = 1;
String additionalParam = "XXX";
bool ethConnected = false;

unsigned long previousMillis = 0;
const unsigned long interval = 200;
Expand Down
1 change: 1 addition & 0 deletions src/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extern int mqttWillQOS;
extern bool mqttWillRetain;
extern bool mqttCleanSession;
extern String additionalParam;
extern bool ethConnected;

// Blink LED vars
extern unsigned long previousMillis; // will store last time LED was updated
Expand Down

0 comments on commit 1e5e032

Please sign in to comment.