Closed ajpaezm closed 4 years ago
I read about issues with the SD card logic on some chinese TTGO boards, which needs some special treatment.
You may try asking this forum.
Since this is not a paxcounter related issue, i close this issue. But you're welcome to add comments.
Reopened labelled as feature enhancement.
Yeah too much printing in memory is causing this rebooting.. and SD card is not closed properly so it cant open again..
Try keeping your ESP_LOGI to minimum data and let me know if it works.. we too are doing similar stuff.
Hi,
I just did it.
Here is the output of my code:
date, time, wifi, bluet 00.00.1970,00:01:11,5,0 00.00.1970,00:02:11,1,0 00.00.1970,00:03:11,3,0
this is just my first test. The format is CSV.
I will have to clean up my code, add some comments etc. Then I will upload it here.
this is the board I used: https://www.aliexpress.com/item/32990008126.html
The board already includes the SDcard-reader.
And I also have no access to a lorawan-gateway here in my little town. So I needed this.
I think I used this library: https://github.com/nhatuan84/esp32-micro-sdcard/blob/master/mySD.h
Thanks! If you commit your Pull Request, please use development branch as base, not master. Thanks.
I will do it but please give me some time.
In the moment I can't do it because I will go to a vacation. When I come back I will work on this topic.
Hey guys, sorry I didn't stay on the loop of this.
Hi @Nethranv! You said:
Yeah too much printing in memory is causing this rebooting.. and SD card is not closed properly so it cant open again..
Try keeping your ESP_LOGI to minimum data and let me know if it works.. we too are doing similar stuff.
I tried this and didn't had much luck :(
Hi @AugustQu! Thanks so much for the interest in this one. I'm curious and looking forward about what you did to make it work.
Hi,
I just did it.
Here is the output of my code:
date, time, wifi, bluet 00.00.1970,00:01:11,5,0 00.00.1970,00:02:11,1,0 00.00.1970,00:03:11,3,0
this is just my first test. The format is CSV.
I will have to clean up my code, add some comments etc. Then I will upload it here.
@ajpaezm when using SPI interface of card reader, have in mind that paxcounter is using SPI for communication with the LORA chip. (Only) If both use same SPI hardware interface you need a mutex when accessing the SPI bus, otherwise there will be race conditions on multitasking esp32 platform.
The above mentioned TTGO board is using separate interface for SD card reader, so hardware should be suitable.
SD_DATA1 - GPIO4
SD_DATA0 - GPIO2
SD_CLK - GPIO14
SD_CMD - GPIO15
SD_DATA3 - GPIO13
SD_DATA2 - GPIO12
WE are able to save the MAC address , timestamp, RSSI into SD card. I will share the code for files i modified.
Main.cpp: ESP_LOGE(TAG, "ZzZzZzZz **** ZZzZzZzZzZ***"); ESP_LOGI(TAG, "Using SDMMC peripheral"); sdmmc_host_t host = SDMMC_HOST_DEFAULT();
// This initializes the slot without card detect (CD) and write protect (WP) signals.
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
// To use 1-line SD mode, uncomment the following line:
slot_config.width = 1;
// GPIOs 15, 2, 4, 12, 13 should have external 10k pull-ups.
// Internal pull-ups are not sufficient. However, enabling internal pull-ups
// does make a difference some boards, so we do that here.
gpio_set_pull_mode(GPIO_NUM_15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes
gpio_set_pull_mode(GPIO_NUM_2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes
gpio_set_pull_mode(GPIO_NUM_4, GPIO_PULLUP_ONLY); // D1, needed in 4-line mode only
gpio_set_pull_mode(GPIO_NUM_12, GPIO_PULLUP_ONLY); // D2, needed in 4-line mode only
gpio_set_pull_mode(GPIO_NUM_13, GPIO_PULLUP_ONLY); // D3, needed in 4- and 1-line modes
// Options for mounting the filesystem.
// If format_if_mount_failed is set to true, SD card will be partitioned and
// formatted in case when mounting fails.
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = true,
.max_files = 5,
.allocation_unit_size = 16 * 1024
};
// Use settings defined above to initialize SD card and mount FAT filesystem.
// Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function.
// Please check its source code and implement error recovery when developing
// production applications.
sdmmc_card_t* card;
esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
if (ret != ESP_OK) {
if (ret == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount filesystem. "
"If you want the card to be formatted, set format_if_mount_failed = true.");
} else {
ESP_LOGE(TAG, "Failed to initialize the card (%s). "
"Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret));
}
return;
}
ESP_LOGE(TAG, "ZzZzZzZz ******************************** ZZzZzZzZzZ***************************");
// Card has been initialized, print its properties
sdmmc_card_print_info(stdout, card);
ESP_LOGE(TAG, "ZzZzZzZz ******************************** ZZzZzZzZzZ***************************");
/
Globals.h:
wifiscan.cpp:
FILE* f = fopen("/sdcard/Log_file.txt", "a+");
fprintf(f,"%02X:%02X:%02X:%02X:%02X:%02X | %u | %u | %02d\n",
hdr->addr2[0],hdr->addr2[1],hdr->addr2[2],hdr->addr2[3],hdr->addr2[4],hdr->addr2[5],
(ppkt->rx_ctrl.timestamp)/1000000,
sequencenumber1,
ppkt->rx_ctrl.rssi);
fprintf(f, "\n");
fclose(f);
Hi,
I'm back from my vacation and started working on the code again. Are you still interested in my approach to the SDcard-handling?
Hi,
this is what I did:
I renamed my existing project so that I can start with a clean directory
Then I added the code from here.
Then I added the code from here to the lib-directory and removed the "-master" from the name of the directorsy.
In src/hal I added a new file: ttgov21SD.h
In include I adeded a file sdcard.h and modified senddata.h
In src I:
For making the code compile with the enhancements:
in platformio.ini:
[board] ;halfile = generic.h .... halfile = ttgov21SD.h
added an (empty) loraconf.h
added an (empty) ota.conf
this is the output of my test:
date, time, wifi, bluet 00.00.1970,00:01:09,2,0 00.00.1970,00:02:09,1,0 00.00.1970,00:03:09,2,0
Next step for me would be:
You may then check it. And naturally we can discuss the contents of the output or the code or
yes, do add a branch for your modifications. I will review it.
Please do not create special hal files, but an option which can be used in all hal files. Like #define Display etc.
Hi,
I was not able to create a branch here so I copied the whole code from here to my repository, created a branch sdcard there and added my modifications. You will find my code here: https://github.com/AugustQu/PaxCounter
some questions:
forgot: there are some restrictions on the cheap sd-card-readers:
these restrictions are valid as far as I know. Didn't check these, for me these restrictions are acceptable.
My code will create a file with the name PAXCOUNT.xx where xx goes from 00 to 99. It will start with 00, check to see if such a file already exists and if yes it will continue with the next number (up to 99 - in this case it will return no sd-card).
The data is written to the card and after 3 write-operations the data is flushed to the disk. So maybe the last 3 minutes of data get lost.
just created a pull-request from sdcard (on my repository) against development-branch here. Hope that's OK.
I did a quick overlook.
@AugustQu i merged your code contributions by hand. You find it here. Please use this branch for further developments. Thanks.
Thanks for your work.
I think the idea with the file ttgov21SD.h (in src/hal) is a bad one. I will remove this. A better approach would be a description of what to add to an existing hal-file in case one wants to use this feature.
One has to add these lines to the hal-file used:
define HAS_SDCARD 1 // this board has an SD-card-reader/writer
// Pins for SD-card
define SDCARD_CS (13) // fill in the correct numbers for your board
define SDCARD_MOSI (15)
define SDCARD_MISO (2)
define SDCARD_SCLK (14)
I will start writing an explanation. Where to put it? In README?
Hi,
blocking functions: I did not encounter any problems with my approach.
And 2nd: I'm totally new in programming for the ESP32-environment. So I will have to look what to do here.
Usage of blocking functions may affect time critical routines. In paxcounter such are found in the lmic (lora) task, i.e. while waiting for RXing data. Your approach does not consider this. But it's mitigated since you used sendPayload() for writing to SD-card. SendPayload() is called by the interrupthandler, which considers if the device is in a time critical state. So far, so good.
But we may have to expect performance drop in MAC sniffing due to packet loss while the device is busy with writing to SD-card. Since this is done cyclic (controled by sendcycle) i think it's okay. So we keep this approach initially. A more elaborated approach would use queues.
I will start writing an explanation. Where to put it? In README?
Please put it in generic.h
and readme.md
.
You can also append credits at the end of readme.md
;-)
done.
I've added some lines to the README. I hope it's complete.
ah, my changes did not appear because:
You’re editing a file in a project you don’t have write access to. Submitting a change to this file will write it to a new branch in your fork AugustQu/ESP32-Paxcounter, so you can send a pull request.
OK, did the modifications again. You can find them in AugustQu/ESP32-Paxcounter/patch-2
I've also created a pull request against the development-branch here.
I added sdcard support to branch development, and deleted branch sdcard. After i have tested sdcard support on different boards, i will merge #511 4e1472c with master and close this feature request.
Hi,
I'd like to know if anyone here managed to use the SD card successfully to store anything from the Paxcounter.
What I want to do is simple, I want to have a back-up from the counters and timestamps for posterior analysis.
These are the contents of sdcard.h and sdcard.cpp I've written, using the libraries for the SD card of ESP32, my board is a LoRa32 V2.1_1.6:
sdcard.h:
sdcard.cpp:
Is all good when I initialize it or even create the test file "myCounters.txt", but then, when I try to call "save_scan" or "writeFile" or "appendFile" inside senddata.cpp, I get this error (after reaching the same line of code for a second time, the first time what it does is rebooting):
Are there any suggestions to this on how to solve this? Is this an issue about the core being used for the task? I'm lost to be fair.
Any assistance on this I'd be extremely glad.