I managed to focus some more time on tidying up my AI2 app for sending Mailbox messages via Bluetooth from my Android phone to an EV3. The EV3 code is really simple and looks like this:
The AI2 code provides two BT related buttons, Connect & Disconnect, a text box and a Go button to send the text:
When the text is entered and Go pressed it is sent as a Mailbox message with the name “beep” to the EV3, and displayed on its screen. The code to send it has to construct a message in the form:
MLenL, MLenH, 0x01, 0x00, 0x81, 0x9E, NLen, NameBytes, 0x00, TLenL, TLenH, TextBytes, 0x00
Which breakdown as:
- MLenL, MLenH = 16 bit little endian length of the rest of the message
- 0x0001 = Message counter
- 0x81 = System command, no reply
- 0x9E = Mailbox message
- NLen = 8 bit name length, including 0x00 termination
- NameBytes + 0x00 = The Mailbox name
- TLenL, TLenH = 16 bit little endian length of the text
- TextBytes + 0x00 = The Mailbox text
This in terms of code looks like:
If you would like to play with the code it’s available from my resources site at:
The code is released under the Creative Commons Attribution-ShareAlike 4.0 International License