working with DEBUG
This commit is contained in:
parent
25c11e465e
commit
258a0c051f
7 changed files with 61 additions and 33 deletions
|
@ -15,6 +15,11 @@ pico_set_program_version(${CMAKE_PROJECT_NAME} ${PROJECT_VERSION})
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-volatile")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-volatile")
|
||||||
|
|
||||||
|
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
|
||||||
|
# If the debug configuration pass the DEBUG define to the compiler
|
||||||
|
"$<$<CONFIG:DEBUG>:DEBUG>"
|
||||||
|
)
|
||||||
|
|
||||||
# Add the standard include files to the build
|
# Add the standard include files to the build
|
||||||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
|
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include <cstdio>
|
// #include <cstdio>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -23,6 +23,10 @@ int main() {
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
rtc_init();
|
rtc_init();
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("!!! DEBUG mode!!!\n\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
WS2812 led(WS2812_PIN);
|
WS2812 led(WS2812_PIN);
|
||||||
|
|
||||||
wifi_setup();
|
wifi_setup();
|
||||||
|
@ -31,16 +35,22 @@ int main() {
|
||||||
HttpClient client;
|
HttpClient client;
|
||||||
std::string csv("");
|
std::string csv("");
|
||||||
for (int i = 1; i <= 10; i++) {
|
for (int i = 1; i <= 10; i++) {
|
||||||
|
#ifdef DEBUG
|
||||||
printf("Attempt %d for retrieving data.\n", i);
|
printf("Attempt %d for retrieving data.\n", i);
|
||||||
|
#endif
|
||||||
csv = client.retrieveWasteDatesAsCsv();
|
csv = client.retrieveWasteDatesAsCsv();
|
||||||
if (csv.length() > 0) {
|
if (csv.length() > 0) {
|
||||||
|
#ifdef DEBUG
|
||||||
printf("Data received!\n");
|
printf("Data received!\n");
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (csv.length() == 0) {
|
if (csv.length() == 0) {
|
||||||
|
#ifdef DEBUG
|
||||||
printf("Error getting data. Exiting!");
|
printf("Error getting data. Exiting!");
|
||||||
|
#endif
|
||||||
cyw43_arch_deinit();
|
cyw43_arch_deinit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -50,13 +60,12 @@ int main() {
|
||||||
datetime_t dt;
|
datetime_t dt;
|
||||||
|
|
||||||
auto dates = parseCsv(csv);
|
auto dates = parseCsv(csv);
|
||||||
|
#ifdef DEBUG
|
||||||
printf("Number of Dates: %d\n", dates.size());
|
printf("Number of Dates: %d\n", dates.size());
|
||||||
|
#endif
|
||||||
while (true) {
|
while (true) {
|
||||||
rtc_get_datetime(&dt);
|
rtc_get_datetime(&dt);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
datetime_to_str(datetime_str, sizeof(datetime_buf), &dt);
|
datetime_to_str(datetime_str, sizeof(datetime_buf), &dt);
|
||||||
// printf("DateTime: %s\n", datetime_str);
|
// printf("DateTime: %s\n", datetime_str);
|
||||||
led.switchColor(Color::OFF);
|
led.switchColor(Color::OFF);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "http_client.h"
|
#include "http_client.h"
|
||||||
|
|
||||||
|
/*
|
||||||
void result_callback(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res,
|
void result_callback(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res,
|
||||||
err_t err) {
|
err_t err) {
|
||||||
printf("Transfer complete\n");
|
printf("Transfer complete\n");
|
||||||
|
@ -19,14 +20,15 @@ err_t headers_callback(httpc_state_t *connection, void *arg, struct pbuf *hdr, u
|
||||||
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
err_t body_callback(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err) {
|
err_t body_callback(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err) {
|
||||||
bool *test = (bool *)arg;
|
bool *received = (bool *)arg;
|
||||||
//printf("...");
|
|
||||||
pbuf_copy_partial(p, myBuffer, p->tot_len, 0);
|
pbuf_copy_partial(p, myBuffer, p->tot_len, 0);
|
||||||
// printf("%s", myBuffer);
|
// printf("%s", myBuffer);
|
||||||
|
|
||||||
*test = true;
|
*received = true;
|
||||||
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
@ -40,27 +42,27 @@ HttpClient::HttpClient() {
|
||||||
std::string HttpClient::retrieveWasteDatesAsCsv() {
|
std::string HttpClient::retrieveWasteDatesAsCsv() {
|
||||||
uint16_t port = 80;
|
uint16_t port = 80;
|
||||||
|
|
||||||
std::string test("");
|
std::string result("");
|
||||||
|
|
||||||
err_t err = httpc_get_file_dns("beenas.brodbeck-online.de", port, "/abfall/abfall.csv",
|
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, &m_received, nullptr);
|
||||||
//printf("Status %d\n", err);
|
|
||||||
|
|
||||||
//printf("Waiting for waste dates ");
|
// If there was an error, return empty result.
|
||||||
|
if (err != ERR_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
uint wait_count = 0;
|
uint wait_count = 0;
|
||||||
while (m_received == false) {
|
while (m_received == false) {
|
||||||
++wait_count;
|
++wait_count;
|
||||||
//printf(".");
|
|
||||||
if (wait_count >= 10) {
|
if (wait_count >= 10) {
|
||||||
return test;
|
return result;
|
||||||
}
|
}
|
||||||
sleep_ms(1000);
|
sleep_ms(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf(" received.\n");
|
result.append(myBuffer);
|
||||||
|
|
||||||
test.append(myBuffer);
|
return result;
|
||||||
|
|
||||||
return test;
|
|
||||||
}
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "lwip/apps/http_client.h"
|
#include "lwip/apps/http_client.h"
|
||||||
#include "pico/cyw43_arch.h"
|
#include "pico/cyw43_arch.h"
|
||||||
#include "pico/stdlib.h"
|
//#include "pico/stdlib.h"
|
||||||
|
|
||||||
static char myBuffer[2048];
|
static char myBuffer[2048];
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#include "ntp_client.h"
|
#include "ntp_client.h"
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
#include "hardware/rtc.h"
|
#include "hardware/rtc.h"
|
||||||
|
|
||||||
#include "pico/util/datetime.h"
|
#include "pico/util/datetime.h"
|
||||||
|
|
||||||
|
|
||||||
// Called by lwip sntp in order to set the time
|
// Called by lwip sntp in order to set the time
|
||||||
void set_system_time(u32_t sec) {
|
void set_system_time(u32_t sec) {
|
||||||
time_t epoch = sec;
|
time_t epoch = sec;
|
||||||
|
@ -17,9 +18,14 @@ void set_system_time(u32_t sec) {
|
||||||
datetime.min = utc->tm_min;
|
datetime.min = utc->tm_min;
|
||||||
datetime.sec = utc->tm_sec;
|
datetime.sec = utc->tm_sec;
|
||||||
datetime.dotw = utc->tm_wday;
|
datetime.dotw = utc->tm_wday;
|
||||||
if (rtc_set_datetime(&datetime) == true) {
|
|
||||||
|
bool success = rtc_set_datetime(&datetime);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (success) {
|
||||||
printf("RTC successfully set.\n");
|
printf("RTC successfully set.\n");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void NtpClient::setDateTime() {
|
void NtpClient::setDateTime() {
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
|
|
||||||
#include "lwip/apps/sntp.h"
|
#include "lwip/apps/sntp.h"
|
||||||
|
|
|
@ -51,25 +51,30 @@ std::vector<WasteDate> parseCsv(const std::string &csv) {
|
||||||
|
|
||||||
switch (tokenPos) {
|
switch (tokenPos) {
|
||||||
case 0:
|
case 0:
|
||||||
printf("Gelber Sack: %s\n", token.c_str());
|
// printf("Gelber Sack: %s\n", token.c_str());
|
||||||
wd.wasteTypes.push_back(Waste::GelberSack);
|
wd.wasteTypes.push_back(Waste::GelberSack);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
printf("Papiertonne: %s\n", token.c_str());
|
// printf("Papiertonne: %s\n", token.c_str());
|
||||||
wd.wasteTypes.push_back(Waste::Papiertonne);
|
wd.wasteTypes.push_back(Waste::Papiertonne);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
printf("Biotonne: %s\n", token.c_str());
|
// printf("Biotonne: %s\n", token.c_str());
|
||||||
wd.wasteTypes.push_back(Waste::Biotonne);
|
wd.wasteTypes.push_back(Waste::Biotonne);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
printf("Restmüll: %s\n", token.c_str());
|
// printf("Restmüll: %s\n", token.c_str());
|
||||||
wd.wasteTypes.push_back(Waste::Restmuell);
|
wd.wasteTypes.push_back(Waste::Restmuell);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
printf("Problemstoffmobil: %s\n", token.c_str());
|
// printf("Problemstoffmobil: %s\n", token.c_str());
|
||||||
wd.wasteTypes.push_back(Waste::Problemstoffmobil);
|
wd.wasteTypes.push_back(Waste::Problemstoffmobil);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("Unknown waste token detected.\n");
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,11 +83,11 @@ std::vector<WasteDate> parseCsv(const std::string &csv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//for(const auto& ymd: dates) {
|
// for(const auto& ymd: dates) {
|
||||||
// std::cout << "Current Year: " << static_cast<int>(ymd.date.year())
|
// std::cout << "Current Year: " << static_cast<int>(ymd.date.year())
|
||||||
// << ", Month: " << static_cast<unsigned>(ymd.date.month())
|
// << ", Month: " << static_cast<unsigned>(ymd.date.month())
|
||||||
// << ", Day: " << static_cast<unsigned>(ymd.date.day()) << '\n';
|
// << ", Day: " << static_cast<unsigned>(ymd.date.day()) << '\n';
|
||||||
//}
|
// }
|
||||||
|
|
||||||
return dates;
|
return dates;
|
||||||
}
|
}
|
||||||
|
@ -126,8 +131,9 @@ int wifi_setup_impl(uint32_t country, const string &ssid, const string &pw, bool
|
||||||
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);
|
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);
|
||||||
} else {
|
} else {
|
||||||
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
|
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
|
||||||
|
#ifdef DEBUG
|
||||||
printf("IP: %s\n", ip4addr_ntoa(netif_ip_addr4(netif_default)));
|
printf("IP: %s\n", ip4addr_ntoa(netif_ip_addr4(netif_default)));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
@ -145,7 +151,9 @@ void wifi_setup() {
|
||||||
res = wifi_setup_impl(country, ssid, pw, true);
|
res = wifi_setup_impl(country, ssid, pw, true);
|
||||||
firstTry = false;
|
firstTry = false;
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef DEBUG
|
||||||
printf("Setting up connection failed. Trying again after 5 sec...\n");
|
printf("Setting up connection failed. Trying again after 5 sec...\n");
|
||||||
|
#endif
|
||||||
sleep_ms(5000);
|
sleep_ms(5000);
|
||||||
res = wifi_setup_impl(country, ssid, pw, false);
|
res = wifi_setup_impl(country, ssid, pw, false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue