I have attached a project which I'm sure many will be able to improve on. As I only started using B4A a couple days ago so I still don't fully understand the syntax.
What this project does:
1. Scan and connect to BLE device
2. Allow 3 individual UUIDs
3. Send Button with "DATA TO SEND GOES HERE" text
4. Receive window
If you are using a Micorchip RN4871 as I am, you will first need to configure it using the host microcontroller.
The default baud rate for the RN4781 and most likely other Microchip BLE module is 115200 so you will need to be able to reach this rate with the host microcontroller.
The RN4871 does not do well with a slight mis-match so if you are getting either it sometimes working or perhaps not at all, you might need to compare the length of the bytes going in and coming out of your module to ensure they are the same.
If you don't have a scope you can keep changing the OSCTUNE bits or frequency offset of your host microcontroller until you get a reliable response from your module.
Once you have a good link with the RN4871(or other BLE Module using Transparent UART) you will need to configure your module, this is done every time on power up by your host microcontroller.
You will need to send at 115200:
[Pseudo Code] (As you might be writing firmware in another syntax)
Power up your RN4871 holding the RESET pin
When you are ready release the RESET pin.
Wait 101 Milliseconds
Wait for data response ' Now you are in Command mode
Wait for data response ' This turns on Echo, you need this to ensure that you have a reliable data link and no miss-match in frequency.
You can send a nice long string as I have then check it's the same string, if not you can trim your microcontroller frequency or change your baudrate slightly to compensate.
Send "SS,C0" ' You might as I have, needed to send "S" , "S" , "," , "C" , "0" because my hardware serial port on the microcontroller sent the bytes too close together for the RN4871. This enables Transparent UART Mode
Wait for data response
Send "R,1" ' This does a reset to apply your change and when it comes back up it will be in Data mode
Wait for data response. ' You need to do this twice as it will acknowledge the reset then there will be a short time when it comes back on
Now you are ready to use the Transparent UART Service...
Use the Project below as a starting point, the button Sub sends "DATA TO SEND GOES HERE" and data back from your RN4871 goes in to the txtlog.
Any issues getting the RN4871 up and running Message me.