Hello there.
I'm making a bluetooth app to connect to an esp32-Vroom-32 so that I can make the controls of a miniature house with LEDs lights and servo doors. My app connects to the esp32 but the buttons only work sometimes. So when I turn it on and off and then on again it seems to work for a few seconds. I'm stumped as to why this is happening. I stitched my code together from a few youtube videos on the topic.
The phone I'm using to test the app is a moto e6 play with android 9.0
I tried using the AI companion to see if there were any errors, but nothing conclusive showed up.
You can't request permissions without checking the Android version, and then requesting permissions that version requires. Search the forum for the permissions Classic Bluetooth requires on your version of Android. If you are going to distribute/share your App then your code needs to check the Android Version or SDK Version. You can use the extension "GetApiLevel" to do that.
You have a nice microprocessor, the Vroom supports Classic Bluetooth and BLE (and WiFi).
To help you with the logic of your button events, we need to see your esp32 Script (Sketch). I'm not available today but another Power User will pick-up the baton.
Note that Bluetooth's enemy is metal obstacles. The Vroom's enemy is insufficient power.
I will try to work on using the extension you said. But I need to access my school's lab to be able to test the app so I might take a little while to respond.
Dear @Jairo_Lourenco_dos_S ,
wait a while !
In your ESP32 code you are using the classic BT and therefore you shall not use the BLE on AI2 side.
So, classic BT on ESP32 shall pair classic BT on AI2, as in your first post.
IMHO, due to its ease of use and long-term reliability, this is the best choice.
Later on, whether you'll need a lower power consumption, and once you have become familiar with the BT, you might pass to BLE. Only in that case (BLE) you need the extension.
Having said that, there are several things you shall pay attention to.
In your AI2 code you transmits bytes, while you assign strings to variables, that is:
Since button1 is assigned to be "11" (or "10"), this means a couple of characters "1" "0" or "1" 1".
Each one in ASCII is a byte (0x31 0x30) = "10"; (0x31 0x31) = "11". When you transmits a single byte, only the first one is transmitted.
If you still want to transmit only one byte at a time, you shall assign to the button1 variable a mathematical value (i.e. blue blocks).
Since you will do different actions according to the received data, while you don't use characters ?
By sending characters, i.e. "A", "B", "C",..... your case intruction on the ESP32 code will be simply
case "A":
....
...
break;
case "B":
...
...
break;
and so on without the need to work on 'dadorecibido' (which in turn shall be declared simply char)
In addition to this, I see that in your ESP32 code you send data to the app:
but where is the clock in AI2 to receive these data ? I don't see it in the blocks you posted.
In attachment you can find an old example that I did some time ago.
The app sends characters according to pushbuttons, the ESP32 receives those characters, displays them on the PC monitor and sends them back to AI2. BT_to_ESP32.aia (25.5 KB) ESP32_BT_Monitor.ino (1.4 KB)
Wow, I hadn't even considered using characters in my case statements. That's brilliant!
If you're okay with it, I'd love to use your app as inspiration for my own project.
As for the data-sending part, I ended up abandoning that idea. Initially, I was planning to use a DHT11 sensor to monitor the humidity and temperature of my little 3D-printed house, but I ran into issues with the data transmission and now knowing how to display the text in the app.
I will make a few changes in my app and hopefully test it the day after tomorrow. I will keep you posted on any other issues I may have.
EDIT: if you want to transmit from Arduino (i.e. DHT11) please consider to transmit characters/strings also in that case. Since Temp & Hum are float type you can convert them to int, then to strings, so the AI2 app can use the receive.text, which is far simpler to handle.