Skip to content

Commit

Permalink
ethernet support
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnymalina committed Oct 26, 2023
1 parent a53d7b4 commit f7ce162
Showing 1 changed file with 55 additions and 2 deletions.
57 changes: 55 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,64 @@ void loraInitialise()

#include <WiFiClient.h>
#include <PubSubClient.h>
#include <ETH.h>

#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";
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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f7ce162

Please sign in to comment.