Access an sdCard during http GET
Posted: Fri Dec 03, 2021 9:40 am
In their examples, Espressif provide a simple http server. https://github.com/espressif/esp-idf/tr ... ver/simple
When a GET-request arrives, a handler replies with a string:
(The handler is a callback registered via the httpd_register_uri_handler() ESP32 library API https://docs.espressif.com/projects/esp ... ttpd_uri_t)
In my case however, the string is stored on an sdCard. So I want to do something like
Elsewhere however, I have a freeRTOS task that occasionally writes to the same sdCard, and I'm worried about problems should read_sdcard() occur whilst a write is ongoing.
To solve this, I am thinking to use a mutex to co-ordinate reads/writes. Something like:
Is this a sensible approach? Is it safe to add RTOS "stuff" like this inside a get_handler() ?
FreeRTOS say " xSemaphoreTake() must not be called from an ISR“
I don’t know how Espressif’s http server works ‘under the hood’.
Can I be confident that basic_auth_get_handler() isn’t an ISR?
thanks for any advice
When a GET-request arrives, a handler replies with a string:
Code: Select all
// GET request handler (pseudo code)
static esp_err_t basic_auth_get_handler(httpd_req_t *req) {
…
// Send a string reply
httpd_resp_send(“some string”)); //etc.
}
In my case however, the string is stored on an sdCard. So I want to do something like
Code: Select all
// GET request handler (pseudo-code)
static esp_err_t basic_auth_get_handler(httpd_req_t *req) {
…
// Fetch reply-string from sd-card
myString = read_sdcard()
httpd_resp_send(myString)); //etc.
}
To solve this, I am thinking to use a mutex to co-ordinate reads/writes. Something like:
Code: Select all
//GET request handler (pseudo-code)
static esp_err_t basic_auth_get_handler(httpd_req_t *req) {
…
// Use a mutex to safely access sdCard.
if (xSemaphoreTake(myMutex, portMAX_DELAY) == pdTRUE) {
myString = read_sd_card(myFile)
xSemaphoreGive(myMutex);
}
httpd_resp_send(myString)); // etc
}
FreeRTOS say " xSemaphoreTake() must not be called from an ISR“
I don’t know how Espressif’s http server works ‘under the hood’.
Can I be confident that basic_auth_get_handler() isn’t an ISR?
thanks for any advice