Skip to content

Commit d95d388

Browse files
committed
Simplify logging in SafeBoot
1 parent d884b5c commit d95d388

File tree

4 files changed

+29
-44
lines changed

4 files changed

+29
-44
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ if (partition) {
245245

246246
Squezing everything into the SafeBoot partition (655360 bytes only) is a tight fit especially on ethernet enabled boards.
247247

248-
Disabling the logging capabilites saves about 12 kbytes in the final build. Just comment out `MYCILA_LOGGER_SUPPORT` in `platformio.ini`.
248+
Disabling the logging capabilites saves about 12 kbytes in the final build. Just comment out `SAFEBOOT_LOGGING` in `platformio.ini`.
249249

250250
```ini
251-
; -D MYCILA_LOGGER_SUPPORT
251+
; -D SAFEBOOT_LOGGING
252252
```
253253

254254
Disabling mDNS saves about 24 kbytes. Enable both [...]\_NO_DNS options in `platformio.ini` to reduce the build size:
@@ -502,10 +502,10 @@ if (partition) {
502502

503503
Squezing everything into the SafeBoot partition (655360 bytes only) is a tight fit especially on ethernet enabled boards.
504504

505-
Disabling the logging capabilites saves about 12 kbytes in the final build. Just comment out `MYCILA_LOGGER_SUPPORT` in `platformio.ini`.
505+
Disabling the logging capabilites saves about 12 kbytes in the final build. Just comment out `SAFEBOOT_LOGGING` in `platformio.ini`.
506506

507507
```ini
508-
; -D MYCILA_LOGGER_SUPPORT
508+
; -D SAFEBOOT_LOGGING
509509
```
510510

511511
Disabling mDNS saves about 24 kbytes. Enable both [...]\_NO_DNS options in `platformio.ini` to reduce the build size:

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ if (partition) {
245245

246246
Squezing everything into the SafeBoot partition (655360 bytes only) is a tight fit especially on ethernet enabled boards.
247247

248-
Disabling the logging capabilites saves about 12 kbytes in the final build. Just comment out `MYCILA_LOGGER_SUPPORT` in `platformio.ini`.
248+
Disabling the logging capabilites saves about 12 kbytes in the final build. Just comment out `SAFEBOOT_LOGGING` in `platformio.ini`.
249249

250250
```ini
251-
; -D MYCILA_LOGGER_SUPPORT
251+
; -D SAFEBOOT_LOGGING
252252
```
253253

254254
Disabling mDNS saves about 24 kbytes. Enable both [...]\_NO_DNS options in `platformio.ini` to reduce the build size:

platformio.ini

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ lib_deps =
2727
Update
2828
WebServer
2929
mathieucarbou/MycilaESPConnect @ 9.0.1
30-
mathieucarbou/MycilaLogger @ 3.3.0
3130
lib_ignore =
3231
ArduinoJson
3332
AsyncTCP
@@ -46,7 +45,7 @@ build_flags =
4645
; -D MYCILA_SAFEBOOT_NO_MDNS
4746
; ------------------------------
4847
; Logging OFF by default
49-
; -D MYCILA_LOGGER_SUPPORT
48+
; -D SAFEBOOT_LOGGING
5049
; ------------------------------
5150
; C++
5251
-Wall -Wextra
@@ -77,7 +76,7 @@ board = denky_d4
7776
board = esp32-c3-devkitc-02
7877
build_flags =
7978
${env.build_flags}
80-
-D MYCILA_LOGGER_SUPPORT
79+
-D SAFEBOOT_LOGGING
8180

8281
[env:esp32-c6-devkitc-1]
8382
board = esp32-c6-devkitc-1
@@ -115,37 +114,37 @@ build_flags =
115114
board = esp32-s2-saola-1
116115
build_flags =
117116
${env.build_flags}
118-
-D MYCILA_LOGGER_SUPPORT
117+
-D SAFEBOOT_LOGGING
119118

120119
[env:esp32-s3-devkitc-1]
121120
board = esp32-s3-devkitc-1
122121
build_flags =
123122
${env.build_flags}
124-
-D MYCILA_LOGGER_SUPPORT
123+
-D SAFEBOOT_LOGGING
125124

126125
[env:esp32-solo1]
127126
board = esp32-solo1
128127
build_flags =
129128
${env.build_flags}
130-
-D MYCILA_LOGGER_SUPPORT
129+
-D SAFEBOOT_LOGGING
131130

132131
[env:esp32dev]
133132
board = esp32dev
134133
build_flags =
135134
${env.build_flags}
136-
-D MYCILA_LOGGER_SUPPORT
135+
-D SAFEBOOT_LOGGING
137136

138137
[env:esp32s3box]
139138
board = esp32s3box
140139
build_flags =
141140
${env.build_flags}
142-
-D MYCILA_LOGGER_SUPPORT
141+
-D SAFEBOOT_LOGGING
143142

144143
[env:lilygo-t-eth-lite-s3]
145144
board = esp32s3box
146145
build_flags =
147146
${env.build_flags}
148-
-D MYCILA_LOGGER_SUPPORT
147+
-D SAFEBOOT_LOGGING
149148
-D ESPCONNECT_ETH_SUPPORT
150149
-D ETH_PHY_ADDR=1
151150
-D ETH_PHY_CS=9
@@ -160,7 +159,7 @@ build_flags =
160159
board = lolin_s2_mini
161160
build_flags =
162161
${env.build_flags}
163-
-D MYCILA_LOGGER_SUPPORT
162+
-D SAFEBOOT_LOGGING
164163

165164
[env:tinypico]
166165
board = tinypico
@@ -169,7 +168,7 @@ board = tinypico
169168
board = wemos_d1_uno32
170169
build_flags =
171170
${env.build_flags}
172-
-D MYCILA_LOGGER_SUPPORT
171+
-D SAFEBOOT_LOGGING
173172

174173
[env:wipy3]
175174
board = wipy3

src/main.cpp

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,12 @@
1515
#include <ESPmDNS.h>
1616
#endif
1717

18-
#ifdef MYCILA_LOGGER_SUPPORT
19-
#include <MycilaLogger.h>
20-
Mycila::Logger logger;
21-
#define LOGD(tag, format, ...) logger.debug(tag, format, ##__VA_ARGS__)
22-
#define LOGI(tag, format, ...) logger.info(tag, format, ##__VA_ARGS__)
23-
#define LOGW(tag, format, ...) logger.warn(tag, format, ##__VA_ARGS__)
24-
#define LOGE(tag, format, ...) logger.error(tag, format, ##__VA_ARGS__)
18+
#ifdef SAFEBOOT_LOGGING
19+
#define LOG(format, ...) Serial.printf(format, ##__VA_ARGS__)
2520
#else
26-
#define LOGD(tag, format, ...)
27-
#define LOGI(tag, format, ...)
28-
#define LOGW(tag, format, ...)
29-
#define LOGE(tag, format, ...)
21+
#define LOG(format, ...)
3022
#endif
3123

32-
#define TAG "SafeBoot"
33-
3424
extern const char* __COMPILED_APP_VERSION__;
3525

3626
static WebServer webServer(80);
@@ -49,7 +39,7 @@ static String getChipIDStr() {
4939
}
5040

5141
void setup() {
52-
#ifdef MYCILA_LOGGER_SUPPORT
42+
#ifdef SAFEBOOT_LOGGING
5343
Serial.begin(115200);
5444
#if ARDUINO_USB_CDC_ON_BOOT
5545
Serial.setTxTimeoutMs(0);
@@ -58,12 +48,9 @@ void setup() {
5848
while (!Serial)
5949
yield();
6050
#endif
61-
62-
logger.forwardTo(&Serial);
63-
logger.setLevel(ARDUHAL_LOG_LEVEL_DEBUG);
6451
#endif
6552

66-
LOGI(TAG, "SafeBoot Version: %s", __COMPILED_APP_VERSION__);
53+
LOG("SafeBoot Version: %s\n", __COMPILED_APP_VERSION__);
6754

6855
// Set next boot partition
6956
const esp_partition_t* partition = esp_partition_find_first(esp_partition_type_t::ESP_PARTITION_TYPE_APP, esp_partition_subtype_t::ESP_PARTITION_SUBTYPE_APP_OTA_0, nullptr);
@@ -104,7 +91,7 @@ void setup() {
10491

10592
espConnect.listen([](Mycila::ESPConnect::State previous, Mycila::ESPConnect::State state) {
10693
if (state == Mycila::ESPConnect::State::NETWORK_TIMEOUT) {
107-
LOGW(TAG, "Connect timeout! Starting AP mode...");
94+
LOG("Connect timeout! Starting AP mode...\n");
10895
// if ETH DHCP times out, we start AP mode
10996
espConnectConfig.apMode = true;
11097
espConnect.setConfig(espConnectConfig);
@@ -114,18 +101,17 @@ void setup() {
114101
// connect...
115102
espConnect.begin(espConnectConfig.hostname.c_str(), "", espConnectConfig);
116103

117-
LOGI(TAG, "IP Address: %s", espConnect.getIPAddress().toString().c_str());
118-
LOGI(TAG, "Hostname: %s", espConnect.getHostname().c_str());
119-
if (espConnect.getWiFiSSID().length()) {
120-
LOGI(TAG, "SSID: %s", espConnect.getWiFiSSID().c_str());
121-
}
122104
if (espConnectConfig.apMode) {
123-
LOGI(TAG, "Access Point: %s", espConnect.getAccessPointSSID().c_str());
105+
LOG("Access Point: %s\n", espConnect.getAccessPointSSID().c_str());
106+
} else if (espConnect.getWiFiSSID().length()) {
107+
LOG("SSID: %s\n", espConnect.getWiFiSSID().c_str());
124108
}
109+
LOG("IP Address: %s\n", espConnect.getIPAddress().toString().c_str());
110+
LOG("Hostname: %s\n", espConnect.getHostname().c_str());
125111

126112
// start http
127113
webServer.begin();
128-
LOGI(TAG, "Web Server started");
114+
LOG("Web Server started\n");
129115

130116
#ifndef MYCILA_SAFEBOOT_NO_MDNS
131117
// Start mDNS
@@ -138,7 +124,7 @@ void setup() {
138124
ArduinoOTA.setRebootOnSuccess(true);
139125
ArduinoOTA.setMdnsEnabled(true);
140126
ArduinoOTA.begin();
141-
LOGI(TAG, "Arduino OTA Server started on port 3232");
127+
LOG("Arduino OTA Server started on port 3232\n");
142128
}
143129

144130
void loop() {

0 commit comments

Comments
 (0)