mirror of
https://github.com/Lurkars/esp-ena.git
synced 2026-05-08 20:10:37 +02:00
read and parse Key Export, started WiFi and CWA connection
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
idf_component_register(
|
||||
SRCS
|
||||
"main.c"
|
||||
"display-interface.c"
|
||||
"wifi.c"
|
||||
INCLUDE_DIRS ""
|
||||
)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
menu "Wifi Setup"
|
||||
|
||||
config WIFI_SSID
|
||||
string "WiFi SSID"
|
||||
default "myssid"
|
||||
help
|
||||
SSID (network name) for the example to connect to.
|
||||
|
||||
config WIFI_PASSWORD
|
||||
string "WiFi Password"
|
||||
default "mypassword"
|
||||
help
|
||||
WiFi password (WPA or WPA2) for the example to use.
|
||||
|
||||
config WIFI_MAXIMUM_RETRY
|
||||
int "Maximum retry"
|
||||
default 5
|
||||
help
|
||||
Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent.
|
||||
endmenu
|
||||
@@ -0,0 +1,153 @@
|
||||
// Copyright 2020 Lukas Haubaum
|
||||
//
|
||||
// Licensed under the GNU Affero General Public License, Version 3;
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// https://www.gnu.org/licenses/agpl-3.0.html
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "ds3231.h"
|
||||
#include "ena-exposure.h"
|
||||
#include "ena-interface.h"
|
||||
#include "ena-interface-menu.h"
|
||||
#include "ena-interface-datetime.h"
|
||||
#include "ssd1306.h"
|
||||
|
||||
void interface_display_time(void *pvParameter)
|
||||
{
|
||||
static time_t curtime;
|
||||
static char *curtime_text;
|
||||
static struct tm rtc_time;
|
||||
static bool edit_invert = false;
|
||||
while (1)
|
||||
{
|
||||
curtime = time(NULL);
|
||||
localtime_r(&curtime, &rtc_time);
|
||||
curtime_text = asctime(&rtc_time);
|
||||
ssd1306_text_line(SSD1306_ADDRESS, curtime_text, 0, false);
|
||||
gmtime_r(&curtime, &rtc_time);
|
||||
curtime_text = asctime(&rtc_time);
|
||||
ssd1306_text_line(SSD1306_ADDRESS, curtime_text, 1, false);
|
||||
if (ena_interface_get_state() == ENA_INTERFACE_STATE_SET_DATETIME)
|
||||
{
|
||||
edit_invert = !edit_invert;
|
||||
ds3231_set_time(&rtc_time);
|
||||
char edit_year[4] = "";
|
||||
char edit_month[3] = "";
|
||||
char edit_day[2] = "";
|
||||
char edit_hour[2] = "";
|
||||
char edit_minute[2] = "";
|
||||
char edit_second[2] = "";
|
||||
switch (ena_interface_datetime_state())
|
||||
{
|
||||
|
||||
case ENA_INTERFACE_DATETIME_STATE_YEAR:
|
||||
memcpy(&edit_year, &curtime_text[20], 4);
|
||||
ssd1306_text_line_column(SSD1306_ADDRESS, edit_year, 0, 20, edit_invert);
|
||||
break;
|
||||
case ENA_INTERFACE_DATETIME_STATE_MONTH:
|
||||
memcpy(&edit_month, &curtime_text[4], 3);
|
||||
ssd1306_text_line_column(SSD1306_ADDRESS, edit_month, 0, 4, edit_invert);
|
||||
break;
|
||||
case ENA_INTERFACE_DATETIME_STATE_DAY:
|
||||
memcpy(&edit_day, &curtime_text[8], 2);
|
||||
ssd1306_text_line_column(SSD1306_ADDRESS, edit_day, 0, 8, edit_invert);
|
||||
break;
|
||||
case ENA_INTERFACE_DATETIME_STATE_HOUR:
|
||||
memcpy(&edit_hour, &curtime_text[11], 2);
|
||||
ssd1306_text_line_column(SSD1306_ADDRESS, edit_hour, 0, 11, edit_invert);
|
||||
break;
|
||||
case ENA_INTERFACE_DATETIME_STATE_MINUTE:
|
||||
memcpy(&edit_minute, &curtime_text[14], 2);
|
||||
ssd1306_text_line_column(SSD1306_ADDRESS, edit_minute, 0, 14, edit_invert);
|
||||
break;
|
||||
case ENA_INTERFACE_DATETIME_STATE_SECONDS:
|
||||
memcpy(&edit_second[0], &curtime_text[17], 2);
|
||||
ssd1306_text_line_column(SSD1306_ADDRESS, edit_second, 0, 17, edit_invert);
|
||||
break;
|
||||
}
|
||||
}
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void interface_display_status(void *pvParameter)
|
||||
{
|
||||
static bool get_status = true;
|
||||
while (1)
|
||||
{
|
||||
if (ena_interface_get_state() == ENA_INTERFACE_STATE_STATUS)
|
||||
{
|
||||
if (get_status)
|
||||
{
|
||||
ena_exposure_summary_t summary;
|
||||
ena_exposure_summary(ena_exposure_default_config(), &summary);
|
||||
char buffer[23];
|
||||
sprintf(buffer, "Days: %d", summary.days_since_last_exposure);
|
||||
ssd1306_text_line(SSD1306_ADDRESS, buffer, 3, false);
|
||||
sprintf(buffer, "Exposures: %d", summary.num_exposures);
|
||||
ssd1306_text_line(SSD1306_ADDRESS, buffer, 4, false);
|
||||
sprintf(buffer, "Score: %d, Max: %d", summary.risk_score_sum, summary.max_risk_score);
|
||||
ssd1306_text_line(SSD1306_ADDRESS, buffer, 5, false);
|
||||
get_status = false;
|
||||
}
|
||||
}
|
||||
else if (!get_status)
|
||||
{
|
||||
ssd1306_clear_line(SSD1306_ADDRESS, 3, false);
|
||||
ssd1306_clear_line(SSD1306_ADDRESS, 4, false);
|
||||
ssd1306_clear_line(SSD1306_ADDRESS, 5, false);
|
||||
get_status = true;
|
||||
}
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void interface_display_idle(void *pvParameter)
|
||||
{
|
||||
static bool set_status = true;
|
||||
while (1)
|
||||
{
|
||||
if (ena_interface_get_state() == ENA_INTERFACE_STATE_IDLE)
|
||||
{
|
||||
if (set_status)
|
||||
{
|
||||
ssd1306_on(SSD1306_ADDRESS, false);
|
||||
set_status = false;
|
||||
}
|
||||
}
|
||||
else if (!set_status)
|
||||
{
|
||||
ssd1306_on(SSD1306_ADDRESS, true);
|
||||
set_status = true;
|
||||
}
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void display_interface_start(void)
|
||||
{
|
||||
ssd1306_start(SSD1306_ADDRESS);
|
||||
ssd1306_clear(SSD1306_ADDRESS);
|
||||
|
||||
ena_interface_start();
|
||||
ena_interface_menu_start();
|
||||
|
||||
xTaskCreate(&interface_display_time, "interface_display_time", 4096, NULL, 5, NULL);
|
||||
xTaskCreate(&interface_display_status, "interface_display_status", 4096, NULL, 5, NULL);
|
||||
xTaskCreate(&interface_display_idle, "interface_display_idle", 4096, NULL, 5, NULL);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2020 Lukas Haubaum
|
||||
//
|
||||
// Licensed under the GNU Affero General Public License, Version 3;
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// https://www.gnu.org/licenses/agpl-3.0.html
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef _display_interface_H_
|
||||
#define _display_interface_H_
|
||||
|
||||
/**
|
||||
* @brief start display + interface
|
||||
*/
|
||||
void display_interface_start(void);
|
||||
|
||||
#endif
|
||||
+25
-128
@@ -11,7 +11,6 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
@@ -24,149 +23,47 @@
|
||||
#include "ena-storage.h"
|
||||
#include "ena-beacons.h"
|
||||
#include "ena-exposure.h"
|
||||
#include "ena-bluetooth-advertise.h"
|
||||
#include "ena-bluetooth-scan.h"
|
||||
#include "ena-interface.h"
|
||||
#include "ena-interface-menu.h"
|
||||
#include "ena-interface-datetime.h"
|
||||
#include "ssd1306.h"
|
||||
#include "ena-cwa.h"
|
||||
#include "ds3231.h"
|
||||
#include "wifi.h"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
static time_t curtime;
|
||||
|
||||
void interface_display_time(void *pvParameter)
|
||||
{
|
||||
static char *curtime_text;
|
||||
static struct tm rtc_time;
|
||||
static bool edit_invert = false;
|
||||
while (1)
|
||||
{
|
||||
curtime = time(NULL);
|
||||
localtime_r(&curtime, &rtc_time);
|
||||
curtime_text = asctime(&rtc_time);
|
||||
ssd1306_text_line(SSD1306_ADDRESS, curtime_text, 0, false);
|
||||
gmtime_r(&curtime, &rtc_time);
|
||||
curtime_text = asctime(&rtc_time);
|
||||
ssd1306_text_line(SSD1306_ADDRESS, curtime_text, 1, false);
|
||||
if (ena_interface_get_state() == ENA_INTERFACE_STATE_SET_DATETIME)
|
||||
{
|
||||
edit_invert = !edit_invert;
|
||||
ds3231_set_time(&rtc_time);
|
||||
char edit_year[4] = "";
|
||||
char edit_month[3] = "";
|
||||
char edit_day[2] = "";
|
||||
char edit_hour[2] = "";
|
||||
char edit_minute[2] = "";
|
||||
char edit_second[2] = "";
|
||||
switch (ena_interface_datetime_state())
|
||||
{
|
||||
|
||||
case ENA_INTERFACE_DATETIME_STATE_YEAR:
|
||||
memcpy(&edit_year, &curtime_text[20], 4);
|
||||
ssd1306_text_line_column(SSD1306_ADDRESS, edit_year, 0, 20, edit_invert);
|
||||
break;
|
||||
case ENA_INTERFACE_DATETIME_STATE_MONTH:
|
||||
memcpy(&edit_month, &curtime_text[4], 3);
|
||||
ssd1306_text_line_column(SSD1306_ADDRESS, edit_month, 0, 4, edit_invert);
|
||||
break;
|
||||
case ENA_INTERFACE_DATETIME_STATE_DAY:
|
||||
memcpy(&edit_day, &curtime_text[8], 2);
|
||||
ssd1306_text_line_column(SSD1306_ADDRESS, edit_day, 0, 8, edit_invert);
|
||||
break;
|
||||
case ENA_INTERFACE_DATETIME_STATE_HOUR:
|
||||
memcpy(&edit_hour, &curtime_text[11], 2);
|
||||
ssd1306_text_line_column(SSD1306_ADDRESS, edit_hour, 0, 11, edit_invert);
|
||||
break;
|
||||
case ENA_INTERFACE_DATETIME_STATE_MINUTE:
|
||||
memcpy(&edit_minute, &curtime_text[14], 2);
|
||||
ssd1306_text_line_column(SSD1306_ADDRESS, edit_minute, 0, 14, edit_invert);
|
||||
break;
|
||||
case ENA_INTERFACE_DATETIME_STATE_SECONDS:
|
||||
memcpy(&edit_second[0], &curtime_text[17], 2);
|
||||
ssd1306_text_line_column(SSD1306_ADDRESS, edit_second, 0, 17, edit_invert);
|
||||
break;
|
||||
}
|
||||
}
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void interface_display_status(void *pvParameter)
|
||||
{
|
||||
static bool get_status = true;
|
||||
while (1)
|
||||
{
|
||||
if (ena_interface_get_state() == ENA_INTERFACE_STATE_STATUS)
|
||||
{
|
||||
if (get_status)
|
||||
{
|
||||
ena_exposure_summary_t summary;
|
||||
ena_exposure_summary(ena_exposure_default_config(), &summary);
|
||||
char buffer[23];
|
||||
sprintf(buffer, "Days: %d", summary.days_since_last_exposure);
|
||||
ssd1306_text_line(SSD1306_ADDRESS, buffer, 3, false);
|
||||
sprintf(buffer, "Exposures: %d", summary.num_exposures);
|
||||
ssd1306_text_line(SSD1306_ADDRESS, buffer, 4, false);
|
||||
sprintf(buffer, "Score: %d, Max: %d", summary.risk_score_sum, summary.max_risk_score);
|
||||
ssd1306_text_line(SSD1306_ADDRESS, buffer, 5, false);
|
||||
get_status = false;
|
||||
}
|
||||
}
|
||||
else if (!get_status)
|
||||
{
|
||||
ssd1306_clear_line(SSD1306_ADDRESS, 2, false);
|
||||
ssd1306_clear_line(SSD1306_ADDRESS, 3, false);
|
||||
ssd1306_clear_line(SSD1306_ADDRESS, 4, false);
|
||||
get_status = true;
|
||||
}
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void interface_display_idle(void *pvParameter)
|
||||
{
|
||||
static bool set_status = true;
|
||||
while (1)
|
||||
{
|
||||
if (ena_interface_get_state() == ENA_INTERFACE_STATE_IDLE)
|
||||
{
|
||||
if (set_status)
|
||||
{
|
||||
ssd1306_on(SSD1306_ADDRESS, false);
|
||||
set_status = false;
|
||||
}
|
||||
}
|
||||
else if (!set_status)
|
||||
{
|
||||
ssd1306_on(SSD1306_ADDRESS, true);
|
||||
set_status = true;
|
||||
}
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// debug only own LOG TAGs
|
||||
esp_log_level_set("*", ESP_LOG_WARN);
|
||||
esp_log_level_set(ENA_LOG, ESP_LOG_DEBUG);
|
||||
esp_log_level_set(ENA_BEACON_LOG, ESP_LOG_DEBUG);
|
||||
esp_log_level_set(ENA_ADVERTISE_LOG, ESP_LOG_DEBUG);
|
||||
esp_log_level_set(ENA_SCAN_LOG, ESP_LOG_DEBUG);
|
||||
esp_log_level_set(ENA_EXPOSURE_LOG, ESP_LOG_DEBUG);
|
||||
esp_log_level_set(ENA_STORAGE_LOG, ESP_LOG_INFO);
|
||||
esp_log_level_set(ENA_CWA_LOG, ESP_LOG_DEBUG);
|
||||
esp_log_level_set(ENA_INTERFACE_LOG, ESP_LOG_DEBUG);
|
||||
esp_log_level_set(WIFI_LOG, ESP_LOG_DEBUG);
|
||||
|
||||
// set system time from DS3231
|
||||
struct tm rtc_time;
|
||||
ds3231_get_time(&rtc_time);
|
||||
curtime = mktime(&rtc_time);
|
||||
|
||||
time_t curtime = mktime(&rtc_time);
|
||||
struct timeval tv = {0};
|
||||
tv.tv_sec = curtime;
|
||||
settimeofday(&tv, NULL);
|
||||
esp_log_level_set(ENA_STORAGE_LOG, ESP_LOG_INFO);
|
||||
|
||||
// Hardcoded timezome of UTC+2 for now (consider POSIX notation!)
|
||||
setenv("TZ", "UTC-2", 1);
|
||||
tzset();
|
||||
|
||||
ssd1306_start(SSD1306_ADDRESS);
|
||||
ssd1306_clear(SSD1306_ADDRESS);
|
||||
|
||||
ena_interface_start();
|
||||
ena_interface_menu_start();
|
||||
|
||||
ena_start();
|
||||
|
||||
xTaskCreate(&interface_display_time, "interface_display_time", 4096, NULL, 5, NULL);
|
||||
xTaskCreate(&interface_display_status, "interface_display_status", 4096, NULL, 5, NULL);
|
||||
xTaskCreate(&interface_display_idle, "interface_display_idle", 4096, NULL, 5, NULL);
|
||||
while (1)
|
||||
{
|
||||
ena_run();
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
// Copyright 2020 Lukas Haubaum
|
||||
//
|
||||
// Licensed under the GNU Affero General Public License, Version 3;
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// https://www.gnu.org/licenses/agpl-3.0.html
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <string.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sys.h"
|
||||
|
||||
#include "ena-cwa.h"
|
||||
|
||||
#include "wifi.h"
|
||||
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
static EventGroupHandle_t s_wifi_event_group;
|
||||
|
||||
static int s_retry_num = 0;
|
||||
|
||||
static bool connected = false;
|
||||
|
||||
void wifi_stop(void)
|
||||
{
|
||||
connected = false;
|
||||
esp_wifi_stop();
|
||||
esp_wifi_deinit();
|
||||
esp_event_loop_delete_default();
|
||||
}
|
||||
|
||||
static void event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START)
|
||||
{
|
||||
esp_wifi_connect();
|
||||
}
|
||||
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED)
|
||||
{
|
||||
if (s_retry_num < WIFI_MAXIMUM_RETRY)
|
||||
{
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
ESP_LOGD(WIFI_LOG, "retry to connect to the AP");
|
||||
}
|
||||
else
|
||||
{
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
ESP_LOGD(WIFI_LOG, "connect to the AP fail");
|
||||
connected = false;
|
||||
}
|
||||
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP)
|
||||
{
|
||||
s_retry_num = 0;
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
connected = true;
|
||||
|
||||
heap_caps_check_integrity_all(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGD(WIFI_LOG, "eventbase %s, eventid %d", event_base, event_id);
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_start(void)
|
||||
{
|
||||
|
||||
// init NVS for WIFI
|
||||
esp_err_t ret;
|
||||
ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
|
||||
{
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
}
|
||||
|
||||
s_wifi_event_group = xEventGroupCreate();
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
esp_netif_create_default_wifi_sta();
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
esp_event_handler_instance_t instance_got_ip;
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_any_id));
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_got_ip));
|
||||
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = WIFI_SSID,
|
||||
.password = WIFI_PASSWORD,
|
||||
/* Setting a password implies station will connect to all security modes including WEP/WPA.
|
||||
* However these modes are deprecated and not advisable to be used. Incase your Access point
|
||||
* doesn't support WPA2, these mode can be enabled by commenting below line */
|
||||
.threshold.authmode = WIFI_AUTH_WPA2_PSK,
|
||||
|
||||
.pmf_cfg = {
|
||||
.capable = true,
|
||||
.required = false},
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
|
||||
* number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */
|
||||
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
|
||||
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
|
||||
pdFALSE,
|
||||
pdFALSE,
|
||||
portMAX_DELAY);
|
||||
|
||||
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
|
||||
* happened. */
|
||||
if (bits & WIFI_CONNECTED_BIT)
|
||||
{
|
||||
ESP_LOGV(WIFI_LOG, "connected to ap SSID:%s",
|
||||
WIFI_SSID);
|
||||
}
|
||||
else if (bits & WIFI_FAIL_BIT)
|
||||
{
|
||||
ESP_LOGI(WIFI_LOG, "Failed to connect to SSID:%s",
|
||||
WIFI_SSID);
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(WIFI_LOG, "UNEXPECTED EVENT");
|
||||
}
|
||||
|
||||
/* The event will not be processed after unregister */
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, instance_got_ip));
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, instance_any_id));
|
||||
vEventGroupDelete(s_wifi_event_group);
|
||||
}
|
||||
|
||||
bool wifi_is_connected(void)
|
||||
{
|
||||
return connected;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// Copyright 2020 Lukas Haubaum
|
||||
//
|
||||
// Licensed under the GNU Affero General Public License, Version 3;
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// https://www.gnu.org/licenses/agpl-3.0.html
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef _wifi_H_
|
||||
#define _wifi_H_
|
||||
|
||||
#define WIFI_LOG "ESP-ENA-wifi" // TAG for Logging
|
||||
|
||||
#define WIFI_SSID (CONFIG_WIFI_SSID)
|
||||
#define WIFI_PASSWORD (CONFIG_WIFI_PASSWORD)
|
||||
#define WIFI_MAXIMUM_RETRY (CONFIG_WIFI_MAXIMUM_RETRY)
|
||||
|
||||
/**
|
||||
* @brief start wifi connection to configured AP
|
||||
*/
|
||||
void wifi_start(void);
|
||||
|
||||
/**
|
||||
* @brief stop wifi (restart does not work for now!)
|
||||
*/
|
||||
void wifi_stop(void);
|
||||
|
||||
/**
|
||||
* @brief check if a wifi is connected
|
||||
*/
|
||||
bool wifi_is_connected(void);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user