Connecting IoT with Blockchain II

Connecting IoT with Blockchain II

In the second part of a two-part blog series, Sam Davies, Lead Technologist for Creative Programmes at Digital Catapult, blogs about how he created an IoT blockchain using two Raspberry Pis and an AWS instance.

Since our previous blog on this topic we have now built our IoT blockchain prototype. Our prototype consists of two Raspberry Pis (a Pi2 and Pi3), along with a micro AWS instance. By attaching a light sensor to the Raspberry Pi3 (our Sensor Pi), we were able to create a light sensing system.

Using Python and Node.js we created a simple server, which took a reading from the light sensor twice a second. We used a 20 second sliding window to calculate an average light level along with the standard deviation for this window. If a reading came into the system that was greater or lesser than one standard deviation, we put the whole 20 second data up for sale using a smart contract with the price of the data proportional to the delta between the peak light level and the average.


Sensor Pi recording data for sale, bids for data & sales of data

We connected this sensor Pi to a private Ethereum blockchain and when the server had data for sale, it registered this with a smart contract associated with the sensor. Whenever the smart contract received a notification that there was new data for sale, it created an event and any device, which was listening out for these events, could then attempt to buy this data.


Raspberry Pi with LinkSprite ADC and light sensor

Our two other devices, (our bidder Pi and bidder AWS) were used to bid for this data. Each device was connected to the same blockchain as the sensor Pi and was registered to listen for the sale data events posted by the Sensor Pi smart contract. When these were received, the two bidding devices took the sale price and used an arbitrary bidcoefficient (calculated from a restricted random number limited between 1 and 1.5) to create a bid (if sufficient funds were present, which was submitted to the sensor Pi.) The sensor Pi smart contract had a buying window built into the sale event and any bids received during this bidding window were compared and the highest bidder won.   The winner was then announced and upon receipt of payment, the data was released to the winning device.


Successful purchase of IoT Data

As our sensor Pi was selling data, it did not need to be involved in mining the blocks on the blockchain. However, in order to afford the data both the bidder Pi and bidder AWS needed to mine in order to raise funds for purchasing data. Here we found the bidder Pi was at a distinct disadvantage as they did not possess anywhere near the processing power of the bidder AWS, it very rarely mined any blocks and so had very low funds.

In order to register as a selling device, the Ethereum address of the smart contract needs to publicly be announced along with the ABI, the Application Binary Interface, of the contract. This enables other devices to know where the contract is and what functions are available to interact with. It would be really interesting to see if standards such as HyperCat could be extended to include this information too.

This would allow IoT devices to autonomously find other devices and begin trading data. As we found, low powered devices are easily out-muscled when it comes to mining blocks and so we would be interested in extending this work to include other Sensor Pis in the system. Thus, devices could offer other data instead of cryptocurrencies, as payment. This could easily be extended to allow these devices to trade with any asset that can be digitally represented: power, intellectual property or personal data to name just a few. Extending the idea from our previous blog where we saw the potential to trade energy, we can extend this to trade any digitally trackable asset, energy, home IoT access or data, driving data or simple light data.

You can follow Sam Davies, Lead Technologist for Creative Programmes at Digital Catapult, on Twitter @DigitalCatapult and IoTUK @IoTUKNews.

Sam Davies

Post a Comment

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