Android Question BLE Peripheral - advertising data

jvetterli

Member
Licensed User
Playing around with the BLE peripheral library, I'm wondering if it's possible to change the advertising data. When doing a BLE scan with a RedBear Duo, it shows me:

reportCallback:
The advEventType: 0
The peerAddrType: 1
The peerAddr: 64 D6 55 74 E2 D9
The rssi: -55
The advertising data: 2 1 1A E 9 42 34 41 50 65 72 69 70 68 65 72 61 6C 2 A F9 3 3 1 0
The length of Complete Local Name : D
The Complete Local Name is : B4APeripheral

Local name can be changed, but the advertising data stays the same with different phones.
 

Erel

Administrator
Staff member
Licensed User
It is currently not possible to change it.

It will be simple to add an option for manufacturer specific data if anyone needs it.
 

Erel

Administrator
Staff member
Licensed User
I've sent you a new version (v1.10). Please try it.

You can set the manufacturer data with:
B4X:
BlePeripheral2.ManufacturerData = CreateMap(123: "this is my data".GetBytes("utf8"), 124: Array As Byte(1, 2, 3, 4))
You need to set it before you call Start.
 

jvetterli

Member
Licensed User
Hi Erel, I'm sorry for the late reply, thanks for the new version, didn't have a chance to try until today.
Unfortunately it doesn't work, if I set the manufacturer data, BLEperipheral2 doesn't seem to work anymore (without showing any errors in the log view), as the two phones I'm testing with, aren't showing up anymore.
 

Erel

Administrator
Staff member
Licensed User
Are there any messages in the unfiltered logs?

Can you post the code?
 

jvetterli

Member
Licensed User
I don't see any abnormalities in the log, I've attached them, BLEnew.txt for the version including the manufacturer-date.

I'm using your BlePeripheral sample and only changed Manager_StateChanged with two variations:

B4X:
Private Sub Manager_StateChanged (State As Int)
    If State <> manager.STATE_POWERED_ON Then
        ToastMessageShow("Please enable Bluetooth", True)
        NotAvailable = True
    Else
        peripheral.Initialize("peripheral", manager)
        
        'peripheral.ManufacturerData = CreateMap(123: "this is my data".GetBytes("utf8"))
        peripheral.ManufacturerData = CreateMap(123: "this is my data".GetBytes("utf8"), 124: Array As Byte(1, 2, 3, 4))
        
        If peripheral.IsPeripheralSupported = False Then
            ToastMessageShow("Peripheral mode not supported.", True)
            NotAvailable = True
        Else
            peripheral.Start("B4APeripheral")
            Wait For Peripheral_Start (Success As Boolean)
            Log("Peripheral started successfully? " & Success)
        End If
    End If
    SetState(False)
End Sub
 

Attachments

Erel

Administrator
Staff member
Licensed User
The problem is with the id that is probably reserved.

This works:
B4X:
per.ManufacturerData = CreateMap(0x0700: "abc".GetBytes("utf8"))
 

Erel

Administrator
Staff member
Licensed User
The above code worked for me in a small example. I've tested it on Nexus 5X. I used an iPhone app to scan for BLE and read the advertising data.
 

jvetterli

Member
Licensed User
Pretty strange, I've tested with a Samsung Note4 and Blackview A7 without success. As soon as I comment the ManufacturerData out, the phone will show up on BLEscanner
 
Top