Skip to content

Improve constants for picow_ntp_client.c #690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pico_w/wifi/ntp_client/picow_ntp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ typedef struct NTP_T_ {
#define NTP_MSG_LEN 48
#define NTP_PORT 123
#define NTP_DELTA 2208988800 // seconds between 1 Jan 1900 and 1 Jan 1970
#define NTP_TEST_TIME_MS (30 * 1000)
#define NTP_RESEND_TIME_MS (10 * 1000)
#define NTP_REQUEST_TIME_MS (30 * 1000)
#define NTP_FAILED_HANDLER_TIME_MS (10 * 1000)

// Called with results of operation
static void ntp_result(NTP_T* state, int status, time_t *result) {
Expand All @@ -36,8 +36,8 @@ static void ntp_result(NTP_T* state, int status, time_t *result) {
utc->tm_hour, utc->tm_min, utc->tm_sec);
}
async_context_remove_at_time_worker(cyw43_arch_async_context(), &state->resend_worker);
hard_assert(async_context_add_at_time_worker_in_ms(cyw43_arch_async_context(), &state->request_worker, NTP_TEST_TIME_MS)); // repeat the request in future
printf("Next request in %ds\n", NTP_TEST_TIME_MS / 1000);
hard_assert(async_context_add_at_time_worker_in_ms(cyw43_arch_async_context(), &state->request_worker, NTP_REQUEST_TIME_MS)); // repeat the request in future
printf("Next request in %ds\n", NTP_REQUEST_TIME_MS / 1000);
}

// Make an NTP request
Expand Down Expand Up @@ -94,7 +94,7 @@ static void ntp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_ad
// Called to make a NTP request
static void request_worker_fn(__unused async_context_t *context, async_at_time_worker_t *worker) {
NTP_T* state = (NTP_T*)worker->user_data;
hard_assert(async_context_add_at_time_worker_in_ms(cyw43_arch_async_context(), &state->resend_worker, NTP_RESEND_TIME_MS)); // in case UDP request is lost
hard_assert(async_context_add_at_time_worker_in_ms(cyw43_arch_async_context(), &state->resend_worker, NTP_FAILED_HANDLER_TIME_MS)); // in case UDP request is lost
int err = dns_gethostbyname(NTP_SERVER, &state->ntp_server_address, ntp_dns_found, state);
if (err == ERR_OK) {
ntp_request(state); // Cached DNS result, make NTP request
Expand Down
Loading