2020-06-08
上周五开始搞smartconfig,遇到问题,获取到正确的ssid和password之后,wifi始终连不上。
在网上找了ESP32 LyraT V4.3的软件,但是没找到。然后翻到一个帖子,说官方adf里面有smartconfig的例程。二话不说,翻了一些文件夹,确实有。
cd examples/wifi/smart_config
make all
make flash 报错了。然后make clean清除了旧的数据。重新make all
ok了
开心啊,折腾了几天终于能连上wifi了。
之前在开源一小步上例程移植的一直连不上。晚点再研究一下。。总之很开心
2020-06-08晚
将官方的例程整个.c文件的内容拷贝到我自己新建的工程上,编译,还是不ok。无语,估计前面我自己新建的工程哪里有问题,和原来的代码没太大关系。。。明天继续努力!
2020-06-09
今天直接将官方idf里面smartconfig_main.c拷贝到我自己的工程里面,编译,测试ok。把其他功能移植回来,程序都正常了。附上我的例程代码
/* Esptouch example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "esp_wpa2.h"
#include "esp_event_loop.h"
#include "esp_log.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "tcpip_adapter.h"
#include "esp_smartconfig.h"
#define LED_IO 22
#define KEY_REC_IO 36
#define KEY_MODE_IO 39
uint8_t key_value = 0;
uint16_t timer_ms_cnt = 0;
uint16_t timer_1s_cnt = 0;
uint8_t led_flag = 0;
//定时器句柄
esp_timer_handle_t fw_timer_handle = 0;
void read_key(void);
void fw_timer_cb(void *arg);
/* FreeRTOS event group to signal when we are connected & ready to make a request */
static EventGroupHandle_t wifi_event_group;
/* The event group allows multiple bits for each event,
but we only care about one event - are we connected
to the AP with an IP? */
static const int CONNECTED_BIT = BIT0;
static const int ESPTOUCH_DONE_BIT = BIT1;
static const char *TAG = "sc";
void smartconfig_example_task(void * parm);
static esp_err_t event_handler(void *ctx, system_event_t *event)
{
switch(event->event_id) {
case SYSTEM_EVENT_STA_START:
xTaskCreate(smartconfig_example_task, "smartconfig_example_task",</