Cannot set custom descriptors #5770
Replies: 1 comment
-
Posted at 2023-03-07 by @gfwilliams Please can you explain a bit more about what you want? What additional metadata do you want to include? Apart from the text description (which is implemented, but it seems nobody really uses) I wasn't aware of much other metadata that could stored for characteristics. What sample rate do you want to change? Is there a problem with just sending a command over the Nordic UART characteristics?
Is the problem that you want to use your own UUID in setServices, not one of the 16 bit pre-defined ones? If so, https://www.espruino.com/About+Bluetooth+LE might help, but you can just make a random number like Then change the second set of 4 digits:
Posted at 2023-03-12 by Espruino🥵Espressif🥵 Lets say I have a service that sends me stored accelerometery data, I want to store additional information like whats the sampling rate configured for this accelerometer. Right now the only way I think we could implement this is one characteristic that is for reading accelerometery data and one characteristic for the sampling rate to be read from and written too however from what I've understood about ble this sampling rate should be configured as a descriptor and not as a characteristic. I don't see anyway to configure a custom descriptor to achieve such functionality in espruino Posted at 2023-03-13 by @fanoush If you want sample rate to be written/changed, then I think it should be another characteristics in same service, why not? Posted at 2023-03-13 by Espruino🥵Espressif🥵 I'm looking at how xiaomi is handling their weighing scales, they've set their weigh unit as a descriptor which you can set/get to configure whether the data is recorded in LBs or KG. I don't have a problem with creating a characteristic but I thought I'd implement it how standards assume it to be. Posted at 2023-03-13 by @fanoush
check gatt supplement here https://www.bluetooth.com/specifications/assigned-numbers/ EDIT: also the first document with IDs has UUIDs of all standard descriptors on page 81 Posted at 2023-03-13 by @fanoush I see for weight they do this thing even directly in the characteristics data, it is a structure and first byte Flags has metric/imperial flag Posted at 2023-03-13 by Espruino🥵Espressif🥵 Thank you, I'll just use a characteristic. I apologize for asking an unrelated question on this thread but I'd appreciate if you could guide me. I am recording accelerometry data and would like to be able to read that data on request from the host device that is connected. This is important that I am able to get data in a pull based approach rather than a push based approach as is the case with The approach I'm thinking of is to make data available in a characteristics value and the host to read from it and write to it to request the next data to be available on the characteristic. Currently I don't see anyway to update the value of a characteristic without using Also is there a maximum length for the value of a characteristic, in bytes. Posted at 2023-03-13 by @gfwilliams
This isn't the case - you can call this just fine when you're connected. It's what it is designed for. What you're hitting is that you're calling 'setServices' to set up the services, but Espruino can't set them up while you're connected. Once the characteristics are set up though, updateServices will work fine
It depends on the device, but on Bangle.js the MTU is 131 - I can't remember exactly but I think that means maybe 128 bytes? Posted at 2023-03-13 by @fanoush
Here is my small test of something that works like the nordic uart - you can write to it to run javascript code and get output back. the https://gist.github.com/fanoush/04d0777f99bb4d153aa1a40aa218db55 Default MTU in BLE is 23 so 20 is typical value without larger MTU negotiation. The example is cut from larger one https://gist.github.com/fanoush/e8db2729844972ef1a0ae31719f31537 which does emulation of AT commands for fitness trackers described here https://github.com/fanoush/ds-d6/wiki/Bracelet-commands EDIT: Posted at 2023-03-13 by @fanoush I am testing now the example and it doesnt work very well. Longer output is incomplete. Even with maxlen 20 to rule out MTU issues I get something like this
This is bleconsole on Windows 10 which can be buggy but I get same thing in nrfconnect on Android phone. I receive only some random subset of splitted array. What is also strange is that sometimes I don't get last part of the output so later calls do not overwrite previous ones. Also at least first two or mostly three are OK, it breaks later. Will retest with some other device without lot of stuff running on the background Posted at 2023-03-14 by @fanoush Interesting. I tested newer 2v16 build on 52832, just bare Espruino and the example works fine - get all parts in order. I have updated Bangle to 2.17 release, updated all apps and it still does this. Good for verifying this is also Serial Bluetooth Terminal app for Android, one can select custom characteristics for input/ouput when connecting to device (hold on the name, there is menu). I'll test 52840 dongle too. EDIT:
in the console I see twice this
Posted at 2023-03-14 by @fanoush seems to be related to this line https://github.com/espruino/Espruino/blob/master/libs/bluetooth/jswrap_bluetooth.c#L1604 Posted at 2023-03-14 by @fanoush so I have commented out all the ignored error codes to let it throw exception and I rewrote the loop to retry
and now it works well, I get everything sent and the error is 0x13 = NRF_ERROR_RESOURCES
I wonder what is the reason for ignoring errors when trying to send notifications? Isn't it better to throw exception so it can be handled. I'd remove all those ignored errors starting here https://github.com/espruino/Espruino/blob/master/libs/bluetooth/jswrap_bluetooth.c#L1606 EDIT: I retested with 52832/SDK12 and I see it too. It mostly does not happen when maxchars is 20 so I did not notice before but when I set it to 50 I see something very similar Posted at 2023-03-14 by Espruino🥵Espressif🥵 Do I have to be worried about whats happening here? Because I honestly don't understand whats happening. Posted at 2023-03-14 by @fanoush
NRF.updateServices does not work reliably to send notifications, sometimes nothing is sent. Posted at 2023-03-14 by Espruino🥵Espressif🥵 I don't think this will probably affect me because I plan on polling the characteristic anyway but getting notifications would be much better so data can be sent automatically. Is this related to how fast you call updateServices? @gfwilliams have you experienced this problem Posted at 2023-03-15 by @fanoush
Yes but with more testing I've seen it failing even with first call. It looks random, probably depends on timing in bluetooth stack -whether it is currently possible to send data or not. It is also discussed here (there may be some queue size to tune) Posted at 2023-03-15 by @gfwilliams
No, I haven't - but I do tend to just use the built-in Nordic UART for sending large amounts of data from devices.
I could understand it maybe failing if you're calling it repeatedly, but are you saying it fails on the first call sometimes? Maybe you're also sending a bunch of stuff on the Nordic UART at the same time? But as you say it seems like we probably shouldn't be ignoring errors from that function - that code looks to be very old (6+ years) so I'm not entirely sure the reasoning behind it being there in the first place. @fanoush maybe you could do a PR? Posted at 2023-03-15 by @fanoush
yes, that is what I've seen in post #12 with 52840 dongle, first line is
Maybe if you are updating more stuff at once, not just one value, then it would not continue with another value but still I'd better throw exception, caller can do more granular approach. Posted at 2023-03-16 by Espruino🥵Espressif🥵 I'm getting a weird error too when I use
I've set an interval of 40 seconds, to update the characteristic, it's not like it's updating a few times a second. Is there any reason for this? Posted at 2023-03-16 by @gfwilliams Does that error happen exactly once every 40 seconds? Maybe you could add a print before and after updateServices to see if it is that which is causing the problem? Because generally that error happens if you Ctrl-C out of something that was taking a long time to execute (or some event handler causes the device to run out of memory) but not much else Posted at 2023-03-17 by Espruino🥵Espressif🥵 We're adding logs to findout where the problem is stemming from. It probably is related to running out of memory but we changed all of our allocations to be static so not sure why thats happening |
Beta Was this translation helpful? Give feedback.
-
Posted at 2023-03-06 by Espruino🥵Espressif🥵
So I'm new to bluetooth and from what I've seen reading up on conventions I want to be able to customize the sampling rate on my bangle as well as provide additional metadata about a characteristic. There doesn't seem to be a way to create a custom descriptor that holds a specific value that I would specify, it's in neither NRF.setServices or NRF.updateServices. I want to use this instead of having many characteristics, however from what I see theres no other way.
Beta Was this translation helpful? Give feedback.
All reactions