sandeepmistry / node-sensortag

Node.js lib for the TI SensorTag
MIT License
218 stars 111 forks source link

How to read other characteristics? #31

Closed Nesh108 closed 9 years ago

Nesh108 commented 9 years ago

Hello,

I am using this (awesome) library to connect my BeagleBone to a TI CC2541.

I noticed that it is possible to access most of the characteristics but I was wondering if I could read (and write) data from other services.

Namely, I would like to be able to access the Test Service and its characteristics. I have their UUID's, is there any way to use this lib for that?

Cheers and thanks a lot for your work :+1:

Nesh108 commented 9 years ago

Hello,

I tried to access the data from the Test Config field but I was unable to read its value. Is 'data.readInt8(0)' enough?

sandeepmistry commented 9 years ago

@Nesh108 can you provide a larger code snippet for what you tried?

Which UUID are you trying to read - AA62? http://processors.wiki.ti.com/index.php/SensorTag_User_Guide#Test_Service

var TEST_CONFIGURATION_UUID = 'f000aa6204514000b000000000000000';

SensorTag.prototype.readTestConfiguration = function(callback) {
  this.readDataCharacteristic(TEST_CONFIGURATION_UUID, function(data) {
    callback(data.readInt8(0));
  }.bind(this));
};

Pull request for new API would be great once you get it working ...

Nesh108 commented 9 years ago

Hello Sandeep,

Here is a larger snippet:

var LOCK_CONFIG_UUID                        =     'f000aa6204514000b000000000000000';

SensorTag.prototype.readLockState = function(callback) { 
  this.readDataCharacteristic(LOCK_CONFIG_UUID, function(data) {
    this.decodeLock(data, callback);
  }.bind(this));
};

SensorTag.prototype.decodeLock = function(data, callback) {
    var locked = data.readUInt8(0);
    callback(locked);
};

The only difference I see is your 'readInt8(0)' instead of UInt. Could that be the problem?

EDIT: Tried with 'readInt8(0)' and nothing changed :/

sandeepmistry commented 9 years ago

@Nesh108 see 9973e5a5c09a2a392ce9604620abf428228bd5f0 - it works for me.

Nesh108 commented 9 years ago

Mmm weird. Which FW are you using? 1.4 or 1.5?

sandeepmistry commented 9 years ago

1.5 (Oct 23 2013)

Nesh108 commented 9 years ago

I will try with my other sensortag and see if anything changes...

sandeepmistry commented 9 years ago

What happens when you run the latest test.js from master?

Debug mode: sudo DEBUG=l2cap-ble node test.js

Nesh108 commented 9 years ago

I think the problem was the device. With my other one, it worked flawlessly.

Thanks, dude!

sandeepmistry commented 9 years ago

@Nesh108 no problem, glad you got it working with the other device.