-
new Uint8Array([battery_status_flags, power_state_flags>>8, power_state_flags&255, battery_level]).buffer
Are you sure this is correct? It seems like you're encoding it in big endian, wouldn't the correct encoding be
new Uint8Array([battery_status_flags, power_state_flags&0xff, power_state_flags>>8, battery_level]).buffer
-
I'm getting a weird error too when I use
NRF.updateServices
,Execution Interrupted during event processing. Execution Interrupted during event processing.
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?
-
-
Oops sorry my bad, it's this GATT_Specification_Supplement_v8 the
-1
was appended by windows I guess it's stopped using(1)
to indicate duplicate files. I've added screenshots from the specification directly. Do you know why the specification is so difficult to implement, seems like it's raising the barrier of entry for no reason. Specially since they provide basically no information on how to actually implement it. Do you think you have any reference implementations or blogs that can help. -
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?
@Gordon have you experienced this problem
-
Hello, I'm trying to implement the Bluetooth SIG Battery Service but it's very complicated and there's absolutely no help in terms of example available online. I'm not trying to implement all of the characteristics in that service only
battery_level
&battery_level_status
. Implementing is very confusing because the documentation provided by bluetooth doesn't match any of the implementations you can observe on github. Even in NRF's own implementation of the specification the battery service only has two characteristics as opposed to the 5 provided by the specification. Also apparently you're supposed to combine the unit for a value with the actual value somehow which I don't understand and I can't really find any references for it in the specification.Can someone please look over my implementation if it follows the specification correctly. For reference I am using
Assigned Numbers
Revision Date: 20230313
&GATT_Specification_Supplement_v8-1
as reference. I really appreciate the help, thank you in advance.let IS_CHARGING = false; // Globals let IS_CONNECTED; function onConnect() { IS_CONNECTED = true } function onDisconnect() { IS_CONNECTED = false } function onCharge(charging) { IS_CHARGING = charging } function build_battery_status(){ const battery_level = E.getBattery() // 0 good, 1 bad let is_charge_good = battery_level > 80 ? true: false const battery_status_flags = 2; let power_state_flags = 1 if(IS_CHARGING){ // Charging power_state_flags = power_state_flags | 32 }else{ // Active Discharging power_state_flags = power_state_flags | 64 } if(is_charge_good){ // Good power_state_flags = power_state_flags | 128 }else{ // Bad power_state_flags = power_state_flags | 256 } // I know this part is technically incorrect because battery_status_flags & // battery_level should be 1 octet but since I don't know I don't understand // the endianness(I know it's little endian) I have referained from encoding // it directly const encoded = new Uint16Array([battery_status_flags, power_state_flags, battery_level]).buffer return encoded } function update_battery_status(){ NRF.updateServices({ 0x180F: { 0x2A19: { value: [E.getBattery()] }, 0x2BED: { value:build_battery_status() }, }, }) } function onInit() { Bangle.on('charging', onCharge); NRF.on('connect', onConnect); NRF.on('disconnect', onDisconnect); NRF.setServices({ // Battery level service 0x180F: { 0x2A19: { notify: true, readable: true, indicate: true, description: "Battery Level", value: [E.getBattery()] }, 0x2BED: { notify: true, readable: true, indicate: true, description: "Battery Status", value:build_battery_status() }, } }) setInterval(update_battery_status, 40_000) }
-
-
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
Bluetooth.write
andBluetooth.println
. With the push based approach the device is informed about the disconnect with a delay which leads to data loss. Also sinceBluetooth.write
is on serial I get some random console strings coming in through too randomly which is not good.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
NRF.updateServices
which requires that the device is no longer connected to any host. If there's another way I can approach this which would fulfill my requirement or maybe get the way I'm planning to work.Also is there a maximum length for the value of a characteristic, in bytes.
-
-
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
-
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.
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