diff --git a/src/http_client.cpp b/src/http_client.cpp index 319360d..9ea3e99 100644 --- a/src/http_client.cpp +++ b/src/http_client.cpp @@ -1,13 +1,16 @@ #include "http_client.h" #include +#include + +std::unique_ptr myBodyBuffer = nullptr; +uint16_t offset{0}; +bool received{false}; void result_callback(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res, err_t err) { #ifdef DEBUG printf("Transfer complete\n"); - // printf("Local result=%d\n", httpc_result); - // printf("Http result=%d\n", srv_res); #endif received = true; offset = 0; @@ -17,9 +20,10 @@ err_t headers_callback(httpc_state_t *connection, void *arg, struct pbuf *hdr, u u32_t content_len) { #ifdef DEBUG printf("Headers received\n"); - printf("Content length=%d\n", content_len); - printf("Header length=%d\n", hdr_len); + printf("Content length=%lu\n", content_len); + printf("Header length=%u\n", hdr_len); #endif + myBodyBuffer = std::make_unique(content_len + 1); return ERR_OK; } @@ -64,7 +68,7 @@ std::string HttpClient::retrieveWasteDatesAsCsv() { sleep_ms(1000); } - result.append(myBodyBuffer); + result.append(myBodyBuffer.get()); received = false; #ifdef DEBUG diff --git a/src/http_client.h b/src/http_client.h index 378aaa7..48da672 100644 --- a/src/http_client.h +++ b/src/http_client.h @@ -6,10 +6,6 @@ #include "pico/cyw43_arch.h" #include "pico/stdlib.h" -static char myBodyBuffer[2048]; -static uint16_t offset{0}; -static bool received{false}; - void result_callback(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res, err_t err);