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 let 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
- Running the End-to-End “Build you First Network” scenario to validate our build.
Lets get started!
Setting up a Hyperledger Fabric development environment on a Raspberry Pi
Setup your Raspi
For this project I used Raspbian Jessie Lite (who needs a GUI am I right!) . Download and follow the install guide for your OS on raspberrypi.org.
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:
Check this site for the latest link (look for the one that says “arm6l” in it ;) ) – copy the link and use wget to pull it in.
sudo tar -C /usr/local -xzf go1.8.3.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 docker-compose
Install Python Libraries
sudo pip install –upgrade pip
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
(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.
Clone the Repo
mkdir -p go/src/github.com/hyperledger
git clone https://github.com/hyperledger/fabric.git
Note: The official guide says to clone from the Gerrit repo… which requires you to sign up for an LFID… which is a pain in the ass. It’s ONLY NECESSARY if you actually plan to contribute code. I’m not a Go programmer, nor do I want to be… so cloning from the Gerrit repo is unnecessary. The github repo is a “read-only” copy of the Gerrit repo and it’s updated every commit they make. I guess you also have to sign up for an LFID if you want to join their chat. Personally the chat was hit or miss for me. In my experience 60-80% of any questions you put to the fabric channel will go unanswered by the community/channel. The channel is constantly littered by people asking for help setting up a non “BYFN” networks, posting error logs, and asking for answers to questions that honestly could be simply found if one looked through the documentation provided. It doesn’t help that the current setup documentation really only covers one super simple use case at the moment (the BYFN). At this point in the project I think the expectation is that you will just have to figure out everything beyond the basics yourself, which means there is a really steep learning curve. Most of the time if you ask a question you just won’t get an answer. To be fair they really should have a moderator for the channel telling people to post their questions out on StackOverflow because the same questions are being asked over and over (which is probably why they are being ignored). Granted there are a few people on there that will help others when they know the answer or are online. Chat channels are nice but when a project of this complexity is open to the public and there’s little support for it… it kinda leaves you feeling more frustrated than supported.
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.