ESP32编辑笔记(9)——Smartconfig

ESP8266/ESP32的Smartconfig快速配网技术详解
本文介绍了物联网时代如何通过ESP8266和ESP32的ESP-Touch协议实现Smartconfig快速配网,包括设备初始化、监听smartconfig报文和通过UDP广播获取网络配置的过程。

前言

随着智能家居,物联网的兴起,越来越多的设备需要连接家庭wifi网络。而WIFI网络的接入是需要知道无线路由器的SSID和密码。大部分的设备是没有输入接口的,在设备中预置WIFI的SSID和密码是不现实的,为了解决这个问题,smartconfig配网方式应运而生。

ESP8266,ESP32使用了ESP-Touch协议,采用的是Smartconfig(快连)技术。当前设备没有和其他设备建立任何实际连接状态下,使用smartconfig一键配置该设备接入WIFI。

smartconfig只需要通过手机UDP发送报文,设备扫描可用无线信道,找到smartconfig的报文,并锁定在这一信道上开始接收数据。

lt4he89m.png

使用smartconfig配网只需要以下3个步骤

  1. 设备初始化,开始监听smartconfig报文数据

  2. 手机设置wifi的SSID和密码后,发送UDP广播

  3. 设备获得报文,配置网络,接入WIFI。

代码说明

  1. 头文件

#include "esp_smartconfig.h
2. 使用 esp_smartconfig_start() 函数配置 smartconfig并开始等待smartconfig报文数据。

*esp_err_t esp_smartconfig_start(const smartconfig_start_config_t config)
3. 配置完成后使用 **esp_err_t esp_smartconfig_stop() ** 函数停止smartconfig

实例

代码还是有点问题,先水一篇文章吧。

#include <stdio.h>
#include <string.h>

#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "esp_netif.h"
#include "esp_wifi.h"
#include "esp_smartconfig.h"
#include "lwip/sockets.h"

#define TCP_SERVER "192.168.8.104"


const char *TAG="smartconfig";




static void System_Init(void);
static void WiFi_init(void);
static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *data);
static void smartconfig_task(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CeHi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值