-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subscribing to characteristics #29
Comments
Btw, I think the documentation and example lacks basic info like this. So if anyone can help with this problem then I'll submit working code to the project so that the example/docs are more complete. |
Hi how can read data from HM-10 BLE device? |
Is anyone monitoring this forum? |
As I am not making example-codes for all kind of possible BLE-use-cases, either something or my or your end is incorrect. Please feel free to submit a fix if something does not work for you. |
OK, I followed the core bluetooth examples and when I try to subscribe to either the battery or immediate alert service by setting notify value to true, I am not getting state change callbacks. here is my code for attempting to get the value and state changes for the battery service:
and output:
I'm not sure why the characteristic value is showing as I, and the immediate alert service:
output:
When i press the button on the peripheral that changes the Immediate Alert State I am not getting a value change callback response. So it appears that its not subscribing to the characteristic, or the callback isnt working. |
There are a couple of issues in your code, one sinificant is: p.setNotifyValueForCharacteristic(true, characteristic);
p.readValueForCharacteristic(characteristic);
Ti.API.info('Characteristic Value:', characteristic.value); You cannot set, get and display a value synchronously. Writing will fire |
Hi FizixRichard have you solved? |
No I haven't, I'm looking through the BTLE core docs and examples as per hansemannn's suggestion. However it doesn't seem to mesh with this API. In the examples it appears as though they are subscribing to the service characteristic and then listening for state changes from the device. Similarly with that expensive titanium BT plugin, the heart rate sensor just subscribes to the characteristic and then listens for value change notifications. It feels like there is something "missing" that's going on behind this that I'm not seeing. |
Hi hansemannn what is the right code for read Characteristic notifications from BLE device? |
If I can figure it out I'll post code and an example to the project. Still, any help would be greatly appreciated. |
every time the peripheral updates value, |
Hi wilson, var BLE = require('ti.bluetooth'); var win = Ti.UI.createWindow({ var btn1 = Ti.UI.createButton({ var centralManager = BLE.createCentralManager(); btn1.addEventListener('click', function() {
}); var btn2 = Ti.UI.createButton({ btn2.addEventListener('click', function() { /**
centralManager.addEventListener('didDiscoverPeripheral', function(e) {
}); centralManager.addEventListener('didUpdateState', function(e) {
}); centralManager.addEventListener('didConnectPeripheral', function(e) {
}); centralManager.addEventListener('willRestoreState', function(e) { centralManager.addEventListener('didFailToConnectPeripheral', function(e) { /**
peripheralManager.addEventListener('didUpdateState', function(e) { peripheralManager.addEventListener('willRestoreState', function(e) { peripheralManager.addEventListener('didStartAdvertising', function(e) { peripheralManager.addEventListener('didAddService', function(e) { peripheralManager.addEventListener('didSubscribeToCharacteristic', function(e) { peripheralManager.addEventListener('didUnsubscribeFromCharacteristic', function(e) { peripheralManager.addEventListener('didReceiveReadRequest', function(e) { peripheralManager.addEventListener('didReceiveWriteRequests', function(e) { peripheralManager.addEventListener('readyToUpdateSubscribers', function(e) { function _didUpdateValueForCharacteristic(e) { win.add(btn1); |
and this is my output: |
what is wrong? |
....this is that my module send: 1999-12-01T10:52:48+10:00 simple timestamp.... |
woah, this is a lot, haha, maybe you tell me what are you trying to do and what doesn't work, so that i can pin point the problem and save some time |
i have a simple project where my device (HM-10) send data to mobile (similar serial communication). |
yes you can, so I assume you can get the characteristic now? i think the problem of your code is the way you listen to
|
This is the code:
}); |
the result is the same |
you should be more specific, or I can't help you |
This isn't working for me.
output:
I have a keyfob type peripheral device with a button on it, pressing the button sets the alert level between off, low and high alerts. My app needs to know the current alert level. According to the documentation for the device I can write the alert level or be notified of the alert level. Unfortunately the docs dont explain how. Using the example you've provided, pressing the button returns no response. |
@FizixRichard
|
No change, its not notifying me >< |
Did it go into 'Alert Level Characteristic Found' here? |
Here is the code:
|
Yep, same as before. One interesting thing. It kinda works if I change the service/characteristic to the GAP Profile on service: 00001C00-D102-11E1-9B23-000EFB0000A7, characteristics 00001C0F-D102-11E1-9B23-000EFB0000A7 and 00001C01-D102-11E1-9B23-000EFB0000A7 If I attempt to listen to these then I get a response when I press the button:
I assume one callback for each of the two characteristics. This service is labelled as the Find Me Profile but is undocumented in their docs and I assume bespoke. The reason it only kind of works is because I don't know whether this is off, low or high alert and it only fires once, if I press the button again it does not trigger. |
are you using the latest version? 1.3.0 |
1.2.2, I didn't notice a 1.3.0 update, I'll just update and see what happens |
1.3.0 accepts multiple button presses on the proprietary service. Immediate Alert doesn't activate callbacks though. But, I'm getting callbacks so thank you! Two questions though:
|
hi with 1.3.0 version i have this error: message = "undefined is not an object (evaluating 'peripheralManager.addEventListener')"; |
|
@lazzaratom shouldn't be, are you sure your peripheralManager is in the same namespace? |
Thanks. I'm going to do some expansion on it and I'll put them into some examples and submit them so you can include them in this project if you want. |
@FizixRichard you're welcome :) |
YESSSSSS!!!!!! |
@lazzaratom congrats, and small tips for you guys, you must do the event listener house keeping, or it will cause memory leaks |
just a last question (i hope). and this is the result from BLE: Is there a limit on characteristic length? |
@lazzaratom yes there's a limit but shouldn't be that short |
I have read the limit is 20 bytes it's possible? |
maybe, and I think you can do some research on how to increase the MTU, never try this before |
one last thing. On getting the value
returns:
I'm getting a TiBlob object, how do I get the actual value from that? I'm not at all familiar with blobs. |
Yes I will clean up event listeners :) |
@FizixRichard |
I assumed as much, how strange. It's definitely reporting a TiBlob though. |
sorry mate, can't help you with this, do you know what type it should be? or try toString again? |
I think it is a buffer …
|
It's ok, I'll figure it out. It should be a string (battery level) or int (alert level) |
Yep, that's why a buffer is required, so you are independent of the type (int or string). |
@focussing correct, e.characteristic.value is a buffer (TiBlob), use toString on it should be able to convert it to string |
hmm, battery level comes back as a random character like ">" or ";" whether I output it raw or use ToString(). Could it be getting garboled somewhere? |
Thanks for all the help. How do I submit example code to you for documentation? I've got working code to fetch devices, find characteristics, subscribe and listen for state changes on those characteristics. I need to tidy it up first though. I have a new question though, this doesn't work for the Android module. I made a copy for Android and make changes as per the example, and stripped it down. It appears that on Android the process is quite different. It finds devices, appears to auto connect and list services. However:
I have a sneaking suspicion it doesn't work because there don't appear to be any exposed methods for subscribing and listening for characteristic events, and the documentation looks like the android module is incomplete. |
Hi,
I'm having trouble subscribing to characteristics and the documentation doesn't explain how. Following the XCode Core Bluetooth documentation isn't helping.
I am trying to subscribe to a couple of services on a BT device, battery and immediate alert.
I'm successfully scanning for devices, finding the device, getting its data, listing services and getting the characteristics.
What I need to do from here is to subscribe to the characteristics I need and receive callbacks whenever the battery level changes or the alert level changes on the BT device. I've tried a number of approaches but none seem to be working.
Code up to subscription below:
The text was updated successfully, but these errors were encountered: