Inital ESP32 Ethernet support

This commit is contained in:
arovak 2020-11-03 22:52:41 +01:00
parent 07293d0d47
commit ba8f5b1fa0
7 changed files with 109 additions and 8 deletions

View File

@ -107,6 +107,21 @@
#endif
#if HASP_USE_ETHERNET > 0
#if defined(ARDUINO_ARCH_ESP32)
#include <ETH.h>
#define ETH_ADDR 0
#define ETH_POWER_PIN -1
#define ETH_MDC_PIN 23
#define ETH_MDIO_PIN 18
#define NRST 5
#define ETH_TYPE ETH_PHY_LAN8720
#define ETH_CLKMODE ETH_CLOCK_GPIO17_OUT
#include "hasp_ethernet_esp32.h"
#warning Using ESP32 Ethernet LAN8720
#else
#if USE_BUILTIN_ETHERNET > 0
#include <LwIP.h>
#include <STM32Ethernet.h>
@ -121,6 +136,7 @@
#endif
#include "hasp_ethernet.h"
#endif
#endif
#if HASP_USE_MQTT > 0
#include "hasp_mqtt.h"

View File

@ -4,7 +4,7 @@
#include "hasp_conf.h"
#include "hasp_hal.h"
#if HASP_USE_ETHERNET > 0
#if HASP_USE_ETHERNET > 0 && !defined(ARDUINO_ARCH_ESP32)
EthernetClient EthClient;
IPAddress ip;

View File

@ -0,0 +1,64 @@
#include <Arduino.h>
#include "ArduinoJson.h"
#include "ArduinoLog.h"
#include "hasp_conf.h"
#include "hasp_hal.h"
#if HASP_USE_ETHERNET > 0
IPAddress ip;
void EthernetEvent(WiFiEvent_t event)
{
switch (event) {
case SYSTEM_EVENT_ETH_START:
Log.notice(F(LOG_ETH_CTR "Started"));
//set eth hostname here
ETH.setHostname("esp32-ethernet");
break;
case SYSTEM_EVENT_ETH_CONNECTED:
Log.notice(F(LOG_ETH_CTR "Connected"));
break;
case SYSTEM_EVENT_ETH_GOT_IP:
Log.notice(F(LOG_ETH_CTR "MAC Address %s"), ETH.macAddress().c_str());
ip = ETH.localIP();
Log.notice(F(LOG_ETH_CTR "IPv4: %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
if (ETH.fullDuplex()) {
Log.notice(F(LOG_ETH_CTR "FULL_DUPLEX"));
}
Log.notice(F(LOG_ETH_CTR "LINK_SPEED %d Mbps"), ETH.linkSpeed());
eth_connected = true;
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
Log.notice(F(LOG_ETH_CTR "Disconnected"));
eth_connected = false;
break;
case SYSTEM_EVENT_ETH_STOP:
Log.notice(F(LOG_ETH_CTR "Stopped"));
eth_connected = false;
break;
default:
break;
}
}
void ethernetSetup()
{
WiFi.onEvent(EthernetEvent);
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLKMODE);
}
void ethernetLoop(void)
{
//
}
bool ethernetEvery5Seconds()
{
Log.warning(F(LOG_ETH_CTR "%s"), eth_connected ? F("ONLINE") : F("OFFLINE"));
return eth_connected;
}
#endif

13
src/hasp_ethernet_esp32.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef HASP_ETHERNET_ESP32_H
#define HASP_ETHERNET_ESP32_H
#define LOG_ETH_CTR "ETH: "
static bool eth_connected = false;
void ethernetSetup();
void ethernetLoop(void);
bool ethernetEvery5Seconds();
#endif

View File

@ -1514,7 +1514,11 @@ void webStart()
(WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str()));
#else
IPAddress ip;
#if defined(ARDUINO_ARCH_ESP32)
ip = ETH.localIP();
#else
ip = Ethernet.localIP();
#endif
Log.notice(F("HTTP: Server started @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
#endif
}

View File

@ -73,13 +73,14 @@ static void kb_event_cb(lv_obj_t * event_kb, lv_event_t event)
strncpy(pass, lv_textarea_get_text(obj), sizeof(pass));
settings[FPSTR(F_CONFIG_PASS)] = pass;
}
#if HASP_USE_WIFI > 0
if(strlen(ssid) > 0) {
wifiSetConfig(settings.as<JsonObject>());
if(wifiTestConnection()) {
dispatchReboot(true);
}
}
#endif
} else if(event == LV_EVENT_CANCEL) {
oobeSetPage(0);
@ -296,6 +297,9 @@ static void oobe_calibrate_cb(lv_obj_t * ta, lv_event_t event)
bool oobeSetup()
{
#if HASP_USE_ETHERNET > 0
if (eth_connected) return false;
#endif
#if HASP_USE_WIFI > 0
char ssid[32];
char pass[32];

View File

@ -9,8 +9,8 @@
| | ... | ${property}=${property} | ${data}=${data}
| | ${time} | Get Time | epoch
| | ${client} | Catenate | SEPARATOR=. | robot.mqtt | ${time}
| | ${topic} | Set Variable | hasp/plate37/command
| | ${restopic} | Set Variable | hasp/plate37/state/json
| | ${topic} | Set Variable | hasp/platetelemetry/command
| | ${restopic} | Set Variable | hasp/platetelemetry/state/json
| | ${qos} | Set Variable | 1
| | ${message} | Set Variable | ${property}=${data}
| | ${result} | Set Variable | {"${property}":"${data}"}
@ -31,8 +31,8 @@
| | ... | ${property}=${property} | ${data}=${data}
| | ${time} | Get Time | epoch
| | ${client} | Catenate | SEPARATOR=. | robot.mqtt | ${time}
| | ${topic} | Set Variable | hasp/plate37/command
| | ${restopic} | Set Variable | hasp/plate37/state/page
| | ${topic} | Set Variable | hasp/platetelemetry/command
| | ${restopic} | Set Variable | hasp/platetelemetry/state/page
| | ${qos} | Set Variable | 1
| | ${message} | Set Variable | ${property}=${data}
| | Subscribe Async | client.id=${client} | topic=${restopic}
@ -50,8 +50,8 @@
| | ... | ${property}=${property} | ${data}=${data}
| | ${time} | Get Time | epoch
| | ${client} | Catenate | SEPARATOR=. | robot.mqtt | ${time}
| | ${topic} | Set Variable | hasp/plate37/command/${property}
| | ${restopic} | Set Variable | hasp/plate37/state/page
| | ${topic} | Set Variable | hasp/platetelemetry/command/${property}
| | ${restopic} | Set Variable | hasp/platetelemetry/state/page
| | ${qos} | Set Variable | 1
| | ${message} | Set Variable | ${data}
| | Connect | ${broker.uri} | ${port} | ${client.id} | ${clean_session}