From 1a4864e4e8748fdacbde09cc03154d268897358a Mon Sep 17 00:00:00 2001 From: Eric Duminil <eric.duminil@gmail.com> Date: Tue, 20 Apr 2021 10:35:49 +0200 Subject: [PATCH] ampel.board --- ampel-firmware/ampel-firmware.ino | 2 +- ampel-firmware/util.cpp | 10 +++++++++- ampel-firmware/util.h | 5 +---- ampel-firmware/web_server.cpp | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ampel-firmware/ampel-firmware.ino b/ampel-firmware/ampel-firmware.ino index a640ff2..e8eef2f 100644 --- a/ampel-firmware/ampel-firmware.ino +++ b/ampel-firmware/ampel-firmware.ino @@ -85,7 +85,7 @@ void setup() { Serial.print(F("Sensor ID: ")); Serial.println(ampel.sensorId); Serial.print(F("Board : ")); - Serial.println(BOARD); + Serial.println(ampel.board); #ifdef AMPEL_WIFI WiFiConnect(ampel.sensorId); diff --git a/ampel-firmware/util.cpp b/ampel-firmware/util.cpp index 06c7424..b555b1a 100644 --- a/ampel-firmware/util.cpp +++ b/ampel-firmware/util.cpp @@ -5,6 +5,14 @@ namespace config { const long utc_offset_in_seconds = UTC_OFFSET_IN_SECONDS; // UTC+1 } +#if defined(ESP8266) +const char *current_board = "ESP8266"; +#elif defined(ESP32) +const char *current_board = "ESP32"; +#else +const char *current_board = "UNKNOWN"; +#endif + // Get last 3 bytes of ESP MAC (worldwide unique) String macToID() { uint8_t mac[6]; @@ -58,7 +66,7 @@ void Ampel::showFreeSpace() { } Ampel::Ampel() : - sensorId("ESP" + macToID()), max_loop_duration(0) { + board(current_board), sensorId("ESP" + macToID()), max_loop_duration(0) { sensor_console::defineIntCommand("set_time", ntp::setLocalTime, " 1618829570 (Sets time to the given UNIX time)"); sensor_console::defineCommand("free", Ampel::showFreeSpace, " (Displays available heap space)"); sensor_console::defineCommand("reset", []() { diff --git a/ampel-firmware/util.h b/ampel-firmware/util.h index 1cb3dc5..b99a5d5 100644 --- a/ampel-firmware/util.h +++ b/ampel-firmware/util.h @@ -8,15 +8,11 @@ #include "src/lib/NTPClient-master/NTPClient.h" // NTP #if defined(ESP8266) -# define BOARD "ESP8266" //TODO: Move to ampel.board? # include <ESP8266WiFi.h> // required to get MAC address # define get_free_heap_size() system_get_free_heap_size() #elif defined(ESP32) -# define BOARD "ESP32" # include <WiFi.h> // required to get MAC address # define get_free_heap_size() esp_get_free_heap_size() -#else -# define BOARD "Unknown" #endif namespace ntp { @@ -40,6 +36,7 @@ class Ampel { private: static void showFreeSpace(); public: + const char *board; const String sensorId; uint32_t max_loop_duration; Ampel(); diff --git a/ampel-firmware/web_server.cpp b/ampel-firmware/web_server.cpp index 4788b00..ee20bf4 100644 --- a/ampel-firmware/web_server.cpp +++ b/ampel-firmware/web_server.cpp @@ -239,7 +239,7 @@ namespace web_server { #endif config::temperature_offset, config::auto_calibrate_sensor ? "Yes" : "No", ampel.sensorId.c_str(), ampel.sensorId.c_str(), WiFi.localIP().toString().c_str(), WiFi.localIP().toString().c_str(), - get_free_heap_size(), ampel.max_loop_duration, BOARD, dd, hh, mm, ss); + get_free_heap_size(), ampel.max_loop_duration, ampel.board, dd, hh, mm, ss); Serial.print(F(" - Body size : ")); http.sendContent(content); -- GitLab