Cold Chain Monitoring With Streamr, Ruuvi, And Ethereum

Cold Chain Monitoring With Streamr, Ruuvi, And Ethereum

In November, we had the pleasure to demo at Slush, Europe’s biggest startup event. We had a very productive time there, with one of the highlights being our meeting with the brilliant guys from Ruuvi. This Finnish company has developed very impressive Bluetooth sensors called RuuviTags. They measure temperature, air pressure, acceleration and humidity, run on a single battery for 3 years, and three devices cost just €69. What’s even more awesome is that both the software and the hardware are open source — a perfect match for the decentralised trustless technology we’re busy building at Streamr.

Once we got back from Slush, we immediately installed a few RuuviTags for demo purposes around our Zug office. The data is freely available on Streamr for prototyping IoT stuff. Search for these stream names in the Editor to add them to your canvas:

  • RuuviDemo Zug Fridge
  • RuuviDemo Zug Freezer
  • RuuviDemo Zug Room 331
  • RuuviDemo Zug Meeting Room
Cold Chain Monitoring With Streamr, Ruuvi, And Ethereum

Using the historical run mode in our Editor, it’s easy to inspect what a few days of data (in this case fridge temperature) looks like:

Cold Chain Monitoring With Streamr, Ruuvi, And Ethereum

The Streamr Engine makes it easy to refine the data and connect results to Ethereum smart contracts in real-time. To illustrate this, we implemented a little cold chain insurance example.

Millions of tons of frozen foods are transported around the world everyday. So ensuring that foods remain frozen whilst in transit is really important for the end consumer. No one wants to buy defrosted then refrozen ice cream and restaurants don’t want to be cooking meat infested with bacteria. So in our scenario, a “courier” places a stake in ETH into a smart contract. If the measured temperature exceeds an agreed threshold (in the demo, 10°C), a penalty is subtracted from the stake and sent to the “beneficiary”.

In this simple demo, the Streamr Engine calculates a one-hour rolling average temperature and reports it (once every hour) to the smart contract. This demonstrates how the Streamr Engine can be used to easily build data processing oracles, reporting the calculation results to smart contracts.

We believe this is a really great (though small scale) example of machine-to-machine verification and payment.

Below you can see the live canvas, embedded onto this blog. You can also open it in the Editor.

Of course we didn’t stop there. We figured if we were going so crazy about RuuviTags, then other people must be too. So now, to make it really easy to connect data from the sensors to Streamr, we’ve created a little library called ruuvi-streamr for node.js. It acts as the glue between the Bluetooth tags and Streamr, allowing you to connect the data. All you need to do is give names to your tags. The library will take care of the rest, including creating the streams and producing data to them. This snippet powers the above demo streams using the library:

// Require the libraryconst RuuviStreamr = require('ruuvi-streamr')// Insert your Streamr api key here. You can create one in Settings -> Profileconst apiKey = 'MY-API-KEY'// Define your tags here. A stream with the tag name will be created, if it does not exist.// Data from each tag will be produced to its respective stream.const tags = {	'4457e1eccefc425fa577669c62cbb733': {		name: 'RuuviDemo Zug Fridge',		description: 'Streamr office fridge in Zug'	},	'8955c5f3cd3046e29c3cd2293f1dcbbe': {		name: 'RuuviDemo Zug Freezer',		description: 'Streamr office freezer in Zug'	},	'6d2b59ffdcc84a759319de9cc3f4086a': {		name: 'RuuviDemo Zug Meeting Room',		description: 'Streamr office meeting room in Zug'	},	'6ef4bc7d2253474bb19d05769cb7ea76': {		name: 'RuuviDemo Zug Office',		description: 'Streamr office in Zug'	}}// Start!let rs = new RuuviStreamr(apiKey, tags) Tech warning: nerdy stuff aheadWe used a Raspberry Pi 3 Model B to act as a gateway between the RuuviTags and Streamr. This computer approximately the size of a credit card features built-in Bluetooth Low Energy (BLE) and Wi-Fi, which makes it easy to connect to the sensors as well as to the internet. In the ruuvi-streamr README you will find tips on how to set up the RasPi3.Notice that the smart contract has also been deployed from the Editor using SolidityModule. You can find the smart contract source code by clicking the “Edit Code” button on the module.To create a Streamr API key and to configure Ethereum accounts to be used by the Streamr Engine, visit your user settings.If you have any questions about how to make the most of Ruuvi and Streamr, drop them in the comments below, or post them in our Reddit FAQ, and we’ll try to answer them as soon as possible. We look forward to hearing from you.

Stay up to date

Get the latest Streamr news and articles delivered to your inbox