Reply
Posts: 4
Registered: ‎02-08-2017

New Open-Source thunderboard-ble Node.js Library Available for Feedback

[ Edited ]

Over the past year or so, I've been a passive member in the Silicon Labs community.  Having played mainly with the Thunderboard React (and now Sense), I wasn't fully versed in the full product offering...but as my project is starting to ramp down, I took a little time to extract some code that I was using to interact with the Thunderboard into a simple light-weight library.

 

In it's current state, it is ideal for auto-connecting to a Thunderboard, setting up monitoring of service characteristics and normalizing measurement data into clean values.

 

It is by no means complete, and is a crude start ... but as long as I'm using the Thunderboard, I'll look to keep it up to date and try to make it better.  

 

Pull requests and issues are welcome, but time is limited...so patience is requested.  Hope it is helpful for someone.  Enjoy =)

 

Check out the GitHub repo:

https://github.com/ryanrutan/thunderboard-ble

 

And here are the NPM details:

https://www.npmjs.com/package/thunderboard-ble

Posts: 4
Registered: ‎02-08-2017

Re: New Open-Source thunderboard-ble Node.js Library Available for Feedback

FWIW, I am currently using this Library on a Raspi3 environment.  I just tried this on Mac OS X Sierra and the it looks like that environment is returning an auto-generated peripheralID and not displaying service information.  Not sure if this is related to bluetooth-hci-socket not being available ... but wanted to let people know that a Linux environment is definitely the intended environment for this library as it currently stands.

Posts: 26
Registered: ‎12-06-2016

Re: New Open-Source thunderboard-ble Node.js Library Available for Feedback

This is great! I've been trying to use the node-thunderboard-react library but it keeps having timing issues connecting with the react. I have a sense now too and that doesn't work for that. 
Having some troubles though. I copy and paste the example give and all I change is the address a the start of the config to be the mac address thing? and then the uuid is the same thing? Or the name seen on the Thunderboard app?

Highlighted
Posts: 4
Registered: ‎02-08-2017

Re: New Open-Source thunderboard-ble Node.js Library Available for Feedback

So the React is a bit finicky (IMO) on when it broadcasts it's information.  I usually will turn off React ... spin up Node instance ... and then turn on React and then press one of the LED buttons after about 1 sec.  Then usually wakes up the board and forces it to broadcast its information. 

 

One other issue I ran into that might be worth mentioning.  My Raspi 3 trusted the React/Sense, and as such connected to it before Node could.  This meant that the React/Sense was visible by address, but no services were discoverable.  Double check that no other device is stealing the BLE connection.

 

 

In my situation, I have a long running Node app ... and it loads the library into memory and just picks up and disconnects automatically.  The configuration you pass in isn't a direct connect, it is configuring Noble to listen for the address and details when it is discovered, so their isn't a concept of a direct connection to the board.  

 

For example, in my node service, this is what I have as my configuration:

 

var thunderboard = new Thunderboard(config["iot-devices"],
function(event) {

//this is the callback that is called when you execute a read/notify/write for confirmation.

//the event object has a structure that let's your route/decipher the normalized values.
console.log("***",event["service"]["name"],event["characteristic"]["name"],event["value"]);

});

 

Works for both React and Sense (still need to finish some of the newer service definitions).  

 

Hope any / all of that helps, and thanks for the feedback!

Posts: 26
Registered: ‎12-06-2016

Re: New Open-Source thunderboard-ble Node.js Library Available for Feedback

?
I was using a different node js module to connect, that was giving me the issues. I am going to try yours now.

How do I get it to recognise my Thunderboard. I have a react and a sense, which is best to use?

Posts: 26
Registered: ‎12-06-2016

Re: New Open-Source thunderboard-ble Node.js Library Available for Feedback

I use this code? But change "000b5bbbaaaa" for "000b570c3b2c"? Which is my BLE mac address?

 

var config = {
        "000b5bbbaaaa" : {
         "uuid" : "000b5bbbaaaa",
         "enabled" : false,
         "family" : "thunderboard",
         "type" : "react",
         "autoconnect" : true,
         "readIntervals" : {
           "environment" : {
             "humidity" : 15000,
             "temperature" : 15000,
             "uv" : 15000
           },
           "ambient-light" : {
             "ambient-light" : 15000
           }
          },
         "services" : {
           "generic-access" : ["device-name"],
           "device-info" : ["manufacturer"],
           "environment" : ["humidity","temperature","uv"],
           "ambient-light" : ["ambient-light"]
        }
      }
    };
 
    var dataCallback = function(data) {
      console.log('Thunderboard Event',data);
    };
 
    var normalizeData = true;
 
    var ThunderBoard = require('thunderboard-ble');
    var tb = new ThunderBoard(config,dataCallback,normalizeData);
 
Also this is the package I was using before that wasn't working:

https://www.npmjs.com/package/node-thunderboard-react#Quick-Start

Its good to finally find someone else who is actually working on thunderboard/Rpi connection. I was at a silabs workshop the other day for the thunderboard but nothing to do with this!

Posts: 4
Registered: ‎02-08-2017

Re: New Open-Source thunderboard-ble Node.js Library Available for Feedback

You can use either...the React is more "complete".  For example, the React had the ambient-light characteristic under its own service, but in the Sense ... it is under the environment service. Its those nuances and new services I have not had a chance to fully vet / map. I've been walking through the gat db for Sense and trying to finish mapping it to the spec structure for the Sense so it is fully available via the config.  Any sensor that is on the React and Sense in the same location should work fine.

 

Hoping to get more cycles on this after our event is over in early May.

See: https://community.jivesoftware.com/groups/jiveworld17/blog/2017/03/30/on-your-mark-get-set-lets-derb...

 

Let me know what you see ... will do my best to offer guidance when/where possible =)

Posts: 26
Registered: ‎12-06-2016

Re: New Open-Source thunderboard-ble Node.js Library Available for Feedback

Using the sense I don't get anything. I get no connection I have shown you the output and a hci dump in the file attached. 
I set enabled to true. Then I got a very weird connection with lots of errors. In the other file.


Interestingly with the nodejs package I was using before the hci dumps would be like 200 lines long for a no connection and If I got a connection for environment  data like yours is it would be like 500 lines long with all manner of read requests, handle notifies , scan enables, meta events ect.



Posts: 26
Registered: ‎12-06-2016

Re: New Open-Source thunderboard-ble Node.js Library Available for Feedback

Oh i guess that warning is just the sense being weird?
The data does seem to be there. But the hcidump is still strange to me

Posts: 26
Registered: ‎12-06-2016

Re: New Open-Source thunderboard-ble Node.js Library Available for Feedback

I set up the config as:

var config = {
"000b5751af26" : {
"uuid" : "000b5751af26",
"enabled" : true,
"family" : "thunderboard",
"type" : "sense",
"autoconnect" : true,
"readIntervals" : {
"acceleration-orientation" : {
"acceleration" : 15000,
"orientation" : 15000,
"control-point" : 15000
}
},
"services" : {
"acceleration-orientation" : ["acceleration","orientation","control-point"],
}
}
};

But I get this message for sense: What is wrong?

 

 

pi@raspberrypi:~/code/ThunderBoard $ sudo node ExampleBLE.js
BLE Auto-Start ... poweredOn
*** Auto-Connecting to Thunderboard 000b5751af26
*** Connected to Device 000b5751af26
Found [1] Services for 000b5751af26
Found Characteristic null[c4c1f6e24be511e5885dfeff819cdc9f] for service a4e649f44be511e5885dfeff819cdc9f
Setting up polling intervals for 000b5751af26 acceleration-orientation acceleration
Found Characteristic null[b7c4b694bee345ddba9ff3b5e994f49a] for service a4e649f44be511e5885dfeff819cdc9f
Setting up polling intervals for 000b5751af26 acceleration-orientation orientation
Found Characteristic null[71e30b8c41314703b0a0b0bbba75856b] for service a4e649f44be511e5885dfeff819cdc9f
Setting up polling intervals for 000b5751af26 acceleration-orientation control-point
buffer.js:825
throw new RangeError('Index out of range');
^

RangeError: Index out of range
at checkOffset (buffer.js:825:11)
at Buffer.readInt16BE (buffer.js:969:5)
at meta.CharacteristicDataParsers.(anonymous function) (/home/pi/node_modules/thunderboard-ble/lib/ThunderboardMeta.js:173:18)
at characteristicListener (/home/pi/node_modules/thunderboard-ble/lib/Thunderboard.js:213:11)
at Characteristic.<anonymous> (/home/pi/node_modules/thunderboard-ble/lib/Thunderboard.js:149:63)
at emitTwo (events.js:106:13)
at Characteristic.emit (events.js:191:7)
at Noble.onRead (/home/pi/node_modules/noble/lib/noble.js:278:22)
at emitMany (events.js:127:13)
at NobleBindings.emit (events.js:201:7)

Posts: 1
Registered: ‎06-23-2017

Re: New Open-Source thunderboard-ble Node.js Library Available for Feedback

Thank you for this lib Ryan.

I'm doing a project from college and it is helping me a lot.

Here is a example using your lib to read only temperature:

https://goo.gl/NjjxP2

Some tips that helped me:

- Make sure you change the uuid with the mac.

- type: sense

- enabled: true

- services: I'm using only temperature for now so I let only temperature on services.