Nil*_*r F 7 arduino arduino-esp8266 arduino-c++ esp32
我正在创建一个涉及蓝牙和 WiFi 的应用程序。我首先将手机连接到蓝牙,并通过它传递 WiFi ssid 和密码。然后,在收到 ssid 和密码后,我尝试将其连接到 WiFi。我设法将 ssid 和密码存储到一个字符数组中。
从蓝牙发送数据后,ESP32 与 WiFi 建立连接后,蓝牙断开。我无法再次连接蓝牙,因为 WiFi 已连接,因为我通过 Bluetooth.read() 控制代码中的某些语句,所以我需要允许连接在 WiFi 和蓝牙之间共存。
该项目由 SPIFFS(闪存保存)组成。首先从蓝牙传递WiFi ssid和密码,然后,我将接收到的蓝牙数据连接到一个字符数组中,以便稍后将其连接到互联网。
\n
我首先想到添加一个回调,在设备尝试连接时发出警报,但在文档中找不到任何能够执行此操作的代码。我有一个回调函数,可以告诉我设备何时连接和断开连接。\n
\n我搜索并找到了相关内容,Menuconfig但找不到它所在的位置。\n
\n这是我正在阅读的内容:https: //www.espressif.com/sites/default/files/documentation/ESP32_FAQs__EN.pdf
5.3.2.\nHow do ESP32 Bluetooth and Wi-Fi coexist?\nIn the menuconfig menu, there is a special option called \xe2\x80\x9cSoftware controls WiFi/ \nBluetooth coexistence\xe2\x80\x9d, which is used to control the ESP32\'s Bluetooth and Wi-Fi \ncoexistence using software, thus balancing the coexistence requirement for controlling \nthe RF module by both the Wi-Fi and Bluetooth modules. Please note that if Option \n\xe2\x80\x9cSoftware controls WiFi/Bluetooth coexistence\xe2\x80\x9d is enabled, the BLE scan \ninterval shall not exceed 0x100 slots (about 160 ms).\nRun Code Online (Sandbox Code Playgroud)\n我找不到menuconfig位置。\n
\n我正在使用 ```BluetoothSerial.h`` 库\n
\n这是一段代码:
// ------------------------------ Inicializa\xc3\xa7\xc3\xa3o do loop ------------------------------ //\nvoid loop() {\n // Preparando String para enviar ao usuario\n line_one_length = line_one.length();\n line_two_length = line_two.length();\n line_three_length = line_three.length();\n\n char receive_line_one[line_one_length], receive_line_two[line_two_length], receive_line_three[line_three_length];\n char receive_wifi_ssid[line_one_length], receive_wifi_pass[line_two_length];\n \n String deletar;\n \n file = SPIFFS.open("/wifi.txt");\n\n // ------------------------------ Ve se o usuario digitou a palavra deletar ------------------------------ //\n if (SerialBT.available()){\n while (SerialBT.available()) {\n insert_chars = SerialBT.read();\n deletar = String(deletar + insert_chars);\n }\n deletar.trim();\n }\n\n // ------------------------------ Conex\xc3\xa3o ao WiFi ------------------------------ //\n if (line_one != "" and wifi_state == 0 and receive_wifi_ssid != ""){\n line_one.toCharArray(receive_wifi_ssid, line_one_length);\n line_two.toCharArray(receive_wifi_pass, line_two_length);\n delay(100);\n WiFi.begin(receive_wifi_ssid, receive_wifi_pass);\n Serial.println("Conectando ao WiFi...");\n while (WiFi.status() != WL_CONNECTED)\n {\n Serial.print(".");\n delay(1000);\n }\n Serial.println("\\nConectado ao WiFi");\n wifi_state = 1;\n }\n\n Serial.print("Estado: ");\n Serial.println(connection_state);\n\n // ------------------------------ V\xc3\xaa se a conteudo dentro do FILE ------------------------------ //\n if (file.size() > 0) {\n if (deletar == "deletar"){\n delete_file_info();\n wifi_ssid = "";\n wifi_password = "";\n database_info = "";\n line_one = "";\n line_two = "";\n line_three = "";\n wifi_state = 0;\n Serial.println("Arquivo deletado com sucesso");\n return;\n }\n read_file_info();\n all_lines();\n }else{ \n if (wifi_ssid == "" and connection_state == 0 and line_one == ""){\n Serial.print("File size: ");\n Serial.print(file.size());\n Serial.println(", O valor dentro da string \xc3\xa9 nulo, nada ser\xc3\xa1 adicionado ao arquivo");\n delay(1000);\n }else if (connection_state == 1 and line_one == ""){\n // Chamando a fun\xc3\xa7\xc3\xa3o para armazenar os dados do usuario dentro do FILE\n bluetooth_while_loop();\n }\n }\n \n file.close();\n delay(3000);\n\nRun Code Online (Sandbox Code Playgroud)\n我需要的是能够同时在 WiFi 和蓝牙之间建立连接。
\n就menuconfig在这里。软件WiFi/BL共存的代码在这里。相关问题在这里。由于 WiFi 和蓝牙使用相同的天线,因此我不建议同时进行 WiFi/BL 共存。相反,您可以同时WiFi.setMode(WiFi_AP_STA)实例化SoftAP模式和STA模式。尝试使用下面的代码来实例化softAP和STA模式:
#include <WiFi.h>
void setup(){
WiFi.setMode(WIFI_AP_STA);
WiFi.begin("my-sta-ssid", "my-sta-pass");
WiFi.softAP("my-ap-ssid", "my-ap-pass");
}
void loop(){}
Run Code Online (Sandbox Code Playgroud)
您可以创建简单的WebServer“运行时配置”事情。
| 归档时间: |
|
| 查看次数: |
22978 次 |
| 最近记录: |