我使用的是VS Code 的PlatformIO IDE 开发的ESP32,当我们同时导入WIFI和蓝牙的头文件时,就会出错。#include //WIFI#include
我使用的是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 network Serial.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 = 0;void loop(){ delay(5000); value; Serial.print("connecting to "); Serial.println(host); // Use WiFiClient class to create TCP connections WiFiClient client; const int httpPort = 80; if (!client.connect(host, httpPort)) { Serial.println("connection failed"); return; } // We now create a URI for the request String url = "/input/"; url = streamId; url = "?private_key="; url = privateKey; url = "&value="; url = value; Serial.print("Requesting URL: "); Serial.println(url); // This will send the request to the server client.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 Serial while(client.available()) { String line = client.readStringUntil('r'); Serial.print(line); } Serial.println(); Serial.println("closing connection");}1、首先在电脑上点击“开始“菜单,点击"控制面板”。
2、然后在控制面板页面,点击“网络和Internet”。
3、然后在新打开的页面点击“网络和共享中心”。
4、点击左侧的“更改配置器设置”,出现“网络连接”窗口。
5、右键点击“无线网络连接”,选择“属性”,出现“属性”对话框,点击“配置”按钮。
6、选择“高级”栏,将其中的”Bluetooth协作“启用,确认完成,冲突问题就解决了。