Fix mac address query

This commit is contained in:
fvanroie 2020-05-07 00:06:50 +02:00
parent 40df9d5125
commit e974bd7f03
9 changed files with 41 additions and 53 deletions

View File

@ -106,8 +106,8 @@
#include "hasp_wifi.h" #include "hasp_wifi.h"
#endif #endif
#if HASP_USE_ETHERNET>0 #if HASP_USE_ETHERNET > 0
#if USE_BUILTIN_ETHERNET>0 #if USE_BUILTIN_ETHERNET > 0
#include <LwIP.h> #include <LwIP.h>
#include <STM32Ethernet.h> #include <STM32Ethernet.h>
#warning Use built-in STM32 Ethernet #warning Use built-in STM32 Ethernet
@ -117,7 +117,6 @@
#warning Use ENC28J60 Ethernet shield #warning Use ENC28J60 Ethernet shield
#else #else
#include "Ethernet.h" #include "Ethernet.h"
#include "EthernetClient.h"
#warning Use W5x00 Ethernet shield #warning Use W5x00 Ethernet shield
#endif #endif
#include "hasp_ethernet.h" #include "hasp_ethernet.h"

View File

@ -311,6 +311,7 @@ void configWriteConfig()
} else { } else {
Log.notice(F("CONF: Configuration did not change")); Log.notice(F("CONF: Configuration did not change"));
} }
configOutput(settings);
} }
void configSetup() void configSetup()

View File

@ -2,17 +2,28 @@
#include "ArduinoJson.h" #include "ArduinoJson.h"
#include "ArduinoLog.h" #include "ArduinoLog.h"
#include "hasp_conf.h" #include "hasp_conf.h"
#include "hasp_hal.h"
#if HASP_USE_ETHERNET > 0 #if HASP_USE_ETHERNET > 0
EthernetClient EthClient; EthernetClient EthClient;
IPAddress ip; IPAddress ip;
void ethernetSetup() 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]; byte mac[6];
uint32_t baseUID = (uint32_t)UID_BASE; uint32_t baseUID = (uint32_t)UID_BASE;
mac[0] = 0x00; mac[0] = 0x00;
@ -32,21 +43,6 @@ void ethernetSetup()
ip = Ethernet.localIP(); 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: 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 #endif
} }

View File

@ -246,9 +246,13 @@ String halGetMacAddress(int start, const char * seperator)
byte mac[6]; byte mac[6];
#if defined(STM32F4xx) #if defined(STM32F4xx)
uint8_t * mac_p; uint8_t * mac_p = nullptr;
//mac_p = Ethernet.MACAddress(); #if USE_BUILTIN_ETHERNET > 0
mac_p = Ethernet.MACAddress();
for(uint8_t i = 0; i < 6; i++) mac[i] = *(mac_p + i); for(uint8_t i = 0; i < 6; i++) mac[i] = *(mac_p + i);
#else
Ethernet.macAddress(mac);
#endif
#else #else
WiFi.macAddress(mac); WiFi.macAddress(mac);
#endif #endif

View File

@ -137,8 +137,8 @@ bool httpIsAuthenticated(const __FlashStringHelper * page)
Log.verbose(F("HTTP: Sending %s page to client connected from: %s"), page, Log.verbose(F("HTTP: Sending %s page to client connected from: %s"), page,
webServer.client().remoteIP().toString().c_str()); webServer.client().remoteIP().toString().c_str());
#else #else
Log.verbose(F("HTTP: Sending %s page to client connected from: %s"), page, // Log.verbose(F("HTTP: Sending %s page to client connected from: %s"), page,
String(webServer.client().remoteIP()).c_str()); // String(webServer.client().remoteIP()).c_str());
#endif #endif
return true; return true;
@ -503,18 +503,9 @@ void webHandleInfo()
{ {
char mqttClientId[64]; char mqttClientId[64];
#if HASP_USE_WIFI > 0 String mac = halGetMacAddress(3, "");
byte mac[6]; mac.toLowerCase();
WiFi.macAddress(mac); snprintf_P(mqttNodeName, sizeof(mqttNodeName), PSTR("plate_%s"), mac.c_str());
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
httpMessage += mqttClientId; httpMessage += mqttClientId;
} }
@ -1375,7 +1366,7 @@ void httpHandleNotFound()
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #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()); Log.notice(F("HTTP: Sending 404 to client connected from: %s"), webServer.client().remoteIP().toString().c_str());
#else #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 #endif
String httpMessage((char *)0); String httpMessage((char *)0);

View File

@ -352,18 +352,11 @@ void mqttReconnect()
bool mqttFirstConnect = true; bool mqttFirstConnect = true;
{ {
#if HASP_USE_WIFI>0 String mac = halGetMacAddress(3, "");
byte mac[6]; mac.toLowerCase();
WiFi.macAddress(mac); snprintf_P(mqttNodeName, sizeof(mqttNodeName), PSTR("plate_%s"), mac.c_str());
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
}
Log.verbose(mqttClientId); Log.verbose(mqttClientId);
}
// Attempt to connect and set LWT and Clean Session // Attempt to connect and set LWT and Clean Session
snprintf_P(buffer, sizeof(buffer), PSTR("%sstatus"), mqttNodeTopic); snprintf_P(buffer, sizeof(buffer), PSTR("%sstatus"), mqttNodeTopic);

View File

@ -13,6 +13,4 @@ bool wifiTestConnection();
bool wifiGetConfig(const JsonObject & settings); bool wifiGetConfig(const JsonObject & settings);
bool wifiSetConfig(const JsonObject & settings); bool wifiSetConfig(const JsonObject & settings);
String wifiGetMacAddress(int start, const char * seperator);
#endif #endif

View File

@ -162,8 +162,13 @@ void loop()
#endif #endif
#if HASP_USE_ETHERNET > 0 #if HASP_USE_ETHERNET > 0
#if USE_BUILTIN_ETHERNET > 0
isConnected = Ethernet.linkStatus() == LinkON; isConnected = Ethernet.linkStatus() == LinkON;
Serial.print(Ethernet.linkStatus()); Serial.print(Ethernet.linkStatus());
#else
isConnected = Ethernet.link() == 1;
Serial.print(Ethernet.link());
#endif
#endif #endif
#if HASP_USE_HTTP > 0 #if HASP_USE_HTTP > 0

View File

@ -31,6 +31,7 @@ build_flags =
;-D HAL_ETH_MODULE_ENABLED=1 ; enable ethernet support ;-D HAL_ETH_MODULE_ENABLED=1 ; enable ethernet support
;-D LAN8742A_PHY_ADDRESS=0x01U ; set LAN8720 PHY address ;-D LAN8742A_PHY_ADDRESS=0x01U ; set LAN8720 PHY address
-D HASP_USE_TASMOTA_SLAVE=1 -D HASP_USE_TASMOTA_SLAVE=1
-D HASP_USE_ETHERNET=1
-D W5500_MOSI=PB15 ;SPI2 MOSI -D W5500_MOSI=PB15 ;SPI2 MOSI
-D W5500_MISO=PB14 ;SPI2 MISO -D W5500_MISO=PB14 ;SPI2 MISO
-D W5500_SCLK=PB13 ;SPI2 SCLK -D W5500_SCLK=PB13 ;SPI2 SCLK
@ -40,11 +41,11 @@ build_flags =
lib_deps = lib_deps =
${env.lib_deps} ${env.lib_deps}
Ticker@^3.1.5 Ticker@^3.1.5
Ethernet ;Ethernet
; STM32duino LwIP@^2.1.2 ; STM32duino LwIP@^2.1.2
; STM32duino STM32Ethernet@^1.0.5 ; STM32duino STM32Ethernet@^1.0.5
https://github.com/stm32duino/LwIP.git 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 https://github.com/khoih-prog/EthernetWebServer_STM32
src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<lv_lib_zifont/> +<stm32f4/> src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<lv_lib_zifont/> +<stm32f4/>