请帮帮我,我只能搜到ESP32的蓝牙,但是无法与其连接,错误代码os code4;ESP32上的代码使用micro python写的,经过nrf connect等蓝牙调试器的测试都能正常连接与通信,但始终无法与生成的app连接上;论坛里诸位大神的代码我也都失败了。
Please help me, I can only search for the ESP32's Bluetooth, but I cannot connect to it, with error code os code 4. The code on the ESP32 is written in MicroPython, and after testing with Bluetooth debuggers like nRF Connect, it can normally connect and communicate. However, I am always unable to connect with the generated app; I have also tried the code from experts on forums, but all attempts have failed
micropython.txt (4.0 KB)
esp32_2.aia (200.5 KB)
Hello 吠唐 鱼
What is the make/model/Android version of your phone?
An excellent phone, shouldn't be an issue. I'm going to take a look at the files you have uploaded. Android 14 has some strict rules for compiled Apps which the projects on the forum don't necessarily cover.
A few things with the App Inventor Project:
-
There should not be a need to manipulate the target address picked from a List - the BLE ConnectWithAddress Block does that for you.
-
Stop Scanning After Picking (no later than that)
-
You have Registered For Strings - that is to receive stream of data, but you are only sending data with your Blocks.
-
On intialising Screen1, you must request permissions for Android 14. How you go about doing that depends on whether the App is only for your Use on your Android 14 phone or if it will be used on other phones and other Android versions. Let us know so we can guide you more.
-
Drag a Location Sensor into the Designer. Your App doesn't need to have a use for it, it's just to satisfy Google's requirement for Bluetooth use.
Thank you, I need some time to study; when it comes to coding, I am still a beginner
Regarding the '!', it's because I found an app to control a car via Bluetooth. After testing, the information that its control buttons pass to the ESP32 is just these. I have temporarily completed my DIY for the lights using it, but I still hope to have an app that can more intuitively control the lights
Hello, first of all, thank you for your help. I have successfully completed the connection with the ESP32. However, during the process of transmitting information, I found that the bytes sent from the app come with a square box, and I am unable to write this square box into MicroPython.
I have already solved my problem
Yes, the 'box' is a line feed character? Read the 1st character of the string received into BLE_MSG, which should be BLE_MSG[0]. I understand that requires Python 3.x
....or this might work on the App side instead:
Thank you for your help, the method worked very well.