当前位置:网站首页>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

手机发送
串口助手退出透传 +++,连续三个+++
发现只有自动发送才能顺利退出透传。

基本连接之后,不会自动退出连接。除非断电。。
边栏推荐
- 使用docker安装mysql
- BioVendor Human Club Cellular Protein (CC16) Elisa Kit Research Fields
- Outsourcing worked for three years, it was abolished...
- Golang分布式应用之Redis
- The underlying data structure of Redis
- Analysis of the status quo of digital transformation of manufacturing enterprises
- [ORB_SLAM2] SetPose, UpdatePoseMatrices
- Hash collisions and consistent hashing
- Entry name 'org/apache/commons/codec/language/bm/gen_approx_greeklatin.txt' collided
- Centos7 安装postgresql并开启远程访问
猜你喜欢

Outsourcing worked for three years, it was abolished...

Power button 1374. Generate each character string is an odd number

四元数、罗德里格斯公式、欧拉角、旋转矩阵推导和资料

Electronic Manufacturing Warehouse Barcode Management System Solution

Safety (2)

Handwritten Blog Platform ~ Day Two

机器人领域期刊会议汇总

Garbage Collector CMS and G1

Remember a pit for gorm initialization

From 2023 onwards, these regions will be able to obtain a certificate with a score lower than 45 in the soft examination.
随机推荐
oracle query scan full table and walk index
[ORB_SLAM2] SetPose, UpdatePoseMatrices
FOFAHUB使用测试
IMU预积分的简单理解
NIO‘s Sword(牛客多校赛)
十字光标太小怎么调节、CAD梦想画图算量技巧
Nanoprobes免疫测定丨FluoroNanogold试剂免疫染色方案
欧拉公式的证明
Centos7 install postgresql and enable remote access
Redis for distributed applications in Golang
2022 NPDP take an examination of how the results?How to query?
nacos启动报错,已配置数据库,单机启动
AntPathMatcher uses
swift project, sqlcipher3 -> 4, cannot open legacy database is there a way to fix it
Install mysql using docker
The underlying data structure of Redis
Scheduled tasks for distributed applications in Golang
数值积分方法:欧拉积分、中点积分和龙格-库塔法积分
列表常用方法
EFCore 反向工程