From 0ba4eded5232785a7fadd57e09a6f371c126939e Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Wed, 4 Dec 2024 21:19:44 -0800 Subject: [PATCH 1/4] Fix compiling for pico2_w. --- libs/pico-telnetd | 2 +- src/fanpico.h | 1 + src/httpd.c | 10 +++++----- src/mqtt.c | 8 +++----- src/syslog.c | 1 - src/telnetd.c | 1 - src/util.c | 14 ++++++++++++++ 7 files changed, 24 insertions(+), 13 deletions(-) diff --git a/libs/pico-telnetd b/libs/pico-telnetd index 82a688d..a4f1d3d 160000 --- a/libs/pico-telnetd +++ b/libs/pico-telnetd @@ -1 +1 @@ -Subproject commit 82a688d553b616d9af4410ec5fa7f29fd11af396 +Subproject commit a4f1d3de741f67c4e4ec8168a9978f7953c4b852 diff --git a/src/fanpico.h b/src/fanpico.h index 306ea69..8b50436 100644 --- a/src/fanpico.h +++ b/src/fanpico.h @@ -508,6 +508,7 @@ struct timespec* time_t_to_timespec(time_t t, struct timespec *ts); char* time_t_to_str(char *buf, size_t size, const time_t t); bool str_to_time_t(const char *str, time_t *t); bool rtc_get_tm(struct tm *tm); +bool rtc_get_time(time_t *t); const char *mac_address_str(const uint8_t *mac); int valid_wifi_country(const char *country); int valid_hostname(const char *name); diff --git a/src/httpd.c b/src/httpd.c index e0698b9..50838b7 100644 --- a/src/httpd.c +++ b/src/httpd.c @@ -23,7 +23,7 @@ #include #include #include -#include "hardware/rtc.h" +#include "pico/aon_timer.h" #include "pico/stdlib.h" #include "cJSON.h" @@ -253,10 +253,10 @@ u16_t fanpico_ssi_handler(const char *tag, char *insert, int insertlen, /* printf("ssi_handler(\"%s\",%lx,%d,%u,%u)\n", tag, (uint32_t)insert, insertlen, current_tag_part, *next_tag_part); */ if (!strncmp(tag, "datetime", 8)) { - datetime_t t; - if (rtc_get_datetime(&t)) { - printed = snprintf(insert, insertlen, "%04d-%02d-%02d %02d:%02d:%02d", - t.year, t.month, t.day, t.hour, t.min, t.sec); + struct timespec ts; + if (aon_timer_is_running()) { + aon_timer_get_time(&ts); + time_t_to_str(insert, insertlen, timespec_to_time_t(&ts)); } } if (!strncmp(tag, "uptime", 6)) { diff --git a/src/mqtt.c b/src/mqtt.c index 8c8529a..be475aa 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -23,9 +23,7 @@ #include #include #include -#include "hardware/rtc.h" #include "pico/stdlib.h" -#include "pico/util/datetime.h" #include "cJSON.h" #ifdef LIB_PICO_CYW43_ARCH #include "pico/cyw43_arch.h" @@ -695,7 +693,7 @@ static char* json_status_message() cJSON *json, *l, *o; int i; float rpm; - datetime_t t; + time_t t; if (!(json = cJSON_CreateObject())) goto panic; @@ -745,10 +743,10 @@ static char* json_status_message() cJSON_AddItemToArray(l, o); } - if ( rtc_get_datetime(&t) ) { + if ( rtc_get_time(&t) ) { /* Send Data Time stamp to broker for possible use */ char datetime_buf[32]; - datetime_to_str(datetime_buf, sizeof(datetime_buf), &t); + time_t_to_str(datetime_buf, sizeof(datetime_buf), t); cJSON_AddItemToObject(json, "datetime", cJSON_CreateString( datetime_buf )); } diff --git a/src/syslog.c b/src/syslog.c index bfc6745..612620a 100644 --- a/src/syslog.c +++ b/src/syslog.c @@ -23,7 +23,6 @@ #include #include #include -#include "hardware/rtc.h" #include "pico/stdlib.h" #include "pico/cyw43_arch.h" #include "lwip/pbuf.h" diff --git a/src/telnetd.c b/src/telnetd.c index f9e9ff4..86da93e 100644 --- a/src/telnetd.c +++ b/src/telnetd.c @@ -23,7 +23,6 @@ #include #include #include -#include "hardware/rtc.h" #include "pico/stdlib.h" #include "pico/stdio/driver.h" #include "pico/cyw43_arch.h" diff --git a/src/util.c b/src/util.c index 94f02e9..4698bd6 100644 --- a/src/util.c +++ b/src/util.c @@ -165,6 +165,20 @@ bool rtc_get_tm(struct tm *tm) } +bool rtc_get_time(time_t *t) +{ + struct timespec ts; + + if (!t || !aon_timer_is_running()) + return false; + + aon_timer_get_time(&ts); + *t = timespec_to_time_t(&ts); + + return true; +} + + const char *mac_address_str(const uint8_t *mac) { static char buf[32]; From b53cb12ed8c64e982e98d48f4a3da19f68729bf7 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Wed, 4 Dec 2024 21:49:00 -0800 Subject: [PATCH 2/4] Update build to use SDK v2.1.0 and add pico2_w to build matrix. --- .github/workflows/cmake.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 2731118..ac5537e 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -10,8 +10,8 @@ env: BUILD_THREADS: 4 BUILD_TYPE: Release # Pico-SDK version - PICO_SDK_REF: 2.0.0 - PICOTOOL_REF: 2.0.0 + PICO_SDK_REF: 2.1.0 + PICOTOOL_REF: 2.1.0 jobs: build: @@ -23,8 +23,8 @@ jobs: strategy: matrix: - fanpico_board: ["0804", "0804D", "0401D" ] - pico_board: ["pico", "pico_w", "pico2"] + fanpico_board: ["0804", "0804D", "0401D"] + pico_board: ["pico", "pico_w", "pico2", "pico2_w"] steps: - name: Arm GNU Toolchain (arm-none-eabi-gcc) From d57ff103d99e9cef9c6b5f0956f509eb12406315 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Wed, 4 Dec 2024 21:56:53 -0800 Subject: [PATCH 3/4] Use SDK 2.1.0 in CodeQL. --- .github/workflows/codeql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index b8df41b..09a3740 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -23,7 +23,7 @@ on: env: BUILD_TYPE: Release # Pico-SDK version - PICO_SDK_REF: 2.0.0 + PICO_SDK_REF: 2.1.0 jobs: analyze: From 752d73831f3ac330fdb28769fc3d94aaa34d612d Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Wed, 4 Dec 2024 22:16:50 -0800 Subject: [PATCH 4/4] Switch to using rtc_get_time() wrapper. --- src/httpd.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/httpd.c b/src/httpd.c index 50838b7..71c4056 100644 --- a/src/httpd.c +++ b/src/httpd.c @@ -23,7 +23,6 @@ #include #include #include -#include "pico/aon_timer.h" #include "pico/stdlib.h" #include "cJSON.h" @@ -253,10 +252,9 @@ u16_t fanpico_ssi_handler(const char *tag, char *insert, int insertlen, /* printf("ssi_handler(\"%s\",%lx,%d,%u,%u)\n", tag, (uint32_t)insert, insertlen, current_tag_part, *next_tag_part); */ if (!strncmp(tag, "datetime", 8)) { - struct timespec ts; - if (aon_timer_is_running()) { - aon_timer_get_time(&ts); - time_t_to_str(insert, insertlen, timespec_to_time_t(&ts)); + time_t t; + if (rtc_get_time(&t)) { + time_t_to_str(insert, insertlen, t); } } if (!strncmp(tag, "uptime", 6)) {