hansemannn / titanium-bluetooth Goto Github PK
View Code? Open in Web Editor NEW📡 Native iOS / Android Bluetooth support for the Axway Titanium SDK
License: Other
📡 Native iOS / Android Bluetooth support for the Axway Titanium SDK
License: Other
Has anyone got a working beacon demo, i want to use this to fire an event when a beacon is in range ?
would i use -> didDiscoverPeripheral (for both ios and android)
any help would be appreciated !!
Hello,
I tried to create the module for android but i have this error:
Launching build and packaging failed
Build failed. Unable to locate generated zip file at /Users/rocco/Documents/Appcelerator_Studio_Workspace/hansemannn.ti.bluetooth-master/dist/ti.bluetooth-android-1.0.1.zip
Can you provide the zip file of the android module?
Hi,
Is possible to upgrade ti.bluetooth module for android platform in order to use with last version of appcelerator sdk?
Hi,
I can't seem to get this to build using Ti. SDK 8.2.0.GA. (ios)
Are you able to?
Add missing android parts
Docs state a constant CHARACTERISTIC_PROPERTY_WRITE_WITH_NO_RESPONSE
Should be CHARACTERISTIC_PROPERTY_WRITE_WITHOUT_RESPONSE
(No idea how to fork/fix the Wiki docs ;) )
<receiver
android:exported="true"
android:name=".ti.bluetooth.BlutoothStateChangedBroadcastReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
<action android:name="android.bluetooth.device.action.BOND_STATE_CHANGED" />
<action android:name="android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED" />
</intent-filter>
</receiver>
Hi, I try to use ti.bluetooth module on android device but unfortunately few method are present and it is unusable.
When this module for Android platform will be upgraded like iOS platform?
In alternative how can i connect BLE device with android device?
Thanks in advance,
Michele.
Hello,
I use your exemple code but When I start scanning, I don't see any peripheral in the log... Any idea why?
Thank you
Module ti.bluetooth version 1.3.0 is missing library file: modules/iphone/ti.bluetooth/1.0/libti.bluetooth.a
I am struggling to implement the following
[INFO] : didDiscoverServices
[INFO] : {
[INFO] : bubbles = 1;
[INFO] : cancelBubble = 0;
[INFO] : error = "<null>";
[INFO] : peripheral = "[object TiBluetoothPeripheral]";
[INFO] : source = "[object TiBluetoothPeripheral]";
[INFO] : type = didDiscoverServices;
[INFO] : }
[INFO] : [object TiBluetoothPeripheral]
[INFO] : (
[INFO] : "[object TiBluetoothService]",
[INFO] : "[object TiBluetoothService]"
[INFO] : )
[INFO] : peripheral has 2 service(s)
[INFO] : service characteristics <null>
[INFO] : service characteristics <null>
Next I want to get the UUIDs from the services, and subscribe to let's say one of them
My code so far:
centralManager.addEventListener('didConnectPeripheral', function(e) {
console.log('\ndidConnectPeripheral');
console.log(e);
console.log(e.peripheral);
centralManager.stopScan();
connectedPeripheral = e.peripheral;
connectedPeripheral.addEventListener('didDiscoverServices', function(e) {
console.log('\ndidDiscoverServices');
console.log(e);
console.log(e.peripheral);
console.log(e.peripheral.services);
console.log('peripheral has ', e.peripheral.services.length, 'service(s)');
var services = e.peripheral.services;
for (var i = 0; i < services.length; i++)
console.log('service characteristics ', services[i].characteristics.uuid);
// if (service.UUID.toLowerCase() == CUSTOM_SERVICE_UUID.toLowerCase()) {
// e.peripheral.discoverCharacteristicsForService(service);
// }
});
connectedPeripheral.addEventListener('didDiscoverCharacteristicsForService', function(e) {
console.log('didDiscoverCharacteristicsForService');
console.log(e);
});
connectedPeripheral.addEventListener('didUpdateValueForCharacteristic', function(e) {
console.log('didUpdateValueForCharacteristic');
console.log(e);
});
connectedPeripheral.discoverServices();
});
Maybe is my fault, but how I can connect to a BLE device once I found that?
@hansemannn I have added 4 new classes in java, but I cannot PR. The system shows me a lot of your changes in folder ios. What can i do?
Hi aca-mobile,
I have tried to implement code for android device with new version of this library. didDiscoverPeripheral find my peripheral (in my sample UART Service);
didConnectPeripheral run correctly;
didUpdateValueForCharacteristic don't run correctly:
This is my log:
[INFO] : didDiscoverPeripheral
[INFO] : UART Service
[INFO] : Connect to [object TiBluetoothPeripheral]
[INFO] : e.peripheral: [object TiBluetoothPeripheral]
[INFO] : e.peripheral.name: UART Service
[INFO] : connecting
[INFO] : Connected to Periperal...
[INFO] : Service Discovery...
[INFO] : peripheral has 3 service(s)
[INFO] : service: 00001801-0000-1000-8000-00805F9B34FB
[INFO] : service: 00001800-0000-1000-8000-00805F9B34FB
[INFO] : service: 6E400001-B5A3-F393-E0A9-E50E24DCCA9E
[INFO] : service Found: 6E400001-B5A3-F393-E0A9-E50E24DCCA9E
[INFO] : Service Found: 00001801-0000-1000-8000-00805F9B34FB
[INFO] : Service Found: 00001800-0000-1000-8000-00805F9B34FB
[INFO] : Service Found: 6E400001-B5A3-F393-E0A9-E50E24DCCA9E
[INFO] : Immediate Alert Service Found6E400001-B5A3-F393-E0A9-E50E24DCCA9E
[INFO] : Characteristic ID: 6E400003-B5A3-F393-E0A9-E50E24DCCA9E
[INFO] : Alert Level Characteristic Found
[INFO] : 6E400003-B5A3-F393-E0A9-E50E24DCCA9E
[INFO] : didUpdateValueForCharacteristic passed -->6E400003-B5A3-F393-E0A9-E50E24DCCA9E
[INFO] : Characteristic ID: 6E400002-B5A3-F393-E0A9-E50E24DCCA9E
[INFO] : Characteristic ID: 6E400003-B5A3-F393-E0A9-E50E24DCCA9E
[INFO] : Alert Level Characteristic Found
[INFO] : 6E400003-B5A3-F393-E0A9-E50E24DCCA9E
[INFO] : didUpdateValueForCharacteristic passed -->6E400003-B5A3-F393-E0A9-E50E24DCCA9E
[INFO] : Characteristic ID: 6E400002-B5A3-F393-E0A9-E50E24DCCA9E
And this is my sample code:
var BLE = require('ti.bluetooth');
var centralManager = BLE.createCentralManager();
var value = '';
var connectedPeripheral;
var SERVICE_UUID = '6E400001-B5A3-F393-E0A9-E50E24DCCA9E';
var CHARACTERISTIC_UUID_RX = '6E400002-B5A3-F393-E0A9-E50E24DCCA9E';
var CHARACTERISTIC_UUID_TX = '6E400003-B5A3-F393-E0A9-E50E24DCCA9E';
var win = Ti.UI.createWindow({
backgroundColor : '#fff'
});
var btn1 = Ti.UI.createButton({
title : 'Start scan',
top : 40
});
btn1.addEventListener('click', function() {
if (centralManager.isScanning()) {
alert('Already scanning, please stop scan first!');
return;
} else if (centralManager.getState() != BLE.MANAGER_STATE_POWERED_ON) {
alert('The BLE manager needs to be powered on before. Call initialize().');
return;
}
centralManager.startScan();
});
var btn2 = Ti.UI.createButton({
title : 'Stop scan',
top : 100
});
btn2.addEventListener('click', function() {
if (!centralManager.isScanning()) {
alert('Not scanning!');
return;
}
centralManager.stopScan();
});
/**
centralManager.addEventListener('didDiscoverPeripheral', function(e) {
Ti.API.info('didDiscoverPeripheral');
Ti.API.info(e.peripheral.name);
Ti.API.info('Connect to ' + e.peripheral);
if (e.peripheral.name == 'UART Service') {
Ti.API.info('e.peripheral:', e.peripheral);
Ti.API.info('e.peripheral.name:', e.peripheral.name);
Ti.API.info('connecting');
centralManager.stopScan();
centralManager.connectPeripheral(e.peripheral, {
notifyOnConnection : true,
notifyOnDisconnection : true
});
}
});
centralManager.addEventListener('didUpdateState', function(e) {
Ti.API.info('didUpdateState');
switch (e.state) {
case BLE.MANAGER_STATE_RESETTING:
Ti.API.info('Resetting');
break;
case BLE.MANAGER_STATE_UNSUPPORTED:
Ti.API.info('Unsupported');
break;
case BLE.MANAGER_STATE_UNAUTHORIZED:
Ti.API.info('Unauthorized');
break;
case BLE.MANAGER_STATE_POWERED_OFF:
Ti.API.info('Powered Off');
break;
case BLE.MANAGER_STATE_POWERED_ON:
Ti.API.info('Powered On');
break;
case BLE.MANAGER_STATE_UNKNOWN:
default:
Ti.API.info('Unknown');
break;
}
});
centralManager.addEventListener('didConnectPeripheral', function(e) {
Ti.API.info('Connected to Periperal...');
connectedPeripheral = e.peripheral;
connectedPeripheral.addEventListener('didDiscoverServices', function(e) {
Ti.API.info('Service Discovery...');
p = e.peripheral;
Ti.API.info('peripheral has', p.services.length, 'service(s)');
p.services.forEach(function(service) {
// Assign service
Ti.API.info("service: " + service.uuid);
if (service.uuid == SERVICE_UUID) {
Ti.API.info("service Found: " + service.uuid);
p.addEventListener('didDiscoverCharacteristicsForService', function(e) {
var peripheral = e.peripheral;
var characteristics = e.service.characteristics;
characteristics.forEach(function(characteristic) {
Ti.API.info('Characteristic ID:', characteristic.uuid);
if (characteristic.uuid == CHARACTERISTIC_UUID_TX) {
Ti.API.info('Alert Level Characteristic Found');
Ti.API.info(characteristic.uuid);
peripheral.addEventListener('didUpdateValueForCharacteristic', _didUpdateValueForCharacteristic);
peripheral.setNotifyValueForCharacteristic(true, characteristic);
Ti.API.info('didUpdateValueForCharacteristic passed -->' + characteristic.uuid);
function _didUpdateValueForCharacteristic(e) {
var characteristic = e.characteristic.value.toString().replace(/(\r\n|\n|\r)/gm, "");
value = value + characteristic;
Ti.API.info(' data:' + characteristic + ' length:' + characteristic.length);
}
}
});
});
p.services.forEach(function(service) {
Ti.API.info("Service Found: " + service.uuid);
if (service.uuid == SERVICE_UUID) {
Ti.API.info('Immediate Alert Service Found' + service.uuid);
p.discoverCharacteristicsForService({
characteristics : [],
service : service
});
}
});
p.discoverCharacteristicsForService({
characteristics : [],
service : service
});
}
});
});
// Discover services
connectedPeripheral.discoverServices();
});
centralManager.addEventListener('didDisconnectPeripheral', function(e) {
Ti.API.info('didDisconnectPeripheral');
Ti.API.info(e);
});
centralManager.addEventListener('willRestoreState', function(e) {
Ti.API.info('willRestoreState');
Ti.API.info(e);
});
centralManager.addEventListener('didFailToConnectPeripheral', function(e) {
Ti.API.info('didFailToConnectPeripheral');
Ti.API.info(e);
});
/**
if (Ti.Platform.name === 'iPhone OS') {
peripheralManager.addEventListener('didUpdateState', function(e) {
Ti.API.info('didUpdateState');
Ti.API.info(e);
});
peripheralManager.addEventListener('willRestoreState', function(e) {
Ti.API.info('willRestoreState');
Ti.API.info(e);
});
peripheralManager.addEventListener('didStartAdvertising', function(e) {
Ti.API.info('didStartAdvertising');
Ti.API.info(e);
});
peripheralManager.addEventListener('didAddService', function(e) {
Ti.API.info('didAddService');
Ti.API.info(e);
});
peripheralManager.addEventListener('didSubscribeToCharacteristic', function(e) {
Ti.API.info('didSubscribeToCharacteristic');
Ti.API.info(e);
});
peripheralManager.addEventListener('didUnsubscribeFromCharacteristic', function(e) {
Ti.API.info('didUnsubscribeFromCharacteristic');
Ti.API.info(e);
});
peripheralManager.addEventListener('didReceiveReadRequest', function(e) {
Ti.API.info('didReceiveReadRequest');
Ti.API.info(e);
});
peripheralManager.addEventListener('didReceiveWriteRequests', function(e) {
Ti.API.info('didReceiveWriteRequests');
Ti.API.info(e);
});
peripheralManager.addEventListener('readyToUpdateSubscribers', function(e) {
Ti.API.info('readyToUpdateSubscribers');
Ti.API.info(e);
});
}
win.add(btn1);
win.add(btn2);
win.open();
Whats's wrong in my code?
The same code in IOS work fine!
Best regards,
Michele.
Tested the new 1.1.0 release.
Main issue is that no reporting of UUIDs is done when reporting discovered peripherals, services and characteristics.
It discovers my Bluetooth device (VB-1913...), and connects to this device.
When the device is connected it finds it's 1 service, and finds that this service has characteristic(s).
However it doesn't report which characteristics.
In order to use this module in an application, the control by specific UUIDs is needed.
[INFO] : didDiscoverPeripheral
[INFO] : VB-19133423006
[INFO] : connecting
[INFO] :
[INFO] : didConnectPeripheral
[INFO] : {
[INFO] : bubbles = 1;
[INFO] : cancelBubble = 0;
[INFO] : peripheral = "[object TiBluetoothPeripheral]";
[INFO] : source = "[object TiBluetoothCentralManager]";
[INFO] : type = didConnectPeripheral;
[INFO] : }
[INFO] : [object TiBluetoothPeripheral]
[INFO] :
[INFO] : didDiscoverServices
[INFO] : {
[INFO] : bubbles = 1;
[INFO] : cancelBubble = 0;
[INFO] : error = "<null>";
[INFO] : peripheral = "[object TiBluetoothPeripheral]";
[INFO] : source = "[object TiBluetoothPeripheral]";
[INFO] : type = didDiscoverServices;
[INFO] : }
[INFO] : [object TiBluetoothPeripheral]
[INFO] : (
[INFO] : "[object TiBluetoothService]"
[INFO] : )
[INFO] : peripheral has 1 service(s)
[INFO] : service characteristics (
[INFO] : )
/**
* Central Manager Events
*/
centralManager.addEventListener('didUpdateState', function(e) {
console.log('didUpdateState');
switch (e.state) {
case BLE.MANAGER_STATE_RESETTING:
console.log('Resetting');
break;
case BLE.MANAGER_STATE_UNSUPPORTED:
console.log('Unsupported');
break;
case BLE.MANAGER_STATE_UNAUTHORIZED:
console.log('Unauthorized');
break;
case BLE.MANAGER_STATE_POWERED_OFF:
console.log('Powered Off');
break;
case BLE.MANAGER_STATE_POWERED_ON:
console.log('Powered On');
centralManager.startScan();
break;
case BLE.MANAGER_STATE_UNKNOWN:
default:
console.log('Unknown');
break;
}
});
centralManager.addEventListener('didDiscoverPeripheral', function(e) {
console.log('didDiscoverPeripheral');
console.log(e.peripheral.name);
if ((e.peripheral.name != null) && e.peripheral.name.indexOf('VB-') != -1) {
console.log('connecting');
var options = {
notifyOnConnection : true,
notifyOnDisconnection : true,
notifyOnNotification : true
};
centralManager.connectPeripheral(e.peripheral);
}
});
centralManager.addEventListener('didConnectPeripheral', function(e) {
console.log('\ndidConnectPeripheral');
console.log(e);
console.log(e.peripheral);
connectedPeripheral = e.peripheral;
connectedPeripheral.addEventListener('didDiscoverServices', function(e) {
console.log('\ndidDiscoverServices');
console.log(e);
console.log(e.peripheral);
console.log(e.peripheral.services);
console.log('peripheral has', e.peripheral.services.length, 'service(s)');
var services = e.peripheral.services;
for (var i = 0; i < services.length; i++)
console.log('service characteristics ', services[i].characteristics);
// if (service.UUID.toLowerCase() == CUSTOM_SERVICE_UUID.toLowerCase()) {
// e.peripheral.discoverCharacteristicsForService(service);
// }
});
connectedPeripheral.addEventListener('didDiscoverCharacteristicsForService', function(e) {
console.log('didDiscoverCharacteristicsForService');
console.log(e);
});
connectedPeripheral.addEventListener('didUpdateValueForCharacteristic', function(e) {
console.log('didUpdateValueForCharacteristic');
console.log(e);
});
connectedPeripheral.discoverServices();
});
centralManager.addEventListener('didDisconnectPeripheral', function(e) {
console.log('didDisconnectPeripheral');
console.log(e);
});
centralManager.addEventListener('willRestoreState', function(e) {
console.log('willRestoreState');
console.log(e);
});
centralManager.addEventListener('didFailToConnectPeripheral', function(e) {
console.log('didFailToConnectPeripheral');
console.log(e);
});
Hello ,
i am trying to build the module for android but i am facing an issue with javac source and target as i think.
Titanium SDK 6.0.4
JDK 1.7
can you please help with this ?
�Failed to compile Java source files: [ERROR] : �� � [ERROR] : �� �warning: [options] bootstrap class path not set in conjunction with -source 1.6 [ERROR] : �� �Note: [KrollBindingGen] Running Kroll binding generator. [ERROR] : �� �Note: [KrollBindingGen] No binding data found, creating new data file: org.appcelerator.titanium.bindings/ti.bluetooth.json [ERROR] : �� �Note: [KrollBindingGen] Found binding for proxy TiBluetoothDevice [ERROR] : �� �Note: [KrollBindingGen] Found binding for module TiBluetooth [ERROR] : �� �Note: [KrollBindingGen] Generating JSON: file:/Users/*/Documents/Appcelerator_Studio_Workspace/titanium-bluetooth/android/build/generated/json/org/appcelerator/titanium/bindings/ti.bluetooth.json [ERROR] : �� �/Users/*/Documents/Appcelerator_Studio_Workspace/titanium-bluetooth/android/src/ti/bluetooth/TiBluetoothDeviceProxy.java:33: error: cannot find symbol [ERROR] : �� � btDevice.connectGatt(ctx, autoConnect, new BluetoothGattCallbackHandler(this)); [ERROR] : �� � ^ [ERROR] : �� � symbol: class BluetoothGattCallbackHandler [ERROR] : �� � location: class TiBluetoothDeviceProxy [ERROR] : �� �Note: /Users/*/Documents/Appcelerator_Studio_Workspace/titanium-bluetooth/android/src/ti/bluetooth/TiBluetoothGattCallbackHandler.java uses unchecked or unsafe operations. [ERROR] : �� �Note: Recompile with -Xlint:unchecked for details. [ERROR] : �� �1 error [ERROR] : �� �1 warning
Hello ,
i did a sample usage of the module , but it craches at launching when i call createCentralManager method.
SDK 6.0.4
IOS : 10.3.1
module version 1.0.3 beta ios
Attempted to load TiBluetoothCentralManagerProxy: Could not find class definition.
[ERROR] : Script Error {
[ERROR] : column = 203;
[ERROR] : line = 1;
[ERROR] : message = "invalid method (createCentralManager) passed to TiBluetoothModule";
[ERROR] : }
I apologize for my english, but I have a big problem in using the form.
While starting the application I get this error:
2020-03-04 23:33:10.721848+0100 poc-app-transfer-data-ble[1490:537465] [DEBUG] Reading stylesheet from: /private/var/containers/Bundle/Application/879F6206-B8F6-445E-801C-A0FA9560BD21/poc-app-transfer-data-ble.app/stylesheet.plist
2020-03-04 23:33:10.766686+0100 poc-app-transfer-data-ble[1490:537465] [INFO] poc-app-transfer-data-ble/1.0 (0.0.0.(null))
2020-03-04 23:33:10.787729+0100 poc-app-transfer-data-ble[1490:537465] [DEBUG] Loading: /private/var/containers/Bundle/Application/879F6206-B8F6-445E-801C-A0FA9560BD21/poc-app-transfer-data-ble.app/ti.main.js, Resource: ti_main_js
2020-03-04 23:33:10.789309+0100 poc-app-transfer-data-ble[1490:537465] [INFO] poc-app-transfer-data-ble 1.0 (Powered by Titanium 8.0.0.3726240fa2)
2020-03-04 23:33:10.789477+0100 poc-app-transfer-data-ble[1490:537465] [DEBUG] Loading: /private/var/containers/Bundle/Application/879F6206-B8F6-445E-801C-A0FA9560BD21/poc-app-transfer-data-ble.app/index.json, Resource: _index__json
2020-03-04 23:33:10.789529+0100 poc-app-transfer-data-ble[1490:537465] [ERROR] Could not load index.json require index, error was File not found
2020-03-04 23:33:10.790661+0100 poc-app-transfer-data-ble[1490:537465] [ERROR] Script Error Couldn't find module: ./ti.internal/extensions/Error for architecture: arm64
2020-03-04 23:33:10.797498+0100 poc-app-transfer-data-ble[1490:537465] [DEBUG] Application booted in 68.318009 ms
The example app works OK for me on Ti SDK 9.2.1.GA ..
But when running on an app built by Ti SDK 10.0.2.GA, it throws this error when trying to connect in the startScanning()
method in the example :
TypeError: centralManager.getState is not a function. (In 'centralManager.getState()', 'centralManager.getState' is undefined)
I seem to be able to get this module working ok on a very old Android device running Android 5.1.
(I'm connecting to an ESP32 dev module.)
But I'm having no luck connecting to anything when running on a newer device with Android 11 using the same code.
iOS is fine.
Anyone have any ideas what might need to be updated?
Hi,
for this we need a BluetoothAdapter.ACTION_DISCOVERY_FINISHED
. event.
case BluetoothAdapter.ACTION_DISCOVERY_FINISHED:
// discovery has finished, give a call to fetchUuidsWithSdp on first
// device in list.
if (!deviceList.isEmpty()) {
boolean result = deviceList.remove(0).fetchUuidsWithSdp();
if (result == false)
Log.e(LCAT, "Cannot fetchUuidsWithSdp");
}
KrollDict kd = new KrollDict();
if (module.hasListeners("didDiscoveryFinished"))
module.fireEvent("didDiscoveryFinished", kd);
break;
The we could:
case BluetoothDevice.ACTION_UUID:
BluetoothDevice deviceExtra = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Parcelable[] uuidExtra = intent
.getParcelableArrayExtra(BluetoothDevice.EXTRA_UUID);
Log.d(LCAT, "DeviceExtra address - " + deviceExtra.getAddress());
if (uuidExtra != null) {
for (Parcelable p : uuidExtra) {
Log.d(LCAT, "uuidExtra - " + p);
}
} else {
Log.w(LCAT, "uuidExtra is still null");
}
if (!deviceList.isEmpty()) {
BluetoothDevice mdevice = deviceList.remove(0);
mdevice.fetchUuidsWithSdp();
}
break;
I've managed to successfully get an app to connect to an ESP32 and receive notifications from it.
I'm probably missing something obvious, but how do I create the Blob required for the value I want to write back to the BLE Server on the ESP32 device.?
eg: If I just wanted to send a number? (counter)
myPeripheral.writeValueForCharacteristicWithType(counter, myService.characteristics[0], BLE.CHARACTERISTIC_WRITE_WITHOUT_RESPONSE);
giving:
"Invalid type passed to function"
.. nativeReason = "expected: TiBlob, was: Number
Do I need to create a File or a Buffer to do it?
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:
// -----------------------------------------------------------------------------
// Peripheral Connect Callback
// -----------------------------------------------------------------------------
centralManager.addEventListener('didConnectPeripheral', function(e)
{
Ti.API.info('Connected to Periperal...');
connectedPeripheral = e.peripheral;
connectedPeripheral.addEventListener('didUpdateValueForCharacteristic', function(e) {
Ti.API.info('didUpdateValueForCharacteristic');
Ti.API.info(e);
});
connectedPeripheral.addEventListener('didDiscoverServices', function(e)
{
Ti.API.info('Service Discovery...');
p = e.peripheral;
Ti.API.info('peripheral has', p.services.length, 'service(s)');
p.services.forEach(function(service)
{
Ti.API.info('service: ', service.uuid);
// Assign battery service
if(service.uuid == gattBattery)
{
Ti.API.info("BatteryService Found");
serviceBattery = service;
p.addEventListener('didDiscoverCharacteristicsForService', function(e)
{
var characteristics = e.service.characteristics;
characteristics.forEach(function(characteristic)
{
Ti.API.info('Characteristic ID:', characteristic.uuid);
// Want to subscribe to this characteristic and receive value changes from peripheral
if(characteristic.uuid == '2A19')
{
}
});
});
p.discoverCharacteristicsForService({
characteristics : [],
service : service
});
}
});
});
// Discover services
connectedPeripheral.discoverServices();
});
Hi!
Until now I worked with the modules from Logicallabs. I would like to test the ti.bluetooth module in my apps. Could you complete or provide otherwise documentation, for example how to connect to a device, subscribe to characteristics, write to a characteristic, etc?
Hi,
i have a problem with event didUpdateValueForCharacteristic.
The response is void:
didDiscoverCharacteristicsForService
[INFO] : {
[INFO] : bubbles = 1;
[INFO] : cancelBubble = 0;
[INFO] : error = "";
[INFO] : peripheral = {
[INFO] : };
[INFO] : service = {
[INFO] : };
[INFO] : source = {
[INFO] : };
[INFO] : type = didDiscoverCharacteristicsForService;
[INFO] : }
I can't read the response of my command.
when i wrote the value with "writeValueForCharacteristicWithType" i set type without response otherwise don't work.
"BLE.CHARACTERISTIC_PROPERTY_WRITE_WITHOUT_RESPONSE".
can someone help me?
thanks
by
@miga Does we need a proxy for this? onScanResult
could return a proxy instead of a simple dict. I think in next step we need methods on this Bluetoothdevice like connectGatt
and ``writetoparcel etc.
Receiver test 1
Error log
Unable to instantiate receiver ti.bluetooth.broadcastReceiver.TiBluetoohBroadcastReceiver: java.lang.InstantiationException: java.lang.Class<ti.bluetooth.broadcastReceiver.TiBluetoohBroadcastReceiver> has no zero argument constructor
This error happened when I switch on the Bluetooth while the app is running.
Hello,
I'm trying to accomplish connection and discover Bluetooth services.
It's working:
!!!! Found MLT !!!!!
[INFO] : didConnectPeripheral
[INFO] : {
[INFO] : bubbles = 1;
[INFO] : cancelBubble = 0;
[INFO] : peripheral = "[object TiBluetoothPeripheral]";
[INFO] : source = "[object TiBluetoothCentralManager]";
[INFO] : type = didConnectPeripheral;
[INFO] : }
[INFO] : State: 2
[INFO] : RSSI: 0
[INFO] : Name: MLT-BT05
[INFO] : didDiscoverServices
[INFO] : {
[INFO] : bubbles = 1;
[INFO] : cancelBubble = 0;
[INFO] : error = "";
[INFO] : peripheral = "[object TiBluetoothPeripheral]";
[INFO] : source = "[object TiBluetoothPeripheral]";
[INFO] : type = didDiscoverServices;
[INFO] : }
Now, I'm in "myPeripheral.addEventListener('didDiscoverServices') event, and trying to get characteristics for service by running this code:
myPeripheral.discoverCharacteristicsForService(myPeripheral.services[0]);
But error:
message = "*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]";
I analysed source code and found there is a deprecated method "discoverCharacteristicsForService" with 2 arguments. This one running, but not firing any callback event.
What am I missing ?
I am currently in the process of refactoring the iOS module. We should be more flexible when having peripherals vs. centrals. Example:
var centralManager = BLE.createCentralManager(args);
var peripheralManager = CLE.createPeripheralManager(args);
Involved API's (not all creatable):
Central
CentralManager
PeripheralManager
Descriptor
Service
Request
Characteristic
Then we can scan (central manager) and advertise (peripheral manager) with those instances. Since this concept is very common, a cross-platform API could be even better to realise and we are more flexible for more API's in the future. We should update the readme and examples accordingly.
User found an interesting way to freeze the app with the module:
[DEBUG] TiBaseActivity: (main) [1967,2063] onBackPressed: exit
[DEBUG] Window: Window is closed normally.
[DEBUG] BluetoothAdapter: onBluetoothServiceDown: android.bluetooth.IBluetooth$Stub$Proxy@c43963d
[DEBUG] BluetoothAdapter: onBluetoothServiceUp: android.bluetooth.IBluetooth$Stub$Proxy@bbbe32
[DEBUG] AndroidRuntime: Shutting down VM
-> app won't start. timeout/crash:
BroadcastQueue: Timeout of broadcast BroadcastRecord{20cdeef u0 android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED} - receiver=android.os.BinderProxy@935654a, started 60000ms ago
BroadcastQueue: Receiver during timeout of BroadcastRecord{20cdeef u0 android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED} : ResolveInfo{1d4dcbb com.miga.tiscale/ti.bluetooth.ti.bluetooth.broadcastReceiver.TiBluetoohBroadcastReceiver m=0x108000}
BroadcastQueue: Background execution not allowed: receiving Intent { act=android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED flg=0x4000010 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver
Setup
Current workaround:
removing <action android:name="android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED"/>
from the timodule.xml manifest. ti.bluetooth-android-4.0.1.zip
Still trying to find a better way around this. But since there aren't any other code parts inside the module that use a2dp we might just remove that line
Hello,
I have installed ti.module for android, but unfortunately the applications crashes directly when i include the module.
SDK : 6.3.0 GA
Android : 4.4
Best regards.
First of all, thanks for this awesome module. I've been able to scan and identify the bluetooth device I'm looking for. What I can't figure out, however, is how to authenticate to it. I was able to connect, but it immediately disconnected. I don't need to necessarily know the authentications codes, just how one would go about it. It connected and immediately disconnected.
[INFO] connecting!
[INFO] didConnectPeripheral
[INFO] {
[INFO] bubbles = 1;
[INFO] cancelBubble = 0;
[INFO] peripheral = "[object TiBluetoothPeripheral]";
[INFO] source = "[object TiBluetoothCentralManager]";
[INFO] type = didConnectPeripheral;
[INFO] }
[INFO] didDisconnectPeripheral
[INFO] {
[INFO] bubbles = 1;
[INFO] cancelBubble = 0;
[INFO] peripheral = "[object TiBluetoothPeripheral]";
[INFO] source = "[object TiBluetoothCentralManager]";
[INFO] type = didDisconnectPeripheral;
[INFO] }
The device I'm trying to connect to is a Dexcom G5 Glucose Monitor. Much of the work has already been done, I'm just trying to do it in Titanium. https://github.com/LoopKit/xDripG5/blob/5cdf2d3e7783435072cffa997bd123a5b0c0c258/xDripG5/BluetoothServices.swift
Hi,
I've forked this and tried to import the project into Studio and it does not seem to recognise the iOS version. Only Package Android Module is available.
I seem to often have this problem with cross-platform (dual) modules. And I have never been able to set one up myself. (Always two separate projects).
Is there a trick I'm missing? ;) Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.