Selling your environment data with RuuviTags, Streamr and Raspberry Pi [Tutorial]

Downgii
6 min readMay 29, 2018

--

In this tutorial I want to show you how to stream your environmental data, recorded by a RuuviTag to the Streamr marketplace via a Raspberry Pi 3B and sell it.

There already is a small tutorial made by the Streamr team, but it is not very beginner friendly: https://github.com/streamr-dev/ruuvi-streamr

Here is an overview of what you will need:

Step 1: Getting a Streamr API key

You will have to make a Streamr account, to use the Streamr Editor and to sell your data on the Streamr data marketplace. For that go to https://www.streamr.com/ and click on “Sign up” in the top right corner and follow the instructions.

Streamr profile.

When you are finished, navigate to “Profile” and generate an API key by assigning a name and clicking the “+” sign or just use the default.

And that’s already it for this part. Easy, right?

Step 2.1: Setting up the Raspberry Pi

The first thing you’ll have to do is flashing the Raspbian operating system onto the SD card. To do that, you have to insert it into your Laptop or computer.

If you are using an old SD card, please install Formatter 4 and format your SD card.

There is an easy tutorial on how to install the operating system at raspberrypi.org. Follow it and come back after that.

Stick the SD card into your Raspi, connect keyboard, mouse and monitor. It will boot up as soon as you give it power.

Click on the raspberry (the fruit icon) in the top left corner, go to Preferences > Raspberry Pi Configuration > Localisation. There you can change language etc. If you want to connect via Wifi, you have to set the Wifi Country aswell. You can also set the keyboard layout (recommended).
Connect to the internet via Wifi or a different method now.

Open up the terminal. You can find it at the top left in the task bar. Run this command (especially, if you are using an already in use Raspberry):

sudo apt-get update && sudo apt-get upgrade

To run the programm, you will have to install Nodejs and NPM. That is done via

curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs

After that you should check if

node -v && sudo node -v

return the same version (it should be version 9.x, even though 10.x is the newest atm).

After that you can install the ruuvi-streamr library via

npm install ruuvi-streamr --save

and switch into the ruuvi-streamr folder:

cd node_modules/ruuvi-streamr

To be able to listen to Bluetooth as a non-root user, use the following commands:

sudo apt-get install libcap2-bin
sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)

For that, replace`which node` with the .js file name (f.e. example.js ).

To run the program, use

sudo node example.js

You will see something like this:

Listening for RuuviTags... 
Found tag: d2d41c4c3c1d
Warning: Ignoring tag d2d41c4c3c1d because it is not defined in the "tags" argument to RuuviStreamr(apiKey, tags): {
"dataFormat": 3,
"rssi": -49,
"humidity": 52,
"temperature": 29.47,
"pressure": 101205,
"accelerationX": 4,
"accelerationY": -28,
"accelerationZ": 1024,
"battery": 2977
}

Now copy the tag in the second line and open the file “example.js” in the “ruuvi-streamr” folder (which is found in the “node_modules” folder). Go to

const tags = { 
'4457e1eccefc425fa577669c62cbb733': {
name: 'RuuviDemo Zug Fridge',
description: 'Streamr office fridge in Zug'
}

and replace the existing tag with your tag. You can also edit “name” and “description”. Do that for all the RuuviTags you want to connect and delete the tags you don’t need.

A few lines up you can see

const apiKey = 'MY-API-KEY'

Here you have to insert your API key, which you generated in Step 1 of this tutorial. After that you can save and run the file again as before. You should see something like:

Listening for RuuviTags... 
Found tag: d2d41c4c3c1d (Ruuvi 1)
Found tag: e5bea69a5d65 (Ruuvi 2)
Created stream: Ruuvi 1 (WtomzCu6QneGX9Gf8XCjig)
Created stream: Ruuvi 2 (dBcAqFQPSd-trZbFW8aJmQ)

When you initially run the program, the streams will be created for you (next time you won’t see this output, because they already exist).

Step 2.2 (optional): Run automatically on boot

I’d recommend making the program auto-run on boot. You will only have to plug your Raspberry Pi into some power source and it will automatically connect to the RuuviTags and stream the data. You won’t need a monitor, mouse or keyboard anymore! :)

To do this, open a new unit file using

cd ~ #this is only used to switch to home folder
sudo nano /lib/systemd/system/example.service

Add in the following text:

 [Unit] 
Description=Example Ruuvi-Streamr Service
After=multi-user.target
[Service]
Type=idle
ExecStart=/usr/bin/node /home/pi/node_modules/ruuvi-streamr/example.js > /home/pi/node_modules/ruuvi-streamr/example.log 2>&1
Restart=always
[Install]
WantedBy=multi-user.target

Make sure that the paths are correct. To find out where node is installed, type in

which node

and it will tell you the right path.

Now save and exit the nano editor. The permission on the unit file needs to be set to 644 :

sudo chmod 644 /lib/systemd/system/example.service

Use the following commands to tell the system to start the unit file during boot:

sudo systemctl daemon-reload
sudo systemctl enable example.service

Now you can reboot the Raspberry Pi and it will automatically run your program. You will be able to see that it is actually running, when doing the next steps.

Step 3 (optional): Using the Streamr editor

You can now go to https://www.streamr.com/stream/list where you will see something like this:

Streamr stream overview.

You can click on one of the streams to get more info:

Streamr stream detailed info.

If you want to visualize or edit your data, go to the Streamr editor via the top menu or via this link https://www.streamr.com/canvas/editor

I highly recommend doing the “Tours”, which you can find by clicking the “?” at the top right corner. After that you should have a basic understanding of how the Streamr editor works. An easy example would be to visualize your temperature data:

Easy example on how to visualize your data.

Step 4: Sell your data on the Streamr data marketplace

For the last step to get your data on the Streamr data marketplace, go to https://marketplace.streamr.com/

Click on “Create a product”:

Create a product on the Streamr data marketplace.

Here you can name your product, add an image, add a description and set a category. To add your sensor data, click on the “Edit” button, select your Streams and click on “Add”.

To set a price, click on “Edit price”

Setting up the price for your data.

Set your price, set payment address to your ERC-20 token compatible ETH wallet address and click “Finish”.

After everything is set, you can click on “Publish”. You will have to make a small transaction, because of the smart contract, unless you put your data for free.

And that’s it! Now everybody can buy your environment data on the Streamr data marketplace.

I hope I could help you with this tutorial! Please leave feedback, suggestions and questions in the comments below :)

Recommended links:

--

--