diff --git a/src/main.cpp b/src/main.cpp index 24db0af..051b635 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,6 +58,16 @@ void loraInitialise() #include #include +#include + +#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT +#define ETH_POWER_PIN -1 +#define ETH_TYPE ETH_PHY_LAN8720 +#define ETH_ADDR 0 +#define ETH_MDC_PIN 23 +#define ETH_MDIO_PIN 18 +#define NRST 5 + const char *mqtt_broker = "10.10.42.4"; const char *mqtt_username = "mqtt-user"; const char *mqtt_password = "HesloMqtt196455"; @@ -65,6 +75,47 @@ const int mqtt_port = 1883; WiFiClient espClient; PubSubClient client(espClient); +static bool eth_connected = false; + +void WiFiEvent(WiFiEvent_t event) +{ + switch (event) + { + case SYSTEM_EVENT_ETH_START: + Serial.println("ETH Started"); + // set eth hostname here + ETH.setHostname("esp32-ethernet"); + break; + case SYSTEM_EVENT_ETH_CONNECTED: + Serial.println("ETH Connected"); + break; + case SYSTEM_EVENT_ETH_GOT_IP: + Serial.print("ETH MAC: "); + Serial.print(ETH.macAddress()); + Serial.print(", IPv4: "); + Serial.print(ETH.localIP()); + if (ETH.fullDuplex()) + { + Serial.print(", FULL_DUPLEX"); + } + Serial.print(", "); + Serial.print(ETH.linkSpeed()); + Serial.println("Mbps"); + eth_connected = true; + break; + case SYSTEM_EVENT_ETH_DISCONNECTED: + Serial.println("ETH Disconnected"); + eth_connected = false; + break; + case SYSTEM_EVENT_ETH_STOP: + Serial.println("ETH Stopped"); + eth_connected = false; + break; + default: + break; + } +} + void mqttInitialize() { client.setServer(mqtt_broker, mqtt_port); @@ -373,8 +424,10 @@ void setup() loraInitialise(); - wifiConnect(); - + // wifiConnect(); + WiFi.onEvent(WiFiEvent); + ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE); + ETH.config(IPAddress(10, 10, 42, 5), IPAddress(10, 10, 42, 1), IPAddress(255, 255, 255, 0)); mqttInitialize(); ElegantOTA.begin(&server);