How can i send a byte array with BluetoothLE extension?

2,326 views
Skip to first unread message

George Loungos

unread,
Jan 27, 2017, 6:42:24 PM1/27/17
to MIT App Inventor Forum
Hello, i successfully connected to a BLE device and i found that i must send a byte array to control it. It turns on if i send "5510010D0A" and off if i send "5510000D0A". That's a 5 byte array. So my question is if it's possible to send it with the Bluetooth BLE extension and if it is then how?

I really appreciate any help you can provide.

Abraham Getzler

unread,
Jan 28, 2017, 5:19:09 PM1/28/17
to MIT App Inventor Forum
You can generate hex characters using a trick of one of the Web component blocks, then join them together into a text string.

See attached example.

ABG
CR.png
CRLF.aia
CRLF_to_LF.png
hexify.png
length_of_CRLF.png
LF.png
TAB.png

George Loungos

unread,
Jan 29, 2017, 9:04:29 AM1/29/17
to mitappinv...@googlegroups.com
Hello Abraham and thanks for your reply but i don't exactly understand how your answer helps me with my problem. With BluetoothLE extension i can send only 1 byte and i must send 5.

Abraham Getzler

unread,
Jan 29, 2017, 11:10:17 AM1/29/17
to MIT App Inventor Forum
Does the BLE extension allow you to send arbitrary text strings?

That's what I was shooting for with my text encoding techniques.

ABG

George Loungos

unread,
Jan 29, 2017, 12:09:48 PM1/29/17
to mitappinv...@googlegroups.com
It has a WriteStringValue block so i thing it can send a string.

(Oct 2017 edit:  These blocks and the .aia are obsolete.
See the AI2 FAQ for the current BLE blocks - ABG)
BLE.PNG
Beewi.aia

Abraham Getzler

unread,
Jan 29, 2017, 12:51:09 PM1/29/17
to MIT App Inventor Forum
So the string value you would send would be a five-way text JOIN of
hexify("55"), hexify("10"), hexify("00"), hexify("0D"), hexify("0A")

Use the blue box to add sockets to the JOIN block as needed.

The hexify Web trick only works 1 byte at a time, unfortunately.
ABG
hexify.png

George Loungos

unread,
Jan 29, 2017, 7:03:05 PM1/29/17
to MIT App Inventor Forum
It works like a charm. Thank you for your help i really appreciate it...!!!

Abraham Getzler

unread,
Jan 29, 2017, 10:24:07 PM1/29/17
to MIT App Inventor Forum
Feel free to post the completed project here, so I can point to it from my FAQ's BLE section.

Ghica

unread,
Jan 30, 2017, 9:47:42 AM1/30/17
to MIT App Inventor Forum
@ABG: pointing to this thread in the BLE section of the FAQ would already be very helpful!
Cheers, Ghica.

Abraham Getzler

unread,
Jan 30, 2017, 9:55:04 AM1/30/17
to MIT App Inventor Forum
Link to the hexify post in this thread added to the FAQ's BlueTooth/BLE section.
Feel free to add a complete project to this thread.
ABG

George Loungos

unread,
Jan 30, 2017, 10:15:08 AM1/30/17
to MIT App Inventor Forum
My project so far is this one attached to the post. The device that i control is a Beewi smart led color bulb. It has many other futures like change the RGB color, warm and cold light but all these are a diffirent 5 byte value that works the same way as on and off. 
Beewi.aia

Abraham Getzler

unread,
Jan 30, 2017, 10:59:55 AM1/30/17
to MIT App Inventor Forum
Nice and simple!

Do you have a link to the API you can add?
ABG

blocks.png

George Loungos

unread,
Jan 30, 2017, 11:17:23 AM1/30/17
to MIT App Inventor Forum
Which API do you mean?

Abraham Getzler

unread,
Jan 30, 2017, 11:53:15 AM1/30/17
to MIT App Inventor Forum
The place where you got the list of hex codes to send to turn the bulb on and off?
ABG

George Loungos

unread,
Jan 30, 2017, 12:07:43 PM1/30/17
to MIT App Inventor Forum
I didn't found exactly a site that provides me the hex codes. I used Bluetooth HCI and Wireshark to look at the log file. This is how i found the UUID and the hex codes.

Abraham Getzler

unread,
Jan 30, 2017, 12:19:22 PM1/30/17
to MIT App Inventor Forum
That should serve nicely.
Thanks for the links and the sample!
ABG

Andrew Mckinney

unread,
Mar 7, 2017, 12:55:26 PM3/7/17
to MIT App Inventor Forum
We are investigating this and adding this to our next version coming soon.

Andrew McKinney
MIT App Inventor 
Technical Lead.




Reply all
Reply to author
Forward
0 new messages