Sync network time.
This commit is contained in:
1 parent
b2a3aa18f2
commit
baf1144351
3 files changed
+766
-527
No files matched your search
+12
-5
@@ -1,5 +1,6 @@
|
||||
#include "wifi.h"
|
||||
#include "secrets.h"
|
||||
#include "config.h"
|
||||
|
||||
/* WiFi station Example
|
||||
|
||||
@@ -51,10 +52,16 @@ void wifi_init_sta(void) {
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
esp_netif_create_default_wifi_sta();
|
||||
esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
#ifndef ESP_HOSTNAME
|
||||
#error "ESP_HOSTNAME is not defined in config.h"
|
||||
#endif
|
||||
|
||||
esp_err_t err = esp_netif_set_hostname(sta_netif, ESP_HOSTNAME);
|
||||
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
esp_event_handler_instance_t instance_got_ip;
|
||||
@@ -96,11 +103,11 @@ void wifi_init_sta(void) {
|
||||
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
|
||||
* happened. */
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
|
||||
ESP_WIFI_SSID, ESP_WIFI_PASS);
|
||||
ESP_LOGI(TAG, "connected to ap SSID:%s.",
|
||||
ESP_WIFI_SSID);
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
|
||||
ESP_WIFI_SSID, ESP_WIFI_PASS);
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID:%s.",
|
||||
ESP_WIFI_SSID);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user