Giter VIP home page Giter VIP logo

Comments (22)

wsliaw avatar wsliaw commented on June 10, 2024 1

Yea, I think I'll make a PR for that

This is how I do it:

e.service.characteristics.forEach(function(characteristic) {
	p.writeValueForCharacteristicWithType(toBlob('hello world, I\'m ' + Ti.Platform.username), characteristic, BLE.CHARACTERISTIC_PROPERTY_WRITE_WITH_RESPONSE);
});

function toBlob(str) {
	var buf = Ti.createBuffer({ value: str });
	return buf.toBlob();
}

from titanium-bluetooth.

hansemannn avatar hansemannn commented on June 10, 2024 1

PR ready for the UUID properties, 1.1.2 on the way.

from titanium-bluetooth.

hansemannn avatar hansemannn commented on June 10, 2024

Hey there, thanks for the demo-code and logs. I am curious if this a module problem, here is why: We basically wrap all native API's, but especially on events, we don't do any other business-logic. See some details here:

  • We fire the event here
  • We wrap the native peripheral here
  • We return the services here
  • We return the service-characteristics here

And that's basically it. If there are characteristics, there are wrapped here, otherwise, an empty array is returned. Not sure how to debug this, since I do not have a proper Bluetooth-device with me right now.

from titanium-bluetooth.

focussing avatar focussing commented on June 10, 2024

Thanks Hans, I am not "at home" in iOS source code, but I can see what is going on. Sorry for that.
I have tested again with the new release 1.1.1 released this morning. Still I can't get any UUID information in the console.

Also firing discoverCharacteristicsForService does not result in a didDiscoverCharacteristicsForService event being fired. Maybe the call is not correct; I can't derive that from the source code nor the Wiki.

	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.uuid);
				e.peripheral.discoverCharacteristicsForService({
					characteristics: [],
					service : services[i]
				});
			}
		});

		// if (service.UUID.toLowerCase() == CUSTOM_SERVICE_UUID.toLowerCase()) {

		connectedPeripheral.addEventListener('didDiscoverCharacteristicsForService', function(e) {
			console.log('didDiscoverCharacteristicsForService');
			console.log(e);
		});

		connectedPeripheral.addEventListener('didUpdateValueForCharacteristic', function(e) {
			console.log('didUpdateValueForCharacteristic');
			console.log(e);
		});

		connectedPeripheral.discoverServices();
	});

The log:

[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>

from titanium-bluetooth.

hansemannn avatar hansemannn commented on June 10, 2024

I know @wsliaw recently did a lot with the module, maybe he can help?

from titanium-bluetooth.

wsliaw avatar wsliaw commented on June 10, 2024
  1. For now the module hasn't expose uuid for service & characteristic
  2. Try move didDiscoverCharacteristicsForService & didUpdateValueForCharacteristic listeners inside didDiscoverServices callback
centralManager.addEventListener('didConnectPeripheral', function(e) {
	connectedPeripheral = e.peripheral;

	connectedPeripheral.addEventListener('didDiscoverServices', function(e) {

		var p = e.peripheral;

		p.addEventListener('didDiscoverCharacteristicsForService', function(e) {
			console.log('didDiscoverCharacteristicsForService');
			console.log(e);
		});

		p.addEventListener('didUpdateValueForCharacteristic', function(e) {
			console.log('didUpdateValueForCharacteristic');
			console.log(e);
		});

		p.services.forEach(function(service) {
			p.discoverCharacteristicsForService({
				characteristics: [],
				service: service
			});
		});

	});

	connectedPeripheral.discoverServices();

});

from titanium-bluetooth.

focussing avatar focussing commented on June 10, 2024

Thanks! didDiscoverCharacteristicsForService is now fired. Maybe the example should be updated with this.

Could the module be updated so the UUID's are exposed for service & characteristic and also for peripheral?
This is needed when building an app where multipe UUID's are present.

Another question; how can I send a UINT64 value (byte array length 8) over Bluetooth? Javascript does not support > 53bits accuracy. If I create a Ti.Buffer, should I use Ti.Codec.TYPE_BYTE and fill the buffer bytes with the byteArray bytes?

Thanks!!

from titanium-bluetooth.

focussing avatar focussing commented on June 10, 2024

I just see that the didDiscoverCharacteristicsForService is only fired once, yet there are 2 services having 5 characteristics each.

This is the log when I use the BLE module from Logicallabs

[INFO] :   16:02:13 (208) peripheral has 2 services
[INFO] :   16:02:13 (209) service UUID: 180A
[INFO] :   16:02:13 (211) service UUID: 500AAE11-CDEC-C0AE-5FD5-B10E85910100
[INFO] :   16:02:13 (217) entering digestCharacteristics for service 180A
[INFO] :   16:02:13 (218) service has 5 characteristic(s).
[INFO] :   16:02:13 (220) characteristic: 2A29
[INFO] :   16:02:13 (221) characteristic: 2A24
[INFO] :   16:02:13 (221) characteristic: 2A28
[INFO] :   16:02:13 (222) characteristic: 2A26
[INFO] :   16:02:13 (223) characteristic: 2A25
[INFO] :   16:02:13 (224) entering digestCharacteristics for service 500AAE11-CDEC-C0AE-5FD5-B10E85910100
[INFO] :   16:02:13 (224) service has 5 characteristic(s).
[INFO] :   16:02:13 (225) characteristic: 500AAE11-CDEC-C0AE-5FD5-B10E8591010A
[INFO] :   16:02:13 (226) characteristic: 500AAE11-CDEC-C0AE-5FD5-B10E8591010B
[INFO] :   16:02:13 (227) characteristic: 500AAE11-CDEC-C0AE-5FD5-B10E85910110
[INFO] :   16:02:13 (228) subscribing to characteristic 500AAE11-CDEC-C0AE-5FD5-B10E85910110
[INFO] :   16:02:13 (229) characteristic: 500AAE11-CDEC-C0AE-5FD5-B10E85910120
[INFO] :   16:02:13 (230) characteristic: 500AAE11-CDEC-C0AE-5FD5-B10E85910130

from titanium-bluetooth.

hansemannn avatar hansemannn commented on June 10, 2024

Release 1.1.2: https://github.com/hansemannn/titanium-bluetooth/releases/tag/ios-v1.1.2

from titanium-bluetooth.

wsliaw avatar wsliaw commented on June 10, 2024

@focussing so what did you get from ti.bluetooth ? I never advertise 2 services from a peripheral before

from titanium-bluetooth.

focussing avatar focussing commented on June 10, 2024

The Bluetooth device I am using advertises 2 services. Ti.Bluetooth sees that, so per service a "didDiscoverCharacteristicsForService" has to be done.

I am testing with 1.1.2 version now, but I don't get uuid reported, for example from didDiscoverPeripheral.

	centralManager.addEventListener('didDiscoverPeripheral', function(e) {
		console.log('didDiscoverPeripheral');
		console.log(e.peripheral.name);
		console.log(e.peripheral.uuid);
		if ((e.peripheral.name != null) && e.peripheral.name.indexOf('SQ__') != -1) {
			console.log('connecting');
			var options = {
				notifyOnConnection : true,
				notifyOnDisconnection : true,
				notifyOnNotification : true
			};
			centralManager.connectPeripheral(e.peripheral);
		}
	});

Also didDiscoverCharacteristicsForService is not fired.

from titanium-bluetooth.

hansemannn avatar hansemannn commented on June 10, 2024

@focussing Peripherals do not have a UUID, they are identified via their name and services. The connectPeripheral looks correctly.

from titanium-bluetooth.

focussing avatar focussing commented on June 10, 2024

True! Of course you are right. Sorry!

This is the code and log. The only thing right now is that only the first of 2 service's characteristics are discovered:

	centralManager.addEventListener('didDiscoverPeripheral', function(e) {
		console.log('didDiscoverPeripheral');
		console.log(e.peripheral.name);

		// if ((e.peripheral.name != null) && e.peripheral.name.indexOf('SQ') == 0) {
		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('connected to', e.peripheral.name);

		var connectedPeripheral = e.peripheral;

		connectedPeripheral.addEventListener('didDiscoverServices', function(e) {
			console.log('\ndidDiscoverServices');

			var p = e.peripheral;

			console.log('peripheral has', p.services.length, 'service(s)');

			p.addEventListener('didDiscoverCharacteristicsForService', function(e) {
				console.log('\ndidDiscoverCharacteristicsForService');
				console.log('service:', e.service.uuid);

				var characteristics = e.service.characteristics;
				characteristics.forEach(function(characteristic) {
					console.log('characteristic:', characteristic.uuid);
				});
			});

			p.addEventListener('didUpdateValueForCharacteristic', function(e) {
				console.log('\ndidUpdateValueForCharacteristic');
				console.log(e);
			});

			p.services.forEach(function(service) {
				console.log('service:', service.uuid);
				console.log('calling discoverCharacteristicsForService');
				p.discoverCharacteristicsForService({
					characteristics : [],
					service : service
				});
			});

		});

		connectedPeripheral.discoverServices();
	});

[INFO] :   ti.bluetooth/0.1.0 (6.1.0.6eb8990)
[INFO] :   didUpdateState
[INFO] :   Powered On
[INFO] :   didDiscoverPeripheral
[INFO] :   SQ__859501025
[INFO] :   connecting
[INFO] :   
[INFO] :   didConnectPeripheral
[INFO] :   connected to SQ__859501025
[INFO] :   
[INFO] :   didDiscoverServices
[INFO] :   peripheral has 2 service(s)
[INFO] :   service: 180A
[INFO] :   calling discoverCharacteristicsForService
[INFO] :   service: 500AAE11-CDEC-C0AE-5FD5-B10E85910100
[INFO] :   calling discoverCharacteristicsForService
[INFO] :   
[INFO] :   didDiscoverCharacteristicsForService
[INFO] :   service: 180A
[INFO] :   characteristic: 2A29
[INFO] :   characteristic: 2A24
[INFO] :   characteristic: 2A28
[INFO] :   characteristic: 2A26
[INFO] :   characteristic: 2A25

from titanium-bluetooth.

hansemannn avatar hansemannn commented on June 10, 2024

Maybe because you are using discoverCharacteristicsForService directly after the first service is found, so iOS might guess you are not waiting for others to be discovered? Maybe one of the CoreBluetooth example projects will help you comparing it to the native world, the API naming was pretty much 1:1 aligned to the native one.

from titanium-bluetooth.

wsliaw avatar wsliaw commented on June 10, 2024

@focussing consider discoverServices with UUIDs

connectedPeripheral.discoverServices([serviceUUID_1, serviceUUID_2]);

Please tell me what's the result, thank you

from titanium-bluetooth.

hansemannn avatar hansemannn commented on June 10, 2024

Closing due to inactivity. Feel free to reopen if the issue persists.

from titanium-bluetooth.

focussing avatar focussing commented on June 10, 2024

@wsliaw your suggestion gives an error message.

connectedPeripheral.discoverServices(['49535343-FE7D-4AE5-8FA9-9FAFD205E455']);

Normally do don't know the service UUID on forehand. For a new Bluetooth module, first you list the services and UUID's in the console. And then you'll want to get the Characteristics per Service, and start listening or sending data to specific Characteristics.

from titanium-bluetooth.

focussing avatar focussing commented on June 10, 2024

By the way, off course I switched to the latest release of this module 1.2.1

Getting the same result as earlier:

[INFO] :   didConnectPeripheral
[INFO] :   connected to RN4678-1CD8
[INFO] :   
[INFO] :   didDiscoverServices
[INFO] :   peripheral has 2 service(s)
[INFO] :   service: 180A
[INFO] :   calling discoverCharacteristicsForService
[INFO] :   service: 49535343-FE7D-4AE5-8FA9-9FAFD205E455
[INFO] :   calling discoverCharacteristicsForService
[INFO] :   
[INFO] :   didDiscoverCharacteristicsForService
[INFO] :   service: 180A
[INFO] :   characteristic: 2A29
[INFO] :   characteristic: 2A24
[INFO] :   characteristic: 2A25
[INFO] :   characteristic: 2A27
[INFO] :   characteristic: 2A26
[INFO] :   characteristic: 2A28
[INFO] :   characteristic: 2A23
[INFO] :   characteristic: 2A2A

from titanium-bluetooth.

focussing avatar focussing commented on June 10, 2024

These characteristics are common ones, giving information about manufacturer etc.
The characteristics of the second service is much more interesting :)

from titanium-bluetooth.

hansemannn avatar hansemannn commented on June 10, 2024

@focussing So what exact event / method is not working? If you compare it to some Swift examples, it should be nearly 1:1 the name API naming, so that might lead us to the related issue here. Thanks for keeping this active!

from titanium-bluetooth.

hansemannn avatar hansemannn commented on June 10, 2024

Reopening to keep track about the process. ping @focussing

from titanium-bluetooth.

hansemannn avatar hansemannn commented on June 10, 2024

Thanks to @wsliaw, I just fixed an issue regarding peripherals in 1.2.2 (Download), please check it out!

from titanium-bluetooth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.