B4R Question BLE with B4R, B4A and B4RSerializer & B4XPages

rwblinn

Well-Known Member
Licensed User
Longtime User
Seeking for an example on how to exchange data, using BLE, between B4R (Arduino MEGA with HM-10) and B4A.

Have taken the BLE B4XPages example and able to communicate between B4A (sending data to B4R using blemanager.writedata) & B4R (sending data to B4A via asyncstream.write),
BUT not clear how to use the B4RSerializer and Asyncstream in prefix mode.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
In this case you shouldn't use prefix mode, as BLE in Android isn't implemented with a stream. You can implement the prefix protocol yourself and add it as a header to each message, but I don't think that it is worth the effort.

Simply use B4RSerializator to serialize the data into bytes and then deserialize on the other side.
If you are encountering issues with messages being split then you can increase AStream.WaitForMoreDataDelay (in B4R).
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Thanks for the steer.
Implemented serialized data, i.e. objects, sent from B4A to B4R via BLE = Working fine.
The other way around, i.e. B4R to B4A using asyncstream write is also working =requires manager.setnotify.

Background
Working on a LEGO Showcase to remote control LEGO trains (via B4A) and accessories (via B4R with connected IO devices) using BLE.
The B4A client to control up-to3 LEGO trains is done (PUTrains). Developed and tested a B4XLib to control LEGO hubs, like movehub, powered-up.
Next working on setting the state of the railroad switch points using servo motors. Thereafter other sensors like rfid, led's etc...
Will share more info whilst making progress.

B4A App- running the green train forward at speed 40 - live data.
1642358391009.png

B4R - Prototype of a LEGO city switch track (#53407) with (strong) servo motor (HS-311) controlled by an Arduino MEGA with BLE HM-10 module.
The LEGO touch sensor (#9843) enables to switch as well. Testing using a B4A app.
Note: The Arduino motor shield on the MEGA is not required and has been used to test other solutions like a LEGO NXT or Power Functions motor.
1642358338559.png

BTW: someone is watching :)
 
Last edited:
Upvote 0
Top