Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions libs/avm_network/src/network.erl
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@
-type ap_config() :: {ap, [ap_config_property()]}.

-type sntp_host_config() :: {host, string() | binary()}.
-type sntp_timezone_config() :: {timezone, string() | binary()}.
-type sntp_synchronized_config() ::
{synchronized, fun(({non_neg_integer(), non_neg_integer()}) -> term())}.
-type sntp_config_property() ::
sntp_host_config()
| sntp_timezone_config()
| sntp_synchronized_config().
-type sntp_config() :: {sntp, [sntp_config_property()]}.

Expand Down
15 changes: 15 additions & 0 deletions src/platforms/esp32/components/avm_builtins/network_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static const char *const sta_connected_atom = ATOM_STR("\xD", "sta_connected");
static const char *const sta_beacon_timeout_atom = ATOM_STR("\x12", "sta_beacon_timeout");
static const char *const sta_disconnected_atom = ATOM_STR("\x10", "sta_disconnected");
static const char *const sta_got_ip_atom = ATOM_STR("\xA", "sta_got_ip");
static const char *const timezone_atom = ATOM_STR("\x8", "timezone");
static const char *const network_down_atom = ATOM_STR("\x0C", "network_down");

ESP_EVENT_DECLARE_BASE(sntp_event_base);
Expand Down Expand Up @@ -1148,6 +1149,20 @@ static void maybe_set_sntp(term sntp_config, GlobalContext *global)
} else {
ESP_LOGE(TAG, "Unable to locate sntp host in configuration");
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, it make sense, but I was wondering about if we should rather add an atomvm:set_timezone() NIF, since it can be useful also in other scenarios without sntp, and it can be more general than just ESP32.
What's your opinion here: @pguyot @petermm ?

term timezone_term = interop_kv_get_value(sntp_config, timezone_atom, global);
if (!term_is_invalid_term(timezone_term)) {
int tz_ok;
char *tz = interop_term_to_string(timezone_term, &tz_ok);
if (LIKELY(tz_ok)) {
setenv("TZ", tz, 1);
tzset();
ESP_LOGI(TAG, "Timezone set to %s", tz);
free(tz);
} else {
ESP_LOGE(TAG, "Unable to parse timezone string in configuration");
}
}
}
}

Expand Down
Loading