Using the TI SensorTag with Samsung’s ARTIK Cloud

2 minute read

Overview:

This is a pretty simple project, made even easier by the excellent node-sensortag library that connects and reads sensor data from the TI SensorTag and posts it to ARTIK Cloud. I’ve made a public device type for the TI SensorTag cc2650 on the Samsung ARTIK Cloud IoT platform. This example code stands to be refactored, but I figured it’d be a good place for people to start to experiment with the TI SensorTag and Samsung ARTIK Cloud.

Installing Node.js and Noble

The key technologies driving this project are Node.js and the noble library. Installing Node.js can be done by downloading the appropriate installer for your platform and installing according to the instructions for your platform. Noble has some additional prerequisites outlined in the Readme, but installations is pretty straightforward.

Finally, download the zip or git clone the sample code to a working directory.

git clone https://github.com/zanycadence/ti_sensordata.git

cd into the directory and run

npm install

to install the dependencies outlined in the package.json file.

Add TI SensorTag to ARTIK Cloud

Sign in to your ARTIK Cloud account and go to the devices page found in My ARTIK Cloud > Devices. Click +Connect Another Device and search for the TI SensorTag cc2650 device to add a SensorTag to your device dashboard. Generate and copy the devices Token and ID by clicking on the gear adjacent to the device you just created.

Add Device ID and Token to Upload Code

At the top of the app.js file you’ll find a section with:

//ARTIK cloud stuff
var bearer = "Bearer INSERT_DEVICE_TOKEN_HERE";
var sdid = "INSERT_DEVICE_ID_HERE";
var artikCloud = "https://api.artik.cloud/v1.1/messages";

Replace INSERT_DEVICE_TOKEN_HERE and INSERT_DEVICE_ID_HERE with the previously generated Device Token and ID. Make sure that the bearer variable starts with “Bearer “ before the Device Token. The post is constructed and made in a function called postData() at the bottom of the file. setTimeout() is used with a delay of 600000ms to comply with ARTIK Clouds rate limits for the free platform. If you wish to upload at a faster/slower rate, simply change this number.

function postData(){
setTimeout(function(){
  sensorTagPost.data.ts = new Date().valueOf();
  c.post(artikCloud, sensorTagPost, function(data, response){
    console.log(data);
  });
  postData();
}, 600000);
};

Run the app.js file

Launch the file with

node app.js

and press the power button on top of the SensorTag. Watch as the notifications for the services are subscribed to and data values are read out and logged to the ARTIK Cloud!