Collaboration: Raspberry Pi Indy Agent
Intro
This page serves as a place to collaborate and document challenges and successes with using Indy/Aries software with the Raspberry Pi. This document will most likely find a home as a markdown file in a GitHub repo.
Todo
- Add instructions for building libindy on the Raspberry Pi.
libindy for ARMv7
Cross-compile
Haven't managed to do it. Some of the links maybe useful:
Cross compiling rust for raspberry pi within docker: https://github.com/Ragnaroek/rust-on-raspberry-docker
Prebuilt dependencies(libsodium,zmq,openssl) for armv7 https://github.com/evernym/indy-android-dependencies/tree/master/prebuilt
General guide for cross compiling rust https://hackernoon.com/compiling-rust-for-the-raspberry-pi-49fdcd7df658
Discussions for the compilation flags on raspberry Pi, maybe useful when linking all the .o files in the last step https://lb.raspberrypi.org/forums/viewtopic.php?t=144115
Native
Building libindy directly on pi, mainly from the setup guide of libindy ubuntu https://github.com/hyperledger/indy-sdk/blob/master/docs/build-guides/ubuntu-build.md.
Install rust and rustup on pi:
curl https://sh.rustup.rs -sSf | sh
Install required native libraries and utilities:
sudo apt-get update && \
sudo apt-get install -y \
build-essential \
pkg-config \
cmake \
libssl-dev \
libsqlite3-dev \
libzmq3-dev \
libncursesw5-dev
Build and install lib-sodium from source:
cd /tmp && \
curl https://download.libsodium.org/libsodium/releases/old/libsodium-1.0.14.tar.gz | tar -xz && \
cd /tmp/libsodium-1.0.14 && \
./configure --disable-shared && \
make && \
sudo make install && \
rm -rf /tmp/libsodium-1.0.14
- Increase the swap file size of raspberry pi, since its RAM is insufficient for completing the compilation of libindy
Editing the dphys-swapfile: https://www.bitpi.co/2015/02/11/how-to-change-raspberry-pis-swapfile-size-on-rasbian/
sudo vi /etc/dphys-swapfile
change the field
CONF_SWAPSIZE=100
to
CONF_SWAPSIZE=1024
then restart the service by executing the following commands:
sudo /etc/init.d/dphys-swapfile stop sudo /etc/init.d/dphys-swapfile start
Or can just create a swapfile and make it swap space:
dd if=/dev/zero of=/path/to/swapfile bs=1M count=1024 # For 1GB swap file
mkswap /path/to/swapfile
swapon /path/to/swapfile
Clone the project, check out the latest stable version and build it on pi:
cd ~
git clone https://github.com/hyperledger/indy-sdk.git
cd ./indy-sdk
git checkout v1.9.0
cd ./libindy
cargo build --release
cd ..
Note: release version is the version built from the command above ( cargo build --release ) if "--release" is excluded debug version is built instead.
Build Times
- Raspberry Pi Zero WH
- just over an hour (70m53.768s)
- Raspberry Pi 3 B+
- just under an hour (~40 minutes)
Agent Framework for ARMv7
- Install the dotnet runtime on the pi.
- build the "web sample" project in arm architecture on a host PC
- transfer files to the pi.
- call dotnet run from the transferred "web sample" project directory to start the sample app.
If you want the agent publically accessible i.e have a public address then you need a tunneling service like ngrok configured.
Python Reference Agent
Before running the python reference agent, make sure LD_LIBRARY_PATH is set, after compiling the libindy, run following command to set:
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/libindy/target/{BUILD TYPE}" >> ~/.bashrc
sudo ldconfig
source ~/.bashrc
As the python reference agent suggested, the requirements of python is 3.6, however, on raspberry pi, the latest version from apt is 3.5.3, therefore, additional steps for installing python3.6 is required. Haven't tested if the default python3.5.3 can work.
cd ~
sudo apt-get install python3-dev libffi-dev libssl-dev -y
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
tar xJf Python-3.6.3.tar.xz
cd Python-3.6.3
./configure
make
sudo make install
sudo pip3 install --upgrade pip
Clone the indy-agent repo:
cd ~
git clone https://github.com/hyperledger/indy-agent.git
cd indy-agent/pythonInstall a Python3.6 virtual environment and have it running
cd ~
mkdir python-virtual-environments && cd python-virtual-environments
# Python 2: virtualenv env # Python 3 python3 -m venv env
source env/bin/activate
Install the requirements:
(venv)
cd ~/indy-agent/python
pip install -r requirements.txt
- Follow the guide on https://github.com/hyperledger/indy-agent/blob/master/python/README.md and test the demo. However, the connection between raspberry pi and pc may not work, in such case, you may try to use hostname options: python3 indy-agent --hostname <yourhostname>.
Aries Cloud Agent
Before running the aries-cloud-agent, make sure LD_LIBRARY_PATH is set, after compiling the libindy, run following command to set:
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/libindy/target/{BUILD TYPE}" >> ~/.bashrc
sudo ldconfig
source ~/.bashrc
Install python 3.6 for raspberry pi
cd ~
sudo apt-get install python3-dev libffi-dev libssl-dev -y
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
tar xJf Python-3.6.3.tar.xz
cd Python-3.6.3
./configure
make
sudo make install
sudo pip3 install --upgrade pip
Clone the aries-cloud-agent repo:
cd ~
git clone https://github.com/hyperledger/aries-cloudagent-python
cd aries-cloudagent-pythonInstall a Python3.6 virtual environment and have it running
cd ~
mkdir python-virtual-environments && cd python-virtual-environments
# Python 2: virtualenv env # Python 3 python3 -m venv env
source env/bin/activate
Install aries-cloud-agent
cd aries-cloudagent-python
pip install wheel
pip install -e .Or can just use the following command
pip install aries-cloudagent
Running the Faber-Alice demo, for an indy pool, consider running a von-network following the guide here: https://github.com/bcgov/von-network#running-the-network-locally, or start local indy nodes following the guide https://github.com/hyperledger/indy-sdk, the detailed instructions would be found here:https://github.com/hyperledger/aries-cloudagent-python/tree/master/demo#Running-Locally. On raspberry pi, we need to increase the timeout for starting the demo, https://github.com/hyperledger/aries-cloudagent-python/blob/ff3835385c1789a4f14116059533ac2c3249f5b8/demo/runners/ support/agent.py#L359, changing it from 10 to 100 would let the agent start normally on raspberry pi.
(venv)
pip3 install prompt_toolkit pygments python3-indy
cd demo
LEDGER_URL=<Your Ledger URL> python3.6 -m runners.faber -p 8020
or
LEDGER_URL=<Your Ledger URL> python3.6 -m runners.alice -p 8030Some issues related to the demo could be found here(updating):
Static Agent
Setting up SenseHat in Virtual Environment
Within the virtual environment, install the prerequisite RTIMU:
- Clone RTIMULib:
git clone https://github.com/RPi-Distro/RTIMULib/
cd RTIMU/Linux/python
python3.6 setup.py build
python3.6 setup.py install
- Clone RTIMULib:
Install sense_hat.
python3.6 -m pip install sense_hat
General Configurations
- Systemd
- Ngrok
- Running RPI Headless
Aries RFC For IoT Control Protocol
We need a standard protocol for reading sensor data and setting GPIO pins on IoT devices.
Can we create a general protocol that can be customized with decorators for particular devices?
How could we take advantage of other protocols like MQTT, DDS. and AMQP?