fixed receiving data!
This commit is contained in:
parent
132b8d49fe
commit
8e62283299
3 changed files with 26 additions and 26 deletions
|
@ -27,7 +27,7 @@ int main() {
|
|||
rtc_init();
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("!!! DEBUG mode!!!\n");
|
||||
printf("!!! DEBUG mode !!!\n");
|
||||
#endif
|
||||
|
||||
WS2812 led(WS2812_PIN);
|
||||
|
|
|
@ -2,40 +2,35 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
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);
|
||||
// printf("Local result=%d\n", httpc_result);
|
||||
// printf("Http result=%d\n", srv_res);
|
||||
#endif
|
||||
received = true;
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
err_t headers_callback(httpc_state_t *connection, void *arg, struct pbuf *hdr, u16_t hdr_len,
|
||||
u32_t content_len) {
|
||||
#ifdef DEBUG
|
||||
printf("Headers received\n");
|
||||
printf("Content length=%d\n", content_len);
|
||||
printf("Header length=%d\n", hdr_len);
|
||||
|
||||
pbuf_copy_partial(hdr, myHeaderBuffer, hdr->tot_len, 0);
|
||||
printf("Headers \n");
|
||||
printf("%s", myHeaderBuffer);
|
||||
#endif
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
err_t body_callback(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err) {
|
||||
bool *received = (bool *)arg;
|
||||
|
||||
if (err != ERR_OK) {
|
||||
printf("PROBLEM!!\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
pbuf_copy_partial(p, myBodyBuffer, p->tot_len, 0);
|
||||
printf("HUHU:\n%s", myBodyBuffer);
|
||||
|
||||
*received = true;
|
||||
pbuf_copy_partial(p, &myBodyBuffer[offset], p->tot_len, 0);
|
||||
offset += p->len;
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
@ -52,7 +47,7 @@ std::string HttpClient::retrieveWasteDatesAsCsv() {
|
|||
std::string result("");
|
||||
|
||||
err_t err = httpc_get_file_dns("beenas.brodbeck-online.de", port, "/abfall/abfall.csv",
|
||||
&m_settings, body_callback, &m_received, nullptr);
|
||||
&m_settings, body_callback, nullptr, nullptr);
|
||||
|
||||
// If there was an error, return empty result.
|
||||
if (err != ERR_OK) {
|
||||
|
@ -60,7 +55,7 @@ std::string HttpClient::retrieveWasteDatesAsCsv() {
|
|||
}
|
||||
|
||||
uint wait_count = 0;
|
||||
while (m_received == false) {
|
||||
while (received == false) {
|
||||
++wait_count;
|
||||
|
||||
if (wait_count >= 10) {
|
||||
|
@ -70,6 +65,11 @@ std::string HttpClient::retrieveWasteDatesAsCsv() {
|
|||
}
|
||||
|
||||
result.append(myBodyBuffer);
|
||||
received = false;
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cout << result << std::endl;
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
|
@ -4,16 +4,17 @@
|
|||
|
||||
#include "lwip/apps/http_client.h"
|
||||
#include "pico/cyw43_arch.h"
|
||||
//#include "pico/stdlib.h"
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
static char myHeaderBuffer[2048];
|
||||
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);
|
||||
void result_callback(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res,
|
||||
err_t err);
|
||||
|
||||
err_t headers_callback(httpc_state_t *connection, void *arg, struct pbuf *hdr,
|
||||
u16_t hdr_len, u32_t content_len);
|
||||
err_t headers_callback(httpc_state_t *connection, void *arg, struct pbuf *hdr, u16_t hdr_len,
|
||||
u32_t content_len);
|
||||
|
||||
err_t body_callback(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err);
|
||||
|
||||
|
@ -21,7 +22,6 @@ class HttpClient {
|
|||
public:
|
||||
HttpClient();
|
||||
std::string retrieveWasteDatesAsCsv();
|
||||
bool m_received{false};
|
||||
|
||||
private:
|
||||
httpc_connection_t m_settings;
|
||||
|
|
Loading…
Reference in a new issue