Merge branch 'main' into feat/i18n-zh
This commit is contained in:
commit
ae61416468
104 files changed
+33385
-693
No files matched your search
@@ -0,0 +1,29 @@
|
||||
#include <WiFi.h>
|
||||
|
||||
// Ersetzen Sie dies durch Ihre Wi-Fi-Zugangsdaten
|
||||
const char* ssid = "NAME_IHRES_WIFI_NETZWERKS";
|
||||
const char* password = "PASSWORT_IHRES_WIFI_NETZWERKS";
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
Serial.println("Verbindung zum Wi-Fi wird aufgebaut...");
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
// Verbindung wird abgewartet
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("Wi-Fi erfolgreich verbunden!");
|
||||
Serial.print("IP-Adresse: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Aqui você pode colocar o código principal do seu programa
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#include "esp_log.h"
|
||||
#include "audio_pipeline.h"
|
||||
#include "audio_element.h"
|
||||
#include "audio_event_iface.h"
|
||||
#include "audio_common.h"
|
||||
#include "i2s_stream.h"
|
||||
#include "mp3_decoder.h"
|
||||
#include "fatfs_stream.h"
|
||||
#include "esp_peripherals.h"
|
||||
#include "periph_sdcard.h"
|
||||
|
||||
static const char *TAG = "HELLO_ADF";
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Inicializa periféricos (como o SD card)
|
||||
esp_periph_config_t periph_cfg = DEFAULT_ESP_PERIPH_SET_CONFIG();
|
||||
esp_periph_set_handle_t set = esp_periph_set_init(&periph_cfg);
|
||||
periph_sdcard_cfg_t sd_cfg = {
|
||||
.root = "/sdcard",
|
||||
};
|
||||
esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sd_cfg);
|
||||
esp_periph_start(set, sdcard_handle);
|
||||
|
||||
// Espera o SD card montar
|
||||
periph_sdcard_wait_for_ready(sdcard_handle, portMAX_DELAY);
|
||||
|
||||
ESP_LOGI(TAG, "SD card montado!");
|
||||
|
||||
// Cria o pipeline
|
||||
audio_pipeline_handle_t pipeline;
|
||||
audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG();
|
||||
pipeline = audio_pipeline_init(&pipeline_cfg);
|
||||
|
||||
// Elementos: arquivo (fatfs), decodificador (mp3) e saída (i2s)
|
||||
audio_element_handle_t fatfs_stream_reader, i2s_stream_writer, mp3_decoder;
|
||||
|
||||
fatfs_stream_cfg_t fatfs_cfg = FATFS_STREAM_CFG_DEFAULT();
|
||||
fatfs_cfg.type = AUDIO_STREAM_READER;
|
||||
fatfs_stream_reader = fatfs_stream_init(&fatfs_cfg);
|
||||
|
||||
mp3_decoder_cfg_t mp3_cfg = DEFAULT_MP3_DECODER_CONFIG();
|
||||
mp3_decoder = mp3_decoder_init(&mp3_cfg);
|
||||
|
||||
i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT();
|
||||
i2s_cfg.type = AUDIO_STREAM_WRITER;
|
||||
i2s_stream_writer = i2s_stream_init(&i2s_cfg);
|
||||
|
||||
// Registra e conecta elementos
|
||||
audio_pipeline_register(pipeline, fatfs_stream_reader, "file");
|
||||
audio_pipeline_register(pipeline, mp3_decoder, "mp3");
|
||||
audio_pipeline_register(pipeline, i2s_stream_writer, "i2s");
|
||||
|
||||
audio_pipeline_link(pipeline, (const char *[]) {"file", "mp3", "i2s"}, 3);
|
||||
|
||||
// Define o arquivo MP3 a ser tocado
|
||||
audio_element_set_uri(fatfs_stream_reader, "/sdcard/test.mp3");
|
||||
|
||||
// Inicia o pipeline
|
||||
ESP_LOGI(TAG, "Iniciando pipeline...");
|
||||
audio_pipeline_run(pipeline);
|
||||
|
||||
// Mantém o pipeline rodando
|
||||
while (1) {
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
// (Nunca chega aqui, mas seria o cleanup)
|
||||
audio_pipeline_stop(pipeline);
|
||||
audio_pipeline_wait_for_stop(pipeline);
|
||||
audio_pipeline_terminate(pipeline);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include "esp_dsp.h"
|
||||
|
||||
#define N 8 // Tamanho do vetor
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Vetor de entrada (exemplo de sinal)
|
||||
float x[N] = {1.0, -2.0, 3.0, -4.0, 2.5, -1.5, 0.0, 4.5};
|
||||
float y[N]; // Vetor de saída
|
||||
|
||||
// Inicializa o ESP-DSP
|
||||
esp_err_t ret = dsps_fft2r_init_fc32(NULL, CONFIG_DSP_MAX_FFT_SIZE);
|
||||
if (ret != ESP_OK) {
|
||||
printf("Erro ao inicializar o ESP-DSP!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Sinal de entrada:\n");
|
||||
for (int i = 0; i < N; i++) {
|
||||
printf("%f ", x[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// Calcula o quadrado de cada valor
|
||||
dsps_mulc_f32(x, y, N, 1.0f);
|
||||
dsps_mul_f32(y, y, y, N, 1, 1, 1);
|
||||
|
||||
// Soma todos os quadrados
|
||||
float soma = 0;
|
||||
dsps_sum_f32(y, N, &soma, 1);
|
||||
|
||||
// Calcula a magnitude (raiz da soma dos quadrados)
|
||||
float magnitude = sqrtf(soma);
|
||||
|
||||
printf("Magnitude do vetor: %f\n", magnitude);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* ESP-IDF v5.x+ Beispiel für ESP32
|
||||
* Demonstration von Systeminitialisierung, FreeRTOS-Task-Management und einheitlichem Logging
|
||||
*
|
||||
* Komponentenverwaltung (main/idf_component.yml):
|
||||
* dependencies:
|
||||
* espressif/led_strip: "^2.5.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_chip_info.h"
|
||||
|
||||
static const char *TAG = "main_app";
|
||||
|
||||
#define BLINK_GPIO GPIO_NUM_2 // Passen Sie dies an den LED-Pin Ihres Boards an
|
||||
|
||||
static void blink_task(void *pvParameters)
|
||||
{
|
||||
// Konfiguriert den GPIO-Pin mit der neuen ESP-IDF-API
|
||||
gpio_reset_pin(BLINK_GPIO);
|
||||
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
|
||||
|
||||
bool led_state = false;
|
||||
|
||||
while (1) {
|
||||
led_state = !led_state;
|
||||
gpio_set_level(BLINK_GPIO, led_state);
|
||||
|
||||
ESP_LOGI(TAG, "LED %s | Freier Heap: %lu Bytes",
|
||||
led_state ? "EIN" : "AUS",
|
||||
(unsigned long)esp_get_free_heap_size());
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Informações do chip SoC
|
||||
esp_chip_info_t chip_info;
|
||||
esp_chip_info(&chip_info);
|
||||
|
||||
ESP_LOGI(TAG, "===========================================");
|
||||
ESP_LOGI(TAG, " Iniciando ESP-IDF v5.x Modern Application ");
|
||||
ESP_LOGI(TAG, " Modelo do Chip: %d | Núcleos: %d | Rev: %d",
|
||||
chip_info.model, chip_info.cores, chip_info.revision);
|
||||
ESP_LOGI(TAG, "===========================================");
|
||||
|
||||
// Cria uma tarefa FreeRTOS dedicada
|
||||
xTaskCreate(blink_task, "blink_task", 3072, NULL, 5, NULL);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Exemplo ESP-IoT-Solution para ESP32
|
||||
* Inicialização de Botão Inteligente com Callbacks e Driver de Display/Sensores
|
||||
*
|
||||
* Dependência (idf_component.yml):
|
||||
* espressif/button: "^3.3.0"
|
||||
* espressif/led_indicator: "^1.2.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "iot_button.h"
|
||||
#include "led_indicator.h"
|
||||
|
||||
static const char *TAG = "iot_solution_app";
|
||||
|
||||
#define BUTTON_GPIO_NUM 0 // Botão BOOT nativo
|
||||
#define LED_INDICATOR_GPIO 2 // LED indicador
|
||||
|
||||
static led_indicator_handle_t led_handle = NULL;
|
||||
|
||||
/* Callback para clique único do botão */
|
||||
static void button_single_click_cb(void *arg, void *data)
|
||||
{
|
||||
ESP_LOGI(TAG, "Evento: Clique Único detectado!");
|
||||
led_indicator_start(led_handle, BLINK_DOUBLE_FAST);
|
||||
}
|
||||
|
||||
/* Callback para clique longo (> 3 segundos) */
|
||||
static void button_long_press_cb(void *arg, void *data)
|
||||
{
|
||||
ESP_LOGW(TAG, "Evento: Pressionamento Longo! Acionando modo de reset de fábrica.");
|
||||
led_indicator_start(led_handle, BLINK_BREATHE_FAST);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Iniciando ESP-IoT-Solution Component Suite");
|
||||
|
||||
// 1. Configuração do LED Indicator
|
||||
led_indicator_gpio_config_t led_cfg = {
|
||||
.is_active_level_high = true,
|
||||
.gpio_num = LED_INDICATOR_GPIO,
|
||||
};
|
||||
led_handle = led_indicator_create(&led_cfg);
|
||||
|
||||
// 2. Configuração do Botão com debounce de hardware/software automático
|
||||
button_config_t btn_cfg = {
|
||||
.type = BUTTON_TYPE_GPIO,
|
||||
.long_press_time = 3000,
|
||||
.short_press_time = 180,
|
||||
.gpio_button_config = {
|
||||
.gpio_num = BUTTON_GPIO_NUM,
|
||||
.active_level = 0,
|
||||
},
|
||||
};
|
||||
|
||||
button_handle_t btn_handle = iot_button_create(&btn_cfg);
|
||||
assert(btn_handle != NULL);
|
||||
|
||||
// Registra callbacks para diferentes gestos
|
||||
iot_button_register_cb(btn_handle, BUTTON_SINGLE_CLICK, button_single_click_cb, NULL);
|
||||
iot_button_register_cb(btn_handle, BUTTON_LONG_PRESS_START, button_long_press_cb, NULL);
|
||||
|
||||
ESP_LOGI(TAG, "Drivers inicializados com sucesso! Pressione o botão GPIO 0.");
|
||||
|
||||
while (1) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include "esp_log.h"
|
||||
#include "esp_matter.h"
|
||||
#include "esp_matter_controller.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
static const char *TAG = "esp-matter-example";
|
||||
|
||||
void app_event_cb(const esp_matter_event_t *event)
|
||||
{
|
||||
switch (event->event_id) {
|
||||
case ESP_MATTER_EVENT_ATTRIBUTE_UPDATE: {
|
||||
const esp_matter_attr_update_t *attr_update = &event->data.attr_update;
|
||||
if (attr_update->endpoint_id == 1 && attr_update->cluster_id == ESP_MATTER_ON_OFF_CLUSTER_ID) {
|
||||
bool on = false;
|
||||
esp_matter_attribute_get(attr_update->endpoint_id, attr_update->cluster_id,
|
||||
attr_update->attribute_id, &on);
|
||||
ESP_LOGI(TAG, "Lâmpada %s", on ? "ligada" : "desligada");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Inicializa NVS
|
||||
esp_err_t err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
}
|
||||
|
||||
// Inicializa o Matter node
|
||||
esp_matter::node_t *node = esp_matter::node::create(NULL, app_event_cb);
|
||||
esp_matter::endpoint_t *endpoint = esp_matter::endpoint::create(node, ESP_MATTER_ENDPOINT_TYPE_ON_OFF_LIGHT);
|
||||
|
||||
// Inicia o stack Matter
|
||||
ESP_ERROR_CHECK(esp_matter::start(node));
|
||||
|
||||
ESP_LOGI(TAG, "Dispositivo Matter iniciado. Aguardando comissionamento...");
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include "esp_nn.h"
|
||||
#include "esp_nn_defs.h"
|
||||
|
||||
#define INPUT_SIZE 4
|
||||
#define OUTPUT_SIZE 3
|
||||
|
||||
void print_array(const char *label, int16_t *array, int size) {
|
||||
printf("%s: ", label);
|
||||
for (int i = 0; i < size; i++) {
|
||||
printf("%d ", array[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Vetor de entrada (ex: saída de uma camada anterior)
|
||||
int16_t input[INPUT_SIZE] = {1, 2, 3, 4};
|
||||
|
||||
// Pesos da camada densa (3x4)
|
||||
int8_t weights[OUTPUT_SIZE * INPUT_SIZE] = {
|
||||
1, -1, 2, 0,
|
||||
0, 1, -1, 1,
|
||||
2, 0, 1, -2
|
||||
};
|
||||
|
||||
// Bias de cada neurônio
|
||||
int16_t bias[OUTPUT_SIZE] = {10, -5, 0};
|
||||
|
||||
// Saída
|
||||
int16_t output[OUTPUT_SIZE];
|
||||
|
||||
// Multiplicação da matriz: output = weights * input + bias
|
||||
esp_nn_mul_mat_16x8_16(weights, input, bias, output,
|
||||
OUTPUT_SIZE, INPUT_SIZE, /*shift=*/0);
|
||||
|
||||
print_array("Antes da ReLU", output, OUTPUT_SIZE);
|
||||
|
||||
// Aplicar função de ativação ReLU
|
||||
esp_nn_relu_16(output, OUTPUT_SIZE);
|
||||
|
||||
print_array("Depois da ReLU", output, OUTPUT_SIZE);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Exemplo ESP-NOW para ESP32
|
||||
* Comunicação Sem Fio Ponto-a-Ponto e Broadcast sem roteador Wi-Fi
|
||||
*
|
||||
* Protocolo nativo integrado no ESP-IDF
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_now.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
static const char *TAG = "esp_now_demo";
|
||||
|
||||
// Estrutura de dados enviada no pacote
|
||||
typedef struct {
|
||||
uint32_t sensor_id;
|
||||
float temperatura;
|
||||
float umidade;
|
||||
uint32_t tempo_ms;
|
||||
} __attribute__((packed)) dados_pacote_t;
|
||||
|
||||
// Endereço MAC de Broadcast (envia para todos os nós ESP-NOW por perto)
|
||||
static const uint8_t broadcast_mac[ESP_NOW_ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
|
||||
/* Callback executado ao enviar um pacote */
|
||||
static void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status)
|
||||
{
|
||||
ESP_LOGI(TAG, "Envio concluído: %s", status == ESP_NOW_SEND_SUCCESS ? "SUCESSO (ACK)" : "FALHA");
|
||||
}
|
||||
|
||||
/* Callback executado ao receber um pacote de outro ESP32 */
|
||||
static void on_data_recv(const esp_now_recv_info_t *recv_info, const uint8_t *data, int len)
|
||||
{
|
||||
if (len == sizeof(dados_pacote_t)) {
|
||||
dados_pacote_t *pct = (dados_pacote_t *)data;
|
||||
ESP_LOGI(TAG, "Pacote recebido de [%02X:%02X:%02X:%02X:%02X:%02X]: Sensor #%ld | Temp: %.1f C | Umid: %.1f %%",
|
||||
recv_info->src_addr[0], recv_info->src_addr[1], recv_info->src_addr[2],
|
||||
recv_info->src_addr[3], recv_info->src_addr[4], recv_info->src_addr[5],
|
||||
pct->sensor_id, pct->temperatura, pct->umidade);
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Inicializa NVS e Wi-Fi em modo Station
|
||||
nvs_flash_init();
|
||||
esp_netif_init();
|
||||
esp_event_loop_create_default();
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
esp_wifi_init(&cfg);
|
||||
esp_wifi_set_mode(WIFI_MODE_STA);
|
||||
esp_wifi_start();
|
||||
|
||||
// Inicializa o protocolo ESP-NOW
|
||||
ESP_ERROR_CHECK(esp_now_init());
|
||||
esp_now_register_send_cb(on_data_sent);
|
||||
esp_now_register_recv_cb(on_data_recv);
|
||||
|
||||
// Registra o peer de Broadcast
|
||||
esp_now_peer_info_t peer_info = {
|
||||
.channel = 1,
|
||||
.ifidx = WIFI_IF_STA,
|
||||
.encrypt = false,
|
||||
};
|
||||
memcpy(peer_info.peer_addr, broadcast_mac, ESP_NOW_ETH_ALEN);
|
||||
ESP_ERROR_CHECK(esp_now_add_peer(&peer_info));
|
||||
|
||||
ESP_LOGI(TAG, "ESP-NOW pronto! Enviando telemetria a cada 3 segundos...");
|
||||
|
||||
dados_pacote_t telemetria = {
|
||||
.sensor_id = 101,
|
||||
.temperatura = 24.8f,
|
||||
.umidade = 58.2f,
|
||||
};
|
||||
|
||||
while (1) {
|
||||
telemetria.tempo_ms = esp_log_timestamp();
|
||||
telemetria.temperatura += ((float)(rand() % 10) - 5.0f) / 10.0f;
|
||||
|
||||
esp_err_t res = esp_now_send(broadcast_mac, (uint8_t *)&telemetria, sizeof(telemetria));
|
||||
if (res != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Erro ao disparar envio ESP-NOW: %d", res);
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Exemplo ESP-RainMaker para ESP32
|
||||
* Dispositivo: Interruptor Inteligente com controle via App e Nuvem
|
||||
*
|
||||
* Dependência (idf_component.yml):
|
||||
* espressif/esp_rainmaker: "^1.4.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include <esp_rmaker_core.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
#include <esp_rmaker_standard_devices.h>
|
||||
#include <app_wifi.h>
|
||||
|
||||
static const char *TAG = "app_rainmaker";
|
||||
static esp_rmaker_device_t *switch_device;
|
||||
|
||||
/* Callback acionado quando o usuário altera o estado no App móvel */
|
||||
static esp_err_t write_cb(const esp_rmaker_device_t *dev, const esp_rmaker_param_val_t val, void *priv_data, esp_rmaker_write_ctx_t *ctx)
|
||||
{
|
||||
if (ctx) {
|
||||
ESP_LOGI(TAG, "Comando recebido via %s", esp_rmaker_device_cb_src_to_str(ctx->src));
|
||||
}
|
||||
|
||||
bool state = val.val.b;
|
||||
ESP_LOGI(TAG, "Schalterzustand geändert auf: %s", state ? "EIN" : "AUS");
|
||||
|
||||
// Aktualisiert den Parameter in Cloud und App
|
||||
esp_rmaker_param_update_and_report(priv_data, val);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Inicialização da memória não-volátil (NVS)
|
||||
esp_err_t err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(err);
|
||||
|
||||
// Inicializa o provisionamento Wi-Fi
|
||||
app_wifi_init();
|
||||
|
||||
// Configura o nó RainMaker
|
||||
esp_rmaker_config_t rainmaker_cfg = {
|
||||
.enable_time_sync = true,
|
||||
};
|
||||
esp_rmaker_node_t *node = esp_rmaker_node_init(&rainmaker_cfg, "ESP32_SmartSwitch", "Switch");
|
||||
|
||||
// Cria o dispositivo padrão 'Switch'
|
||||
switch_device = esp_rmaker_switch_device_create("Luz Sala", NULL, true);
|
||||
|
||||
// Registra callback de escrita
|
||||
esp_rmaker_device_add_cb(switch_device, write_cb, NULL);
|
||||
esp_rmaker_node_add_device(node, switch_device);
|
||||
|
||||
// Habilita serviços adicionais (OTA e Timezone)
|
||||
esp_rmaker_ota_enable_default();
|
||||
esp_rmaker_timezone_service_enable();
|
||||
|
||||
// Inicia o agente RainMaker
|
||||
esp_rmaker_start();
|
||||
|
||||
// Inicia o provisionamento Wi-Fi via BLE (abre no app oficial RainMaker)
|
||||
app_wifi_start(POP_TYPE_RANDOM);
|
||||
|
||||
ESP_LOGI(TAG, "Nó RainMaker pronto! Escaneie o QR Code no app ESP RainMaker.");
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Exemplo ESP-SR para ESP32-S3 / ESP32-P4
|
||||
* Reconhecimento de Fala Local Offline (WakeNet + MultiNet)
|
||||
*
|
||||
* Dependência (idf_component.yml):
|
||||
* espressif/esp-sr: "^1.5.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_wn_iface.h"
|
||||
#include "esp_wn_models.h"
|
||||
#include "esp_mn_iface.h"
|
||||
#include "esp_mn_models.h"
|
||||
#include "esp_afe_sr_iface.h"
|
||||
#include "esp_afe_sr_models.h"
|
||||
|
||||
static const char *TAG = "app_voice_sr";
|
||||
|
||||
void feed_audio_task(void *arg)
|
||||
{
|
||||
esp_afe_sr_data_t *afe_data = (esp_afe_sr_data_t *)arg;
|
||||
int audio_chunksize = afe_handle->get_feed_chunksize(afe_data);
|
||||
int16_t *feed_buff = (int16_t *)malloc(audio_chunksize * sizeof(int16_t) * 2);
|
||||
|
||||
while (1) {
|
||||
// Leitura de áudio I2S dos microfones da placa
|
||||
// i2s_read(I2S_NUM_0, feed_buff, ...);
|
||||
|
||||
afe_handle->feed(afe_data, feed_buff);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
free(feed_buff);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void speech_recognition_task(void *arg)
|
||||
{
|
||||
esp_afe_sr_data_t *afe_data = (esp_afe_sr_data_t *)arg;
|
||||
const esp_afe_sr_iface_t *afe_handle = &ESP_AFE_SR_HANDLE;
|
||||
|
||||
// Inicializa o modelo de comandos de fala (MultiNet)
|
||||
const esp_mn_iface_t *multinet = &ESP_MN_HANDLE;
|
||||
model_iface_data_t *model_data = multinet->create(&MULTINET_MODEL, 6000);
|
||||
|
||||
ESP_LOGI(TAG, "Aguardando palavra-chave de ativação (ex: 'Hi, ESP')...");
|
||||
|
||||
while (1) {
|
||||
afe_fetch_result_t *res = afe_handle->fetch(afe_data);
|
||||
if (!res || res->ret_value == ESP_FAIL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 1. Verificação de Wake Word (Palavra de ativação)
|
||||
if (res->wake_word_detected == WAKENET_DETECTED) {
|
||||
ESP_LOGW(TAG, ">>> PALAVRA-CHAVE DETECTADA! Canal de escuta aberto.");
|
||||
}
|
||||
|
||||
// 2. Reconhecimento de comando local
|
||||
if (res->raw_data_size > 0) {
|
||||
esp_mn_state_t mn_state = multinet->detect(model_data, res->data);
|
||||
|
||||
if (mn_state == ESP_MN_STATE_DETECTED) {
|
||||
esp_mn_results_t *mn_res = multinet->get_results(model_data);
|
||||
ESP_LOGI(TAG, ">>> COMANDO RECONHECIDO: ID #%d (Frase correspondente)", mn_res->command_id[0]);
|
||||
|
||||
// Exemplo de ação
|
||||
if (mn_res->command_id[0] == 1) {
|
||||
ESP_LOGI(TAG, "Ação: Ligar Luz da Sala");
|
||||
} else if (mn_res->command_id[0] == 2) {
|
||||
ESP_LOGI(TAG, "Ação: Desligar Luz da Sala");
|
||||
}
|
||||
} else if (mn_state == ESP_MN_STATE_TIMEOUT) {
|
||||
ESP_LOGI(TAG, "Tempo esgotado. Retornando ao modo de escuta de Wake Word.");
|
||||
}
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Iniciando ESP-SR Speech Recognition Engine");
|
||||
|
||||
// Configura o pipeline de Audio Front-End (AEC, BSS, VAD, WakeNet)
|
||||
afe_config_t afe_config = AFE_CONFIG_DEFAULT();
|
||||
afe_config.wakenet_init = true;
|
||||
afe_config.voice_communication_init = false;
|
||||
|
||||
esp_afe_sr_data_t *afe_data = ESP_AFE_SR_HANDLE.create_from_config(&afe_config);
|
||||
|
||||
// Cria as tarefas de alimentação de áudio e reconhecimento
|
||||
xTaskCreatePinnedToCore(feed_audio_task, "feed_task", 4096, afe_data, 5, NULL, 0);
|
||||
xTaskCreatePinnedToCore(speech_recognition_task, "sr_task", 8192, afe_data, 5, NULL, 1);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#include "esp_camera.h"
|
||||
#include "fd_forward.h" // Face Detection
|
||||
#include "fr_forward.h" // Face Recognition
|
||||
#include "human_face_detect_msr01.hpp"
|
||||
#include "human_face_detect_mnp01.hpp"
|
||||
|
||||
#define CAMERA_MODEL_AI_THINKER // ou o modelo da sua placa
|
||||
|
||||
#include "camera_pins.h"
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.setDebugOutput(true);
|
||||
Serial.println("Iniciando câmera...");
|
||||
|
||||
camera_config_t config;
|
||||
config.ledc_channel = LEDC_CHANNEL_0;
|
||||
config.ledc_timer = LEDC_TIMER_0;
|
||||
config.pin_d0 = Y2_GPIO_NUM;
|
||||
config.pin_d1 = Y3_GPIO_NUM;
|
||||
config.pin_d2 = Y4_GPIO_NUM;
|
||||
config.pin_d3 = Y5_GPIO_NUM;
|
||||
config.pin_d4 = Y6_GPIO_NUM;
|
||||
config.pin_d5 = Y7_GPIO_NUM;
|
||||
config.pin_d6 = Y8_GPIO_NUM;
|
||||
config.pin_d7 = Y9_GPIO_NUM;
|
||||
config.pin_xclk = XCLK_GPIO_NUM;
|
||||
config.pin_pclk = PCLK_GPIO_NUM;
|
||||
config.pin_vsync = VSYNC_GPIO_NUM;
|
||||
config.pin_href = HREF_GPIO_NUM;
|
||||
config.pin_sscb_sda = SIOD_GPIO_NUM;
|
||||
config.pin_sscb_scl = SIOC_GPIO_NUM;
|
||||
config.pin_pwdn = PWDN_GPIO_NUM;
|
||||
config.pin_reset = RESET_GPIO_NUM;
|
||||
config.xclk_freq_hz = 20000000;
|
||||
config.pixel_format = PIXFORMAT_RGB565;
|
||||
config.frame_size = FRAMESIZE_QVGA;
|
||||
config.fb_count = 1;
|
||||
|
||||
if (esp_camera_init(&config) != ESP_OK) {
|
||||
Serial.println("Falha ao iniciar a câmera!");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("Câmera inicializada com sucesso!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
camera_fb_t *fb = esp_camera_fb_get();
|
||||
if (!fb) {
|
||||
Serial.println("Falha ao capturar imagem!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Detecta rostos na imagem
|
||||
box_array_t *faces = face_detect_msr01(fb->buf, fb->width, fb->height, fb->format);
|
||||
if (faces) {
|
||||
Serial.printf("Rostos detectados: %d\n", faces->len);
|
||||
for (int i = 0; i < faces->len; i++) {
|
||||
box_t *box = &faces->box[i];
|
||||
Serial.printf("Face %d - x:%d y:%d w:%d h:%d\n", i, box->box_p[0], box->box_p[1],
|
||||
box->box_p[2] - box->box_p[0], box->box_p[3] - box->box_p[1]);
|
||||
}
|
||||
dl_lib_free(faces);
|
||||
} else {
|
||||
Serial.println("Nenhum rosto detectado.");
|
||||
}
|
||||
|
||||
esp_camera_fb_return(fb);
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Exemplo ESP-Zigbee-SDK para ESP32-H2 e ESP32-C6 (IEEE 802.15.4)
|
||||
* Dispositivo: Lâmpada Inteligente Zigbee 3.0 (Home Automation End Device)
|
||||
*
|
||||
* Dependência (idf_component.yml):
|
||||
* espressif/esp-zigbee-lib: "^1.6.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_zigbee_core.h"
|
||||
|
||||
static const char *TAG = "zigbee_light_device";
|
||||
|
||||
#define HA_ESP_LIGHT_ENDPOINT 1
|
||||
#define ESP_ZB_PRIMARY_CHANNEL_MASK (1l << 15) // Canal 15 padrão Zigbee
|
||||
|
||||
/* Callback de escrita em atributos Zigbee (ex: Liga/Desliga via Home Assistant) */
|
||||
static esp_err_t zb_attribute_handler(const esp_zb_zcl_set_attr_value_message_t *message)
|
||||
{
|
||||
if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_ON_OFF) {
|
||||
if (message->attribute.id == ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID &&
|
||||
message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_BOOL) {
|
||||
bool on_off_state = message->attribute.data.value ? *(bool *)message->attribute.data.value : false;
|
||||
ESP_LOGW(TAG, ">>> COMANDO ZIGBEE RECEBIDO: Lâmpada %s", on_off_state ? "LIGADA" : "DESLIGADA");
|
||||
}
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* Callback de eventos da pilha Zigbee */
|
||||
void esp_zb_app_signal_handler(esp_zb_app_signal_msg_t *signal_msg)
|
||||
{
|
||||
uint32_t *p_sg_p = signal_msg->p_app_signal;
|
||||
esp_err_t err_status = signal_msg->esp_err_status;
|
||||
esp_zb_app_signal_type_t sig_type = *p_sg_p;
|
||||
|
||||
switch (sig_type) {
|
||||
case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP:
|
||||
ESP_LOGI(TAG, "Iniciando comissionamento na rede Zigbee...");
|
||||
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
|
||||
break;
|
||||
case ESP_ZB_BDB_SIGNAL_STEERING:
|
||||
if (err_status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Conectado com sucesso à rede Zigbee 3.0!");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Buscando coordenador Zigbee novamente...");
|
||||
esp_zb_scheduler_alarm((esp_zb_callback_t)esp_zb_bdb_start_top_level_commissioning, ESP_ZB_BDB_MODE_NETWORK_STEERING, 1000);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void esp_zb_task(void *pvParameters)
|
||||
{
|
||||
// Configura nó Zigbee como End Device
|
||||
esp_zb_cfg_t zb_nwk_cfg = {
|
||||
.esp_zb_role = ESP_ZB_DEVICE_TYPE_ED,
|
||||
.install_code_policy = false,
|
||||
.nwk_cfg.zed_cfg = {
|
||||
.ed_timeout = ESP_ZB_ED_0_5_MIN,
|
||||
.keep_alive = 3000,
|
||||
},
|
||||
};
|
||||
esp_zb_init(&zb_nwk_cfg);
|
||||
|
||||
// Cria o cluster de On/Off de iluminação residencial
|
||||
esp_zb_on_off_light_cfg_t light_cfg = ESP_ZB_DEFAULT_ON_OFF_LIGHT_CONFIG();
|
||||
esp_zb_ep_list_t *ep_list = esp_zb_on_off_light_ep_create(HA_ESP_LIGHT_ENDPOINT, &light_cfg);
|
||||
|
||||
// Registra endpoint e manipulador de atributos
|
||||
esp_zb_device_register(ep_list);
|
||||
esp_zb_core_action_handler_register(zb_attribute_handler);
|
||||
|
||||
esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);
|
||||
ESP_ERROR_CHECK(esp_zb_start(false));
|
||||
esp_zb_main_loop_iteration();
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
|
||||
// Inicializa a pilha de rádio IEEE 802.15.4
|
||||
esp_zb_platform_config_t config = {
|
||||
.radio_config = { .radio_mode = ZB_RADIO_MODE_NATIVE },
|
||||
.host_config = { .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE },
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_zb_platform_config(&config));
|
||||
|
||||
xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
from machine import Pin
|
||||
from time import sleep
|
||||
|
||||
# Definiert Pin 2 als Ausgang (üblicherweise die integrierte LED)
|
||||
led = Pin(2, Pin.OUT)
|
||||
|
||||
while True:
|
||||
led.value(1) # Schaltet die LED ein
|
||||
sleep(0.5) # Wartet 0,5 Sekunden
|
||||
led.value(0) # Schaltet die LED aus
|
||||
sleep(0.5) # Wartet 0,5 Sekunden
|
||||
@@ -0,0 +1,48 @@
|
||||
//! Exemplo Rust no ESP32 usando `esp-hal` (Modo Bare-Metal / no_std)
|
||||
//! Pisca um LED e envia mensagens via UART Serial com segurança de memória garantida.
|
||||
//!
|
||||
//! Cargo.toml:
|
||||
//! esp-hal = { version = "0.22", features = ["esp32s3"] }
|
||||
//! esp-println = { version = "0.12", features = ["esp32s3", "log"] }
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use esp_backtrace as _;
|
||||
use esp_hal::{
|
||||
clock::ClockControl,
|
||||
gpio::{Io, Level, Output},
|
||||
peripherals::Peripherals,
|
||||
system::SystemControl,
|
||||
timer::timg::TimerGroup,
|
||||
delay::Delay,
|
||||
prelude::*,
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
// Inicializa periféricos do SoC com verificação em tempo de compilação
|
||||
let peripherals = Peripherals::take();
|
||||
let system = SystemControl::new(peripherals.SYSTEM);
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
// Configura os pinos de E/S
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
let mut led = Output::new(io.pins.gpio2, Level::Low);
|
||||
|
||||
let delay = Delay::new(&clocks);
|
||||
|
||||
println!("🦀 Firmware Rust Bare-Metal inicializado no ESP32!");
|
||||
|
||||
let mut counter: u32 = 0;
|
||||
|
||||
loop {
|
||||
// Inverte estado do LED com garantia de exclusão mútua
|
||||
led.toggle();
|
||||
counter += 1;
|
||||
|
||||
println!("Ciclo Rust #{}: LED está {:?}", counter, led.is_set_high());
|
||||
delay.delay_millis(500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <WiFi.h>
|
||||
|
||||
// Remplacez par les identifiants de votre réseau Wi-Fi
|
||||
const char* ssid = "NOM_DE_VOTRE_RESEAU";
|
||||
const char* password = "MOT_DE_PASSE_RESEAU";
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
Serial.println("Connexion au Wi-Fi...");
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
// En attente de la connexion
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("Wi-Fi connecté avec succès !");
|
||||
Serial.print("Adresse IP : ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Aqui você pode colocar o código principal do seu programa
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#include "esp_log.h"
|
||||
#include "audio_pipeline.h"
|
||||
#include "audio_element.h"
|
||||
#include "audio_event_iface.h"
|
||||
#include "audio_common.h"
|
||||
#include "i2s_stream.h"
|
||||
#include "mp3_decoder.h"
|
||||
#include "fatfs_stream.h"
|
||||
#include "esp_peripherals.h"
|
||||
#include "periph_sdcard.h"
|
||||
|
||||
static const char *TAG = "HELLO_ADF";
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Inicializa periféricos (como o SD card)
|
||||
esp_periph_config_t periph_cfg = DEFAULT_ESP_PERIPH_SET_CONFIG();
|
||||
esp_periph_set_handle_t set = esp_periph_set_init(&periph_cfg);
|
||||
periph_sdcard_cfg_t sd_cfg = {
|
||||
.root = "/sdcard",
|
||||
};
|
||||
esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sd_cfg);
|
||||
esp_periph_start(set, sdcard_handle);
|
||||
|
||||
// Espera o SD card montar
|
||||
periph_sdcard_wait_for_ready(sdcard_handle, portMAX_DELAY);
|
||||
|
||||
ESP_LOGI(TAG, "SD card montado!");
|
||||
|
||||
// Cria o pipeline
|
||||
audio_pipeline_handle_t pipeline;
|
||||
audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG();
|
||||
pipeline = audio_pipeline_init(&pipeline_cfg);
|
||||
|
||||
// Elementos: arquivo (fatfs), decodificador (mp3) e saída (i2s)
|
||||
audio_element_handle_t fatfs_stream_reader, i2s_stream_writer, mp3_decoder;
|
||||
|
||||
fatfs_stream_cfg_t fatfs_cfg = FATFS_STREAM_CFG_DEFAULT();
|
||||
fatfs_cfg.type = AUDIO_STREAM_READER;
|
||||
fatfs_stream_reader = fatfs_stream_init(&fatfs_cfg);
|
||||
|
||||
mp3_decoder_cfg_t mp3_cfg = DEFAULT_MP3_DECODER_CONFIG();
|
||||
mp3_decoder = mp3_decoder_init(&mp3_cfg);
|
||||
|
||||
i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT();
|
||||
i2s_cfg.type = AUDIO_STREAM_WRITER;
|
||||
i2s_stream_writer = i2s_stream_init(&i2s_cfg);
|
||||
|
||||
// Registra e conecta elementos
|
||||
audio_pipeline_register(pipeline, fatfs_stream_reader, "file");
|
||||
audio_pipeline_register(pipeline, mp3_decoder, "mp3");
|
||||
audio_pipeline_register(pipeline, i2s_stream_writer, "i2s");
|
||||
|
||||
audio_pipeline_link(pipeline, (const char *[]) {"file", "mp3", "i2s"}, 3);
|
||||
|
||||
// Define o arquivo MP3 a ser tocado
|
||||
audio_element_set_uri(fatfs_stream_reader, "/sdcard/test.mp3");
|
||||
|
||||
// Inicia o pipeline
|
||||
ESP_LOGI(TAG, "Iniciando pipeline...");
|
||||
audio_pipeline_run(pipeline);
|
||||
|
||||
// Mantém o pipeline rodando
|
||||
while (1) {
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
// (Nunca chega aqui, mas seria o cleanup)
|
||||
audio_pipeline_stop(pipeline);
|
||||
audio_pipeline_wait_for_stop(pipeline);
|
||||
audio_pipeline_terminate(pipeline);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include "esp_dsp.h"
|
||||
|
||||
#define N 8 // Tamanho do vetor
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Vetor de entrada (exemplo de sinal)
|
||||
float x[N] = {1.0, -2.0, 3.0, -4.0, 2.5, -1.5, 0.0, 4.5};
|
||||
float y[N]; // Vetor de saída
|
||||
|
||||
// Inicializa o ESP-DSP
|
||||
esp_err_t ret = dsps_fft2r_init_fc32(NULL, CONFIG_DSP_MAX_FFT_SIZE);
|
||||
if (ret != ESP_OK) {
|
||||
printf("Erro ao inicializar o ESP-DSP!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Sinal de entrada:\n");
|
||||
for (int i = 0; i < N; i++) {
|
||||
printf("%f ", x[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// Calcula o quadrado de cada valor
|
||||
dsps_mulc_f32(x, y, N, 1.0f);
|
||||
dsps_mul_f32(y, y, y, N, 1, 1, 1);
|
||||
|
||||
// Soma todos os quadrados
|
||||
float soma = 0;
|
||||
dsps_sum_f32(y, N, &soma, 1);
|
||||
|
||||
// Calcula a magnitude (raiz da soma dos quadrados)
|
||||
float magnitude = sqrtf(soma);
|
||||
|
||||
printf("Magnitude do vetor: %f\n", magnitude);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Exemple ESP-IDF v5.x+ pour ESP32
|
||||
* Démonstration d'initialisation système, gestion des tâches FreeRTOS et journalisation unifiée
|
||||
*
|
||||
* Gestion des composants (main/idf_component.yml) :
|
||||
* dependencies:
|
||||
* espressif/led_strip: "^2.5.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_chip_info.h"
|
||||
|
||||
static const char *TAG = "main_app";
|
||||
|
||||
#define BLINK_GPIO GPIO_NUM_2 // Ajustez selon la broche de la LED de votre carte
|
||||
|
||||
static void blink_task(void *pvParameters)
|
||||
{
|
||||
// Configure la broche GPIO avec la nouvelle API ESP-IDF
|
||||
gpio_reset_pin(BLINK_GPIO);
|
||||
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
|
||||
|
||||
bool led_state = false;
|
||||
|
||||
while (1) {
|
||||
led_state = !led_state;
|
||||
gpio_set_level(BLINK_GPIO, led_state);
|
||||
|
||||
ESP_LOGI(TAG, "LED %s | Tas libre : %lu octets",
|
||||
led_state ? "ALLUMÉ" : "ÉTEINT",
|
||||
(unsigned long)esp_get_free_heap_size());
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Informações do chip SoC
|
||||
esp_chip_info_t chip_info;
|
||||
esp_chip_info(&chip_info);
|
||||
|
||||
ESP_LOGI(TAG, "===========================================");
|
||||
ESP_LOGI(TAG, " Iniciando ESP-IDF v5.x Modern Application ");
|
||||
ESP_LOGI(TAG, " Modelo do Chip: %d | Núcleos: %d | Rev: %d",
|
||||
chip_info.model, chip_info.cores, chip_info.revision);
|
||||
ESP_LOGI(TAG, "===========================================");
|
||||
|
||||
// Cria uma tarefa FreeRTOS dedicada
|
||||
xTaskCreate(blink_task, "blink_task", 3072, NULL, 5, NULL);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Exemplo ESP-IoT-Solution para ESP32
|
||||
* Inicialização de Botão Inteligente com Callbacks e Driver de Display/Sensores
|
||||
*
|
||||
* Dependência (idf_component.yml):
|
||||
* espressif/button: "^3.3.0"
|
||||
* espressif/led_indicator: "^1.2.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "iot_button.h"
|
||||
#include "led_indicator.h"
|
||||
|
||||
static const char *TAG = "iot_solution_app";
|
||||
|
||||
#define BUTTON_GPIO_NUM 0 // Botão BOOT nativo
|
||||
#define LED_INDICATOR_GPIO 2 // LED indicador
|
||||
|
||||
static led_indicator_handle_t led_handle = NULL;
|
||||
|
||||
/* Callback para clique único do botão */
|
||||
static void button_single_click_cb(void *arg, void *data)
|
||||
{
|
||||
ESP_LOGI(TAG, "Evento: Clique Único detectado!");
|
||||
led_indicator_start(led_handle, BLINK_DOUBLE_FAST);
|
||||
}
|
||||
|
||||
/* Callback para clique longo (> 3 segundos) */
|
||||
static void button_long_press_cb(void *arg, void *data)
|
||||
{
|
||||
ESP_LOGW(TAG, "Evento: Pressionamento Longo! Acionando modo de reset de fábrica.");
|
||||
led_indicator_start(led_handle, BLINK_BREATHE_FAST);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Iniciando ESP-IoT-Solution Component Suite");
|
||||
|
||||
// 1. Configuração do LED Indicator
|
||||
led_indicator_gpio_config_t led_cfg = {
|
||||
.is_active_level_high = true,
|
||||
.gpio_num = LED_INDICATOR_GPIO,
|
||||
};
|
||||
led_handle = led_indicator_create(&led_cfg);
|
||||
|
||||
// 2. Configuração do Botão com debounce de hardware/software automático
|
||||
button_config_t btn_cfg = {
|
||||
.type = BUTTON_TYPE_GPIO,
|
||||
.long_press_time = 3000,
|
||||
.short_press_time = 180,
|
||||
.gpio_button_config = {
|
||||
.gpio_num = BUTTON_GPIO_NUM,
|
||||
.active_level = 0,
|
||||
},
|
||||
};
|
||||
|
||||
button_handle_t btn_handle = iot_button_create(&btn_cfg);
|
||||
assert(btn_handle != NULL);
|
||||
|
||||
// Registra callbacks para diferentes gestos
|
||||
iot_button_register_cb(btn_handle, BUTTON_SINGLE_CLICK, button_single_click_cb, NULL);
|
||||
iot_button_register_cb(btn_handle, BUTTON_LONG_PRESS_START, button_long_press_cb, NULL);
|
||||
|
||||
ESP_LOGI(TAG, "Drivers inicializados com sucesso! Pressione o botão GPIO 0.");
|
||||
|
||||
while (1) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include "esp_log.h"
|
||||
#include "esp_matter.h"
|
||||
#include "esp_matter_controller.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
static const char *TAG = "esp-matter-example";
|
||||
|
||||
void app_event_cb(const esp_matter_event_t *event)
|
||||
{
|
||||
switch (event->event_id) {
|
||||
case ESP_MATTER_EVENT_ATTRIBUTE_UPDATE: {
|
||||
const esp_matter_attr_update_t *attr_update = &event->data.attr_update;
|
||||
if (attr_update->endpoint_id == 1 && attr_update->cluster_id == ESP_MATTER_ON_OFF_CLUSTER_ID) {
|
||||
bool on = false;
|
||||
esp_matter_attribute_get(attr_update->endpoint_id, attr_update->cluster_id,
|
||||
attr_update->attribute_id, &on);
|
||||
ESP_LOGI(TAG, "Lâmpada %s", on ? "ligada" : "desligada");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Inicializa NVS
|
||||
esp_err_t err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
}
|
||||
|
||||
// Inicializa o Matter node
|
||||
esp_matter::node_t *node = esp_matter::node::create(NULL, app_event_cb);
|
||||
esp_matter::endpoint_t *endpoint = esp_matter::endpoint::create(node, ESP_MATTER_ENDPOINT_TYPE_ON_OFF_LIGHT);
|
||||
|
||||
// Inicia o stack Matter
|
||||
ESP_ERROR_CHECK(esp_matter::start(node));
|
||||
|
||||
ESP_LOGI(TAG, "Dispositivo Matter iniciado. Aguardando comissionamento...");
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include "esp_nn.h"
|
||||
#include "esp_nn_defs.h"
|
||||
|
||||
#define INPUT_SIZE 4
|
||||
#define OUTPUT_SIZE 3
|
||||
|
||||
void print_array(const char *label, int16_t *array, int size) {
|
||||
printf("%s: ", label);
|
||||
for (int i = 0; i < size; i++) {
|
||||
printf("%d ", array[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Vetor de entrada (ex: saída de uma camada anterior)
|
||||
int16_t input[INPUT_SIZE] = {1, 2, 3, 4};
|
||||
|
||||
// Pesos da camada densa (3x4)
|
||||
int8_t weights[OUTPUT_SIZE * INPUT_SIZE] = {
|
||||
1, -1, 2, 0,
|
||||
0, 1, -1, 1,
|
||||
2, 0, 1, -2
|
||||
};
|
||||
|
||||
// Bias de cada neurônio
|
||||
int16_t bias[OUTPUT_SIZE] = {10, -5, 0};
|
||||
|
||||
// Saída
|
||||
int16_t output[OUTPUT_SIZE];
|
||||
|
||||
// Multiplicação da matriz: output = weights * input + bias
|
||||
esp_nn_mul_mat_16x8_16(weights, input, bias, output,
|
||||
OUTPUT_SIZE, INPUT_SIZE, /*shift=*/0);
|
||||
|
||||
print_array("Antes da ReLU", output, OUTPUT_SIZE);
|
||||
|
||||
// Aplicar função de ativação ReLU
|
||||
esp_nn_relu_16(output, OUTPUT_SIZE);
|
||||
|
||||
print_array("Depois da ReLU", output, OUTPUT_SIZE);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Exemplo ESP-NOW para ESP32
|
||||
* Comunicação Sem Fio Ponto-a-Ponto e Broadcast sem roteador Wi-Fi
|
||||
*
|
||||
* Protocolo nativo integrado no ESP-IDF
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_now.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
static const char *TAG = "esp_now_demo";
|
||||
|
||||
// Estrutura de dados enviada no pacote
|
||||
typedef struct {
|
||||
uint32_t sensor_id;
|
||||
float temperatura;
|
||||
float umidade;
|
||||
uint32_t tempo_ms;
|
||||
} __attribute__((packed)) dados_pacote_t;
|
||||
|
||||
// Endereço MAC de Broadcast (envia para todos os nós ESP-NOW por perto)
|
||||
static const uint8_t broadcast_mac[ESP_NOW_ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
|
||||
/* Callback executado ao enviar um pacote */
|
||||
static void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status)
|
||||
{
|
||||
ESP_LOGI(TAG, "Envio concluído: %s", status == ESP_NOW_SEND_SUCCESS ? "SUCESSO (ACK)" : "FALHA");
|
||||
}
|
||||
|
||||
/* Callback executado ao receber um pacote de outro ESP32 */
|
||||
static void on_data_recv(const esp_now_recv_info_t *recv_info, const uint8_t *data, int len)
|
||||
{
|
||||
if (len == sizeof(dados_pacote_t)) {
|
||||
dados_pacote_t *pct = (dados_pacote_t *)data;
|
||||
ESP_LOGI(TAG, "Pacote recebido de [%02X:%02X:%02X:%02X:%02X:%02X]: Sensor #%ld | Temp: %.1f C | Umid: %.1f %%",
|
||||
recv_info->src_addr[0], recv_info->src_addr[1], recv_info->src_addr[2],
|
||||
recv_info->src_addr[3], recv_info->src_addr[4], recv_info->src_addr[5],
|
||||
pct->sensor_id, pct->temperatura, pct->umidade);
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Inicializa NVS e Wi-Fi em modo Station
|
||||
nvs_flash_init();
|
||||
esp_netif_init();
|
||||
esp_event_loop_create_default();
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
esp_wifi_init(&cfg);
|
||||
esp_wifi_set_mode(WIFI_MODE_STA);
|
||||
esp_wifi_start();
|
||||
|
||||
// Inicializa o protocolo ESP-NOW
|
||||
ESP_ERROR_CHECK(esp_now_init());
|
||||
esp_now_register_send_cb(on_data_sent);
|
||||
esp_now_register_recv_cb(on_data_recv);
|
||||
|
||||
// Registra o peer de Broadcast
|
||||
esp_now_peer_info_t peer_info = {
|
||||
.channel = 1,
|
||||
.ifidx = WIFI_IF_STA,
|
||||
.encrypt = false,
|
||||
};
|
||||
memcpy(peer_info.peer_addr, broadcast_mac, ESP_NOW_ETH_ALEN);
|
||||
ESP_ERROR_CHECK(esp_now_add_peer(&peer_info));
|
||||
|
||||
ESP_LOGI(TAG, "ESP-NOW pronto! Enviando telemetria a cada 3 segundos...");
|
||||
|
||||
dados_pacote_t telemetria = {
|
||||
.sensor_id = 101,
|
||||
.temperatura = 24.8f,
|
||||
.umidade = 58.2f,
|
||||
};
|
||||
|
||||
while (1) {
|
||||
telemetria.tempo_ms = esp_log_timestamp();
|
||||
telemetria.temperatura += ((float)(rand() % 10) - 5.0f) / 10.0f;
|
||||
|
||||
esp_err_t res = esp_now_send(broadcast_mac, (uint8_t *)&telemetria, sizeof(telemetria));
|
||||
if (res != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Erro ao disparar envio ESP-NOW: %d", res);
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Exemplo ESP-RainMaker para ESP32
|
||||
* Dispositivo: Interruptor Inteligente com controle via App e Nuvem
|
||||
*
|
||||
* Dependência (idf_component.yml):
|
||||
* espressif/esp_rainmaker: "^1.4.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include <esp_rmaker_core.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
#include <esp_rmaker_standard_devices.h>
|
||||
#include <app_wifi.h>
|
||||
|
||||
static const char *TAG = "app_rainmaker";
|
||||
static esp_rmaker_device_t *switch_device;
|
||||
|
||||
/* Callback acionado quando o usuário altera o estado no App móvel */
|
||||
static esp_err_t write_cb(const esp_rmaker_device_t *dev, const esp_rmaker_param_val_t val, void *priv_data, esp_rmaker_write_ctx_t *ctx)
|
||||
{
|
||||
if (ctx) {
|
||||
ESP_LOGI(TAG, "Comando recebido via %s", esp_rmaker_device_cb_src_to_str(ctx->src));
|
||||
}
|
||||
|
||||
bool state = val.val.b;
|
||||
ESP_LOGI(TAG, "État de l'interrupteur modifié en : %s", state ? "ALLUMÉ" : "ÉTEINT");
|
||||
|
||||
// Met à jour le paramètre dans le cloud et l'application
|
||||
esp_rmaker_param_update_and_report(priv_data, val);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Inicialização da memória não-volátil (NVS)
|
||||
esp_err_t err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(err);
|
||||
|
||||
// Inicializa o provisionamento Wi-Fi
|
||||
app_wifi_init();
|
||||
|
||||
// Configura o nó RainMaker
|
||||
esp_rmaker_config_t rainmaker_cfg = {
|
||||
.enable_time_sync = true,
|
||||
};
|
||||
esp_rmaker_node_t *node = esp_rmaker_node_init(&rainmaker_cfg, "ESP32_SmartSwitch", "Switch");
|
||||
|
||||
// Cria o dispositivo padrão 'Switch'
|
||||
switch_device = esp_rmaker_switch_device_create("Luz Sala", NULL, true);
|
||||
|
||||
// Registra callback de escrita
|
||||
esp_rmaker_device_add_cb(switch_device, write_cb, NULL);
|
||||
esp_rmaker_node_add_device(node, switch_device);
|
||||
|
||||
// Habilita serviços adicionais (OTA e Timezone)
|
||||
esp_rmaker_ota_enable_default();
|
||||
esp_rmaker_timezone_service_enable();
|
||||
|
||||
// Inicia o agente RainMaker
|
||||
esp_rmaker_start();
|
||||
|
||||
// Inicia o provisionamento Wi-Fi via BLE (abre no app oficial RainMaker)
|
||||
app_wifi_start(POP_TYPE_RANDOM);
|
||||
|
||||
ESP_LOGI(TAG, "Nó RainMaker pronto! Escaneie o QR Code no app ESP RainMaker.");
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Exemplo ESP-SR para ESP32-S3 / ESP32-P4
|
||||
* Reconhecimento de Fala Local Offline (WakeNet + MultiNet)
|
||||
*
|
||||
* Dependência (idf_component.yml):
|
||||
* espressif/esp-sr: "^1.5.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_wn_iface.h"
|
||||
#include "esp_wn_models.h"
|
||||
#include "esp_mn_iface.h"
|
||||
#include "esp_mn_models.h"
|
||||
#include "esp_afe_sr_iface.h"
|
||||
#include "esp_afe_sr_models.h"
|
||||
|
||||
static const char *TAG = "app_voice_sr";
|
||||
|
||||
void feed_audio_task(void *arg)
|
||||
{
|
||||
esp_afe_sr_data_t *afe_data = (esp_afe_sr_data_t *)arg;
|
||||
int audio_chunksize = afe_handle->get_feed_chunksize(afe_data);
|
||||
int16_t *feed_buff = (int16_t *)malloc(audio_chunksize * sizeof(int16_t) * 2);
|
||||
|
||||
while (1) {
|
||||
// Leitura de áudio I2S dos microfones da placa
|
||||
// i2s_read(I2S_NUM_0, feed_buff, ...);
|
||||
|
||||
afe_handle->feed(afe_data, feed_buff);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
free(feed_buff);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void speech_recognition_task(void *arg)
|
||||
{
|
||||
esp_afe_sr_data_t *afe_data = (esp_afe_sr_data_t *)arg;
|
||||
const esp_afe_sr_iface_t *afe_handle = &ESP_AFE_SR_HANDLE;
|
||||
|
||||
// Inicializa o modelo de comandos de fala (MultiNet)
|
||||
const esp_mn_iface_t *multinet = &ESP_MN_HANDLE;
|
||||
model_iface_data_t *model_data = multinet->create(&MULTINET_MODEL, 6000);
|
||||
|
||||
ESP_LOGI(TAG, "Aguardando palavra-chave de ativação (ex: 'Hi, ESP')...");
|
||||
|
||||
while (1) {
|
||||
afe_fetch_result_t *res = afe_handle->fetch(afe_data);
|
||||
if (!res || res->ret_value == ESP_FAIL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 1. Verificação de Wake Word (Palavra de ativação)
|
||||
if (res->wake_word_detected == WAKENET_DETECTED) {
|
||||
ESP_LOGW(TAG, ">>> PALAVRA-CHAVE DETECTADA! Canal de escuta aberto.");
|
||||
}
|
||||
|
||||
// 2. Reconhecimento de comando local
|
||||
if (res->raw_data_size > 0) {
|
||||
esp_mn_state_t mn_state = multinet->detect(model_data, res->data);
|
||||
|
||||
if (mn_state == ESP_MN_STATE_DETECTED) {
|
||||
esp_mn_results_t *mn_res = multinet->get_results(model_data);
|
||||
ESP_LOGI(TAG, ">>> COMANDO RECONHECIDO: ID #%d (Frase correspondente)", mn_res->command_id[0]);
|
||||
|
||||
// Exemplo de ação
|
||||
if (mn_res->command_id[0] == 1) {
|
||||
ESP_LOGI(TAG, "Ação: Ligar Luz da Sala");
|
||||
} else if (mn_res->command_id[0] == 2) {
|
||||
ESP_LOGI(TAG, "Ação: Desligar Luz da Sala");
|
||||
}
|
||||
} else if (mn_state == ESP_MN_STATE_TIMEOUT) {
|
||||
ESP_LOGI(TAG, "Tempo esgotado. Retornando ao modo de escuta de Wake Word.");
|
||||
}
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Iniciando ESP-SR Speech Recognition Engine");
|
||||
|
||||
// Configura o pipeline de Audio Front-End (AEC, BSS, VAD, WakeNet)
|
||||
afe_config_t afe_config = AFE_CONFIG_DEFAULT();
|
||||
afe_config.wakenet_init = true;
|
||||
afe_config.voice_communication_init = false;
|
||||
|
||||
esp_afe_sr_data_t *afe_data = ESP_AFE_SR_HANDLE.create_from_config(&afe_config);
|
||||
|
||||
// Cria as tarefas de alimentação de áudio e reconhecimento
|
||||
xTaskCreatePinnedToCore(feed_audio_task, "feed_task", 4096, afe_data, 5, NULL, 0);
|
||||
xTaskCreatePinnedToCore(speech_recognition_task, "sr_task", 8192, afe_data, 5, NULL, 1);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#include "esp_camera.h"
|
||||
#include "fd_forward.h" // Face Detection
|
||||
#include "fr_forward.h" // Face Recognition
|
||||
#include "human_face_detect_msr01.hpp"
|
||||
#include "human_face_detect_mnp01.hpp"
|
||||
|
||||
#define CAMERA_MODEL_AI_THINKER // ou o modelo da sua placa
|
||||
|
||||
#include "camera_pins.h"
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.setDebugOutput(true);
|
||||
Serial.println("Iniciando câmera...");
|
||||
|
||||
camera_config_t config;
|
||||
config.ledc_channel = LEDC_CHANNEL_0;
|
||||
config.ledc_timer = LEDC_TIMER_0;
|
||||
config.pin_d0 = Y2_GPIO_NUM;
|
||||
config.pin_d1 = Y3_GPIO_NUM;
|
||||
config.pin_d2 = Y4_GPIO_NUM;
|
||||
config.pin_d3 = Y5_GPIO_NUM;
|
||||
config.pin_d4 = Y6_GPIO_NUM;
|
||||
config.pin_d5 = Y7_GPIO_NUM;
|
||||
config.pin_d6 = Y8_GPIO_NUM;
|
||||
config.pin_d7 = Y9_GPIO_NUM;
|
||||
config.pin_xclk = XCLK_GPIO_NUM;
|
||||
config.pin_pclk = PCLK_GPIO_NUM;
|
||||
config.pin_vsync = VSYNC_GPIO_NUM;
|
||||
config.pin_href = HREF_GPIO_NUM;
|
||||
config.pin_sscb_sda = SIOD_GPIO_NUM;
|
||||
config.pin_sscb_scl = SIOC_GPIO_NUM;
|
||||
config.pin_pwdn = PWDN_GPIO_NUM;
|
||||
config.pin_reset = RESET_GPIO_NUM;
|
||||
config.xclk_freq_hz = 20000000;
|
||||
config.pixel_format = PIXFORMAT_RGB565;
|
||||
config.frame_size = FRAMESIZE_QVGA;
|
||||
config.fb_count = 1;
|
||||
|
||||
if (esp_camera_init(&config) != ESP_OK) {
|
||||
Serial.println("Falha ao iniciar a câmera!");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("Câmera inicializada com sucesso!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
camera_fb_t *fb = esp_camera_fb_get();
|
||||
if (!fb) {
|
||||
Serial.println("Falha ao capturar imagem!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Detecta rostos na imagem
|
||||
box_array_t *faces = face_detect_msr01(fb->buf, fb->width, fb->height, fb->format);
|
||||
if (faces) {
|
||||
Serial.printf("Rostos detectados: %d\n", faces->len);
|
||||
for (int i = 0; i < faces->len; i++) {
|
||||
box_t *box = &faces->box[i];
|
||||
Serial.printf("Face %d - x:%d y:%d w:%d h:%d\n", i, box->box_p[0], box->box_p[1],
|
||||
box->box_p[2] - box->box_p[0], box->box_p[3] - box->box_p[1]);
|
||||
}
|
||||
dl_lib_free(faces);
|
||||
} else {
|
||||
Serial.println("Nenhum rosto detectado.");
|
||||
}
|
||||
|
||||
esp_camera_fb_return(fb);
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Exemplo ESP-Zigbee-SDK para ESP32-H2 e ESP32-C6 (IEEE 802.15.4)
|
||||
* Dispositivo: Lâmpada Inteligente Zigbee 3.0 (Home Automation End Device)
|
||||
*
|
||||
* Dependência (idf_component.yml):
|
||||
* espressif/esp-zigbee-lib: "^1.6.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_zigbee_core.h"
|
||||
|
||||
static const char *TAG = "zigbee_light_device";
|
||||
|
||||
#define HA_ESP_LIGHT_ENDPOINT 1
|
||||
#define ESP_ZB_PRIMARY_CHANNEL_MASK (1l << 15) // Canal 15 padrão Zigbee
|
||||
|
||||
/* Callback de escrita em atributos Zigbee (ex: Liga/Desliga via Home Assistant) */
|
||||
static esp_err_t zb_attribute_handler(const esp_zb_zcl_set_attr_value_message_t *message)
|
||||
{
|
||||
if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_ON_OFF) {
|
||||
if (message->attribute.id == ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID &&
|
||||
message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_BOOL) {
|
||||
bool on_off_state = message->attribute.data.value ? *(bool *)message->attribute.data.value : false;
|
||||
ESP_LOGW(TAG, ">>> COMANDO ZIGBEE RECEBIDO: Lâmpada %s", on_off_state ? "LIGADA" : "DESLIGADA");
|
||||
}
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* Callback de eventos da pilha Zigbee */
|
||||
void esp_zb_app_signal_handler(esp_zb_app_signal_msg_t *signal_msg)
|
||||
{
|
||||
uint32_t *p_sg_p = signal_msg->p_app_signal;
|
||||
esp_err_t err_status = signal_msg->esp_err_status;
|
||||
esp_zb_app_signal_type_t sig_type = *p_sg_p;
|
||||
|
||||
switch (sig_type) {
|
||||
case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP:
|
||||
ESP_LOGI(TAG, "Iniciando comissionamento na rede Zigbee...");
|
||||
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
|
||||
break;
|
||||
case ESP_ZB_BDB_SIGNAL_STEERING:
|
||||
if (err_status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Conectado com sucesso à rede Zigbee 3.0!");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Buscando coordenador Zigbee novamente...");
|
||||
esp_zb_scheduler_alarm((esp_zb_callback_t)esp_zb_bdb_start_top_level_commissioning, ESP_ZB_BDB_MODE_NETWORK_STEERING, 1000);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void esp_zb_task(void *pvParameters)
|
||||
{
|
||||
// Configura nó Zigbee como End Device
|
||||
esp_zb_cfg_t zb_nwk_cfg = {
|
||||
.esp_zb_role = ESP_ZB_DEVICE_TYPE_ED,
|
||||
.install_code_policy = false,
|
||||
.nwk_cfg.zed_cfg = {
|
||||
.ed_timeout = ESP_ZB_ED_0_5_MIN,
|
||||
.keep_alive = 3000,
|
||||
},
|
||||
};
|
||||
esp_zb_init(&zb_nwk_cfg);
|
||||
|
||||
// Cria o cluster de On/Off de iluminação residencial
|
||||
esp_zb_on_off_light_cfg_t light_cfg = ESP_ZB_DEFAULT_ON_OFF_LIGHT_CONFIG();
|
||||
esp_zb_ep_list_t *ep_list = esp_zb_on_off_light_ep_create(HA_ESP_LIGHT_ENDPOINT, &light_cfg);
|
||||
|
||||
// Registra endpoint e manipulador de atributos
|
||||
esp_zb_device_register(ep_list);
|
||||
esp_zb_core_action_handler_register(zb_attribute_handler);
|
||||
|
||||
esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);
|
||||
ESP_ERROR_CHECK(esp_zb_start(false));
|
||||
esp_zb_main_loop_iteration();
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
|
||||
// Inicializa a pilha de rádio IEEE 802.15.4
|
||||
esp_zb_platform_config_t config = {
|
||||
.radio_config = { .radio_mode = ZB_RADIO_MODE_NATIVE },
|
||||
.host_config = { .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE },
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_zb_platform_config(&config));
|
||||
|
||||
xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
from machine import Pin
|
||||
from time import sleep
|
||||
|
||||
# Définit la broche 2 en sortie (généralement la LED intégrée)
|
||||
led = Pin(2, Pin.OUT)
|
||||
|
||||
while True:
|
||||
led.value(1) # Allume la LED
|
||||
sleep(0.5) # Attend 0,5 seconde
|
||||
led.value(0) # Éteint la LED
|
||||
sleep(0.5) # Attend 0,5 seconde
|
||||
@@ -0,0 +1,48 @@
|
||||
//! Exemplo Rust no ESP32 usando `esp-hal` (Modo Bare-Metal / no_std)
|
||||
//! Pisca um LED e envia mensagens via UART Serial com segurança de memória garantida.
|
||||
//!
|
||||
//! Cargo.toml:
|
||||
//! esp-hal = { version = "0.22", features = ["esp32s3"] }
|
||||
//! esp-println = { version = "0.12", features = ["esp32s3", "log"] }
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use esp_backtrace as _;
|
||||
use esp_hal::{
|
||||
clock::ClockControl,
|
||||
gpio::{Io, Level, Output},
|
||||
peripherals::Peripherals,
|
||||
system::SystemControl,
|
||||
timer::timg::TimerGroup,
|
||||
delay::Delay,
|
||||
prelude::*,
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
// Inicializa periféricos do SoC com verificação em tempo de compilação
|
||||
let peripherals = Peripherals::take();
|
||||
let system = SystemControl::new(peripherals.SYSTEM);
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
// Configura os pinos de E/S
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
let mut led = Output::new(io.pins.gpio2, Level::Low);
|
||||
|
||||
let delay = Delay::new(&clocks);
|
||||
|
||||
println!("🦀 Firmware Rust Bare-Metal inicializado no ESP32!");
|
||||
|
||||
let mut counter: u32 = 0;
|
||||
|
||||
loop {
|
||||
// Inverte estado do LED com garantia de exclusão mútua
|
||||
led.toggle();
|
||||
counter += 1;
|
||||
|
||||
println!("Ciclo Rust #{}: LED está {:?}", counter, led.is_set_high());
|
||||
delay.delay_millis(500);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user