当前位置:网站首页>esp32经典蓝牙和单片机连接,,,手机蓝牙作为主机
esp32经典蓝牙和单片机连接,,,手机蓝牙作为主机
2022-08-02 02:22:00 【ooolmf】
步骤
1、编译AT固件,把金典蓝牙打开,默认不打开,烧录esp32;
2、按照
https://docs.espressif.com/projects/esp-at/zh_CN/latest/esp32/Compile_and_Develop/how_to_enable_at_classic_bluetooth.html
置开启SPP功能,上面截图的A2DP 不打开。
3、https://docs.espressif.com/projects/esp-at/zh_CN/latest/esp32/AT_Command_Examples/classic_bluetooth_at_examples.html
以透传模式在移动电话或者 PC 和 ESP32 之间建立 SPP 连接并且设置 IO 能力为 NoInputNoOutput
在本例中,移动电话或 PC 为主机,ESP32 为从机。该示例展示了如何建立 SPP 连接。
Classic Bluetooth 初始化。
命令:
AT+BTINIT=1
响应:
OK
Classic Bluetooth SPP 协议初始化并且设置角色为 slave。
命令:
AT+BTSPPINIT=2
响应:
OK
设置 Classic Bluetooth 设备名称。
命令:
AT+BTNAME=“EXAMPLE”
响应:
OK
设置 Classic Bluetooth 扫描模式为可发现可连接。
命令:
AT+BTSCANMODE=2
响应:
OK
设置 Classic Bluetooth 安全参数。设置 io_cap 为 NoInputNoOutput,pin_type 为 fixed,pin_code 为 9527。
命令:
AT+BTSECPARAM=3,1,“9527”
响应:
OK
开启 Classic Bluetooth SPP 协议。
命令:
AT+BTSPPSTART
响应:
OK
移动电话或者 PC 发起连接。
移动电话或 PC 应能找到名为 “EXAMPLE” 的蓝牙设备。如果移动电话或 PC 发起连接并成功建立连接,ESP32 将提示:
+BTSPPCONN:0,“e0:24:81:47:90:bc”
说明:
您获取到的地址可能与上述响应中的不同。
在透传模式下发送数据。
命令:
AT+BTSPPSEND
响应:
OK
上述响应表示 AT 已经进入透传模式。
说明:
AT 进入透传模式后,串口收到的数据会传输到移动电话或者 PC 端。
停止发送数据。
在透传发送数据过程中,若识别到单独的一包数据 +++,则系统会退出透传发送。此时请至少等待 1 秒,再发下一条 AT 命令。请注意,如果直接用键盘打字输入 +++,有可能因时间太慢而不能被识别为连续的三个 +。更多介绍请参考 AT+BTSPPSEND。
重要
使用 +++ 可退出透传发送数据,回到正常 AT 命令模式。您也可以使用 AT+BTSPPSEND 命令恢复透传。
断开 Classic Bluetooth SPP 连接。
命令:
AT+BTSPPDISCONN=0
响应:
+BTSPPDISCONN:0,“e0:24:81:47:90:bc”
OK
说明:
您获取到的地址可能与上述响应中的不同。
实现成功,是透传模式。。
从机发送+++,退出透传。
后面实现以下两个ESP32自动进入透传。。
测试
AT回车,发送,返回OK;
AT+BTINIT=1 初始化,有时候会失败,不管。
设置从机
AT+BTSPPINIT=2
打开扫描,AT+BTSCANMODE=2
开始通信,之后等待蓝牙连接。
AT+BTSPPSTART如果已经拦截,这个返回错误。
手机发送55556
串口助手得到返回
串口助手发送透传模式,进入透传模式就没有前面的返回,或者关闭回显ATE0
AT+BTSPPSEND
手机发送
串口助手退出透传 +++,连续三个+++
发现只有自动发送才能顺利退出透传。
基本连接之后,不会自动退出连接。除非断电。。
边栏推荐
- 罗德里格斯公式(Rodrigues‘ Rotation Formula)推导
- 2022-08-01 Reflection
- 2022-08-01 Install mysql monitoring tool phhMyAdmin
- Use DBeaver for mysql data backup and recovery
- Moonbeam and Project integration of the Galaxy, bring brand-new user experience for the community
- 力扣(LeetCode)213. 打家劫舍 II(2022.08.01)
- Centos7 install postgresql and enable remote access
- 使用docker安装mysql
- BI - SQL 丨 WHILE
- Software testing Interface automation testing Pytest framework encapsulates requests library Encapsulates unified request and multiple base path processing Interface association encapsulation Test cas
猜你喜欢
BI-SQL丨WHILE
[LeetCode Daily Question]——654. The largest binary tree
BioVendor人俱乐部细胞蛋白(CC16)Elisa试剂盒研究领域
oracle查询扫描全表和走索引
工程师如何对待开源
"NetEase Internship" Weekly Diary (3)
Nanoprobes多组氨酸 (His-) 标签标记:重组蛋白检测方案
BioVendor Human Club Cellular Protein (CC16) Elisa Kit Research Fields
【web】Understanding Cookie and Session Mechanism
Redis Subscription and Redis Stream
随机推荐
cocos中使用async await异步加载资源
Redis Persistence - RDB and AOF
789. 数的范围
BioVendor Human Club Cellular Protein (CC16) Elisa Kit Research Fields
【 wheeled odometer 】
The state status is displayed incorrectly after the openGauss switch
工程师如何对待开源
考完PMP学什么?前方软考等着你~
MySQL8 download, start, configure, verify
The underlying data structure of Redis
2022河南青训联赛第(三)场
The principle and code implementation of intelligent follower robot in the actual combat of innovative projects
[Server data recovery] Data recovery case of server Raid5 array mdisk disk offline
软件测试 接口自动化测试 pytest框架封装 requests库 封装统一请求和多个基础路径处理 接口关联封装 测试用例写在yaml文件中 数据热加载(动态参数) 断言
IMU预积分的简单理解
[Unity entry plan] 2D Game Kit: A preliminary understanding of the composition of 2D games
极大似然估计
一次SQL优化,数据库查询速度提升 60 倍
字典常用方法
【web】理解 Cookie 和 Session 机制