ESP32同时使用WIFI和蓝牙时出错
我使用的是VS Code 的PlatformIO IDE 开发的ESP32,当我们同时导入WIFI和蓝牙的头文件时,就会出错 。
#include//WIFI#include//蓝牙出现以下错误,因为同时导入蓝牙和WIFI导致程序过大,

文章插图
错误代码
解决方法
添加路径,如下图所示"C:/Users/Administrator/.platformio/packages/framework-arduinoespressif32/tools/partitions",//添加配置文件路径

文章插图
配置文件 , 添加以下代码board_build.partitions = huge_app.csv

文章插图
再次编译 , 欧克
蓝牙连接代码
#include #include BluetoothSerial SerialBT;void setup(){Serial.begin(115200);SerialBT.begin("Homepea"); // 如果没有参数传入则默认是蓝牙名称是: "ESP32"SerialBT.setPin("1234");// 蓝牙连接的配对码Serial.printf("BT initial ok and ready to pair. rn");}void loop(){if (Serial.available()){SerialBT.write(Serial.read());}if (SerialBT.available()){Serial.write(SerialBT.read());}delay(1);}WIFI连接代码
/* *This sketch sends data via HTTP GET requests to data.sparkfun.com service. * *You need to get streamId and privateKey at data.sparkfun.com and paste them *below. Or just customize this script to talk to other HTTP servers. * */#include const char* ssid= "your-ssid";const char* password = "your-password";const char* host = "data.sparkfun.com";const char* streamId= "....................";const char* privateKey = "....................";void setup(){Serial.begin(115200);delay(10);// We start by connecting to a WiFi networkSerial.println();Serial.println();Serial.print("Connecting to ");Serial.println(ssid);WiFi.begin(ssid, password);while (WiFi.status() != WL_CONNECTED) {delay(500);Serial.print(".");}Serial.println("");Serial.println("WiFi connected");Serial.println("IP address: ");Serial.println(WiFi.localIP());}int value = https://www.pyjctjgg.com/keji/0;void loop(){delay(5000);value;Serial.print("connecting to ");Serial.println(host);// Use WiFiClient class to create TCP connectionsWiFiClient client;const int httpPort = 80;if (!client.connect(host, httpPort)) {Serial.println("connection failed");return;}// We now create a URI for the requestString url = "/input/";url= streamId;url= "?private_key=";url= privateKey;url= "&value="https://www.pyjctjgg.com/keji/;url= value;Serial.print("Requesting URL: ");Serial.println(url);// This will send the request to the serverclient.print(String("GET ")url" HTTP/1.1rn""Host: "host"rn""Connection: closernrn");unsigned long timeout = millis();while (client.available() == 0) {if (millis() - timeout > 5000) {Serial.println(">>> Client Timeout !");client.stop();return;}}// Read all the lines of the reply from server and print them to Serialwhile(client.available()) {String line = client.readStringUntil('r');Serial.print(line);}Serial.println();Serial.println("closing connection");}

文章插图
蓝牙和wifi不能同时使用什么办蓝牙和Wi-Fi信号两者主要都是使用2.4GHz频段,导致同时开启时,蓝牙的数据吞吐量会急剧下降,配对设备困难,Wi-Fi间歇性中断,网络受到限制 。目前基本没什么办法可以根治这个问题,但可以用下面的方案临时解决一些问题 。
提供了4种方法,可以参考下 。
方法1:连接至5GHz无线网络
既然知道了问题出在频段冲突上,那么可以考虑购买一个双频(2.4GHz + 5GHz)路由器,并连接至5GHz的Wi-Fi网络 。该方法可以彻底解决干扰问题,但银子也是必不可少的 。
方法2:更换Wi-Fi信道
以TP-Link路由器为例,登录路由器Web管理页,在无线设置->基本设置中找到信道选项,将其改为1、6、11中的任何一个 。这些为2.4GHz的不重叠传输信道,相较于其他信道更稳定一些 。
- 苹果解释airpodspro2第二代耳塞与初代耳机不兼容原因,苹果耳机airpods pro 2代使用教程
- 不会使用打印机,打印机不会自动打印怎么办
- 荣耀畅玩7双卡双待吗,荣耀畅玩7c使用感受
- 骑行头盔蓝牙耳机或将被禁止使用你赞同吗
- 在安卓手机上使用airpods怎么样,airpods配对安卓
- 苹果手机连不上wifi是怎么办「使用苹果手机发现iphone连不上wifi怎么办连不上wifi解决方法」
- 连接不上蓝牙设备,win10 蓝牙无法连接
- 为什么计算机进入睡眠状态后不能使用蓝牙装置唤醒功能,电脑睡眠黑屏无法唤醒
- mac连接不上妙控键盘,mac蝶式键盘失灵维修
- 音频矩阵 音频矩阵使用方法