Commit 67505912 authored by Eric Duminil's avatar Eric Duminil
Browse files

Display MAC address at startup and in html

parent 95eb0555
...@@ -70,6 +70,8 @@ void setup() { ...@@ -70,6 +70,8 @@ void setup() {
Serial.println(); Serial.println();
Serial.print(F("Sensor ID: ")); Serial.print(F("Sensor ID: "));
Serial.println(ampel.sensorId); Serial.println(ampel.sensorId);
Serial.print(F("MAC : "));
Serial.println(ampel.macAddress);
Serial.print(F("Board : ")); Serial.print(F("Board : "));
Serial.println(ampel.board); Serial.println(ampel.board);
Serial.print(F("Firmware : ")); Serial.print(F("Firmware : "));
......
...@@ -70,9 +70,18 @@ void Ampel::showFreeSpace() { ...@@ -70,9 +70,18 @@ void Ampel::showFreeSpace() {
} }
char sensorId[10]; // e.g "ESPxxxxxx\0" char sensorId[10]; // e.g "ESPxxxxxx\0"
char macAddress[18]; // e.g "XX:XX:XX:XX:XX:XX\0"
uint8_t mac[6];
char* getMacString() {
WiFi.macAddress(mac);
// Get all 6 bytes of ESP MAC
snprintf(macAddress, sizeof(macAddress), "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4],
mac[5]);
return macAddress;
}
char* getSensorId() { char* getSensorId() {
uint8_t mac[6];
WiFi.macAddress(mac); WiFi.macAddress(mac);
// Get last 3 bytes of ESP MAC (worldwide unique) // Get last 3 bytes of ESP MAC (worldwide unique)
snprintf(sensorId, sizeof(sensorId), "ESP%02x%02x%02x", mac[3], mac[4], mac[5]); snprintf(sensorId, sizeof(sensorId), "ESP%02x%02x%02x", mac[3], mac[4], mac[5]);
...@@ -80,7 +89,7 @@ char* getSensorId() { ...@@ -80,7 +89,7 @@ char* getSensorId() {
} }
Ampel::Ampel() : Ampel::Ampel() :
board(current_board), sensorId(getSensorId()), max_loop_duration(0) { board(current_board), sensorId(getSensorId()), macAddress(getMacString()), max_loop_duration(0) {
sensor_console::defineIntCommand("set_time", ntp::setLocalTime, F("1618829570 (Sets time to the given UNIX time)")); sensor_console::defineIntCommand("set_time", ntp::setLocalTime, F("1618829570 (Sets time to the given UNIX time)"));
sensor_console::defineCommand("free", Ampel::showFreeSpace, F("(Displays available heap space)")); sensor_console::defineCommand("free", Ampel::showFreeSpace, F("(Displays available heap space)"));
sensor_console::defineCommand("reset", []() { sensor_console::defineCommand("reset", []() {
......
...@@ -38,9 +38,10 @@ class Ampel { ...@@ -38,9 +38,10 @@ class Ampel {
private: private:
static void showFreeSpace(); static void showFreeSpace();
public: public:
const char *version = "v0.2.2-DEV"; // Update manually after significant changes. const char *version = "v0.2.3-DEV"; // Update manually after significant changes.
const char *board; const char *board;
const char *sensorId; const char *sensorId;
const char *macAddress;
uint32_t max_loop_duration; uint32_t max_loop_duration;
Ampel(); Ampel();
}; };
......
...@@ -111,6 +111,7 @@ namespace web_server { ...@@ -111,6 +111,7 @@ namespace web_server {
"<tr><td>Auto-calibration?</td><td>%s</td></tr>\n" "<tr><td>Auto-calibration?</td><td>%s</td></tr>\n"
"<tr><td>Local address</td><td><a href='http://%s.local/'>%s.local</a></td></tr>\n" "<tr><td>Local address</td><td><a href='http://%s.local/'>%s.local</a></td></tr>\n"
"<tr><td>Local IP</td><td><a href='http://%s'>%s</a></td></tr>\n" "<tr><td>Local IP</td><td><a href='http://%s'>%s</a></td></tr>\n"
"<tr><td>MAC</td><td>%s</td></tr>\n"
"<tr><td>Free heap space</td><td>%6d bytes</td></tr>\n" "<tr><td>Free heap space</td><td>%6d bytes</td></tr>\n"
"<tr><td>Largest heap block</td><td>%6d bytes</td></tr>\n" "<tr><td>Largest heap block</td><td>%6d bytes</td></tr>\n"
"<tr><td>Max loop duration</td><td>%5d ms</td></tr>\n" "<tr><td>Max loop duration</td><td>%5d ms</td></tr>\n"
...@@ -239,8 +240,8 @@ namespace web_server { ...@@ -239,8 +240,8 @@ namespace web_server {
config::lorawan_sending_interval, config::lorawan_sending_interval,
#endif #endif
config::temperature_offset, config::auto_calibrate_sensor ? "Yes" : "No", ampel.sensorId, ampel.sensorId, config::temperature_offset, config::auto_calibrate_sensor ? "Yes" : "No", ampel.sensorId, ampel.sensorId,
wifi::local_ip, wifi::local_ip, ESP.getFreeHeap(), esp_get_max_free_block_size(), ampel.max_loop_duration, wifi::local_ip, wifi::local_ip, ampel.macAddress, ESP.getFreeHeap(), esp_get_max_free_block_size(),
ampel.board, ampel.version, dd, hh, mm, ss); ampel.max_loop_duration, ampel.board, ampel.version, dd, hh, mm, ss);
// Serial.print(F(" - Body size : ")); // Serial.print(F(" - Body size : "));
// Serial.print(strlen(content)); // Serial.print(strlen(content));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment