How to send a byte array to BLE device

523 views
Skip to first unread message

Zimbu

unread,
May 12, 2019, 9:31:23 PM5/12/19
to mitappinv...@googlegroups.com
Struggling with this for two full days now, so I'm finally crying for help...

What I want to do is to send a byte array from my MIT AI2 app to a BLE beacon that I have connected to. 

Everything works fine. I'm connected successfully, I can read data from various characteristics (ReadBytes and ReadStrings), etc. Now I need to send a byte array in order to UNLOCK the beacon so I can make some changes to the configuration of the beacon. 

In nRF Connect, I simply send 0x30303030303030303030303030303030 (hex for 0000000000000000) to the correct characteristic UUID, and violá, the beacon is unlocked. Now I am trying to do the same in my MIT AI2 app. 

I have tried every variation of WriteBytes, WriteStrings, WriteInts, etc. etc. that I have found in the forums, but nothing works...here's are just a few examples of the many approaches that I have tried:

Screen Shot 2019-05-12 at 6.09.14 PM.png

Screen Shot 2019-05-12 at 6.17.37 PM.png

Screen Shot 2019-05-12 at 6.19.24 PM.png

Screen Shot 2019-05-12 at 6.24.46 PM.png

etc. etc.


Any suggestions would be greatly appreciated! 


Thanks,


Zimbu


Chris Ward

unread,
May 12, 2019, 9:48:13 PM5/12/19
to MIT App Inventor Forum
Hi Zimbu

Try making the list (of zero integers) as a Global variable, and feeding that to the BLE write bytes function. Of course, one too many or one too less zeros would cause a failure.

I'm surprised that you can unlock a BLE Beacon in this way, it should be far more secure...........

ABG

unread,
May 12, 2019, 10:29:59 PM5/12/19
to MIT App Inventor Forum
 0x3030303030303030 (hex for 0000000000000000) 

So which is it, 8 bytes or 16 bytes?

ABG
 

ABG

unread,
May 12, 2019, 10:43:25 PM5/12/19
to MIT App Inventor Forum
Character '0' is hex 0x30, but is decimal 48.

Have you tried changing the list of decimal 30's to a list of decimal 48's ?

AI2 doesn't really have hex support, so every number is assumed decimal.

(listening for faraway sound of facepalm)
ABG


Zimbu

unread,
May 12, 2019, 10:50:21 PM5/12/19
to MIT App Inventor Forum
My bad. It should be 0x30303030303030303030303030303030 (hex for 0000000000000000). I will correct the original post. Thanks for pointing that out. 

Zimbu

unread,
May 12, 2019, 10:55:13 PM5/12/19
to MIT App Inventor Forum
O M G....

ABG's suggestion works! (slap my head emoji goes here)

Screen Shot 2019-05-12 at 7.53.45 PM.png


Zimbu

unread,
May 12, 2019, 10:58:12 PM5/12/19
to MIT App Inventor Forum
It's fairly secure since this password can be modified by the beacon owner. Also, if the beacon is not in "connectable mode" (set via the app), then someone would need to find the beacon, click the button (hardware way of making the beacon connectable), then guess the correct password.

ABG

unread,
May 13, 2019, 1:13:48 PM5/13/19
to MIT App Inventor Forum
Thanks for the update!
ABG

Reply all
Reply to author
Forward
0 new messages