La linea que se debe de agregar en CMakeList.txt, es el que se encuentra a nivel raiz del proyecto.
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
La linea que se debe de agregar en CMakeList.txt, es el que se encuentra a nivel raiz del proyecto.
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
¿En verdad existen las redes WIFI?
¿No estará mal empleado el termino?
¿No es una certificación?
Muestro : IP obtenida Netmask Gateway . .
#include <stdio.h>
#include "esp_wifi.h"
#include "nvs_flash.h"
#include "protocol_examples_common.h"
esp_netif_ip_info_t ip_info;
esp_netif_t* netif = NULL;
void app_main(void)
{
nvs_flash_init();
esp_netif_init();
esp_event_loop_create_default();
example_connect();
netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
if (netif == NULL)
{
printf("No hay interfaz\n");
}
else
{
esp_netif_get_ip_info(netif, &ip_info);
printf("************************************************************\n");
printf("IP : %d.%d.%d.%d\n ", IP2STR(&ip_info.ip));
printf("Net mask : %d.%d.%d.%d\n ", IP2STR(&ip_info.netmask));
printf("Gateway : %d.%d.%d.%d\n ", IP2STR(&ip_info.gw));
};
}
. . El resultado es: .
I (5587) example_common: Connected to example_netif_sta
I (5597) example_common: - IPv4 address: 192.168.26.252,
I (5597) example_common: - IPv6 address: fe80:0000:0000:0000:daa0:1dff:fe42:d550, type: ESP_IP6_ADDR_IS_LINK_LOCAL
************************************************************
IP : 192.168.26.252
Net mask : 255.255.255.0
Gateway : 192.168.26.225
I (5627) main_task: Returned from app_main()
I (420797) wifi:<ba-add>idx:1 (ifx:0, a6:d0:ad:16:81:5f), tid:6, ssn:2, winSize:64
. . Este es resultado del comando ping: .
/Dropbox/cursos/notebooks/programacion_de_nicrocontroladores_esp32/wifi ping 192.168.26.252
PING 192.168.26.252 (192.168.26.252) 56(84) bytes of data.
64 bytes from 192.168.26.252: icmp_seq=1 ttl=255 time=714 ms
64 bytes from 192.168.26.252: icmp_seq=2 ttl=255 time=123 ms
64 bytes from 192.168.26.252: icmp_seq=3 ttl=255 time=157 ms
64 bytes from 192.168.26.252: icmp_seq=4 ttl=255 time=60.9 ms
^C
--- 192.168.26.252 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 60.933/263.532/713.528/262.071 ms
hola, es que tengo un problema con la conexión de la esp32, el programa compila normal, pero ya en la esp no conecta con mi punto de acceso, que podrá ser?, les dejo el código que copie del video.
#include <stdio.h>
#include "esp_wifi.h"
#include "nvs_flash.h"
#include "protocol_examples_common.h"
void app_main(void)
{
nvs_flash_init();
esp_netif_init();
esp_event_loop_create_default();
example_connect();
esp_netif_ip_info_t ip_info;
esp_netif_t* netif = NULL;
netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
if(netif == NULL){
printf("no hay interfaz.\n");
}else{
esp_netif_get_ip_info(netif, &ip_info);
printf("IP: %d.%d.%d.%d\n",IP2STR(&ip_info.ip));
}
}
hola, tengo problemas con la línea que se agrega al cMakeList.txt, me aparece el siguiente error:
Current directory 'C:/Espressif/frameworks/esp-idf-v5.0.1' is not
buildable. Change directories to one of the example projects in
'C:/Espressif/frameworks/esp-idf-v5.0.1/examples' and try again.
la línea que agregué es esta:
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
ya probé a invertitr los slash como para windows (\) y me sale el mismo error.
¿alquien tiene alguna idea de que puedo estar haciendo mal?
gracias de antemano
si estas viendo esto en el 2035 hubo háganos cambios del uso de la de los eventos y actualizaciónes
#include <stdio.h>#include "nvs_flash.h"#include "esp_wifi.h"#include "esp_event.h"#include "esp_log.h"#include "esp_netif.h"#include "driver/gpio.h"#include "freertos/FreeRTOS.h"#include "freertos/task.h" #define LED_GPIO GPIO_NUM_4 // Conector 4 static const char *TAG = "wifi_led";static TaskHandle_t led_task_handle = NULL;static bool wifi_connected = false; // Tarea para hacer parpadear el LED mientras se conectavoid led_blink_task(void *pvParameter) { while (!wifi_connected) { gpio_set_level(LED_GPIO, 1); vTaskDelay(pdMS_TO_TICKS(300)); gpio_set_level(LED_GPIO, 0); vTaskDelay(pdMS_TO_TICKS(300)); } vTaskDelete(NULL); // Tarea termina cuando ya hay conexión} // Manejador de eventosstatic void wifi_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) { ESP_LOGI(TAG, "Desconectado. Reintentando..."); wifi_connected = false; esp_wifi_connect(); // Reiniciar tarea de parpadeo si es necesario if (led_task_handle == NULL) { xTaskCreate(led_blink_task, "led_blink_task", 2048, NULL, 5, &led_task_handle); } } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; ESP_LOGI(TAG, "Conectado con IP: " IPSTR, IP2STR(&event->ip_info.ip)); wifi_connected = true; // Encender LED fijo gpio_set_level(LED_GPIO, 1); // Eliminar tarea de parpadeo si sigue corriendo if (led_task_handle != NULL) { vTaskDelete(led_task_handle); led_task_handle = NULL; } }} void app_main(void){ // Inicializar NVS esp_err_t 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()); ret = nvs_flash_init(); } ESP_ERROR_CHECK(ret); // Inicializar red y eventos ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); // Configurar GPIO del LED gpio_config_t io_conf = { .pin_bit_mask = (1ULL << LED_GPIO), .mode = GPIO_MODE_OUTPUT, .pull_up_en = 0, .pull_down_en = 0, .intr_type = GPIO_INTR_DISABLE }; gpio_config(&io_conf); gpio_set_level(LED_GPIO, 0); // Apagar inicialmente // Crear interfaz Wi-Fi STA esp_netif_create_default_wifi_sta(); // Configurar Wi-Fi wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); wifi_config_t wifi_config = { .sta = { .ssid = WIFI_SSID, .password = WIFI_PASS, }, }; // Registrar eventos ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL)); ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &wifi_event_handler, NULL)); // Configurar Wi-Fi como estación 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()); ESP_LOGI(TAG, "Wi-Fi inicializado. Conectando a %s...", WIFI_SSID); // Iniciar tarea de parpadeo xTaskCreate(led_blink_task, "led_blink_task", 2048, NULL, 5, &led_task_handle);}
Hola, estoy haciendo un proyecto usando el ESP32 y PN532. La idea es que se prenda cuatro motores cuando pasa la tarjeta por el sensor o por medio de wifi, para el caso de wifi lo estoy haciendo conectando el celular a la red que se crea desde el ESP. Los motores deben dejar de vibrar cuando contador es igual a 20 o por medio de un botón (usando una interrupción). Tengo dos dudas la primera es que cuando se cumple alguna de las dos condiciones antes mencionadas me sale un error al usar este comando nfc.startPassiveTargetIDDetection(PN532_MIFARE_ISO14443A) pero si no lo uso el sensor lee la tarjeta la primera vez y no la vuelve a leer. La segunda es que cuando integro la parte de wifi con la parte donde uso el PN532 no carga la interfaz creada (solo lo hace mientras la variable LeeTarjeta es verdadera) ¿Cómo puedo solucionarlo?
//Declaración de Librerías
#include <Wire.h>
#include <SPI.h> //Librería para comunicación SPI serial parallel interface
#include <WiFi.h> // Libreria Wifi
#include <UNIT_PN532.h> //Librería Modificada ya que la tasa de bits que viene predefinida
//en la librería de Adafruit es demasiado rápida para el ESP32 por lo cual se debe modificar este dato para poder utilizarlo con esta placa
//Conexiones SPI del ESP32
#define PN532_SCK (18)
#define PN532_MOSI (23)
#define PN532_SS (5)
#define PN532_MISO (19)
#define motor1 (33)
#define motor2 (32)
#define motor3 (25)
#define motor4 (26)
#define boton1 (2)
// variables a usar
uint8_t DatoRecibido[4]; //Para almacenar los datos
int contador=0;
int boton_restart=0;
void IRAM_ATTR onTimer();
boolean LeeTarjeta=false; //Variable para almacenar la detección de una tarjeta
UNIT_PN532 nfc(PN532_SS);// Línea enfocada para la comunicación por SPI
hw_timer_t * timer = NULL;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Búfer para almacenar el UID devuelto
uint8_t LongitudUID; //Variable para almacenar la longitud del UID de la tarjeta
const char* ssid = "Faja-Punto-Acceso";
const char* password = "123456789";
// Set web server port number to 80
WiFiServer server(80);
// Variable to store the HTTP request
String header;
// Auxiliar variables to store the current output state
String outputMotores1 = "off";
String outputMotores2 = "off";
void setup() {
Serial.begin(115200); //Inicio de puerto Serial a 115200 baudios
// Connect to Wi-Fi network with SSID and password
Serial.print("Setting AP (Access Point)…");
// Remove the password parameter, if you want the AP (Access Point) to be open
WiFi.softAP(ssid, password);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);
server.begin();
nfc.begin(); //Comienza la comunicación del PN532
uint32_t versiondata = nfc.getFirmwareVersion();//Obtiene información de la placa
if (! versiondata) { //Si no se encuentra comunicación con la placa --->
Serial.print("No se encontró la placa PN53x");
while (1); // Detener
}
//Establezca el número máximo de reintentos para leer de una tarjeta.
//Esto evita que tengamos que esperar eternamente por una tarjeta,
//que es el comportamiento predeterminado del PN532.
nfc.setPassiveActivationRetries(0xFF);
nfc.SAMConfig(); //Configura la placa para realizar la lectura
// Serial.println("Esperando una tarjeta ISO14443A ...");
pinMode(motor1, OUTPUT); // Se configuran los pines como salidas
pinMode(motor2, OUTPUT);
pinMode(motor3, OUTPUT);
pinMode(motor4, OUTPUT);
pinMode(boton1, INPUT_PULLDOWN);
attachInterrupt(boton1,isr_boton,RISING);
}
void loop() {
Serial.println("loop");
//Recepción y detección de los datos de la tarjeta y almacenamiento en la variable "LeeTarjeta"
LeeTarjeta = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &LongitudUID);
WiFiClient client = server.available(); // Listen for incoming clients
//Se detecto un tarjeta RFID
if (LeeTarjeta) {
timer = timerBegin(0, 80, true); // timer 0, MWDT clock periodo = 12.5 ns * TIMGn_Tx_WDT_CLK_PRESCALE -> 12.5 ns * 80 -> 1000 ns = 1 us, countUp--> conteo ascendente
timerAttachInterrupt(timer, &onTimer, true); // edge (not level) triggered
timerAlarmWrite(timer, 1000000, true); // 1000000 * 1 us = 1 s, autoreload true
timerAlarmEnable(timer); // enable
}
//Si no se detecta tarjeta
else
{
Serial.print(PN532_SCK);
Serial.println("Se agotó el tiempo de espera de una tarjeta");
}
vTaskDelay(portMAX_DELAY); // wait as much as posible ...
//wifi
if (client) { // If a new client connects,
Serial.println("New Client."); // print a message out in the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) {
// loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();
// turns the GPIOs on and off
if (header.indexOf("GET /26/on") >= 0) {
Serial.println("GPIO 26 on");
outputMotores1 = "on";
digitalWrite(motor1, HIGH);
digitalWrite(motor2, HIGH);
digitalWrite(motor3, HIGH);
digitalWrite(motor4, HIGH);
} else if (header.indexOf("GET /26/off") >= 0) {
Serial.println("GPIO 26 off");
outputMotores1 = "off";
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
digitalWrite(motor3, LOW);
digitalWrite(motor4, LOW);
} else if (header.indexOf("GET /27/on") >= 0) {
digitalWrite(motor1, HIGH);
digitalWrite(motor2, HIGH);
digitalWrite(motor3, HIGH);
digitalWrite(motor4, HIGH);
outputMotores2 = "on";
delay(100);
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
digitalWrite(motor3, LOW);
digitalWrite(motor4, LOW);
outputMotores2 = "off";
}
// Display the HTML web page
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your preferences
client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
client.println(".button { background-color: #FF689D; border: none; color: white; padding: 16px 40px;");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
client.println(".button2 {background-color: #555555;}</style></head>");
// Web Page Heading
client.println("<body><h2>Adiestramiento perros</h2>");
// Display current state, and ON/OFF buttons for GPIO 26
client.println("<p>vibracion continua - State " + outputMotores1 + "</p>");
// If the output26State is off, it displays the ON button
if (outputMotores1=="off") {
client.println("<p><a href=\"/26/on\"><button class=\"button\">ON</button></a></p>");
} else {
client.println("<p><a href=\"/26/off\"><button class=\"button button2\">OFF</button></a></p>");
}
// Display current state, and ON/OFF buttons for GPIO 27
client.println("<p>pulso - State " + outputMotores2 + "</p>");
// If the output27State is off, it displays the ON button
if (outputMotores2=="off") {
client.println("<p><a href=\"/27/on\"><button class=\"button\">ON</button></a></p>");
} else {
client.println("<p><a href=\"/27/off\"><button class=\"button button2\">OFF</button></a></p>");
}
client.println("</body></html>");
// The HTTP response ends with another blank line
client.println();
// Break out of the while loop
break;
} else { // if you got a newline, then clear currentLine
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}
void isr_boton(){
boton_restart=1;
}
void IRAM_ATTR onTimer(){ // interrupción del timer cuando se c
digitalWrite(motor1,!digitalRead(motor1)); // cambio de estado de los leds
digitalWrite(motor2,!digitalRead(motor2));
digitalWrite(motor3,!digitalRead(motor3));
digitalWrite(motor4,!digitalRead(motor4));
contador++;
if (contador==20||boton_restart==1){
digitalWrite(motor1,LOW); // cambio de estado de los leds
digitalWrite(motor2,LOW);
digitalWrite(motor3,LOW);
digitalWrite(motor4,LOW);
contador=0;
timerDetachInterrupt(timer);
nfc.startPassiveTargetIDDetection(PN532_MIFARE_ISO14443A);
Serial.print("fin");
}
}
Y est es el error que sale
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x40086192 PS : 0x00050531 A0 : 0x800d2fbb A1 : 0x3ffc0260
A2 : 0x00000044 A3 : 0x00018044 A4 : 0x000637ff A5 : 0x3ffc0240
A6 : 0x000000ff A7 : 0x00000001 A8 : 0x000000ff A9 : 0x4008cc38
A10 : 0x00000003 A11 : 0x00060a23 A12 : 0x80081b98 A13 : 0x3ffc0220
A14 : 0x3ffc17b4 A15 : 0x00000000 SAR : 0x0000001b EXCCAUSE: 0x0000001c
EXCVADDR: 0x800d2fc7 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xfffffffe
Core 1 was running in ISR context:
EPC1 : 0x40086192 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x40084a80
ELF file SHA256: 0000000000000000
Backtrace: 0x40086192:0x3ffc0260 0x400d2fb8:0x3ffbc6d0 0x400e74e3:0x3ffbc6f0 0x4008bcd5:0x3ffbc710 0x4008a52e:0x3ffbc730
Rebooting...
ets Jul 29 2019 12:21:46
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5856
entry 0x400806a8
Setting AP (Access Point)…AP IP address: 192.168.4.1