modified: firmware/main/src/controller.c
modified: firmware/main/src/leds.c modified: firmware/main/src/main.c modified: firmware/main/src/wifi.c
This commit is contained in:
1 parent
19b7b5791f
commit
7db85d712e
4 files changed
+65
-31
No files matched your search
@@ -3,16 +3,38 @@
|
||||
#include <esp_log.h>
|
||||
#include <esp_wifi.h>
|
||||
//#include <esp_http_client.h>
|
||||
//#include "esp_netif.h"
|
||||
#include "functions.h"
|
||||
#include "wifi.h"
|
||||
#include "leds.h"
|
||||
|
||||
static const char * TAG = "wifi.c";
|
||||
|
||||
esp_err_t wifi_init(void) {
|
||||
esp_err_t wifi_init() {
|
||||
// Init IP Stack
|
||||
tcpip_adapter_init();
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static bool wait_for_connected() {
|
||||
tcpip_adapter_ip_info_t ip_info;
|
||||
|
||||
unsigned repeats = 10;
|
||||
for(unsigned i = 0; i < repeats; ++i)
|
||||
{
|
||||
if ( tcpip_adapter_get_ip_info( TCPIP_ADAPTER_IF_STA, &ip_info ) == ESP_OK && ip_info.ip.addr != 0 ) {
|
||||
ESP_LOGI(TAG, "IP Address: " IPSTR, IP2STR(&ip_info.ip));
|
||||
return ESP_OK;
|
||||
}
|
||||
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||
}
|
||||
ESP_LOGE(TAG, "Timed out waiting for ip address from dhcp server.");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
// Function to turn on WiFi
|
||||
esp_err_t wifi_on() {
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
@@ -34,18 +56,20 @@ esp_err_t wifi_init(void) {
|
||||
//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;
|
||||
}
|
||||
|
||||
// Function to turn on WiFi
|
||||
esp_err_t wifi_on() {
|
||||
ESP_LOGI(TAG, "Turning WiFi ON...");
|
||||
esp_wifi_start(); // Start WiFi
|
||||
ESP_LOGI(TAG, "WiFi is ON and connecting...");
|
||||
esp_wifi_connect();
|
||||
ESP_LOGI(TAG, "WiFi is ON and connected to AP.");
|
||||
led1_on();
|
||||
return ESP_OK;
|
||||
ESP_LOGI(TAG, "WiFi is ON and connected to AP.");
|
||||
if (wait_for_connected() == ESP_OK) {
|
||||
led2_on();
|
||||
return ESP_OK;
|
||||
}
|
||||
else {
|
||||
wifi_off();
|
||||
return ESP_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
// Function to turn off WiFi
|
||||
@@ -54,7 +78,9 @@ esp_err_t wifi_off() {
|
||||
esp_wifi_disconnect();
|
||||
ESP_LOGI(TAG, "WiFi disconnected. Turning WiFi OFF...");
|
||||
esp_wifi_stop(); // Stop WiFi
|
||||
ESP_LOGI(TAG, "WiFi is OFF.");
|
||||
esp_wifi_deinit();
|
||||
led1_off();
|
||||
led2_off();
|
||||
ESP_LOGI(TAG, "WiFi is OFF.");
|
||||
return ESP_OK;
|
||||
}
|
||||
Reference in new issue
Block a user