ajout capteur presence

This commit is contained in:
marc 2025-04-27 19:22:17 +02:00
parent e8b2be0023
commit 2000e459c9
4 changed files with 86 additions and 59 deletions

View File

@ -320,7 +320,6 @@ static EventGroupHandle_t s_wifi_event_group;
#define EXAMPLE_ESP_MAXIMUM_RETRY 5
#define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_BOTH
#define EXAMPLE_H2E_IDENTIFIER CONFIG_ESP_WIFI_PW_ID
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
static int s_retry_num = 0;
@ -434,7 +433,7 @@ void wifi_init_sta(void)
*/
.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
.sae_pwe_h2e = ESP_WIFI_SAE_MODE,
.sae_h2e_identifier = EXAMPLE_H2E_IDENTIFIER,
.sae_h2e_identifier = "",
},
};
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));

View File

@ -2,7 +2,7 @@ set(EXTRA_COMPONENT_DIRS ../components)
idf_component_register(SRC_DIRS . fonts
INCLUDE_DIRS "."
REQUIRES heap nvs_flash meteofrance communication esp_netif image_downloader fatfs sdmmc vfs littlefs wifi_logger protocol_examples_common app_update esp_https_ota bsp_extra esp32_p4_function_ev_board
REQUIRES heap nvs_flash meteofrance communication esp_netif image_downloader fatfs sdmmc vfs littlefs wifi_logger protocol_examples_common app_update esp_https_ota bsp_extra esp32_p4_function_ev_board esp_driver_gpio
EMBED_TXTFILES ${project_dir}/main/ca_cert.pem)

View File

@ -1,4 +1,4 @@
menu "Example Configuration"
menu "Domotic Configuration"
config ESP_WIFI_SSID
string "WiFi SSID"
@ -12,56 +12,11 @@ menu "Example Configuration"
help
WiFi password (WPA or WPA2) for the example to use.
choice ESP_WIFI_SAE_MODE
prompt "WPA3 SAE mode selection"
default ESP_WPA3_SAE_PWE_BOTH
config GPIO_INPUT_CAPTEUR_PIR
int "GPIO PIN Capteur PIR"
range ENV_GPIO_RANGE_MIN ENV_GPIO_IN_RANGE_MAX
default 4
help
Select mode for SAE as Hunt and Peck, H2E or both.
config ESP_WPA3_SAE_PWE_HUNT_AND_PECK
bool "HUNT AND PECK"
config ESP_WPA3_SAE_PWE_HASH_TO_ELEMENT
bool "H2E"
config ESP_WPA3_SAE_PWE_BOTH
bool "BOTH"
endchoice
config ESP_WIFI_PW_ID
string "PASSWORD IDENTIFIER"
depends on ESP_WPA3_SAE_PWE_HASH_TO_ELEMENT|| ESP_WPA3_SAE_PWE_BOTH
default ""
help
password identifier for SAE H2E
config ESP_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 ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD
prompt "WiFi Scan auth mode threshold"
default ESP_WIFI_AUTH_WPA2_PSK
help
The weakest authmode to accept in the scan mode.
This value defaults to ESP_WIFI_AUTH_WPA2_PSK incase password is present and ESP_WIFI_AUTH_OPEN is used.
Please select ESP_WIFI_AUTH_WEP/ESP_WIFI_AUTH_WPA_PSK incase AP is operating in WEP/WPA mode.
config ESP_WIFI_AUTH_OPEN
bool "OPEN"
config ESP_WIFI_AUTH_WEP
bool "WEP"
config ESP_WIFI_AUTH_WPA_PSK
bool "WPA PSK"
config ESP_WIFI_AUTH_WPA2_PSK
bool "WPA2 PSK"
config ESP_WIFI_AUTH_WPA_WPA2_PSK
bool "WPA/WPA2 PSK"
config ESP_WIFI_AUTH_WPA3_PSK
bool "WPA3 PSK"
config ESP_WIFI_AUTH_WPA2_WPA3_PSK
bool "WPA2/WPA3 PSK"
config ESP_WIFI_AUTH_WAPI_PSK
bool "WAPI PSK"
endchoice
GPIO pin à utiliser pour le capteur de présence IR.
endmenu

View File

@ -29,9 +29,11 @@
#include "image_downloader.h"
#include "communication.h"
#include "stateManagement.h"
#include "driver/gpio.h"
#include "am2302_rmt.h"
#include "esp_timer.h"
// GPIO assignment
#define AM2302_GPIO 4
@ -237,9 +239,81 @@ void alloc_fail(size_t size, uint32_t caps, const char * function_name){
ESP_LOGE(TAG,"fail alloc %u in %" PRIu32 " in %s", size,caps,function_name);
}
static QueueHandle_t gpio_evt_queue = NULL;
esp_timer_handle_t periodic_timer;
static void IRAM_ATTR gpio_isr_handler(void* arg)
{
uint32_t gpio_num = (uint32_t) arg;
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
}
static void gpio_task_example(void* arg)
{
uint32_t io_num;
int delay=50;
for (;;) {
if (xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
ESP_LOGE(TAG,"Got it !");
for (int i = 0; i < 100; i++)
{
bsp_display_brightness_set(i);
vTaskDelay(delay/portTICK_PERIOD_MS);
}
//On arrete le timer de presence
esp_timer_stop(periodic_timer);
//Pour le redemarrer
ESP_ERROR_CHECK(esp_timer_start_once(periodic_timer, 10*1000*1000));
}
}
}
#define GPIO_INPUT_IO_0 CONFIG_GPIO_INPUT_CAPTEUR_PIR
void initPirSensor(){
//create a queue to handle gpio event from isr
gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
//start gpio task
xTaskCreate(gpio_task_example, "gpio_task_example", 5000, NULL, 10, NULL);
gpio_config_t gpioconf={
.pin_bit_mask= 1ULL<<GPIO_INPUT_IO_0,
.intr_type=GPIO_INTR_POSEDGE,
.mode=GPIO_MODE_INPUT,
.pull_up_en=1
};
ESP_ERROR_CHECK(gpio_config(&gpioconf));
gpio_install_isr_service(0);
gpio_isr_handler_add(GPIO_INPUT_IO_0,gpio_isr_handler,(void*)(GPIO_INPUT_IO_0));
}
/* Ce timer permet d'eteindre l'ecran apres 30s de présence*/
static void periodic_timer_callback(void* arg)
{
int64_t time_since_boot = esp_timer_get_time();
ESP_LOGI(TAG, "Periodic timer called, time since boot: %lld us", time_since_boot);
for (int i = 100; i >= 0; i--)
{
bsp_display_brightness_set(i);
vTaskDelay(20/portTICK_PERIOD_MS);
}
}
void app_main(void)
{
const esp_timer_create_args_t periodic_timer_args = {
.callback = &periodic_timer_callback,
/* name is optional, but may help identify the timer when debugging */
.name = "presence"
};
ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer));
/* Start the timers */
ESP_ERROR_CHECK(esp_timer_start_once(periodic_timer, 30*1000*1000));
initPirSensor();
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
printf("Free heap size: %" PRIu32 " bytes\n", esp_get_free_heap_size());
heap_caps_print_heap_info(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
@ -378,8 +452,7 @@ void app_main(void)
mqtt_app_start();
/*
// Configuration de la sonde Temp/Humid.
am2302_config_t am2302_config = {
.gpio_num = AM2302_GPIO,
@ -391,7 +464,7 @@ void app_main(void)
xTaskCreate(&readTempHumid, "read_temp_task", 8192, NULL, 5, NULL);
*/
//xTaskCreate(&simple_ota_example_task, "ota_example_task", 8192, NULL, 5, NULL);