Skip to content

Commit

Permalink
Rewrote https_post_file
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Mar 17, 2024
1 parent 89a6f30 commit 6e05aef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ monitor_filters = esp32_exception_decoder, log2file
build_flags =
-Wall -Wextra -Wunused -Wmisleading-indentation -Wduplicated-cond -Wlogical-op -Wnull-dereference
; -D TINY_GSM_MODEM_SIM7000
-D TINY_GSM_MODEM_SIM7020
; -D TINY_GSM_MODEM_SIM7020
; -D TINY_GSM_MODEM_SIM7600
; -D TINY_GSM_MODEM_A7608
; -D TINY_GSM_MODEM_A7670
-D TINY_GSM_MODEM_A7670
; -D TINY_GSM_MODEM_SIM7672

[env:esp32dev]
Expand Down
14 changes: 6 additions & 8 deletions src/TinyGsmHttpsA76xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,21 +278,19 @@ class TinyGsmHttpsA76xx
/**
* @brief POSTFile
* @note Send file to server
* @param *filepath:File path and file name, full path required
* @param *filepath:File path and file name, full path required. C:/file for local storage and D:/file for SD card
* @param method: 0 = GET 1 = POST 2 = HEAD 3 = DELETE
* @param sendFileAsBody: 0 = Send file as HTTP header and body , 1 = Send file as Body
* @retval httpCode, -1 = failed
*/
int https_post_file(const char *filepath, uint8_t method = 1, bool sendFileAsBody = 1)
{
// A76XX Series_AT Command Manual_V1.09, Page 363
// AT+HTTPPOSTFILE=<filename>[,<path>[,<method>[,<send_header>]]]
uint8_t path = 1;
if (!filepath)return -1;
if (&filepath[3] == NULL)return -1;
if (filepath[0] == 'd' || filepath[0] == 'D') {
path = 2;
}
thisModem().sendAT("+HTTPPOSTFILE=\"", &filepath[3], "\",", path, ',', method, ',', sendFileAsBody);
// filename: full path required. C:/file for local storage and D:/file for SD card
if (!filepath || strlen(filepath) < 4) return -1; // no file
uint8_t path = filepath[0] == 'd' || filepath[0] == 'D' ? 2 : 1; // storage (2 for SD or 1 for local)
thisModem().sendAT("+HTTPPOSTFILE=\"", filepath[3], "\",", path, ',', method, ',', sendFileAsBody);
if (thisModem().waitResponse(120000UL) != 1) {
return -1;
}
Expand Down

0 comments on commit 6e05aef

Please sign in to comment.