There have already been articles published on the use cases for using IoT with a private Blockchain. The possibilities are really exciting but what if we could run the blockchain ON our IoT network. That sounds like a fun project to me!
With that goal in mind and a bit of research I was led to Hyperledger Fabric. To learn more about it check this out: Hyperledger Overview. Getting Hyperledger Fabric to run on Raspberry Pi presented several major hurdles:
- No one had compiled the project for the ARM architecture before.
- There wasn’t any documentation on how to run the Hyperledger on a Docker Swarm.
But hurdles are what make projects fun right? So lets go through the steps so that you can setup your own.
- Setting up a Hyperledger Fabric development environment on a Raspberry Pi
- Building Hyperledger Fabric on Raspberry Pi
- Setting up a Docker Swarm on Raspberry Pi
- Deploying a Hyperledger Fabric network on the Swarm with Docker Stack and testing with BYFN.
Lets get started!
Setting up a Hyperledger Fabric development environment on a Raspberry Pi
Setup your Raspi
For this project I used Raspbian Lite (who needs a GUI am I right!) . Download and follow the install guide for your OS on raspberrypi.org. I originally did this on Jessie but since Stretch is out I’m testing it with the latest build I’m doing while updating my documentation and this series. So the instructions below apply to Stretch.
Then you’ll need to do some pretty standard initial setup for your RasPi, run raspi-config, change default password, enable SSH, config your keyboard, set the timezone, advanced -> change memory split to 16MB… etc. Once the basic config is done it’s time to get it online. You can use an ethernet cable or follow this guide to setup wifi. Also once you have a network connection established use can use SSH, personally I usually do this so I don’t need to “hand jam” all the commands and can just C&P. You can also copy your private key on your computer to you RasPi so you no longer need a password. When I do this I usually create a new user:
sudo adduser *username*
sudo usermod -aG sudo *username*
After you do the standard stuff I always recommend updating & upgrading:
sudo apt-get update
sudo apt-get dist-upgrade
Setup your development environment
Install the Go programming language:
Hyperledger was built and tested using Go version 1.7.5… so says the documentation (at time of writing – March 9th, 2018). I’ve tried using 1.10, 1.9.4, 1.9.3 and 1.8.7 recently and they all had some issues. Go v1.8.7 build suffer form this issue: https://github.com/golang/go/issues/23739. So I’m going to recommend using Go 1.7.5 since we are targeting a HL v1.0 build. As I learned you need to make sure you target the correct branch for the build you are targeting.
THE VERSION OF GO YOU USE WITH THE BUILD YOU ARE TARGETING IS CRUCIAL.
sudo tar -C /usr/local -xzf go1.7.5.linux-armv6l.tar.gz
sudo echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
sudo echo 'export GOPATH=$HOME/go' >> ~/.profile
curl -sSL https://get.docker.com | sh
Install Docker Compose
curl -s https://packagecloud.io/install/repositories/Hypriot/Schatzkiste/script.deb.sh | sudo bash
Install Required Libraries
sudo apt-get install git python-pip python-dev docker-compose build-essential libtool libltdl-dev libssl-dev libevent-dev libffi-dev
Install Python Libraries
sudo pip install --upgrade pip
sudo pip install --upgrade setuptools
sudo pip install behave nose docker-compose
sudo pip install -I flask==0.10.1 python-dateutil==2.2 pytz==2014.3 pyyaml==3.10 couchdb==1.0 flask-cors==2.0.1 requests==2.4.3 pyOpenSSL==16.2.0 pysha3==1.0b1 grpcio==1.0.4
Reboot & Test
Make sure you actually reboot or re-login to your RasPi otherwise you’ll get nothing from the go version or path (since they were added to your bash profile).
(should be something like /home/user/go)
All of the above commands should output the version or the required software. If they do no you missed something.
If you are getting any errors while installing any libraries please reference the current documentation for Hyperledger.
Anyway… now that we have our development environment setup it’s time to start the build. Check out my next article for the details on this next step.