modified: firmware/main/include/wifi.h
modified: firmware/main/src/leds.c modified: firmware/main/src/main.c modified: firmware/main/src/sht31.c modified: firmware/main/src/wifi.c modified: firmware/sdkconfig
This commit is contained in:
1 parent
2f48a98556
commit
b693e31141
6 files changed
+36
-19
No files matched your search
+24
-13
@@ -2,10 +2,12 @@
|
||||
#include <freertos/task.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_wifi.h>
|
||||
#include <esp_http_client.h>
|
||||
//#include <esp_http_client.h>
|
||||
#include "functions.h"
|
||||
#include "wifi.h"
|
||||
|
||||
static const char * TAG = "wifi.c";
|
||||
|
||||
esp_err_t wifi_init(void) {
|
||||
tcpip_adapter_init();
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
@@ -13,6 +15,7 @@ esp_err_t wifi_init(void) {
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
|
||||
wifi_config_t sta_config = {
|
||||
@@ -23,22 +26,30 @@ esp_err_t wifi_init(void) {
|
||||
};
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &sta_config));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
//ESP_ERROR_CHECK(esp_wifi_start());
|
||||
//ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
|
||||
// Enable power saving
|
||||
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MIN_MODEM));
|
||||
//ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MIN_MODEM));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MAX_MODEM));
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t wifi_sleep() {
|
||||
/*
|
||||
// Enter light sleep mode
|
||||
wifi_fpm_open(); // Enable modem sleep
|
||||
wifi_fpm_do_sleep(0xFFFFFFF); // Enter sleep mode indefinitely
|
||||
// The system will wake up when an interrupt occurs
|
||||
wifi_fpm_close(); // Close modem sleep mode after waking up
|
||||
*/
|
||||
return ESP_OK;
|
||||
// Function to turn on WiFi
|
||||
void wifi_on() {
|
||||
ESP_LOGI(TAG, "Turning WiFi ON...");
|
||||
esp_wifi_start(); // Start WiFi
|
||||
ESP_LOGI(TAG, "WiFi is ON and connecting...");
|
||||
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
ESP_LOGI(TAG, "WiFi is ON and connected to AP.");
|
||||
}
|
||||
|
||||
// Function to turn off WiFi
|
||||
void wifi_off() {
|
||||
ESP_LOGI(TAG, "Disconnecting from AP and turning off WiFi...");
|
||||
ESP_ERROR_CHECK(esp_wifi_disconnect())
|
||||
ESP_LOGI(TAG, "WiFi disconnected. Turning WiFi OFF...");
|
||||
esp_wifi_stop(); // Stop WiFi
|
||||
ESP_LOGI(TAG, "WiFi is OFF.");
|
||||
}
|
||||
Reference in new issue
Block a user