Node-Red – Ti SensorTag Node

Last weekend I spent some time working on yet another Node-Red node. This one is an input node that reads the data published by a small sensor platorm from Ti.

The Ti SensorTag is a Bluetooth 4.0 LE platform designed to be a test source for building new BLE and is very accessible at only $25 dollars especially with the following list of sensors on board:

  • Ambient Temperature
  • IR remote Temperature
  • Air Pressure
  • Humidity
  • Accelerometer
  • Magnetometer
  • Gyroscope
  • 2 Push Buttons

Ti have also set up a open wiki to allow people to document they experiments with the device.

You can find the node in the new node-red-nodes repo on github here it relies on a slightly updated version of Sandeep Mistry‘s node-sensortag, the read me explains how to install my update (until I get round to submitting the pull request) but here is the command to run in the root of your Node-Red directory:

npm install sensortag@

(you may need to install the libbluetooth-dev package for Debian/Ubuntu based distros and bluez-libs-devel on Redhat/Fedora first)

Sandeep has now merged my changes so the sensortag node can now be installed normally with npm with:

npm install sensortag

Once installed you need to run Node-RED as root as this is the only way to get access to the BLE functions, then you can add the node to the canvas and configure which sensors are pushed as events

Please feel free to have a play and let me know what you think

40 thoughts on “Node-Red – Ti SensorTag Node”

  1. Was in /home/pi
    $ npm install sensortag@
    npm http GET
    npm http 200
    npm http GET
    npm http 200
    npm http GET
    npm http 200
    npm http GET
    npm http 304

    > noble@0.2.2 install /home/pi/node_modules/sensortag/node_modules/noble
    > node install.js

    noble install: platform is “linux’
    noble install: running node-gyp …
    noble install: done
    npm ERR! weird error 255
    npm ERR! not ok code 0

    Q1 : where do you look up for any errors to debug the above ?

    Q2 : Should I have been in /home/pi/nred0.3/node-red-0.3.0 and run the npm command instead ?

    Q3 : Should I see some nodes in the palette appearing or not ? if yes then under which category should it be under ?

  2. Stefan

    A1: There should be log written somewhere (I’ll try and find out where for next time), but I can guess the problem. You need to install the bluetooth dev libraries (IIRC – apt-get install libbluetooth-dev)

    A2: Yes, you need to do the install from the root directory of Node-Red so the it ends up in the node_modules directory

    A3: The node won’t show up in the pallet unless all the deps are met

  3. 17th Nov 2013
    Is the Sensor node still available ?

    cd /home/pi/nred/node-red-0.4.0
    $ sudo apt-get install libbluetooth-dev
    $ sudo npm install sensortag@

    npm http GET
    npm http 404
    npm ERR! fetch failed
    npm ERR! Error: 404 Not Found
    npm ERR! at WriteStream. (/usr/local/lib/node_modules/npm/lib/uti
    npm ERR! at WriteStream.EventEmitter.emit (events.js:117:20)
    npm ERR! at fs.js:1596:14
    npm ERR! at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/gracefu
    npm ERR! at Object.oncomplete (fs.js:107:15)
    npm ERR! If you need help, you may report this log at:
    npm ERR!
    npm ERR! or email it to:
    npm ERR!

    npm ERR! System Linux 3.6.11+
    npm ERR! command “/usr/local/bin/node” “/usr/local/bin/npm” “install” “sensortag
    npm ERR! cwd /home/pi/nred/node-red-0.4.0
    npm ERR! node -v v0.10.22
    npm ERR! npm -v 1.3.14
    npm ERR!
    npm ERR! Additional logging details can be found in:
    npm ERR! /home/pi/nred/node-red-0.4.0/npm-debug.log
    npm ERR! not ok code 0
    pi@raspberrypi ~/nred/node-red-0.4.0 $

  4. @Stefan, looks like you missed an “l” off the end of the command when you copy and pasted it. it should end “tarball”

  5. Thanks for spotting I had a missing l at the end of the command !!! Your original npm install line needs an update – not sure how I had the “l” first time round !!

  6. Hey Ben, very nice work?

    May I ask you if you tested this with more than a device?
    If so can I ask you how many devices you managed to have paired at the same time?

    1. I’ve only tested with one device at a time, but in theory it should work if you add 2 nodes to the flow and set the id on each one

  7. Hi Ben.
    Just getting into Node-RED. Loving it.
    Have set up a core to upload some temperature, light and movement, but this TI tag looks fantastic…..
    Im just not sure how I would link it to my Ubuntu 12.04 desktop that is running Node-RED?
    Get a USB BLE adapter?
    How would I link to it in Node-RED?


    1. Hi,

      Yep, pretty much any Bluetooth 4.0 dongle should work, I got one of these from Amazon.

      To use it with Node-Red you just need to add the code for the node mentioned here to your nodes directory. The simplest way is to just checkout the node-red-nodes project into your nodes directory.

      The only think to be careful of is that you have to run Node-Red as root as the BLE support on linux currently only works as root.

  8. Hi Ben,

    My sensors are in the mail, so thought I would install the node…..

    Cant for the life of me figure out this string of errors from the install.

    Thanks for your time and input.

    $sudo npm install sensortag
    npm WARN package.json eyes@0.1.8 No repository field.
    npm WARN package.json growl@1.7.0 No repository field.
    npm WARN package.json wemo@0.0.2 No repository field.
    npm http GET
    npm http 304
    npm http GET
    npm http 304
    npm http GET
    npm http 304

    > noble@0.2.8 install /var/www/nodered/node-red-0.5.0/node_modules/sensortag/node_modules/noble
    > node install.js

    noble install: platform is “linux’
    noble install: running node-gyp …
    make: Entering directory `/var/www/nodered/node-red-0.5.0/node_modules/sensortag/node_modules/noble/build’
    CC(target) Release/
    ../src/hci-ble.c: In function ‘main’:
    ../src/hci-ble.c:40: error: ‘evt_le_meta_event’ undeclared (first use in this function)
    ../src/hci-ble.c:40: error: (Each undeclared identifier is reported only once
    ../src/hci-ble.c:40: error: for each function it appears in.)
    ../src/hci-ble.c:40: error: ‘leMetaEvent’ undeclared (first use in this function)
    ../src/hci-ble.c:41: error: ‘le_advertising_info’ undeclared (first use in this function)
    ../src/hci-ble.c:41: error: ‘leAdvertisingInfo’ undeclared (first use in this function)
    ../src/hci-ble.c:91: error: ‘EVT_LE_META_EVENT’ undeclared (first use in this function)
    ../src/hci-ble.c:110: warning: implicit declaration of function ‘hci_le_set_scan_parameters’
    ../src/hci-ble.c:135: warning: implicit declaration of function ‘hci_le_set_scan_enable’
    ../src/hci-ble.c:152: error: expected expression before ‘)’ token
    ../src/hci-ble.c:164: error: expected expression before ‘)’ token
    ../src/hci-ble.c:167: error: ‘LE_PUBLIC_ADDRESS’ undeclared (first use in this function)
    make: *** [Release/] Error 1
    make: Leaving directory `/var/www/nodered/node-red-0.5.0/node_modules/sensortag/node_modules/noble/build’
    gyp ERR! build error
    gyp ERR! stack Error: `make` failed with exit code: 2
    gyp ERR! stack at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
    gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
    gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:12)
    gyp ERR! System Linux 2.6.32-51-generic-pae
    gyp ERR! command “node” “/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” “configure” “build”
    gyp ERR! cwd /var/www/nodered/node-red-0.5.0/node_modules/sensortag/node_modules/noble
    gyp ERR! node -v v0.10.25
    gyp ERR! node-gyp -v v0.12.2
    gyp ERR! not ok
    noble install: done
    npm ERR! noble@0.2.8 install: `node install.js`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the noble@0.2.8 install script.
    npm ERR! This is most likely a problem with the noble package,
    npm ERR! not with npm itself.
    npm ERR! Tell the author that this fails on your system:
    npm ERR! node install.js
    npm ERR! You can get their info via:
    npm ERR! npm owner ls noble
    npm ERR! There is likely additional logging output above.

    npm ERR! System Linux 2.6.32-51-generic-pae
    npm ERR! command “/usr/bin/node” “/usr/bin/npm” “install” “sensortag”
    npm ERR! cwd /var/www/nodered/node-red-0.5.0
    npm ERR! node -v v0.10.25
    npm ERR! npm -v 1.3.24
    npm ERR! code ELIFECYCLE
    npm ERR!
    npm ERR! Additional logging details can be found in:
    npm ERR! /var/www/nodered/node-red-0.5.0/npm-debug.log
    npm ERR! not ok code 0

    1. All the missing symbols are in the bluetooth/hci.h on my machine (Fedora 19 [and on my rasbian rPi]) so I can only assume the version of the bluez bluetooth stack you have available isn’t Bluetooth 4.0 enabled

  9. Yep. You’re spot on.
    I was running on 10.04 and upgraded to 12.04 and the sensortag npm installed as expected…..
    Just waiting for the two tags to arrive now….

    Thanks for your help.

  10. Update. Google tells me that the ‘mac’ address is the UUID. I see the mac address in my Android TI app.

    Putting this into the sensortag Node and then connecting it to a debug node shows no data.
    There are no errors anywhere from Node-RED.

    Will keep digging. (Sure is a drag having to keep hitting the connect button to test the tag).

    1. Leave the UUID/mac blank. You only need it if you have more than one tag and want to differentiate between them

  11. I seem to be stuck (really grateful for your input).
    Tried a lot of different combinations, just can’t get anything to come out of the Sensortag Node (Android and iOS apps work fine, so I know the tag itself is ok).

    Im wondering if Ubuntu has ‘turned on’ the USB dongle when I plugged it in? (aka, mounted the device).

    Did you do any command line foo before hand to get the BLE USB working?


  12. no, you shouldn’t need to do anything to enable it.

    The only thing I can think of off the top of my head is if you have more than one Bluetooth adapter? If you have a built in one and the new USB adapter you may want to ensure that the your using the new one.

    Also just a reminder that you really have to run Node-Red as root else it won’t work.

  13. Hi Ben,

    Great little NodeRED plugin!

    Just as a heads up, this doesn’t appear to work with multiple devices; I’ve added two sensor tag nodes to a flow, specifically stating the UUID’s of each tag, but it only ever seems to pick up on information from the first tag that was paired – I never get any published topics back from my second tag in the flow.

    It seems that one of the node entries interferes with the other (if I set a different topic on the second one, events still trigger for the first one with the topic I’d set on the second one)

    Here’s the exported flow, notice it only seems to contain one node? There’s actually two in my flowchart!


    To reproduce:

    1. Add two sensorTag nodes, plus two debug nodes that are connected to them.
    2. Set different topics and UUID’s on them both
    3. Use something like key change detection
    4. Deploy
    5. Press keys on sensor tag one and sensor tag two, note it seems to respond to only a key press on one of the sensor tags.


  14. Update:

    Sometimes on startup I also get this stack trace:

    23 Feb 16:58:06 – TypeError: Cannot call method ‘notify’ of undefined
    at SensorTag.notifyCharacteristic (/home/pi/node-red/node_modules/sensortag/index.js:152:18)
    at SensorTag.unnotifyIrTemperature (/home/pi/node-red/node_modules/sensortag/index.js:275:8)
    at enable (/home/pi/node-red/nodes/node-red-nodes/hardware/sensorTag/79-sensorTag.js:111:24)
    at /home/pi/node-red/nodes/node-red-nodes/hardware/sensorTag/79-sensorTag.js:97:17
    at SensorTag. (/home/pi/node-red/node_modules/sensortag/index.js:129:5)
    at Peripheral. (/home/pi/node-red/node_modules/sensortag/node_modules/noble/lib/peripheral.js:87:13)
    at Service. (/home/pi/node-red/node_modules/sensortag/node_modules/noble/lib/service.js:53:7)
    at Service.g (events.js:175:14)
    at Service.EventEmitter.emit (events.js:95:17)
    at Noble.onCharacteristicsDiscover (/home/pi/node-red/node_modules/sensortag/node_modules/noble/lib/noble.js:243:13)

    Looking into this in further detail, and adding in some console.logs just after you declare your “stag” object, this is what I see:

    Attempting to discover **********ae (added to the node_modules/sensortag/index.js:discover() function)
    Attempting to discover **********a8 (added to the node_modules/sensortag/index.js:discover() function)
    Discovered **********ae (added to the node_modules/sensortag/index.js:onDiscover() function)
    Discovered **********a8 (added to the node_modules/sensortag/index.js:onDiscover() function)
    connected to {“uuid”:”**********a8″} (added to the return from discover() in 79-sensorTag.js)
    connected to {“uuid”:”**********a8″} (added to the return from discover() in 79-sensorTag.js)

    So it seems that for some reason, we attempt to connect to the same UUID twice, or there is a double-callback coming from the sensorTag module. This causes the stack trace above upon a change and I imagine is why multiple devices don’t currently work!

    1. Hi sean, I was wondering if you were able to find a way to make two sensortags work. I run into the same problem, it seems like the same sensortag is registered twice.

    2. Hi Sean

      Thanks for your comments!

      Did you manage to collect data from two sensortags at the same time? I am struggling with it!


  15. Thanks for the tip Ben, it once again got me closer to getting it working.

    Looking to see if I had just the one BTLE device…..
    Doing a ‘lsusb’ shows that the device is there and its the only one. ‘dmesg’ is the key, it showed that the firmware was not loaded.
    Googling around brings up the following patch to get the USB working;

    $ git clone git://
    $ cd hex2hcd
    $ make
    $ ./hex2hcd BCM20702A1_001.002.014.0889.0896.hex fw-0a5c_21e8.hcd
    $ sudo cp fw-0a5c_21e8.hcd /lib/firmware/

    (I got the hex file from the WinXP drivers).

    So now its all loaded and working under Ubuntu, but still nothing from the SensorTag Node.
    It is still like there is some step I am missing to turn on the Sensortag NODE.
    For example, when I press the button the side of the tag, the green LED starts to flash, when I connect to it with my Android, the LED stops flashing and I get data in the app.
    When I put the Tag near the PC, the LED just keeps flashing till it times out.

    No matter what I do in Node-RED, I just cant get it to connect to the Sensortag. (Im going straight from the Sensortag to a Debug Node).

  16. Ben,

    Node-Red will only do the bind to the tag as it starts up (or the first time you hit deploy after adding a SensorTag node to the canvas) so need to push the button then start node-red, if you push the button again it will disconnect and not reconnect.

    This is an unfortunate side effect of the firmware on the tag. At some point I need to have a look at modifying the firmware to make it drop back to discoverable after something disconnects.

  17. I feel a little silly, but also very stumped.

    I have been at it now for around 4-5 hours…. Even went and brought a new USB adapter……

    Then I found that each time I ‘sudo node red.js’, there was an error scrolling off the top of my Putty screen;
    [79-sensorTag.js] Error: Cannot find module ‘sensorTag’

    For hours now I have been trying everything I can think of and every Google result… I just can not get the node.js module installed in such a way that the error does not show (and then I’m assuming that the Node will work).

    I don’t want to give up, but wow, this is so much harder than I was expecting……

  18. Try this:

    Assuming you have node-red in your home dir and you checked the extra nodes out into ~/node-red/nodes.

    cd ~/node-red
    npm install sensorTag

    That should install the required modules into ~/node-red/node_modules

  19. Hi Ben,

    Thanks very much for your persistance and patience.

    I had been doing that command, with no joy.
    The interesting thing is that the file structure of the sensortag is very different from say the Wemo and other hardware devices.
    For example, the Wemo node.js ‘driver’ is called wemo.js, but the sensortag ‘driver’ is called index.js
    Also, they are in very different paths/locations.

    Bottom line. I gave up.

    Blew everything away and did a fresh install of 0.6.0

    The sensortag Node shows up in Node-RED web GUI, I add it, add my debug, deploy and straight away get a ‘undefined’ error in the console.

    Doing a command line search for any sensortag.js or .html files shows zero results.
    My guess is thats why its ‘undefined’, the 0.6.0 ‘npm install sensortag’ does not bring in any files.

    Im very mindful of your time Ben, so I am going to post this latest issue over on the Node-RED Google groups.
    A clean install should not have these sorts of issues.

    Will report back once we have it all working.

    Thanks again for all your assistance.


    1. I’ve just done a full fresh build with 0.6.0 and the head stream of the nodes repository and it’s all working fine this end (on Fedora 19)

      cd node-red-0.6.0/nodes
      cd ..
      npm install
      npm install sensortag
      sudo node red
      drag sensortag on to canvas
      drag debug node on to canvas
      link the 2 nodes
      press button on side of tag
      hit deploy
      wait the 10 ish second for the tag to bind and subscribe to feed

  20. Hi Ben,

    Thanks for the sanity check.

    I will keep digging at this end.
    As I said, I have tried two different USB adaptors and I have two sensortags, no combination will get things to work, and Ubuntu does not throw any errors in any logs that I can find.


  21. Hi Ben.

    Well, I have no idea why it took me so long to find the problem…..

    apt-get install bluez

    Away it went.

    It seems to be polling it very aggressively.
    Many times a second!
    Not sure how long the battery will last with multiple polls per second.

    Also the output is a little odd, I get ‘object and ambient’ and ‘temp and humidity’ readings.
    I just have temperature, humidity and pressure selected in the Node. 3 checks, but 4 values coming back…..

    The odd thing is that object, ambient and temp are all different values. (I get that the IR and ambient will be different, but what’s the difference between ambient and temp?)

    Do you have a feel for the battery life yet?

    Wow, so many questions, so exciting to get it working!
    Now to order more and get some range testing done….

    Thanks again for all your help.


  22. To sum up the process;

    Im using Ubuntu Server 12.04 LTS, Kernel 3.8.0
    Node-RED 0.6.0

    apt-get instal libbluetooth-dev bluez

    Plug your BTLE USB dongle into your Linux PC.
    Check it with ‘lsusb’ and ‘dmesg’ to make sure that the device has loaded Ok.
    (One of the USB dongles I got did not load the firmware (the listing on said it was Linux compatiable, its not, well, at least not out of the box. I needed to compile and load a new driver for it on my Ubuntu 12.04 LTS)

    Next install the TI SensorTag app on a compatible Android or iOS device.
    Run the app and bind to the device.
    Make a note of the UUID of the device.
    Have a little play with the device in the app, its pretty cool.

    Then sudo node red.js
    (You need to run as sudo to get the BTLE drivers to work).

    Add the sensortag Node. (I also added a debug Node so I could see the output).
    Put the UUID of the device in the sensortag Node (it will not work with it blank).

    Press the bind button the side of the tag. Then hit deploy in Node-RED
    (Note, you have to do it this way, Node-RED only binds with the device when it is started or deployed).

    You should be up and running with a stream of data in the debug tab.


    1. You shouldn’t need the UUID, it’s only there if you have more than one SensorTag in range (and discoverable) at the same time. It works fine this end with that field empty

  23. My bad.
    Your right. You dont need to have a UUID in there, it can be blank for one SensorTag.
    My USB BLE adaptor was playing up.

    I’m still concerned with the battery life of the sensortag with the aggressive poll rate.
    Have poked around in the code a little, but cant find anything obvious to scale back.

    Do you have any battery life expectations or data?

  24. Hi,

    I am completely new to node.js. node-red, but I’ve been following instructions and install everything without errors.
    When I start red, sensortag is not mentioned. Here is my log:

    # sudo node red.js

    1 Apr 20:18:04 – [red] Server now running at

    Welcome to Node-RED

    1 Apr 20:18:04 – [red] Loading palette nodes
    1 Apr 20:18:04 – ——————————————
    1 Apr 20:18:06 – [73-parsexml.js] Note: Module ‘eyes’ not installed. (not needed, but useful)
    1 Apr 20:18:06 – [74-js2xml.js] Error: Cannot find module ‘js2xmlparser’
    1 Apr 20:18:08 – [35-rpi-gpio-in.js] Error: Cannot find module ‘pi-gpio’
    1 Apr 20:18:08 – [35-rpi-gpio-out.js] Error: Cannot find module ‘pi-gpio’
    1 Apr 20:18:08 – [35-arduino.js] Error: Cannot find module ‘firmata’
    1 Apr 20:18:12 – [23-watch.js] Error: Cannot find module ‘fs.notify’
    1 Apr 20:18:12 – [25-serial.js] Error: Cannot find module ‘serialport’
    1 Apr 20:18:13 – [32-feedparse.js] Error: Cannot find module ‘feedparser’
    1 Apr 20:18:13 – [61-email.js] Error: Cannot find module ‘nodemailer’
    1 Apr 20:18:13 – [61-imap.js] Error: Cannot find module ‘imap’
    1 Apr 20:18:13 – [65-redisout.js] Error: Cannot find module ‘redis’
    1 Apr 20:18:13 – [66-mongodb.js] Error: Cannot find module ‘mongodb’
    1 Apr 20:18:14 –
    1 Apr 20:18:14 – You may ignore any errors above here if they are for
    1 Apr 20:18:14 – nodes you are not using. The nodes indicated will not
    1 Apr 20:18:14 – be available in the main palette until any missing
    1 Apr 20:18:14 – modules are installed, typically by running:
    1 Apr 20:18:14 – npm install {the module name}
    1 Apr 20:18:14 – or any other errors are resolved
    1 Apr 20:18:14 – ——————————————
    1 Apr 20:18:14 – [red] Flows file not found : flows_pi.json

    I also don’t see sensortag in UI.

    1. How did you install Node-Red and the extra nodes (node-red-nodes)? Did you zip both packages or check them out from git?

      You need to unzip or extract the node-red-nodes into node-red/nodes/ directory.

  25. hey guys, can sensorTag be used to log sensor data to its memory to be downloaded later. e.g. log temperature every 10 minutes for 2 weeks and then download it by a bluetooth enabled phone? how much free memory it has?

    1. I think you would have to push your own firmware to get it to do that and I’m not sure how much (if any) RAM would be available to store the values. You will probably do better looking at the wiki and seeing if there is a mailing list.

  26. Is anyone having issues with the range of the sensor tag? When the tag is connected to my iPhone the range is very far. Using the software my range is down to about 20 feet. I thought that it was my USB BLE adapter so I purchased a Plugable 4.0 that is certified as BLE and I have the same issue. The BLE is acting as regular Bluetooth instead.

    Thanks to anyone who replies.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.