From 09d29c1d1f08491966d7451ba2bb8c4274ff0e7c Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 30 Jan 2022 15:32:14 +0100 Subject: [PATCH 1/4] Update paxcounter_orig.conf --- src/paxcounter_orig.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/paxcounter_orig.conf b/src/paxcounter_orig.conf index ee6584d2..f273cdd4 100644 --- a/src/paxcounter_orig.conf +++ b/src/paxcounter_orig.conf @@ -20,8 +20,8 @@ // default settings for transmission of sensor data (first list = data on / second line = data off) #define PAYLOADMASK \ - ((GPS_DATA | MEMS_DATA | COUNT_DATA | SENSOR1_DATA | SENSOR2_DATA | SENSOR3_DATA) \ - & (~BATT_DATA) & (~RESERVED_DATA)) + ((GPS_DATA | MEMS_DATA | COUNT_DATA | SENSOR1_DATA | SENSOR2_DATA | SENSOR3_DATA | BATT_DATA) \ + & (~RESERVED_DATA)) // MAC sniffing parameters #define BLECOUNTER 1 // set to 0 if you do not want to install the BLE sniffer From 2b9c7c8804d82a1d25e5ccbe6dbc1ff87ea0ef31 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 30 Jan 2022 15:32:43 +0100 Subject: [PATCH 2/4] Update platformio_orig.ini --- platformio_orig.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platformio_orig.ini b/platformio_orig.ini index c70bbd9e..58491357 100644 --- a/platformio_orig.ini +++ b/platformio_orig.ini @@ -16,10 +16,10 @@ ;halfile = ttgov1.h ;halfile = ttgov2.h ;halfile = ttgov21old.h -;halfile = ttgov21new.h +halfile = ttgov21new.h ;halfile = ttgofox.h ;halfile = ttgobeam.h -halfile = ttgobeam10.h +;halfile = ttgobeam10.h ;halfile = ttgotdisplay.h ;halfile = ttgotwristband.h ;halfile = fipy.h @@ -133,4 +133,4 @@ upload_protocol = esptool [env:dev] upload_protocol = esptool build_type = debug -platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream \ No newline at end of file +platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream From d45c96e5449b38354bbb8c898f16c32f6e5f5e17 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 30 Jan 2022 21:53:11 +0100 Subject: [PATCH 3/4] sdcard bugfixes --- include/sdcard.h | 2 -- src/sdcard.cpp | 77 ++++++++++++++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 31 deletions(-) diff --git a/include/sdcard.h b/include/sdcard.h index 5a88ea5d..1dfb5f2d 100644 --- a/include/sdcard.h +++ b/include/sdcard.h @@ -8,10 +8,8 @@ #if (HAS_SDCARD) #if HAS_SDCARD == 1 #include -#define MYSD SD #elif HAS_SDCARD == 2 #include -#define MYSD SD_MMC #else #error HAS_SDCARD unknown card reader value, must be either 1 or 2 #endif diff --git a/src/sdcard.cpp b/src/sdcard.cpp index 476e4037..9f7737dd 100644 --- a/src/sdcard.cpp +++ b/src/sdcard.cpp @@ -10,7 +10,7 @@ static const char TAG[] = __FILE__; #ifdef HAS_SDCARD -static bool useSDCard = false; +static bool useSDCard; static void openFile(void); File fileSDCard; @@ -27,20 +27,25 @@ bool sdcard_init(bool create) { // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdmmc_host.html #if HAS_SDCARD == 1 // use SD SPI host driver - useSDCard = MYSD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK); + useSDCard = SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK); #elif HAS_SDCARD == 2 // use SD MMC host driver // enable internal pullups of sd-data lines gpio_set_pull_mode(gpio_num_t(SDCARD_DATA0), GPIO_PULLUP_ONLY); gpio_set_pull_mode(gpio_num_t(SDCARD_DATA1), GPIO_PULLUP_ONLY); gpio_set_pull_mode(gpio_num_t(SDCARD_DATA2), GPIO_PULLUP_ONLY); gpio_set_pull_mode(gpio_num_t(SDCARD_DATA3), GPIO_PULLUP_ONLY); - useSDCard = MYSD.begin(); + useSDCard = SD_MMC.begin(); #endif if (useSDCard) { ESP_LOGI(TAG, "SD-card found"); - cardType = MYSD.cardType(); - cardSize = MYSD.cardSize() / (1024 * 1024); +#if HAS_SDCARD == 1 + cardType = SD.cardType(); + cardSize = SD.cardSize() / (1024 * 1024); +#elif HAS_SDCARD == 2 + cardType = SD_MMC.cardType(); + cardSize = SD_MMC.cardSize() / (1024 * 1024); +#endif } else { ESP_LOGI(TAG, "SD-card not found"); return false; @@ -60,8 +65,7 @@ bool sdcard_init(bool create) { } else { ESP_LOGI(TAG, "SD Card type: UNKNOWN"); } - - ESP_LOGI(TAG, "SD Card Size: %lluMB\n", cardSize); + ESP_LOGI(TAG, "SD Card Size: %lluMB", cardSize); openFile(); @@ -121,35 +125,50 @@ void openFile(void) { snprintf(bufferFilename, sizeof(bufferFilename), "/%s.csv", SDCARD_FILE_NAME); ESP_LOGI(TAG, "SD: looking for file <%s>", bufferFilename); - /* - if (MYSD.exists(bufferFilename)) { - if (MYSD.open(bufferFilename, FILE_APPEND)) - useSDCard = true; - } else { - ESP_LOGI(TAG, "SD: file does not exist, creating it"); - if (MYSD.open(bufferFilename, FILE_WRITE)) - useSDCard = true; - } - */ +#if HAS_SDCARD == 1 + bool fileExists = SD.exists(bufferFilename); +#elif HAS_SDCARD == 2 + bool fileExists = SD_MMC.exists(bufferFilename); +#endif - if (!MYSD.exists(bufferFilename)) - ESP_LOGI(TAG, "SD: file does not exist, creating it"); + // file not exists, create it + if (!fileExists) { + ESP_LOGD(TAG, "SD: file not found, creating..."); - if (MYSD.open(bufferFilename, FILE_WRITE)) - useSDCard = true; +#if HAS_SDCARD == 1 + fileSDCard = SD.open(bufferFilename, FILE_WRITE); +#elif HAS_SDCARD == 2 + fileSDCard = SD_MMC.open(bufferFilename, FILE_WRITE); +#endif - if (useSDCard) { - ESP_LOGI(TAG, "SD: file opened: <%s>", bufferFilename); - fileSDCard.print(SDCARD_FILE_HEADER); + if (fileSDCard) { + ESP_LOGD(TAG, "SD: name opened: <%s>", bufferFilename); + fileSDCard.print(SDCARD_FILE_HEADER); #if (defined BAT_MEASURE_ADC || defined HAS_PMU) - fileSDCard.print(SDCARD_FILE_HEADER_VOLTAGE); // for battery level data + fileSDCard.print(SDCARD_FILE_HEADER_VOLTAGE); // for battery level data #endif #if (HAS_SDS011) - fileSDCard.print(SDCARD_FILE_HEADER_SDS011); + fileSDCard.print(SDCARD_FILE_HEADER_SDS011); #endif - fileSDCard.println(); - } else { - ESP_LOGE(TAG, "SD: file not opened error"); + fileSDCard.println(); + useSDCard = true; + } + } + + // file exists, append data + else { + ESP_LOGD(TAG, "SD: file found, opening..."); + +#if HAS_SDCARD == 1 + fileSDCard = SD.open(bufferFilename, FILE_APPEND); +#elif HAS_SDCARD == 2 + fileSDCard = SD_MMC.open(bufferFilename, FILE_APPEND); +#endif + + if (fileSDCard) { + ESP_LOGD(TAG, "SD: name opened: <%s>", bufferFilename); + useSDCard = true; + } } return; From d6385f1f70d96e7f709457a6004d7b7157e4cb3e Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 30 Jan 2022 22:12:26 +0100 Subject: [PATCH 4/4] further sdcard fixes --- src/sdcard.cpp | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/src/sdcard.cpp b/src/sdcard.cpp index 9f7737dd..59d194d6 100644 --- a/src/sdcard.cpp +++ b/src/sdcard.cpp @@ -17,15 +17,11 @@ File fileSDCard; bool sdcard_init(bool create) { - uint8_t cardType; - uint64_t cardSize; - - ESP_LOGI(TAG, "looking for SD-card..."); - // for usage of SD drivers on ESP32 platform see // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdspi_host.html // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdmmc_host.html + ESP_LOGI(TAG, "looking for SD-card..."); #if HAS_SDCARD == 1 // use SD SPI host driver useSDCard = SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK); #elif HAS_SDCARD == 2 // use SD MMC host driver @@ -39,37 +35,12 @@ bool sdcard_init(bool create) { if (useSDCard) { ESP_LOGI(TAG, "SD-card found"); -#if HAS_SDCARD == 1 - cardType = SD.cardType(); - cardSize = SD.cardSize() / (1024 * 1024); -#elif HAS_SDCARD == 2 - cardType = SD_MMC.cardType(); - cardSize = SD_MMC.cardSize() / (1024 * 1024); -#endif + openFile(); + return true; } else { ESP_LOGI(TAG, "SD-card not found"); return false; } - - if (cardType == CARD_NONE) { - ESP_LOGI(TAG, "No SD card attached"); - return false; - } - - if (cardType == CARD_MMC) { - ESP_LOGI(TAG, "SD Card type: MMC"); - } else if (cardType == CARD_SD) { - ESP_LOGI(TAG, "SD Card type: SDSC"); - } else if (cardType == CARD_SDHC) { - ESP_LOGI(TAG, "SD Card type: SDHC"); - } else { - ESP_LOGI(TAG, "SD Card type: UNKNOWN"); - } - ESP_LOGI(TAG, "SD Card Size: %lluMB", cardSize); - - openFile(); - - return true; } void sdcard_close(void) {