Headless Solar Powered Ardor Blockchain Node with e-ink information screen

Maximize power efficiency of an Ardor node using a Raspberry Pi Zero WH or Pi3 B, solar power, and an e-ink display, with automatic start of Ardor, the display, and forging.

Introduction

In this story I wanted to maximize the power efficiency of my Ardor node and attempt to use a Raspberry Pi Zero. I also wanted to simplify the display and make it only show more useful, concise, information.

Raspberry Pi Zero WH running Ardor

Setup the SD Card

First thing we need to do is setup our SD card. For this I decided on using Raspbian Lite. Raspbian is very well supported for the Raspberry Pi and the lite version is exactly what we want to maximize free memory and energy efficiency. You will need to download the image and to install it onto the SD Card I recommend etcher as it is very easy and simple to use.

https://downloads.raspberrypi.org/raspbian_lite_latest

https://etcher.io/

Once you have the OS image downloaded and etcher installed, you can open it up and follow the 3 steps to setup your SD card.

Choose image (raspian-lite) Select drive (The SD card) Flash!

When it is complete, you will want to remount the SD card to access the boot partition for the next steps.

Enable SSH

With new versions of Raspbian SSH is disabled by default. To enable it, a file named ssh needs to be created on the boot partition of the SD card. You can do this however you would like, an easy way on Linux or Mac is the following command:

touch /{{SD Drive}}/boot/ssh

Disable Bluetooth

We want to maximize power efficiency so we want bluetooth disabled on our Raspberry Pi. The first step in doing this is adding a line to /boot/config.txt

nano /{{SD Drive}}/boot/config.txt

And add the following lines to the file:

# Disable Bluetooth

dtoverlay=pi3-disable-bt

CTRL + X to save and quit. We will remove the now unnecessary software for Bluetooth later.

Add WiFi credentials

Now we need to add the information to connect to your WiFi right away. We will need a file called wpa_supplicant.conf . Again, you can create this however you would like, but on Linux or Mac you can use following command:

nano /{{SD Drive}}/boot/wpa_supplicant.conf

And you need to add the following information:

country=XX

ctrl_interface=/var/run/wpa_supplicant GROUP=netdev

update_config=1

network={

ssid="YOUR_SSID"

psk="YOUR_PASSWORD"

}

You will need to fill in the country code, SSID, and WiFi password. Then save that file, properly eject the SD card, and plug it into your Raspberry Pi.

Setting up the Raspberry Pi OS

We will now SSH into the Pi and you will need to find the IP address of it. The easiest way typically is to log into your router and look for the page with all the devices on your network and their IP addresses (this is sometimes labeled as the DHCP page). In the list you will want to look for one labeled Raspberry Pi, or possibly the newest device in the list. Once you have the IP address we can start the SSH connection. On Windows you may want to get a program called Putty to do the connection. On Mac and Linux you can just open the Terminal and type in:

ssh pi@{{IP Address of Pi}}

Once connected it should ask for the password which defaults to raspberry.

First thing we want to do now is change the default password for the pi user:

passwd

It will ask for the current password raspberry, then it will ask for the new password. Type it in, hit enter, and the type it in again (you will not see anything change when you type as it is all hidden). It should now say passwd: password updated successfully. Then disconnect (exit) SSH and reconnect with the new password (we want to double check it is correct before we start doing any more work :) ). Once reconnected, we will update all the packages to make sure we are fully up-to-date:

sudo apt-get update -y

sudo apt-get upgrade -y

and we will remove the Bluetooth ones since we don’t need them:

sudo apt-get purge bluez -y

sudo apt-get autoremove -y

When this is finished, we want to restart to apply any/all changes, but first we will disable the HDMI on reboot and change the GPU memory. The HDMI setting will save us a little extra power and the GPU doesn’t need much memory so we can maximize what’s available for the OS and Ardor. This project is designed to be a headless setup, and this is why we can make these modifications.

sudo nano /etc/rc.local

and add the following line above exit 0:

/usr/bin/tvservice -o

Increase available memory by lowering GPU memory:

sudo raspi-config

Go to option 7 Advanced Options and pick option A3 Memory Split. Then choose 16MB, close out of this program. Once you do, you will be asked to reboot and click yes. If you aren’t asked you can reboot by typing: reboot now

Install Ardor

Once the Pi starts back up, you can SSH back in and we will install the Ardor node software. The first part installs Java on your Pi, since Ardor needs that. The db.zip file is not a necessary step, but speeds up the process greatly by getting a recent copy of the database.



sudo apt-get install openjdk-8-jre-headless -y

sudo apt-get install openjdk-8-jre screen -y



wget

unzip ardor-client.zip

cd ardor

wget

unzip ardorTest.h2.db.zip

nano run.sh

--Where it says -Xms256M change it to -Xms256M -Xmx450M for the Zero

--Where it says -Xms256M change it to -Xms256M -Xmx950M for the RPi3

CTRL + X and save and quit sudo apt-get purge openjdk-8-jre-headless -ysudo apt-get install openjdk-8-jre-headless -ysudo apt-get install openjdk-8-jre screen -ywget https://www.jelurida.com/ardor-client.zip unzip ardor-client.zipcd ardorwget https://ardor.tools/ardorTest.h2.db.zip unzip ardorTest.h2.db.zipnano run.sh--Where it sayschange it tofor the Zero--Where it sayschange it tofor the RPi3and save and quit

Make your node an open public node (optional, but recommended on RPi3 B to support the network)

For this we will need to create the file nano conf/nxt.properties and add the following information:

nxt.allowedBotHosts=*

nxt.apiServerHost=0.0.0.0

nxt.myAddress={{Your external public IP address}}

CTRL + X to save and quit. Then, you will want to make sure your firewall has ports 27874 and 27876 open and forwarded to your Raspberry Pi. Normally, outgoing ports are open so you will just need log into your router and find the Port Forwarding section to forward those 2 ports to the IP Address of your Pi.

E-Ink Display (optional, but fun)

First, we need make sure the SPI (This is also a good time to set your timezone) is turned on and get the python-dev package.

sudo raspi-config

-5 Interfacing Options > P4 SPI > Enable

-4 Localisation Options > I2 Change Timezone

-Finish

sudo apt-get update

sudo apt-get install python-dev -y

Next we need to install RPi.GPIO package (GPIO interface functions)



mkdir eink

cd eink

wget

tar -xvzf RPi.GPIO-0.6.3.tar.gz

cd RPi.GPIO-0.6.3

sudo python setup.py install

cd ../ cd ~mkdir einkcd einkwget https://files.pythonhosted.org/packages/e2/58/6e1b775606da6439fa3fd1550e7f714ac62aa75e162eed29dbec684ecb3e/RPi.GPIO-0.6.3.tar.gz tar -xvzf RPi.GPIO-0.6.3.tar.gzcd RPi.GPIO-0.6.3sudo python setup.py installcd ../

Next we need to install the spidev library (SPI functions)



wget

tar -xvzf spidev-3.2.tar.gz

cd spidev-3.2

sudo python setup.py install

cd ../

sudo apt-get install python-imaging python-requests -y sudo apt-get install python-smbus python-serial -ywget https://files.pythonhosted.org/packages/36/83/73748b6e1819b57d8e1df8090200195cdae33aaa22a49a91ded16785eedd/spidev-3.2.tar.gz tar -xvzf spidev-3.2.tar.gzcd spidev-3.2sudo python setup.py installcd ../sudo apt-get install python-imaging python-requests -y

Lastly, we will get the python code of what to display on the e-ink display.



wget wget https://ardor.tools/eink/eink213.zip // For the 2.13" displaywget https://ardor.tools/eink/eink27.zip // For the 2.7" display

And then just unzip all the files into the eink directory. The 2.7" screen also includes 4 buttons which is really nice. In my provided python script the buttons work like this:

Manually refreshes the display Goes to next display Goes to previous display Start/stops the script

Also, in my provided code for the 2.7" screen I made 3 possible screens: screen 1 shows forging information, screen 2 shows balance information, and screen 3 shows network information.

Automatic Start and Restart of Ardor

We could do screen -S ardor and sh ./run.sh like we did in the last story to run Ardor, but I want to do something more here. We are going to install a script that a cronjob is going to use to make sure Ardor is running, and if not start it. First, we’ll make the script and we’ll call it checkArdor.sh

cd ~

nano checkArdor.sh

Then input the following code:

#!/bin/bash



ARDOR_DIR="/home/pi/ardor"

EINK_DIR="/home/pi/eink"



check_ardor() {

# Check if it is running

if pgrep -fl java > /dev/null

then

echo "Ardor is already running"

else

echo "Ardor is not currently running"

start_ardor

fi

}



start_ardor() {

if [[ ! -e "ardor.log" ]] ; then

touch "ardor.log"

fi



echo "Starting Ardor"

nohup sh ./run.sh > ardor.log 2>&1&

sleep 30



### Uncomment the next lines to enable automatic restart of the eink display

# if pgrep -fl python > /dev/null

# then

# echo "E-ink is already running"

# else

# echo "E-ink is not currently running. Starting it"

# eval "cd $EINK_DIR"

# nohup python ardor.py > eink.log 2>&1&

# fi



### Uncomment the next line and replace INSERT PASSPHRASE HERE to enable automatic forging when starting Ardor

# nohup curl -k -H "Content-Type: application/x-www-form-urlencoded" -X POST -d 'secretPhrase=INSERT PASSPHRASE HERE' http://localhost:27876/nxt?requestType=startForging > forgingStart.log 2>&1&

}



eval "cd $ARDOR_DIR"

check_ardor



You can change ARDOR_DIR to where you installed Ardor, if it is different. This script will check for java running, since Ardor should be the only thing using java, and if it’s not running it will attempt to start Ardor and log the output to ardor.log . In this script I also added code to make sure the e-ink display code was running. If you are going to use an e-ink display, I recommend uncommenting that section so it is always running. If not, you can leave it commented out.

There is also the option to automatically enable forging when starting Ardor, you just need to uncomment the line and insert the passphrase for the account you want to forge with. The output of the API call will be stored in forgingStart.log .

Now we will make the cronjob. So in the terminal type crontab -e and if it asks for which editor, you can pick nano (option 2) since we’ve been using that one. At the bottom of the file, input the following:

*/5 * * * * bash /home/pi/checkArdor.sh

This will call the script every 5 minutes to make sure it is running. So if Ardor crashed, the power goes out, or the Pi restarts for some reason, Ardor will start back up automatically for us within 5 minutes.

Power usage

In this project I tested both a Raspberry Pi Zero WH and a Raspberry Pi3 B. With the setup described above, here are the power usage numbers I observed

0.6W — Raspberry Pi Zero WH

1.7W—Raspberry Pi3 B

So using that information, I calculated how long the node should run, in theory, if there was no sunlight (real world numbers may be slightly lower):

37.0hrs — Raspberry Pi Zero WH and 6000mAh(22.2Wh) battery

61.7hrs—Raspberry Pi Zero WH and 10000mAh(37.0Wh) battery

103.3hrs—Raspberry Pi Zero WH and 16750mAh(62.0Wh)) battery

13.0hrs—Raspberry Pi3 B and 6000mAh(22.2Wh) battery

21.8hrs—Raspberry Pi3 B and 10000mAh(37.0Wh) battery

36.5hrs—Raspberry Pi3 B and 16750mAh(62.0Wh) battery

Looking at these numbers, the Raspberry Pi Zero is very impressive. You shouldn’t have an issue running it off any of these external batteries. The only issue I have is if it is powerful enough to handle Ardor under any decent load. I have a theory that once Ardor starts getting more transactions the Zero will not be able to keep up and will start crashing. This is also why I don’t include the Zero in the recommended section about making the node a public node. I feel any additional load on the hardware will be too much. Memory is already being maxed out. Instead, I would recommend the Zero is used only as an e-ink display that connects to a remote node to display information about the Ardor network and current pricing.

The Raspberry Pi3 B also has nice power consumption numbers and is a great choice here. I would still recommend at least a 10,000mAh battery as these numbers are the theoretical maximum run-times and you will want extra power for cloudy days.

Parts Recommendation

So after seeing the power numbers, I personally would still recommend a similar setup as I did in the last story. I really like the extra run-time with the 16,750mAh battery and it isn’t that much more money:

If you compare the cost to my last project, you will see they are very similar. The things to notice are that we are using an e-ink display here instead of an LCD, I chose a faster SD card then the one provided previously (However, if you want every little bit of performance, I recommend the Samsung Evo+ for $14, as it has some of the best 4k read/write), and I did not list a case as I chose to 3D print one instead (The files for that can be downloaded here). You could get the cost of this under $100, if you removed the e-ink display and went with a smaller battery. However, the fun in this project was the display and run-time.

If you wanted to just do a Raspberry Pi Zero e-ink display from a remote node, I would recommend these parts:

Taking into consideration that the Allpowers combo seems to have gone up in price to $50, I feel it is very much worth it to spend the extra $30 and get the RPi3 B withe bigger screen and battery.

Conclusion

I’m quite happy with how this project turned out. I really enjoy the e-ink display and by using it with Raspbian Lite, I gained ~12 hours of run-time with the RPi3 B on the battery.