From ba8f5b1fa0b1165e484ab7fdb878a4fd52e0e2a1 Mon Sep 17 00:00:00 2001 From: arovak Date: Tue, 3 Nov 2020 22:52:41 +0100 Subject: [PATCH 1/2] Inital ESP32 Ethernet support --- include/hasp_conf.h | 16 ++++++++++ src/hasp_ethernet.cpp | 2 +- src/hasp_ethernet_esp32.cpp | 64 +++++++++++++++++++++++++++++++++++++ src/hasp_ethernet_esp32.h | 13 ++++++++ src/hasp_http.cpp | 4 +++ src/hasp_oobe.cpp | 6 +++- test/hasp-lvgl.robot | 12 +++---- 7 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 src/hasp_ethernet_esp32.cpp create mode 100644 src/hasp_ethernet_esp32.h diff --git a/include/hasp_conf.h b/include/hasp_conf.h index 134dd1ca..91375a11 100644 --- a/include/hasp_conf.h +++ b/include/hasp_conf.h @@ -107,6 +107,21 @@ #endif #if HASP_USE_ETHERNET > 0 +#if defined(ARDUINO_ARCH_ESP32) +#include + +#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 #include @@ -121,6 +136,7 @@ #endif #include "hasp_ethernet.h" #endif +#endif #if HASP_USE_MQTT > 0 #include "hasp_mqtt.h" diff --git a/src/hasp_ethernet.cpp b/src/hasp_ethernet.cpp index d6f82bff..073de7b1 100644 --- a/src/hasp_ethernet.cpp +++ b/src/hasp_ethernet.cpp @@ -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; diff --git a/src/hasp_ethernet_esp32.cpp b/src/hasp_ethernet_esp32.cpp new file mode 100644 index 00000000..ede1a636 --- /dev/null +++ b/src/hasp_ethernet_esp32.cpp @@ -0,0 +1,64 @@ +#include +#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 \ No newline at end of file diff --git a/src/hasp_ethernet_esp32.h b/src/hasp_ethernet_esp32.h new file mode 100644 index 00000000..ed45e9ea --- /dev/null +++ b/src/hasp_ethernet_esp32.h @@ -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 \ No newline at end of file diff --git a/src/hasp_http.cpp b/src/hasp_http.cpp index 0a218e91..42cb0616 100644 --- a/src/hasp_http.cpp +++ b/src/hasp_http.cpp @@ -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 } diff --git a/src/hasp_oobe.cpp b/src/hasp_oobe.cpp index 6c633ffe..842dff03 100644 --- a/src/hasp_oobe.cpp +++ b/src/hasp_oobe.cpp @@ -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()); 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]; diff --git a/test/hasp-lvgl.robot b/test/hasp-lvgl.robot index 9b3f708f..086766b5 100644 --- a/test/hasp-lvgl.robot +++ b/test/hasp-lvgl.robot @@ -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} From e5ee2328a8c8d6c096982bf056df421fb92ee086 Mon Sep 17 00:00:00 2001 From: arovak Date: Tue, 3 Nov 2020 22:53:23 +0100 Subject: [PATCH 2/2] TTGO ESP32 POE user config --- user_setups/esp32/TTGO-esp32-POE_ili9341.ini | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 user_setups/esp32/TTGO-esp32-POE_ili9341.ini diff --git a/user_setups/esp32/TTGO-esp32-POE_ili9341.ini b/user_setups/esp32/TTGO-esp32-POE_ili9341.ini new file mode 100644 index 00000000..47724a49 --- /dev/null +++ b/user_setups/esp32/TTGO-esp32-POE_ili9341.ini @@ -0,0 +1,35 @@ +;***************************************************; +; Lilygo®Ttgo ESP32 with Lolin TFT 2.4" ; +; - T-Internet-Poe ESP32-WROOM ; +; - LAN8720A with POE ; +; - ili9341 TFT ; +; - xpt2606 touch controller ; +;***************************************************; + +[env:ttgo_esp32-lolintft24] +platform = espressif32@^1.12.0 +board = esp32dev +upload_protocol = espota ; Use ArduinoOTA after flashing over serial +upload_port = 10.4.70.37 ; 10.4.0.198 ; IP of the ESP +upload_flags = + --port=3232 + +;upload_port = COM9 ; To change the port, use platform_override.ini +monitor_port = COM9 ; To change the port, use platform_override.ini +board_build.partitions = esp32_partition_app1300k_spiffs1216k.csv ; default.csv +build_flags = + ${flags.esp32_flags} +; -- TFT_eSPI build options ------------------------ + ${lcd.lolin24} + -D TFT_MISO=2 + -D TFT_MOSI=15 + -D TFT_SCLK=14 + -D TFT_DC=4 + -D TFT_CS=33 + -D TFT_RST=12 ; RST + -D TFT_BCKL=16 ; None, configurable via web UI (e.g. 21) + -D TOUCH_CS=32 ; (can also be 22 or 16) +; -- Options ---------------------------------------- + -D HASP_USE_TELNET=1 + -D HASP_USE_ETHERNET=1 + -D HASP_USE_WIFI=0