I'm using a BLE113 as a peripheral and the central is either an iOS device, Android device, or Win 8.1/10 machine, depending on what my app is running on. The BLE113 is programmed with BGScript. The app is written in the native language for each platform (Objective-C, Java, C#, respectively).
Every one second the BLE113 sends temperature data and the central subscribes to get notified when the new data is sent. Upon receiving new temperature data, the app updates the display to show the latest temperature reading. Pretty basic stuff.
If I don't look at the result returned from attributes_send(connection, handle, value_len, value_data)(result) which gets called every one second, the device seems to work fine. But if I monitor the result, I occasionally get error code 0x0181, "Device is in Wrong State" and then everything continues working.
Is this a sign of something not getting handled correctly on the BLE113 side? On the app side? Should I be worried?
PS: I can attach a heavily expurgated version of the code if needed.
This typically means that the previous indication has not been fully acknowledged by the time you attempt to send another one. It is not a critical error; it simply means that you have to retry the transmission again (or just skip it if is isn't important).
A more efficient approach which should avoid this case would be to keep an internal "previous value" variable in your code, and only push a new update to a connected client when the value actually changes (which is ideally how indications should be used anyway). This should occur much less often than the reading itself takes place.
Thanks Jeff. Good to know.
In the future I will implement temperature updates the way you suggest. For now I think I have to keep updating the value even if it's the same because there are quite a few 3rd party apps that talk to our BLE113 device and changing the behavior now might cause an issue or apparent delay in their apps. Maybe, maybe not. But it probably isn't fair for me to risk it after they've put in the effort on their side.
I'll just live with the 0x0181 return code, comforted with the knowledge that it isn't a ticking time bomb.