feat: support configuration using menuconfig.
This commit is contained in:
parent
dc568e9a21
commit
3184a00bc6
65
main/Kconfig.projbuild
Normal file
65
main/Kconfig.projbuild
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
menu "Display Ambientlight Configuration"
|
||||||
|
config NUMBER_OF_LEDS
|
||||||
|
int "Number of LEDs in the light strip"
|
||||||
|
range 1 65535
|
||||||
|
default 8
|
||||||
|
help
|
||||||
|
Number of LEDs in the light strip.
|
||||||
|
Used to define buffer bytes length.
|
||||||
|
endmenu
|
||||||
|
|
||||||
|
menu "Wi-Fi Configuration"
|
||||||
|
|
||||||
|
config WIFI_SSID
|
||||||
|
string "WiFi SSID"
|
||||||
|
default "Ivan"
|
||||||
|
help
|
||||||
|
SSID (network name) for the example to connect to.
|
||||||
|
|
||||||
|
config WIFI_PASSWORD
|
||||||
|
string "WiFi Password"
|
||||||
|
default "ivanli.cc"
|
||||||
|
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.
|
||||||
|
|
||||||
|
choice WIFI_SCAN_AUTH_MODE_THRESHOLD
|
||||||
|
prompt "WiFi Scan auth mode threshold"
|
||||||
|
default ESP_WIFI_AUTH_OPEN
|
||||||
|
help
|
||||||
|
The weakest authmode to accept in the scan mode.
|
||||||
|
|
||||||
|
config WIFI_AUTH_OPEN
|
||||||
|
bool "OPEN"
|
||||||
|
config WIFI_AUTH_WEP
|
||||||
|
bool "WEP"
|
||||||
|
config WIFI_AUTH_WPA_PSK
|
||||||
|
bool "WPA PSK"
|
||||||
|
config WIFI_AUTH_WPA2_PSK
|
||||||
|
bool "WPA2 PSK"
|
||||||
|
config WIFI_AUTH_WPA_WPA2_PSK
|
||||||
|
bool "WPA/WPA2 PSK"
|
||||||
|
config WIFI_AUTH_WPA3_PSK
|
||||||
|
bool "WPA3 PSK"
|
||||||
|
config WIFI_AUTH_WPA2_WPA3_PSK
|
||||||
|
bool "WPA2/WPA3 PSK"
|
||||||
|
config WIFI_AUTH_WAPI_PSK
|
||||||
|
bool "WAPI PSK"
|
||||||
|
endchoice
|
||||||
|
|
||||||
|
endmenu
|
||||||
|
|
||||||
|
menu "MQTT Configuration"
|
||||||
|
|
||||||
|
config MQTT_BROKER_URL
|
||||||
|
string "Broker URL"
|
||||||
|
default "mqtt://mqtt.eclipseprojects.io"
|
||||||
|
help
|
||||||
|
URL of the broker to connect to
|
||||||
|
|
||||||
|
endmenu
|
@ -12,6 +12,8 @@
|
|||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "mqtt_client.h"
|
#include "mqtt_client.h"
|
||||||
|
|
||||||
|
#define MQTT_BROKER_URL CONFIG_MQTT_BROKER_URL
|
||||||
|
|
||||||
#define MQTT_FAILED_BIT BIT0
|
#define MQTT_FAILED_BIT BIT0
|
||||||
#define MQTT_CONNECTED_BIT BIT1
|
#define MQTT_CONNECTED_BIT BIT1
|
||||||
#define MQTT_DISCONNECTED_BIT BIT2
|
#define MQTT_DISCONNECTED_BIT BIT2
|
||||||
@ -33,6 +35,7 @@
|
|||||||
static const char *MQTT_TAG = "ScreenBgLight_MQTT";
|
static const char *MQTT_TAG = "ScreenBgLight_MQTT";
|
||||||
|
|
||||||
static EventGroupHandle_t s_mqtt_event_group;
|
static EventGroupHandle_t s_mqtt_event_group;
|
||||||
|
static uint8_t *colors;
|
||||||
|
|
||||||
static void log_error_if_nonzero(const char *message, int error_code) {
|
static void log_error_if_nonzero(const char *message, int error_code) {
|
||||||
if (error_code != 0) {
|
if (error_code != 0) {
|
||||||
@ -107,7 +110,7 @@ static void mqtt_app_start() {
|
|||||||
s_mqtt_event_group = xEventGroupCreate();
|
s_mqtt_event_group = xEventGroupCreate();
|
||||||
|
|
||||||
const esp_mqtt_client_config_t mqtt_cfg = {
|
const esp_mqtt_client_config_t mqtt_cfg = {
|
||||||
.uri = "mqtt://192.168.31.11",
|
.uri = MQTT_BROKER_URL,
|
||||||
};
|
};
|
||||||
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
|
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
|
||||||
esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler,
|
esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler,
|
||||||
|
40
main/wifi.c
40
main/wifi.c
@ -25,11 +25,27 @@
|
|||||||
If you'd rather not, just change the below entries to strings with
|
If you'd rather not, just change the below entries to strings with
|
||||||
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
|
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
|
||||||
*/
|
*/
|
||||||
#define EXAMPLE_ESP_WIFI_SSID "Ivan"
|
#define WIFI_SSID CONFIG_WIFI_SSID
|
||||||
#define EXAMPLE_ESP_WIFI_PASS "ivanli.cc"
|
#define WIFI_PASS CONFIG_WIFI_PASSWORD
|
||||||
#define EXAMPLE_ESP_MAXIMUM_RETRY 5
|
#define MAXIMUM_RETRY CONFIG_WIFI_MAXIMUM_RETRY
|
||||||
|
|
||||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK
|
#if CONFIG_WIFI_AUTH_OPEN
|
||||||
|
#define WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_OPEN
|
||||||
|
#elif CONFIG_WIFI_AUTH_WEP
|
||||||
|
#define WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WEP
|
||||||
|
#elif CONFIG_WIFI_AUTH_WPA_PSK
|
||||||
|
#define WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_PSK
|
||||||
|
#elif CONFIG_WIFI_AUTH_WPA2_PSK
|
||||||
|
#define WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
|
||||||
|
#elif CONFIG_WIFI_AUTH_WPA_WPA2_PSK
|
||||||
|
#define WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK
|
||||||
|
#elif CONFIG_WIFI_AUTH_WPA3_PSK
|
||||||
|
#define WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA3_PSK
|
||||||
|
#elif CONFIG_WIFI_AUTH_WPA2_WPA3_PSK
|
||||||
|
#define WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_WPA3_PSK
|
||||||
|
#elif CONFIG_WIFI_AUTH_WAPI_PSK
|
||||||
|
#define WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WAPI_PSK
|
||||||
|
#endif
|
||||||
|
|
||||||
/* FreeRTOS event group to signal when we are connected*/
|
/* FreeRTOS event group to signal when we are connected*/
|
||||||
static EventGroupHandle_t s_wifi_event_group;
|
static EventGroupHandle_t s_wifi_event_group;
|
||||||
@ -51,7 +67,7 @@ static void event_handler(void* arg, esp_event_base_t event_base,
|
|||||||
esp_wifi_connect();
|
esp_wifi_connect();
|
||||||
} else if (event_base == WIFI_EVENT &&
|
} else if (event_base == WIFI_EVENT &&
|
||||||
event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||||
if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) {
|
if (s_retry_num < MAXIMUM_RETRY) {
|
||||||
esp_wifi_connect();
|
esp_wifi_connect();
|
||||||
s_retry_num++;
|
s_retry_num++;
|
||||||
ESP_LOGI(WIFI_TAG, "retry to connect to the AP");
|
ESP_LOGI(WIFI_TAG, "retry to connect to the AP");
|
||||||
@ -88,14 +104,14 @@ bool wifi_init_sta(void) {
|
|||||||
wifi_config_t wifi_config = {
|
wifi_config_t wifi_config = {
|
||||||
.sta =
|
.sta =
|
||||||
{
|
{
|
||||||
.ssid = EXAMPLE_ESP_WIFI_SSID,
|
.ssid = WIFI_SSID,
|
||||||
.password = EXAMPLE_ESP_WIFI_PASS,
|
.password = WIFI_PASS,
|
||||||
/* Setting a password implies station will connect to all security
|
/* Setting a password implies station will connect to all security
|
||||||
* modes including WEP/WPA. However these modes are deprecated and
|
* modes including WEP/WPA. However these modes are deprecated and
|
||||||
* not advisable to be used. Incase your Access point doesn't
|
* not advisable to be used. Incase your Access point doesn't
|
||||||
* support WPA2, these mode can be enabled by commenting below
|
* support WPA2, these mode can be enabled by commenting below
|
||||||
* line */
|
* line */
|
||||||
.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
|
.threshold.authmode = WIFI_SCAN_AUTH_MODE_THRESHOLD,
|
||||||
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
|
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -116,11 +132,11 @@ bool wifi_init_sta(void) {
|
|||||||
* can test which event actually happened. */
|
* can test which event actually happened. */
|
||||||
if (bits & WIFI_CONNECTED_BIT) {
|
if (bits & WIFI_CONNECTED_BIT) {
|
||||||
connected = 1;
|
connected = 1;
|
||||||
ESP_LOGI(WIFI_TAG, "connected to ap SSID:%s password:%s",
|
ESP_LOGI(WIFI_TAG, "connected to ap SSID:%s password:%s", WIFI_SSID,
|
||||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
WIFI_PASS);
|
||||||
} else if (bits & WIFI_FAIL_BIT) {
|
} else if (bits & WIFI_FAIL_BIT) {
|
||||||
ESP_LOGI(WIFI_TAG, "Failed to connect to SSID:%s, password:%s",
|
ESP_LOGI(WIFI_TAG, "Failed to connect to SSID:%s, password:%s", WIFI_SSID,
|
||||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
WIFI_PASS);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(WIFI_TAG, "UNEXPECTED EVENT");
|
ESP_LOGE(WIFI_TAG, "UNEXPECTED EVENT");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user