Some updates
This commit is contained in:
35
ESP32-PoE-Test3/ESP32-PoE-Test3.ino
Normal file
35
ESP32-PoE-Test3/ESP32-PoE-Test3.ino
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
This sketch is combined demo of: 1) SD(esp_32) -- > SD_Test; 2) WiFi --> ETH_LAN8720
|
||||
It displays info about the card on the terminal and initializes LAN after that. You can ping the IP address shown on the terminal.
|
||||
|
||||
*/
|
||||
#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
|
||||
#define ETH_PHY_POWER 12
|
||||
|
||||
#include <ETH.h>
|
||||
|
||||
static bool eth_connected = false;
|
||||
|
||||
void WiFiEvent(WiFiEvent_t event);
|
||||
void testClient(const char * host, uint16_t port);
|
||||
|
||||
#define BUTTON_PRESSED() (!digitalRead (34))
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
WiFi.onEvent(WiFiEvent);
|
||||
ETH.begin();
|
||||
pinMode (34, INPUT); // Button
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (BUTTON_PRESSED()) {
|
||||
if (eth_connected) {
|
||||
Serial.println("Button pressed");
|
||||
testClient("google.com", 80);
|
||||
}
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
42
ESP32-PoE-Test3/esp_eth.ino
Normal file
42
ESP32-PoE-Test3/esp_eth.ino
Normal file
@ -0,0 +1,42 @@
|
||||
#include <ETH.h>
|
||||
|
||||
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");
|
||||
if (ETH.enableIpV6()) {
|
||||
Serial.print(" IPv6 enabled : ");
|
||||
Serial.println(ETH.localIPv6());
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
19
ESP32-PoE-Test3/testclient.ino
Normal file
19
ESP32-PoE-Test3/testclient.ino
Normal file
@ -0,0 +1,19 @@
|
||||
void testClient(const char * host, uint16_t port)
|
||||
{
|
||||
Serial.print("\nconnecting to ");
|
||||
Serial.println(host);
|
||||
|
||||
WiFiClient client;
|
||||
if (!client.connect(host, port)) {
|
||||
Serial.println("connection failed");
|
||||
return;
|
||||
}
|
||||
client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
|
||||
while (client.connected() && !client.available());
|
||||
while (client.available()) {
|
||||
Serial.write(client.read());
|
||||
}
|
||||
|
||||
Serial.println("closing connection\n");
|
||||
client.stop();
|
||||
}
|
||||
Reference in New Issue
Block a user