How to set BLE client name?

Posted on
  • When Bangle JS 2 connects to Android BLE GATT server, the latter shows just BJS2 address, no name.
    Is there a way to set a name for the BJS2 client?

  • When Bangle.js 2 connects to an Android device? I think if the Android device attempted to connect to the Bangle, there's characteristic 0x2A00 on service 0x1800 that shows the device name.

    But since it's effectively the Bangle that is driving the connection, it might be better if you had a characteristic on the Android GATT server that the Bangle wrote the name into.

    Having said that, the Bangle's default advertised name is Bangle.js abcd where abcd is the last 4 digits of the Mac address - so given you have the address it'd be trivial to figure out what the name is

  • The service on Android is standard Current Time Service 1805. It does not have that characteristic. I am just started playing around with this BLE technology, I am complete novice in.
    The Android GATTService API has BluetoothDevice class (https://developer.android.com/reference/­android/bluetooth/BluetoothDevice) that is instantiated upon BJS2 connects. The class has method getName(). I assumed that the name should be populated automatically as a part of connection/bonding protocol. I can see MAC. I expected there will be something like "Bangle 9713" in .getName() that should be somehow passed by NRF device.gatt.connect();.
    Is it not a case? Or my understanding is not correct?

  • I'm not that clued up on how Android handles bluetooth connections I'm afraid.

    But... You get the device name from Advertising packets usually. However, the connecting device doesn't have to advertise at all in order to connect to your Android phone.

    For instance if you connect to the Bangle.js from your PC, at no point is the bluetooth name of the PC ever transferred to the Bangle. I imagine the same is true for Android.

    My guess is BluetoothDevice is used for all kinds of stuff. In the case where you got a BluetoothDevice via Adertising, getName would be populated

  • I assumed that the name should be populated automatically as a part of connection/bonding protocol.

    Maybe when you scan from android for bluetooth devices and then pair device the name is known and remembered. Then later based on same mac address android could fill it from its database. Otherwise there really is no way to know the name as the name is purely optional and is not passed anywhere when device connects to the phone. mac is important, name is just optional user data like anything else (manufacturer, advertised services,...)

    Also maybe it is different for classic bluetooth where the protocol is more heavy so that getName() method and BluetoothDevice class could be there for classic bluetooth?

    BTW BLE is made of separate parts, GAP and GATT are basically unrelated and complementary see e.g. https://learn.adafruit.com/introduction-­to-bluetooth-low-energy/gap so name which is optional part of advertising packet (defined as part of GAP) is not relevant when device makes connection an use GATT api to work with GATT server and its services/characteristics.

  • Hi guys,
    yeah, BLE is weird (from my perspective) :) - Peripheral usually acts as a server and is advertising, Central acts as a client, scans and connects... Will in this case the Peripheral waist power for constant advertising? Other words will a Peripheral use more power for communication than a Central?
    What I want to make is a lightweight program in BJS2 that gets data from "Location and Navigation" GATT service that runs on smartphone (Android). Then it just displays it on screen.
    Assuming that advertisement will eat power I've decided to place the Server on smartphone, and Client on watch. Is it right decision?

    If the Client' name is not part of the GAP, then how I could whitelist clients, so only my watch can connect? By MAC only? I do not think it will be convenient for user to get the watch's MAC somehow and type it into Android. I envisioned it something like a standard BT pairing. Server will show a name of a client that tries to pair an user will allow or not. What is a best practice?
    Can NRF be used to tap watch MAC into Android?

  • Advertising wastes very little power, for some devices (beacons) it is the only way to do BLE and they can still last year from CR2032 coin battery. With connection it is said to allow to use even less power but it is all matter of settings (connection interval, advertising interval) so if advertising is good enough for what you want I wouldn't bother with connections and GATT.

    For power draw it does not matter which side of connection it is. Scanning for advertising packets however takes more power, not sure if android phones can somehow optimize this case but with espruino it needs radio to be constantly on for long time (seconds) to listen for incoming packets. So for two battery powered espruino devices connection is better.

    I envisioned it something like a standard BT pairing.

    Yes it can work like that. The natural way is to make espruino device to be gatt server (= peripheral) and phone to be central/client - phone will scan for device when it is advertising (by name or anything else) and connect to it.

    As for pairing there is such a thing called bonding which even allows secure encrypted connections.

  • not sure if android phones can somehow optimize this case

    just answering myself - yes a bit but not much, there is scan offloading so the bluetooth chip itself can scan and filter while phone can sleep https://source.android.com/devices/bluet­ooth/ble#filtering-scan-results ( "Filtering also works for batch scans, which helps save power as BLE scanning is offloaded to the firmware.") however the radio of the bluetooth chip must be on so it still draws more power just like espruino device https://www.argenox.com/library/bluetoot­h-low-energy/ble-advertising-primer/#ble­-advertisements-and-the-smartphone

  • Scanning for advertising packets however takes more power

    ok, but it happens once (in my case), when I start the app, it scans, connects to Android, then I assume, it just listens for updates. Does it still draws more power?

    Another caveat having a peripheral/server on watch - it will be second peripheral, so no debugging is possible because only one device of each kind is currently supported. Or I am wrong again?

  • ok, but it happens once (in my case), when I start the app, it scans, connects to Android, then I assume, it just listens for updates.

    yes, this was for case when periodically advertising the data (like temperarure, heartrate,...) directly without ever conecting, then for getting updated values one would need to scan repeatedly from phone => more phone battery usage

    as for getting console output, yes that could make that complicated or impossible, maybe reusing same connection could work from same phone (as per https://stackoverflow.com/questions/3403­6893/one-bluetooth-device-with-multiple-­apps ) but not from other devices. It definitely works from two different tabs in Chrome e.g one having app loader and second having web ide connected

  • oh, just tried with gadgetbridge and webide and it somehow works, the trick is to disconnect gadgetbridge temporarily, then connect webide from chrome and then reconnect gadgetbridge, then both are connected and I see what watch sends to GB in webide

    Also when webide already remembers the device it can disconnect and reconnect to it with GB still connected

  • then for getting updated values one would need to scan repeatedly from phone => more phone battery usage

    I thought after the connection between Central and Peripheral is established they agree on a receiving/transmission schedule and turn radio on just in time synchronously, during that periods GATT server may send characteristics updates. So no scan is required.

    With my POC GATT Current Time service I can even stop advertising at Android, and updates are still coming to my Bangle.

    It looks like in BLE Central/Peripheral is independent from Server/Client. It is possible to make Client to play Peripheral role and advertise. Then Server should scan. But it looks quite weird to me, I am used to a world where Servers listen and Clients initiate connection. :)

  • I thought after the connection between Central and Peripheral is established they agree on a receiving/transmission schedule and turn radio on just in time synchronously, during that periods GATT server may send characteristics updates. So no scan is required.

    yes, however I was talking about case with no connection at all, just advertising

    It looks like in BLE Central/Peripheral is independent from Server/Client.

    Yes because first two are GAP terms, second two are GATT terms, as mentioned they are separate parts of BLE.
    also nice explanation here
    https://docs.silabs.com/bluetooth/3.2/ge­neral/connections/central-and-peripheral­-roles#quick-overview
    https://docs.silabs.com/bluetooth/3.2/ge­neral/gatt-protocol/gatt-server-and-clie­nt-roles#quick-overview
    or also here https://www.cardinalpeak.com/blog/what-i­s-ble-and-how-do-its-related-gap-and-gat­t-profiles-work

    There can be BLE devices not using GATT at all, in some BLE stack implementations you can even use just the connectionless part of GAP (Broadcaster, Observer roles) for small size with connection oriented Peripheral/Central roles and all the GATT code not linked in at all. Maybe it helps to stop thinking about 'BLE' and start thinking about 'GAP' and 'GATT' separately. In fact they are typically used at different times - GAP before making connection and GATT after. Also there is no direct relation between them e.g. what service IDs, name or other data you advertise and what attributes/services are visible over GATT once you connect are two separate things.

  • I am lost. :).
    So what would you suggest for my use case? - I want to see a speedometer when I am windsurfing. Smartphone has much better GPS chip and antenna, as well as other capabilities like L5, AGPS, and even DGNSS and RTK. Instead of using internal Bangle GNSS I am going to use the smartphone's one. And Bangle will just display what I need - speed, time, may be map with location and track, may be some supplementary info like accuracy and number of sats.
    So I need to pass that data to the watch. I could make a custom service, but the standard Location and Navigation already includes all I need (except may be timezone). And it can be compatible with other GNSS pocket receivers. I guess they play a peripheral role in GAP. So my smartphone should mimic same.

  • So what would you suggest for my use case?

    I would actually try to use existing android integration described at https://www.espruino.com/Gadgetbridge
    It looks like it could be extended with custom messages in both directions? maybe instead of custom BLE solution your android app could just handle some intent called from your watch app via gadgetbridge and/or send data back to watch via gadgetbridge somehow. @Gordon what do you think, can this work? can some android app hook into gadgetbridge to pass some custom message back to watch via some intent? would GB({ "t":"xxx"... call fit this or watch app should have its own method to receive data from android app instead of GB()?

  • I am not sure about GB. I've made test "Current Time" GATT server, and it works.

    Regarding roles. In the standard L&N GATT it is specified:

    https://www.bluetooth.org/DocMan/handler­s/DownloadDoc.ashx?doc_id=271996
    BLUETOOTH PROFILE SPECIFICATION Page 8 of 32

    Location and Navigation Profile
    2 Configuration
    2.1 Roles
    The profile defines two roles: LN Sensor and Collector. The LN Sensor is the device
    that reports speed, distance, location, elevation, and/or navigation data to a Collector.
    The Collector is the device that receives the data from a LN Sensor while connected to
    a LN Sensor.
    The LN Sensor shall be a GATT Server.
    The Collector shall be a GATT Client
    ...

    • The LN Sensor shall use the GAP Peripheral role

    So, it looks like I've architected my apps correctly :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

How to set BLE client name?

Posted by Avatar for Mark_M @Mark_M

Actions