-
There are quite a few Bluetooth LE tutorials listed at https://www.espruino.com/Tutorials
As for basics check this one: https://www.espruino.com/About+BluetoothÂ+LE@fanoush I looked through a couple of these but didn't find anything exactly like what I'm trying to do.
Not at all. However the Espruino tools tend to look for devices with a certain name or an advertised Nordic UART service. If you change the name and remove the UART service then they will no longer be able to find the device to connect.
As @fanoush says you shouldn't really need to advertise a custom service UUID unless you've got some other thing you're trying to fool/connect to. All they're for is as a way to 'find' a device but if you have the device name then that'd be enough
@Gordon Got it. I do have something I'm trying to fool/connect to. I have a mobile app that broadcasts a specific BLE UUID and I'm trying to mimic that with the puck. Both the Advertised Service and the Name need to be something different than the default Nordic UART service the puck advertises.
I'm thinking of using the push button to alternate between programming mode and service advertising mode. So for programming, I would have this code:
NRF.setServices(undefined, { uart : true });
but then when I want to advertise my custom service UUID I could run this code, disabling the Nordic UART service, and advertise my own:
NRF.setServices(undefined, { uart : false }); //run function that advertises my custom service UUID
Would that work, so I don't have to completely reset the Puck every time I want to test advertising this custom service UUID?
To advertise a 128 bit service UUID (without data) you can use the second argument of setServices - but as you note if you want to do it easily you'll have to disable the UART. Perhaps that's not such a big deal for you though - develop without the service being advertised, then when you're done you can add the line, remove the UART and advertise your custom service.
So for the second argument in setServices, do you mean something like this?
NRF.setServices(undefined, { uart : false, // optional, default is true. Enable BLE UART support advertise: [ 'ABCDABCD-ABCD-ABCD-ABCD-ABCDABCDABCD' ] // optional, list of service UUIDs to advertise });
As NRF.setServices(data, options)
data - The service (and characteristics) to advertise
options - Optional object containing optionsSo I don't need to add the UUID in data, only the options portion under advertise?
Not at all. However the Espruino tools tend to look for devices with a certain name or an advertised Nordic UART service. If you change the name and remove the UART service then they will no longer be able to find the device to connect.
As @fanoush says you shouldn't really need to advertise a custom service UUID unless you've got some other thing you're trying to fool/connect to. All they're for is as a way to 'find' a device but if you have the device name then that'd be enough.
Once connected you can use the first argument of setServices to define 128 bit UUIDs and you're fine.
To advertise a 128 bit service UUID (without data) you can use the second argument of setServices - but as you note if you want to do it easily you'll have to disable the UART. Perhaps that's not such a big deal for you though - develop without the service being advertised, then when you're done you can add the line, remove the UART and advertise your custom service.
However: Espruino advertises service UUIDs in the scan response packet by default. If you want to have UART and your service UUID you can just overwrite the scan response packet with setScanResponse: http://www.espruino.com/Reference#l_NRF_setScanResponse
You'll need to specify the actual binary data for the 128 bit UUID but it's not that bad:
https://www.silabs.com/community/wireless/bluetooth/knowledge-base.entry.html/2017/02/10/bluetooth_advertisin-hGsf
Not tested, but should work...