diff --git a/include/hasp_conf.h b/include/hasp_conf.h index 075102aa..28260cbd 100644 --- a/include/hasp_conf.h +++ b/include/hasp_conf.h @@ -106,8 +106,8 @@ #include "hasp_wifi.h" #endif -#if HASP_USE_ETHERNET>0 -#if USE_BUILTIN_ETHERNET>0 +#if HASP_USE_ETHERNET > 0 +#if USE_BUILTIN_ETHERNET > 0 #include #include #warning Use built-in STM32 Ethernet @@ -117,7 +117,6 @@ #warning Use ENC28J60 Ethernet shield #else #include "Ethernet.h" -#include "EthernetClient.h" #warning Use W5x00 Ethernet shield #endif #include "hasp_ethernet.h" diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp index ba6b14cb..70fc0d50 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -311,6 +311,7 @@ void configWriteConfig() } else { Log.notice(F("CONF: Configuration did not change")); } + configOutput(settings); } void configSetup() diff --git a/src/hasp_ethernet.cpp b/src/hasp_ethernet.cpp index 2d2c93ec..f6c1d694 100644 --- a/src/hasp_ethernet.cpp +++ b/src/hasp_ethernet.cpp @@ -2,17 +2,28 @@ #include "ArduinoJson.h" #include "ArduinoLog.h" #include "hasp_conf.h" +#include "hasp_hal.h" #if HASP_USE_ETHERNET > 0 - - EthernetClient EthClient; IPAddress ip; void ethernetSetup() { -#ifdef W5500_LAN +#if USE_BUILTIN_ETHERNET > 0 + // start Ethernet and UDP + Log.notice(F("ETH: Begin Ethernet LAN8720")); + if(Ethernet.begin() == 0) { + Log.notice(F("ETH: Failed to configure Ethernet using DHCP")); + } else { + ip = Ethernet.localIP(); + Log.notice(F("ETH: DHCP Success got IP=%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); + } + + Log.notice(F("ETH: MAC Address %s"), halGetMacAddress(0, ":")); + +#else byte mac[6]; uint32_t baseUID = (uint32_t)UID_BASE; mac[0] = 0x00; @@ -32,21 +43,6 @@ void ethernetSetup() ip = Ethernet.localIP(); Log.notice(F("ETH: DHCP Success got IP=%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); } - -#else - // start Ethernet and UDP - Log.notice(F("ETH: Begin Ethernet LAN8720")); - if(Ethernet.begin() == 0) { - Log.notice(F("ETH: Failed to configure Ethernet using DHCP")); - } else { - ip = Ethernet.localIP(); - Log.notice(F("ETH: DHCP Success got IP=%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]); - } - - uint8_t * mac; - mac = Ethernet.MACAddress(); - Log.notice(F("ETH: MAC Address %x:%x:%x:%x:%x:%x"), *mac, *(mac + 1), *(mac + 2), *(mac + 3), *(mac + 4), - *(mac + 5)); #endif } diff --git a/src/hasp_hal.cpp b/src/hasp_hal.cpp index b8b6a0e3..0348fec9 100644 --- a/src/hasp_hal.cpp +++ b/src/hasp_hal.cpp @@ -246,9 +246,13 @@ String halGetMacAddress(int start, const char * seperator) byte mac[6]; #if defined(STM32F4xx) - uint8_t * mac_p; - //mac_p = Ethernet.MACAddress(); + uint8_t * mac_p = nullptr; +#if USE_BUILTIN_ETHERNET > 0 + mac_p = Ethernet.MACAddress(); for(uint8_t i = 0; i < 6; i++) mac[i] = *(mac_p + i); +#else + Ethernet.macAddress(mac); +#endif #else WiFi.macAddress(mac); #endif diff --git a/src/hasp_http.cpp b/src/hasp_http.cpp index 2d6b2dbd..69a0dd42 100644 --- a/src/hasp_http.cpp +++ b/src/hasp_http.cpp @@ -137,8 +137,8 @@ bool httpIsAuthenticated(const __FlashStringHelper * page) Log.verbose(F("HTTP: Sending %s page to client connected from: %s"), page, webServer.client().remoteIP().toString().c_str()); #else - Log.verbose(F("HTTP: Sending %s page to client connected from: %s"), page, - String(webServer.client().remoteIP()).c_str()); + // Log.verbose(F("HTTP: Sending %s page to client connected from: %s"), page, + // String(webServer.client().remoteIP()).c_str()); #endif return true; @@ -503,18 +503,9 @@ void webHandleInfo() { char mqttClientId[64]; -#if HASP_USE_WIFI > 0 - byte mac[6]; - WiFi.macAddress(mac); - snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%02x%02x%02x"), mqttNodeName, mac[3], mac[4], - mac[5]); -#endif -#if HASP_USE_ETHERNET > 0 - uint8_t * mac; - mac = Ethernet.MACAddress(); - snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%02x%02x%02x"), mqttNodeName, *(mac + 3), - *(mac + 4), *(mac + 5)); -#endif + String mac = halGetMacAddress(3, ""); + mac.toLowerCase(); + snprintf_P(mqttNodeName, sizeof(mqttNodeName), PSTR("plate_%s"), mac.c_str()); httpMessage += mqttClientId; } @@ -1375,7 +1366,7 @@ void httpHandleNotFound() #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) Log.notice(F("HTTP: Sending 404 to client connected from: %s"), webServer.client().remoteIP().toString().c_str()); #else - Log.notice(F("HTTP: Sending 404 to client connected from: %s"), String(webServer.client().remoteIP()).c_str()); + // Log.notice(F("HTTP: Sending 404 to client connected from: %s"), String(webServer.client().remoteIP()).c_str()); #endif String httpMessage((char *)0); diff --git a/src/hasp_mqtt.cpp b/src/hasp_mqtt.cpp index dcb0e6f6..3b9e6b87 100644 --- a/src/hasp_mqtt.cpp +++ b/src/hasp_mqtt.cpp @@ -352,18 +352,11 @@ void mqttReconnect() bool mqttFirstConnect = true; { -#if HASP_USE_WIFI>0 - byte mac[6]; - WiFi.macAddress(mac); - snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%02x%02x%02x"), mqttNodeName, mac[3], mac[4], mac[5]); -#endif -#if HASP_USE_ETHERNET>0 - uint8_t * mac; - mac = Ethernet.MACAddress(); - snprintf_P(mqttClientId, sizeof(mqttClientId), PSTR("%s-%02x%02x%02x"), mqttNodeName, *(mac+3), *(mac+4), *(mac+5)); -#endif - } + String mac = halGetMacAddress(3, ""); + mac.toLowerCase(); + snprintf_P(mqttNodeName, sizeof(mqttNodeName), PSTR("plate_%s"), mac.c_str()); Log.verbose(mqttClientId); + } // Attempt to connect and set LWT and Clean Session snprintf_P(buffer, sizeof(buffer), PSTR("%sstatus"), mqttNodeTopic); diff --git a/src/hasp_wifi.h b/src/hasp_wifi.h index 3ee27d27..ea7b397c 100644 --- a/src/hasp_wifi.h +++ b/src/hasp_wifi.h @@ -13,6 +13,4 @@ bool wifiTestConnection(); bool wifiGetConfig(const JsonObject & settings); bool wifiSetConfig(const JsonObject & settings); -String wifiGetMacAddress(int start, const char * seperator); - #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 18cd738d..6dbea96c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -162,8 +162,13 @@ void loop() #endif #if HASP_USE_ETHERNET > 0 +#if USE_BUILTIN_ETHERNET > 0 isConnected = Ethernet.linkStatus() == LinkON; Serial.print(Ethernet.linkStatus()); +#else + isConnected = Ethernet.link() == 1; + Serial.print(Ethernet.link()); +#endif #endif #if HASP_USE_HTTP > 0 diff --git a/user_setups/stm32f4xx/stm32f407-black_ili9341.ini b/user_setups/stm32f4xx/stm32f407-black_ili9341.ini index ccb986a9..8f96fa44 100644 --- a/user_setups/stm32f4xx/stm32f407-black_ili9341.ini +++ b/user_setups/stm32f4xx/stm32f407-black_ili9341.ini @@ -31,6 +31,7 @@ build_flags = ;-D HAL_ETH_MODULE_ENABLED=1 ; enable ethernet support ;-D LAN8742A_PHY_ADDRESS=0x01U ; set LAN8720 PHY address -D HASP_USE_TASMOTA_SLAVE=1 + -D HASP_USE_ETHERNET=1 -D W5500_MOSI=PB15 ;SPI2 MOSI -D W5500_MISO=PB14 ;SPI2 MISO -D W5500_SCLK=PB13 ;SPI2 SCLK @@ -40,11 +41,11 @@ build_flags = lib_deps = ${env.lib_deps} Ticker@^3.1.5 - Ethernet + ;Ethernet ; STM32duino LwIP@^2.1.2 ; STM32duino STM32Ethernet@^1.0.5 https://github.com/stm32duino/LwIP.git - ;https://github.com/netwizeBE/Ethernet3.git + https://github.com/netwizeBE/Ethernet3.git https://github.com/khoih-prog/EthernetWebServer_STM32 src_filter = +<*> -<.git/> -<.svn/> - - - - - +