October 2019: The new discovery server had been added to this guide. How to do it, go here: https://medium.com/@CryptoRonny/update-the-discovery-server-of-the-ronny-cheap-mans-skyminer-a985e6033bd2

Installing the Skywire software on a Raspberry Pi 3b(+) — Difficulty level: 2/5

Why another guide?

This guide will explain how to install Skywire software on a Raspberry Pi. I will use screenshots, so you can exactly see what is going on. Once you understand the basics, it is easy to solve problems, do updates or perhaps even contribute.

Hardware

1 x Pi Model 3B(+);

1 x UTP/ Ethernet cable;

1 x USB mini cable(power);

1 x SanDisk micro SDHC 16GB or 32GB (both work);

2 x screws.

Optional, for testing:

+ 1 x SanDisk micro SDHC 16GB or 32GB;

I am using an Apple MacBook running MacOSX to set up my Raspberry Pi.

Download the operating system for your Raspberry Pi

Without an operating system, your Pi cannot operate. Since we will run Skywire from the command line, a desktop version is not necessary. Therefore we install Raspian (Edition, like ‘Stretch’) Lite, the most simple and smallest version of Raspian Stretch, the official supported operating system for Raspberry Pi.

https://downloads.raspberrypi.org/raspbian_lite_latest

After downloading, unzip the package.

Download Etcher

Etcher is a very handy application for MacOSX that can be used to copy (flash) the Raspian Stretch Lite operating system on a SD card that you will use in your Raspberry Pi.

https://etcher.io/

Flash your SD card and enable remote access to your Pi

Using Etcher, select the Raspian Stretch Lite disk image and select the SD card you are going to flash.

Etcher running on MacosX. Select the Raspian Stretch Lite disk image you have downloaded earlier, select the SD card in your Mac and click “Flash!” Download: https://etcher.io/

When finished, eject your SD card securely and insert it again in your computer.

You can use Disk Utility to Eject the SD card (not mounted after flashing)

Now your SD card will be visible on your desktop.

Open a Terminal session. Terminal is an application on MacOSX that we use to setup the Raspberry Pi.

This is the application Terminal that is part of MacOSX. In this screenshot you see that my computername is Skycoin and my username ratrace.

Now we are going to make the SD card we just inserted and therefore is visible on our desktop, the current directory. The command to make something the current directory in Terminal is the cd command.

cd /volumes/name_of_your_SD_card

Note: First type cd, then press spacebar .Using your mouse, you now drop the SD card in the Terminal window.

If you are not using MacOSX from Apple, you can use Putty (https://www.chiark.greenend.org.uk/~sgta...atest.html) to connect to your pi using ssh. Instructions can be found at step 1/7 of the following guide: https://downloads.skycoin.net/skywire/Skywire-Installation-Guide-v1.0.pdf

Enable SSH

SSH, also known as Secure Socket Shell, is a network protocol that provides administrators with a secure way to access a remote computer. In our case a Raspberry Pi.

To enable ssh on the Pi, execute the following commands:

sudo touch ssh

This command creates a new empty file, ssh in the root folder of your Pi. This file will enable ssh on your Raspberry Pi. For the password enter the password you use to log in to your Mac.

When finished, put the SD card in your Raspberry Pi and connect your Raspberry Pi to your local network using an UTP (Ethernet) cable. Power the Raspberry Pi with a USB mini cable.

If the Raspberry Pi is operating properly, the red and green lights of the Raspberry Pi will start to blink.

Connect your Raspberry Pi to your Mac using a USB mini cable. Insert the flashed SD card and connect it to your router that has dhcp enabled.

Find the IP address of the Raspberry Pi on your local network

To be able to find the Raspberry Pi on your local network, your router needs to be DHCP enabled. DHCP will make it possible for the Raspberry Pi to get a local IP number automatically. To find out what that IP number is, you can use the application Lanscan on a Mac. You can also check the IP address in your router, it should be visible in the interface.

https://www.iwaxx.com/lanscan/

With Lanscan it is easy to find the ip address of the Raspberry Pi.

Login to your Raspberry Pi

Following the steps above, you now know what the local IP address of your Pi is. Let’s say it’s 101.10.10.1.

Time to login to this Pi. We are going to do that with SSH. Login as user pi (default) with password raspberry (default).

ssh pi@101.10.10.1

Update the default password:

passwd

This command will ask for your current password (raspberry) and after confirmation, 2 times for a new password. Best practice is to use a long, strong password.

Congrats, you set up a Raspberry Pi with an operating system that can be accessed and controlled by ssh. Your Pi is now ready for further configuration.

Root

Scripts that run automatically on your pi, will be executed by the root. An example of a script that runs automatically, is a script that starts your Skyminer automatically (You will find the code at the end of this guide).

To become user root, execute the following command:

sudo -i

Well done. Until you shutdown, reboot or log off, you are root!

Why is this important?

The Skyminer software needs $HOME to find /root. The software runs best in the folder /root and not in the folder /home/pi.

$HOME for user pi is /home/pi and not /root

If you install Skywire as user root, all files will be placed directly in the right $HOME location: /root. But if you installed as the default user pi (using the sudo command in front of commands that require root), all the files will be located in the folder /home/pi.

To correct a previous installation, done as a different user as root, take a look at my other guide: A solution for the disappearing node app key in Skywire Manager with autostart scripts for your DIY Skyminer on Raspberry Pi and Pine64 Rock64

root@raspberrypi instead of pi@raspberrypi

Update the Raspberry Pi

Now we need to update the Raspberry Pi with the latest software available.

apt-get update

apt-get upgrade -y

Install some additional packages:

apt-get install -y curl git mercurial make binutils gcc bzr bison libgmp3-dev screen gcc build-essential

Downloading, unzipping Golang and setting up the basic folder structure for Skywire in /root.

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. Skywire is built in Go, therefore we need to install Go.

Navigate to root folder as user root.

sudo -i

root: cd ~

From this /root folder we do all the installations and we install Skywire in this location too.

The /root folder is used for 2 things:

a temporary location for unzipping Golang (go). Go is necessary for running Skywire. After downloading and unzipping Go, we move the folder to the right application folder: /usr/local/go. Once the go folder is gone (moved to /usr/local/go) we are going to make a new go folder structure in /root. This will be the location for your Skywire software.

Step 1 Download and install Golang (go)

UPDATE 17 July 2019: Please check and install the latest Go version if you encounter any errors during install of Go or Skywire.

With root access, we download the go package in /root -> go1.12.1.linux-armv6l.tar.gz is suitable for a Raspberry Pi 3 or 3B+.

sudo -i

cd ~

wget https://storage.googleapis.com/golang/go1.12.1.linux-armv6l.tar.gz

Now we are going to unpack this in the same /root folder.

tar xvf go1.12.1.linux-armv6l.tar.gz

If you check the directory now (command ls), you will see a go folder in the directory /root, that was not there before.

This go folder contains the actual application Golang that is used to run Skywire. We are going to move this go folder now to the right location in the directory structure.

sudo mv go /usr/local/go

The final step in setting up Golang is editing .bashrc in /root, it runs at each launch.

cd ~

nano .bashrc

Go to the end of the file and add these preferences for Golang:

export GOROOT=/usr/local/go

export GOPATH=$HOME/go

export GOBIN=$GOPATH/bin

export PATH=$PATH:$GOBIN

GOROOT is linking to Golang (the application) in the folder /usr/local. As you may remember, we moved the folder go, after unpacking, from the /root folder to the /usr/local folder.

GOPATH is linking to the folder $HOME/go. $HOME is the folder /root since we installed as user root -> /root/go.

GOBIN is linked to the folder $GOPATH/bin -> /root/go/bin.

OK, now this is done, we are going to install Golang (go) by executing these commands in Terminal:

ln -s /usr/local/go/bin/go /usr/local/bin/go

ln -s /usr/local/go/bin/godoc /usr/local/bin/godoc

ln -s /usr/local/go/bin/gofmt /usr/local/bin/gofmt

Now test if Golang (go) is installed correctly. To do so type:

go

If there are no errors, Golang is installed and working. You will see the following output:

Great! Golang (go) is running

Congratulations! You installed Golang!

Now, reboot:

reboot

After reboot, log in as root again:

ssh pi@101.10.10.1 //(replace with your Pi ip) sudo -i

cd ~

Step 2 Install Skywire on your Pi

Skywire Manager and Skywire Node

The manager is a graphical interface in your web browser you connect to.

The node is an application that connects to the manager and is the actual engine of your Skyminer. 1 Skywire manager can have different nodes.

Imagine you have 8 Raspberry Pi’s, one of them will be your manager. On this manager, there is also a node running, connecting to the same manager on the same pi. If you have 8 Raspberry Pi’s, you could basically run 8 Skyminers like this, so you have 8 ‘Ronny Cheap Man’s Skyminers’. But you can also connect the nodes of all 8 Raspberry Pi’s to 1 Manager on 1 Raspberry Pi. If you do it like the latter, all nodes will pop-up in that specific manager of your choice. Now your Skyminer has 8 nodes instead of only 1.

8 Raspberry Pi’s use the Skywire Manager of 1 Raspberry Pi.

Let us start bij setting up a Raspberry Pi with 1 Manager and 1 Node.

Now we are going to install the Skywire software. To run the Skywire software, we need to create 3 folders (bin,pkg and src) in /root:

sudo -i

cd ~

mkdir -p $HOME/go/{bin,pkg,src}

Check it:

ls

You will see a new folder go in /root. The folder go will have 3 subfolders: bin, pkg and src.

The next step is that we are going to make a folder which will contain the Skywire application. We are going to clone Skywire from GitHub.



cd $GOPATH/src/github.com/skycoin

git clone mkdir -p $GOPATH/src/github.com/skycoincd $GOPATH/src/github.com/skycoingit clone https://github.com/skycoin/skywire.git

A new Skywire folder is created.

We make the cmd folder in this newly created skywire folder our current folder and build binaries from this.

cd $GOPATH/src/github.com/skycoin/skywire/cmd

go install ./...

It takes some time before it is finished. If the install command finishes without error: Congrats! You have successfully installed Skywire!

Run Skywire and setup scripts to automatically load Skywire at system startup

Now the final part of this guide is to set-up some scripts that will execute when you start your miner or reboot.

Start the command crontab -e. Crontab is a time-based job scheduler, @reboot is executed at boot and reboot. The option -e makes it possible to edit the crontab file.

sudo -i

cd /etc

crontab -e

Select the editor of your choice. In this guide we use Nano.

Now scroll to the end and add (watch out for the space between reboot and /etc..):

@reboot/etc/init.d/MyScript.sh

When ready, press CTRL-X and than Y to save.

As you can see, I choose to put my startup scripts in the folder init.d in the folder etc.

Create MyScript.sh in folder /etc/init.d

Now we are going to create our startup script MyScript.sh with the editor Nano:

sudo -i

cd /etc/init.d

nano MyScript.sh

The code:



export GOPATH=$HOME/go

cd $GOPATH/bin

./skywire-manager -web-dir /root/go/src/github.com/skycoin/skywire/static/skywire-manager > /dev/null 2>&1 &

echo "Skywire is now running in the background. You can now access the Skywire Manager via the web browser"

sleep 5

cd $GOPATH/bin

./skywire-node -connect-manager -manager-address :5998 -manager-web :8000 -discovery-address testnet.skywire.skycoin.com:5999-028ec969bdeb92a1991bb19c948645ac8150468a6919113061899051409de3f243 -address :5000 -web-port :6001 &> /dev/null 2>&1 &

echo "Skywire monitor started."

echo "You can now open the monitor in your browser:

sleep 10 #!/bin/shexport GOPATH=$HOME/gocd $GOPATH/bin./skywire-manager -web-dir /root/go/src/github.com/skycoin/skywire/static/skywire-manager > /dev/null 2>&1 &echo "Skywire is now running in the background. You can now access the Skywire Manager via the web browser"sleep 5cd $GOPATH/bin./skywire-node -connect-manager -manager-address :5998 -manager-web :8000 -discovery-address testnet.skywire.skycoin.com:5999-028ec969bdeb92a1991bb19c948645ac8150468a6919113061899051409de3f243 -address :5000 -web-port :6001 &> /dev/null 2>&1 &echo "Skywire monitor started."echo "You can now open the monitor in your browser: http://#.#.#.#:8000 sleep 10

Ctrl X and Y to save.

Note: if your manager is running on another pi, edit manager-address and manager-web.

Adjust permissions of the MyScript.sh

Adjust permissions:

cd /etc/init.d

chmod 755 MyScript.sh

Test the script:

cd /etc/init.d

./MyScript.sh

No errors?

reboot

After reboot visit ##.##.##.##:8000 in your web-browser.

##.##.##.## is the ip address of your Raspberry Pi, in my case:

After logging into your manager (default password: 1234) you will see this:

When you have done everything according to this guide, you will:

be able to click Check Update -> a window will popup; start ssh; Connect to other nodes; On the bottom, see an app node key with a green button “node”. This app is monitoring your uptime. This is important if you want to get rewards in the testnet; If you click settings, you will see a green mark beside the discovery address; You will be able to find your public address here:

http://testnet.skywire.skycoin.com:8001/conn/getAll

Disclaimer and Warning

This solution is without any warranties and I am not responsible for anything. This article is only for educational purposes. If you use this code, you use it at your own risk. I am not a team member, therefore this is not an official solution.

Always test your code on a spare pi with a spare sd card BEFORE you put it into production or use it!

Cheers!

Ronny

SKYCOIN: 2FBZoLvKQsySAzSz3RV1ve62iRTMjvf9vge

HANDCASH:$RONNY

BTC: 16VynXgJET1JYpL6kZfaGTxkTfuemJq4Ko