Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions libraries/Ethernet/examples/Dhcp/Dhcp.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <Ethernet.h>
#include "WiFi.h"

// declare the ethernet adapter
ESP32Ethernet ethernet;

void WiFiEvent(WiFiEvent_t event){
switch(event) {
case SYSTEM_EVENT_ETH_START:
//set eth hostname here
ethernet.setHostname("esp32-eth");
Serial.println("ETH started");
Serial.print("ETH MAC: ");
Serial.println(ethernet.getMacAddress());
break;
case SYSTEM_EVENT_ETH_CONNECTED:
Serial.println("ETH connected");
break;
case SYSTEM_EVENT_ETH_GOT_IP:
Serial.print("ETH IPv4: ");
Serial.println(ethernet.localIP());
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
Serial.println("ETH disconnected");
break;
default:
break;
}
}

void setup(){
// start the serial console
Serial.begin(115200);
// attach the callback event handler
WiFi.onEvent(WiFiEvent);
// start the ethernet
ethernet.begin();
}

void loop(){
// nothing yet to do here
}

48 changes: 48 additions & 0 deletions libraries/Ethernet/examples/Static/Static.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <Ethernet.h>
#include "WiFi.h"

// declare the ethernet adapter
ESP32Ethernet ethernet;

// define the network settings
IPAddress ip(192, 168, 0, 123);
IPAddress nm(255, 255, 255, 0);
IPAddress gw(192, 168, 0, 1);

void WiFiEvent(WiFiEvent_t event){
switch(event) {
case SYSTEM_EVENT_ETH_START:
//set eth hostname here
ethernet.setHostname("esp32-eth");
Serial.println("ETH started");
Serial.print("ETH MAC: ");
Serial.println(ethernet.getMacAddress());
break;
case SYSTEM_EVENT_ETH_CONNECTED:
Serial.println("ETH connected");
break;
case SYSTEM_EVENT_ETH_GOT_IP:
Serial.print("ETH IPv4: ");
Serial.println(ethernet.localIP());
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
Serial.println("ETH disconnected");
break;
default:
break;
}
}

void setup(){
// start the serial console
Serial.begin(115200);
// attach the callback event handler
WiFi.onEvent(WiFiEvent);
// start the ethernet
ethernet.begin(ip,nm,gw);
}

void loop(){
// nothing yet to do here
}

9 changes: 9 additions & 0 deletions libraries/Ethernet/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=Ethernet(ESP32-EVB)
version=1.0.5
author=Bob Fisch
maintainer=Bob Fisch <bob@fisch.lu>
sentence=Enables network connection (local and Internet) the onboard Ethernet controller. (ESP32-EVB from www.olimex.com)
paragraph=With this library you can use the port Ethernet to connect to Internet. The library permits you to connect to a local network also with DHCP and to resolve DNS.
category=Communication
url=
architectures=esp32
142 changes: 142 additions & 0 deletions libraries/Ethernet/src/Ethernet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#include "Ethernet.h"

extern "C" {
#include "WiFiGeneric.h"
//void tcpipInit();
};


static eth_config_t eth_config = ETH_PHY_CONF;

static void ethernet_config_gpio(void){
// RMII data pins are fixed:
// CRS_DRV = GPIO27
// TXD0 = GPIO19
// TXD1 = GPIO22
// TX_EN = GPIO21
// RXD0 = GPIO25
// RXD1 = GPIO26
// CLK == GPIO0
phy_rmii_configure_data_interface_pins();
// MDC is GPIO 23, MDIO is GPIO 18
phy_rmii_smi_configure_pins(PIN_SMI_MDC, PIN_SMI_MDIO);
}

void tcpipInit();

int EthernetClass::begin()
{
eth_config.phy_addr = ETH_PHY_ADDR;
eth_config.gpio_config = ethernet_config_gpio;
eth_config.tcpip_input = tcpip_adapter_eth_input;
//eth_config.phy_power_enable = ethernet_power_enable;
tcpipInit();
esp_err_t err = esp_eth_init(&eth_config);
if(!err){
err = esp_eth_enable();
return 1;
}
return 0;
}

int EthernetClass::config(IPAddress local_ip, IPAddress subnet, IPAddress gateway)
{
// stop the DHCP service
if(tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_ETH) == ESP_OK) {
// continue
}
else {
return 0;
}

// create a new TCP/IP info
tcpip_adapter_ip_info_t info;
info.ip.addr = static_cast<uint32_t>((local_ip));
info.gw.addr = static_cast<uint32_t>((gateway));
info.netmask.addr = static_cast<uint32_t>((subnet));
// apply the IP settings
if(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_ETH, &info) == ESP_OK) {
// continue
} else {
return 0;
}

return 1;
}

int EthernetClass::begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway)
{
// connect the callback function
esp_event_loop_init(&WiFiGenericClass::_eventCallback, NULL);

// init the TCP/IP adapter
tcpip_adapter_init();

// manually configure the adapter
if(!config(local_ip,subnet,gateway))
{
return 0;
}

eth_config.phy_addr = ETH_PHY_ADDR;
eth_config.gpio_config = ethernet_config_gpio;
eth_config.tcpip_input = tcpip_adapter_eth_input;
//eth_config.phy_power_enable = ethernet_power_enable;
esp_err_t err = esp_eth_init(&eth_config);
if(!err){
err = esp_eth_enable();
return 1;
}

return 0;
}

IPAddress EthernetClass::localIP()
{
tcpip_adapter_ip_info_t ip;
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip);
return IPAddress(ip.ip.addr);
}

IPAddress EthernetClass::subnetMask()
{
tcpip_adapter_ip_info_t ip;
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip);
return IPAddress(ip.netmask.addr);

}

IPAddress EthernetClass::gatewayIP()
{
tcpip_adapter_ip_info_t ip;
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip);
return IPAddress(ip.gw.addr);
}

bool EthernetClass::setHostname(const char * hostname)
{
return tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_ETH, hostname) == 0;
}

bool EthernetClass::isFullDuplex()
{
return eth_config.phy_get_duplex_mode();
}

uint8_t EthernetClass::getLinkSpeed()
{
return eth_config.phy_get_speed_mode()?100:10;
}

String EthernetClass::getMacAddress()
{
uint8_t mac[6];
char macStr[18] = { 0 };
esp_eth_get_mac(mac);
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return String(macStr);
}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_ETHERNET)
EthernetClass Ethernet;
#endif
43 changes: 43 additions & 0 deletions libraries/Ethernet/src/Ethernet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef ethernet_h
#define ethernet_h

//#include <inttypes.h>
#include "IPAddress.h"
#include "WiFi.h"
#include "esp_eth.h"
#include "eth_phy/phy.h"
#include "eth_phy/phy_lan8720.h"

#define ETH_PHY_CONF phy_lan8720_default_ethernet_config
#define ETH_PHY_ADDR PHY0
//#define PIN_PHY_POWER 17
#define PIN_SMI_MDC 23
#define PIN_SMI_MDIO 18

class EthernetClass {
private:

public:
// Initialise the ethernet controller and gain every configuration through DHCP.
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded
int begin();
int begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway);
int config(IPAddress local_ip, IPAddress subnet, IPAddress gateway);

IPAddress localIP();
IPAddress subnetMask();
IPAddress gatewayIP();

bool setHostname(const char * hostname);
bool isFullDuplex();
uint8_t getLinkSpeed();
String getMacAddress();

friend class EthernetClient;
friend class EthernetServer;
};

class ESP32Ethernet : public EthernetClass {
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <Ethernet.h>
#include "WiFi.h"
#include <ESP32WebServer.h>

// declare the ethernet adapter
ESP32Ethernet ethernet;
// define a webserver on port 80
ESP32WebServer server(80);

void setup(){
Serial.begin(115200);

// start the ethernet adapter (DHCP)
ethernet.begin();

// attach handles
server.on("/",handleRoot);
server.on("/test",handleTest);

// start the server
server.begin();
}

void handleRoot()
{
String html = "You just loaded the root of your ESP WebServer<br><br><a href=\"/test\">Goto /test</a>";
server.setContentLength(html.length());
server.send(200,"text/html",html);
}

void handleTest()
{
String html = "You just entered /test ...";
server.setContentLength(html.length());
server.send(200,"text/html",html);
}

void loop(){
// hanle clients
server.handleClient();
}
36 changes: 36 additions & 0 deletions libraries/WebServer/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#######################################
# Syntax Coloring Map For Ultrasound
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

ESP8266WebServer KEYWORD1
HTTPMethod KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

begin KEYWORD2
handleClient KEYWORD2
on KEYWORD2
addHandler KEYWORD2
uri KEYWORD2
method KEYWORD2
client KEYWORD2
send KEYWORD2
arg KEYWORD2
argName KEYWORD2
args KEYWORD2
hasArg KEYWORD2
onNotFound KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################

HTTP_GET LITERAL1
HTTP_POST LITERAL1
HTTP_ANY LITERAL1
9 changes: 9 additions & 0 deletions libraries/WebServer/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=ESP32WebServer
version=1.0
author=Ivan Grokhotkov
maintainer=Ivan Grokhtkov <ivan@esp8266.com>
sentence=Simple web server library
paragraph=The library supports HTTP GET and POST requests, provides argument parsing, handles one client at a time.
category=Communication
url=
architectures=esp32
Loading