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"
#endif
#if HASP_USE_ETHERNET>0
#if USE_BUILTIN_ETHERNET>0
#if HASP_USE_ETHERNET > 0
#if USE_BUILTIN_ETHERNET > 0
#include <LwIP.h>
#include <STM32Ethernet.h>
#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"

View File

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

View File

@ -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
}

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

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

View File

@ -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

View File

@ -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/> -<example/> -<examples/> -<test/> -<tests/> -<lv_lib_zifont/> +<stm32f4/>