-
-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement filesystem operation on spare flash and UNO WiFI OTA #32
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ad93421
Initial implementation of FS handling
facchinm a567034
Add downloadFile helper
facchinm 0723542
Add OTA routine for UNO WiFi rev2
facchinm abb02a3
Adding 'rename' operation necessary for using the WiFiNiNa for OTA
aentinger 65d6e1a
Adding the errno code of the rename operation to the response message
aentinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// esp_http_client.c | ||
#include <dirent.h> | ||
#include <sys/stat.h> | ||
#include "esp_log.h" | ||
#include <stdio.h> | ||
|
||
#include "esp_http_client.h" | ||
|
||
#define MAX_HTTP_RECV_BUFFER 128 | ||
|
||
static const char* TAG = "HTTP_HANDLER"; | ||
|
||
static esp_err_t _http_event_handler(esp_http_client_event_t *evt) | ||
{ | ||
switch(evt->event_id) { | ||
case HTTP_EVENT_ERROR: | ||
case HTTP_EVENT_ON_CONNECTED: | ||
case HTTP_EVENT_HEADER_SENT: | ||
case HTTP_EVENT_ON_FINISH: | ||
case HTTP_EVENT_DISCONNECTED: | ||
case HTTP_EVENT_ON_HEADER: | ||
break; | ||
case HTTP_EVENT_ON_DATA: | ||
if (!esp_http_client_is_chunked_response(evt->client)) { | ||
//fwrite((char*)evt->data, sizeof(uint8_t), evt->data_len, (FILE*)evt->user_data); | ||
} | ||
break; | ||
} | ||
return ESP_OK; | ||
} | ||
|
||
int downloadAndSaveFile(char* url, char* filename, FILE* f) { | ||
|
||
char *buffer = (char*)malloc(MAX_HTTP_RECV_BUFFER); | ||
if (buffer == NULL) { | ||
return -1; | ||
} | ||
esp_http_client_config_t config = { | ||
.url = url, | ||
.event_handler = _http_event_handler, | ||
.user_data = f, | ||
}; | ||
|
||
esp_http_client_handle_t client = esp_http_client_init(&config); | ||
esp_err_t err; | ||
if ((err = esp_http_client_open(client, 0)) != ESP_OK) { | ||
free(buffer); | ||
return -1; | ||
} | ||
int content_length = esp_http_client_fetch_headers(client); | ||
int total_read_len = 0, read_len; | ||
while (total_read_len < content_length) { | ||
read_len = esp_http_client_read(client, buffer, MAX_HTTP_RECV_BUFFER); | ||
fwrite(buffer, sizeof(uint8_t), read_len, f); | ||
if (read_len <= 0) { | ||
break; | ||
} | ||
total_read_len += read_len; | ||
} | ||
esp_http_client_close(client); | ||
esp_http_client_cleanup(client); | ||
free(buffer); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be missing a piece in
arduinoOTA
but is this needed? From what I remember the arduinoOTA binary POSTs to a web server ...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added that method to allow a board to perform OTA even if it's behind a NAT (mostly for Create 🙂 ). I used it also for local deployment
to reduce the amount of code that must be changed to adapt WiFi101OTA for UNO WiFi r2