B4J Question reading data from a module Bluetooth

f0raster0

Well-Known Member
Licensed User
Longtime User
Hi guys - Sorry if asking too much, just trying to use B4J :)

I'm looking for some way to communicate a B4J App with my module nRF52 - like this examples but now using B4J

Maybe the question could be:
Have anyone tried to connect to a Bluetooth module? Using the computer's Bluetooth or the only option will be using an external Bluetooth?

Some thing similar to this, I want to connect to the module and read data - for now :p

Edit: At this stage, looking for the best alternative to communicate a B4J App to my modules then open to options.
 
Last edited:

f0raster0

Well-Known Member
Licensed User
Longtime User
no, no..

I'm lost about B4J, the JBluetooth (I think) can be used to find modules Bluetooth (for example a printer, etc)
but the example is showing: "Bluetooth not available",
 
Last edited:
Upvote 0

GabrielM

Member
Licensed User
Longtime User
There can be other methods, I can only tell about my experience using BLE on a windows machine.
That B4J project needed to receive BLE advertising from a specific device sending its Beacon data.

As could not find a BLE library for B4J I though to consider writing a small Netcore 3.1 C# app (excerpt attached) , that will start a BLE Advertisement Watcher, get the data I was after and send it via a HTTP port on the local machine so the B4J app will get that stream via a server socket and further process it.
While the BLE device was sending advertisements at a 300ms period the best period I got them was about 3.2 seconds, and also not at a constant rate. Tested with external BLE.4 and BLE.5 USB Dongles attached to the machine.
The solution eventually dropped due to this inconsistency.

Public BLEbuffer() As Byte ' gets updated on receiving data stream on socket
Private server As ServerSocket

' initialize in AppStart
server.Initialize(51042, "server")
server.Listen


Sub server_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
astream.Initialize(NewSocket.InputStream, NewSocket.OutputStream, "astream")
End If
server.Listen
End Sub

Sub astream_NewData (Buffer() As Byte)
BLEbuffer = Buffer ' update BLE receive buffer
count_adverts = count_adverts + 1
Log($"Adv.Received: ${count_adverts} @ $Time{DateTime.Now} , ${BytesToString(Buffer, 0, Buffer.Length, "utf8")} "$)
isReceiving = True ' just got data from streamer
End Sub

' Example: need to kill the server if exit the app, etc
Public Sub Kill_Server
server.Close
ProcessKill("your_beacon_rx.exe") ' the name of the C# produced executable
End Sub

Finally, ended up making own USB Dongle based on NRF52840, that will listen for Beacon advertisements and relay them on a virtual serial port that was used by the B4J app, receiving periods were matching exactly the fast pace advertising periods from the external Beacon device.
 

Attachments

  • BLE_AltBeacon_Adverts_Server.zip
    1.6 KB · Views: 91
Upvote 0
Top