added SD card system logging

This commit is contained in:
cyberman54 2022-11-27 21:50:38 +01:00
parent b6f4399138
commit b8c87f0acf
33 changed files with 17 additions and 83 deletions

View File

@ -21,8 +21,6 @@
#include "BintrayClient.h" #include "BintrayClient.h"
// Local logging tag
static const char TAG[] = __FILE__;
BintrayClient::BintrayClient(const String &user, const String &repository, const String &package) BintrayClient::BintrayClient(const String &user, const String &repository, const String &package)
: m_user(user), m_repo(repository), m_package(package), : m_user(user), m_repo(repository), m_package(package),

View File

@ -100,6 +100,8 @@ build_flags_basic =
'-D LIBPAX_WIFI' '-D LIBPAX_WIFI'
'-D LIBPAX_BLE' '-D LIBPAX_BLE'
'-D LIBPAX_ARDUINO' '-D LIBPAX_ARDUINO'
'-DUSE_ESP_IDF_LOG'
'-DTAG=__FILE__'
build_flags_all = build_flags_all =
${common.build_flags_basic} ${common.build_flags_basic}
-mfix-esp32-psram-cache-issue -mfix-esp32-psram-cache-issue

View File

@ -1,6 +1,6 @@
[board] [board]
halfile = ttgotdongles3.h ;halfile = ttgotdongles3.h
;halfile = ttgotdongledisplays3.h halfile = ttgotdongledisplays3.h
;halfile = ttgotdisplays3.h ;halfile = ttgotdisplays3.h
[platformio] [platformio]
@ -22,7 +22,7 @@ platform_espressif32 = espressif32@5.2.0
monitor_speed = 115200 monitor_speed = 115200
upload_speed = 115200 ; set by build.py and taken from hal file upload_speed = 115200 ; set by build.py and taken from hal file
lib_deps_all = lib_deps_all =
bitbank2/BitBang_I2C@^2.2.1 bitbank2/BitBang_I2C@ ^2.2.1
bitbank2/bb_spi_lcd @ ^2.4.0 bitbank2/bb_spi_lcd @ ^2.4.0
fastled/FastLED @ ^3.5.0 fastled/FastLED @ ^3.5.0
;greyrook/libpax @ ^1.0.1 ;greyrook/libpax @ ^1.0.1
@ -40,6 +40,8 @@ build_flags_basic =
'-D LIBPAX_WIFI' '-D LIBPAX_WIFI'
'-D LIBPAX_BLE' '-D LIBPAX_BLE'
'-D LIBPAX_ARDUINO' '-D LIBPAX_ARDUINO'
'-DUSE_ESP_IDF_LOG'
'-DTAG=__FILE__'
build_flags_all = build_flags_all =
${common.build_flags_basic} ${common.build_flags_basic}
-mfix-esp32-psram-cache-issue -mfix-esp32-psram-cache-issue

View File

@ -4,8 +4,6 @@
#include <Arduino.h> #include <Arduino.h>
// Local logging tag
static const char TAG[] = __FILE__;
typedef enum { ANTENNA_INT = 0, ANTENNA_EXT } antenna_type_t; typedef enum { ANTENNA_INT = 0, ANTENNA_EXT } antenna_type_t;

View File

@ -2,8 +2,6 @@
#include "bmesensor.h" #include "bmesensor.h"
// Local logging tag
static const char TAG[] = __FILE__;
bmeStatus_t bme_status = {0, 0, 0, 0, 0, 0, 0, 0}; bmeStatus_t bme_status = {0, 0, 0, 0, 0, 0, 0, 0};

View File

@ -1,8 +1,6 @@
#include "boot.h" #include "boot.h"
#include "reset.h" #include "reset.h"
// Local logging tag
static const char TAG[] = __FILE__;
static hw_timer_t *wdTimer = NULL; static hw_timer_t *wdTimer = NULL;
static WebServer server(80); static WebServer server(80);

View File

@ -3,8 +3,6 @@
#include "globals.h" #include "globals.h"
#include "button.h" #include "button.h"
// Local logging tag
static const char TAG[] = __FILE__;
OneButton button(HAS_BUTTON, !BUTTON_ACTIVEHIGH, !!BUTTON_PULLUP); OneButton button(HAS_BUTTON, !BUTTON_ACTIVEHIGH, !!BUTTON_PULLUP);
TaskHandle_t buttonLoopTask; TaskHandle_t buttonLoopTask;

View File

@ -3,8 +3,6 @@
#include "globals.h" #include "globals.h"
#include "configmanager.h" #include "configmanager.h"
// Local logging tag
static const char TAG[] = __FILE__;
// namespace for device runtime preferences // namespace for device runtime preferences
#define DEVCONFIG "paxcntcfg" #define DEVCONFIG "paxcntcfg"

View File

@ -4,8 +4,6 @@
// Basic config // Basic config
#include "cyclic.h" #include "cyclic.h"
// Local logging tag
static const char TAG[] = __FILE__;
Ticker cyclicTimer; Ticker cyclicTimer;

View File

@ -13,8 +13,6 @@ https://github.com/udoklein/dcf77
#include "dcf77.h" #include "dcf77.h"
// Local logging tag
static const char TAG[] = __FILE__;
// triggered by second timepulse to ticker out DCF signal // triggered by second timepulse to ticker out DCF signal
void DCF77_Pulse(uint8_t bit) { void DCF77_Pulse(uint8_t bit) {

View File

@ -37,8 +37,6 @@ MY_FONT_LARGE: 16x32px = 8 chars / line @ 2 lines
#include "globals.h" #include "globals.h"
#include "display.h" #include "display.h"
// local Tag for logging
static const char TAG[] = __FILE__;
static uint8_t plotbuf[PLOTBUFFERSIZE] = {0}; static uint8_t plotbuf[PLOTBUFFERSIZE] = {0};
uint8_t DisplayIsOn = 0; uint8_t DisplayIsOn = 0;

View File

@ -3,8 +3,6 @@
#include "globals.h" #include "globals.h"
#include "gpsread.h" #include "gpsread.h"
// Local logging tag
static const char TAG[] = __FILE__;
TinyGPSPlus gps; TinyGPSPlus gps;
TaskHandle_t GpsTask; TaskHandle_t GpsTask;

View File

@ -2,8 +2,6 @@
#include "globals.h" #include "globals.h"
#include "i2c.h" #include "i2c.h"
// Local logging tag
static const char TAG[] = __FILE__;
SemaphoreHandle_t I2Caccess; SemaphoreHandle_t I2Caccess;

View File

@ -81,8 +81,6 @@ not evaluated by model BU-190, use "F" instead for this model
#include "if482.h" #include "if482.h"
// Local logging tag
static const char TAG[] = __FILE__;
String IF482_Frame(time_t t) { String IF482_Frame(time_t t) {
char mon, out[IF482_FRAME_SIZE + 1], buf[IF482_FRAME_SIZE - 3]; char mon, out[IF482_FRAME_SIZE + 1], buf[IF482_FRAME_SIZE - 3];

View File

@ -1,7 +1,5 @@
#include "irqhandler.h" #include "irqhandler.h"
// Local logging tag
static const char TAG[] = __FILE__;
TaskHandle_t irqHandlerTask = NULL; TaskHandle_t irqHandlerTask = NULL;

View File

@ -6,8 +6,6 @@
#define MATRIX_DISPLAY_PAGES (2) // number of display pages #define MATRIX_DISPLAY_PAGES (2) // number of display pages
#define LINE_DIAGRAM_DIVIDER (2) // scales pax numbers to led rows #define LINE_DIAGRAM_DIVIDER (2) // scales pax numbers to led rows
// local Tag for logging
static const char TAG[] = __FILE__;
uint8_t MatrixDisplayIsOn = 0; uint8_t MatrixDisplayIsOn = 0;
static uint8_t displaybuf[LED_MATRIX_WIDTH * LED_MATRIX_HEIGHT / 8] = {0}; static uint8_t displaybuf[LED_MATRIX_WIDTH * LED_MATRIX_HEIGHT / 8] = {0};

View File

@ -1,7 +1,5 @@
#include "libpax_helpers.h" #include "libpax_helpers.h"
// Local logging tag
static const char TAG[] = __FILE__;
// libpax payload // libpax payload
struct count_payload_t count_from_libpax; struct count_payload_t count_from_libpax;

View File

@ -3,8 +3,6 @@
#if (HAS_LORA) #if (HAS_LORA)
#include "lorawan.h" #include "lorawan.h"
// Local logging Tag
static const char TAG[] = __FILE__;
#if CLOCK_ERROR_PROCENTAGE > 7 #if CLOCK_ERROR_PROCENTAGE > 7
#warning CLOCK_ERROR_PROCENTAGE value in lmic_config.h is too high; values > 7 will cause side effects #warning CLOCK_ERROR_PROCENTAGE value in lmic_config.h is too high; values > 7 will cause side effects

View File

@ -79,8 +79,6 @@ BME_IRQ <- setBMEIRQ() <- Ticker.h
// Basic Config // Basic Config
#include "main.h" #include "main.h"
// local Tag for logging
static const char TAG[] = __FILE__;
char clientId[20] = {0}; // unique ClientID char clientId[20] = {0}; // unique ClientID

View File

@ -2,8 +2,6 @@
#include "mqttclient.h" #include "mqttclient.h"
static const char TAG[] = __FILE__;
static QueueHandle_t MQTTSendQueue; static QueueHandle_t MQTTSendQueue;
TaskHandle_t mqttTask; TaskHandle_t mqttTask;

View File

@ -32,8 +32,6 @@ const int port = 443;
int volatile contentLength = 0; int volatile contentLength = 0;
bool volatile isValidContentType = false; bool volatile isValidContentType = false;
// Local logging tag
static const char TAG[] = __FILE__;
// helper function to extract header value from header // helper function to extract header value from header
inline String getHeaderValue(String header, String headerName) { inline String getHeaderValue(String header, String headerName) {

View File

@ -13,6 +13,7 @@
#define BOOTMENU 0 // 0 = no bootmenu, 1 = device brings up boot menu before starting application #define BOOTMENU 0 // 0 = no bootmenu, 1 = device brings up boot menu before starting application
#define BOOTDELAY 30 // time [seconds] while devices waits in boot menue for input #define BOOTDELAY 30 // time [seconds] while devices waits in boot menue for input
#define BOOTTIMEOUT 300 // time [seconds] while devices waits to finish upload a firmware file #define BOOTTIMEOUT 300 // time [seconds] while devices waits to finish upload a firmware file
#define SDLOGGING 0 // set to 1 for system logging to SD card (if device has one)
// Payload send cycle and encoding // Payload send cycle and encoding
#define SENDCYCLE 30 // payload send cycle [seconds/2], 0 .. 255 #define SENDCYCLE 30 // payload send cycle [seconds/2], 0 .. 255

View File

@ -2,8 +2,6 @@
#include "globals.h" #include "globals.h"
#include "power.h" #include "power.h"
// Local logging tag
static const char TAG[] = __FILE__;
int8_t batt_level = -1; // percent batt level, global variable, -1 means no batt int8_t batt_level = -1; // percent batt level, global variable, -1 means no batt

View File

@ -2,8 +2,6 @@
#include "globals.h" #include "globals.h"
#include "rcommand.h" #include "rcommand.h"
// Local logging tag
static const char TAG[] = __FILE__;
static QueueHandle_t RcmdQueue; static QueueHandle_t RcmdQueue;
TaskHandle_t rcmdTask; TaskHandle_t rcmdTask;

View File

@ -2,8 +2,6 @@
#include "globals.h" #include "globals.h"
#include "reset.h" #include "reset.h"
// Local logging tag
static const char TAG[] = __FILE__;
// Conversion factor for micro seconds to seconds // Conversion factor for micro seconds to seconds
#define uS_TO_S_FACTOR 1000000ULL #define uS_TO_S_FACTOR 1000000ULL

View File

@ -2,8 +2,6 @@
#include "rtctime.h" #include "rtctime.h"
// Local logging tag
static const char TAG[] = __FILE__;
RtcDS3231<TwoWire> Rtc(Wire); // RTC hardware i2c interface RtcDS3231<TwoWire> Rtc(Wire); // RTC hardware i2c interface

View File

@ -5,9 +5,6 @@
// check whether your card reader supports SPI oder SDMMC and select appropriate // check whether your card reader supports SPI oder SDMMC and select appropriate
// SD interface in board hal file // SD interface in board hal file
// Local logging tag
static const char TAG[] = __FILE__;
#include "sdcard.h" #include "sdcard.h"
sdmmc_card_t *card; sdmmc_card_t *card;
@ -17,9 +14,9 @@ static bool useSDCard = false;
// This file stream will be used for payload logging // This file stream will be used for payload logging
static FILE *data_file; static FILE *data_file;
// This file stream will be used for system logging
#ifdef SD_LOGGING #if (SDLOGGING)
// This file stream will be used for system logging
static FILE *log_file; static FILE *log_file;
// Save UART stdout stream // Save UART stdout stream
@ -30,7 +27,6 @@ static FILE *uart_stdout = stdout;
// @important Do NOT use the ESP_LOG* macro's in this function ELSE // @important Do NOT use the ESP_LOG* macro's in this function ELSE
// recursive loop and stack overflow! So use printf() instead for debug // recursive loop and stack overflow! So use printf() instead for debug
// messages. // messages.
// CURRENTLY NOT WORKING DUE TO AN ISSUE IN ARDUINO-ESP32
int print_to_sd_card(const char *fmt, va_list args) { int print_to_sd_card(const char *fmt, va_list args) {
static bool static_fatal_error = false; static bool static_fatal_error = false;
static const uint32_t WRITE_CACHE_CYCLE = 5; static const uint32_t WRITE_CACHE_CYCLE = 5;
@ -53,12 +49,8 @@ int print_to_sd_card(const char *fmt, va_list args) {
} }
// #2 Smart commit after x writes // #2 Smart commit after x writes
counter_write++; if (counter_write++ % WRITE_CACHE_CYCLE == 0)
if (counter_write % WRITE_CACHE_CYCLE == 0) {
printf("%s() fsync'ing log file (WRITE_CACHE_CYCLE=%u)\n",
WRITE_CACHE_CYCLE);
fsync(fileno(log_file)); fsync(fileno(log_file));
}
} }
// #3 ALWAYS Write to stdout! // #3 ALWAYS Write to stdout!
@ -119,7 +111,8 @@ bool sdcard_init(bool create) {
return false; return false;
} }
// Use settings defined above to initialize SD card and mount FAT filesystem. // Use settings defined above to initialize SD card and mount FAT
// filesystem.
ret = esp_vfs_fat_sdspi_mount(mount_point, &host, &slot_config, &mount_config, ret = esp_vfs_fat_sdspi_mount(mount_point, &host, &slot_config, &mount_config,
&card); &card);
@ -188,16 +181,12 @@ bool sdcard_init(bool create) {
useSDCard = false; useSDCard = false;
} }
#ifdef SD_LOGGING #if (SDLOGGING)
snprintf(bufferFilename, sizeof(bufferFilename), "/%s.log", SDCARD_FILE_NAME); snprintf(bufferFilename, sizeof(bufferFilename), "/%s.log", SDCARD_FILE_NAME);
if (openFile(&log_file, bufferFilename)) { if (openFile(&log_file, bufferFilename)) {
ESP_LOGI(TAG, "redirecting serial output to SD-card"); ESP_LOGI(TAG, "redirecting serial output to SD-card");
esp_log_set_vprintf(&print_to_sd_card); esp_log_set_vprintf(&print_to_sd_card);
// Change stdout for THIS TASK ONLY
// stdout = log_file;
// Change stdout for all new tasks which will be created
//_GLOBAL_REENT->_stdout = log_file;
} else { } else {
useSDCard = false; useSDCard = false;
} }
@ -209,7 +198,7 @@ bool sdcard_init(bool create) {
void sdcard_flush(void) { void sdcard_flush(void) {
if (data_file) if (data_file)
fsync(fileno(data_file)); fsync(fileno(data_file));
#ifdef SD_LOGGING #if (SDLOGGING)
if (log_file) if (log_file)
fsync(fileno(log_file)); fsync(fileno(log_file));
#endif #endif
@ -220,11 +209,9 @@ void sdcard_close(void) {
return; return;
ESP_LOGI(TAG, "closing SD-card"); ESP_LOGI(TAG, "closing SD-card");
sdcard_flush(); sdcard_flush();
#ifdef SD_LOGGING #if (SDLOGGING)
// Reset logging output back to normal // Redirect logging output back to console
ESP_LOGI(TAG, "redirect console back to serial output"); ESP_LOGI(TAG, "redirect console back to serial output");
// stdout = uart_stdout;
//_GLOBAL_REENT->_stdout = uart_stdout;
esp_log_set_vprintf(&vprintf); esp_log_set_vprintf(&vprintf);
#endif #endif
fcloseall(); fcloseall();

View File

@ -2,8 +2,6 @@
#if (HAS_SDS011) #if (HAS_SDS011)
// Local logging tag
static const char TAG[] = __FILE__;
#include "sds011read.h" #include "sds011read.h"

View File

@ -1,8 +1,6 @@
// Basic Config // Basic Config
#include "senddata.h" #include "senddata.h"
// Local logging tag
static const char TAG[] = __FILE__;
void setSendIRQ(TimerHandle_t xTimer) { void setSendIRQ(TimerHandle_t xTimer) {
xTaskNotify(irqHandlerTask, SENDCYCLE_IRQ, eSetBits); xTaskNotify(irqHandlerTask, SENDCYCLE_IRQ, eSetBits);

View File

@ -2,8 +2,6 @@
#include "globals.h" #include "globals.h"
#include "sensor.h" #include "sensor.h"
// Local logging tag
static const char TAG[] = __FILE__;
#define SENSORBUFFER \ #define SENSORBUFFER \
10 // max. size of user sensor data buffer in bytes [default=20] 10 // max. size of user sensor data buffer in bytes [default=20]

View File

@ -30,8 +30,6 @@ licenses. Refer to LICENSE.txt file in repository for more details.
#include <sys/param.h> #include <sys/param.h>
#include <rom/crc.h> #include <rom/crc.h>
static const char TAG[] = __FILE__;
#define HEADER_SIZE 4 #define HEADER_SIZE 4
// SPI transaction size needs to be at least 8 bytes and dividable by 4, see // SPI transaction size needs to be at least 8 bytes and dividable by 4, see
// https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/spi_slave.html // https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/spi_slave.html

View File

@ -4,8 +4,6 @@
#error You must define at most one of IF482 or DCF77! #error You must define at most one of IF482 or DCF77!
#endif #endif
// Local logging tag
static const char TAG[] = __FILE__;
// symbol to display current time source // symbol to display current time source
// G = GPS / R = RTC / L = LORA / * = no sync / ? = never synced // G = GPS / R = RTC / L = LORA / * = no sync / ? = never synced

View File

@ -21,8 +21,6 @@ accept this.
#include "timesync.h" #include "timesync.h"
// Local logging tag
static const char TAG[] = __FILE__;
static bool timeSyncPending = false; static bool timeSyncPending = false;
static uint8_t time_sync_seqNo = (uint8_t)random(TIME_SYNC_MAX_SEQNO), static uint8_t time_sync_seqNo = (uint8_t)random(TIME_SYNC_MAX_SEQNO),