Mining With Solar Power

Here’s a Python script I wrote to check today’s sun rise/set times given a coordinate:

https://github.com/raynix/solar-hours/blob/master/solar_hours.py

It uses api.sunrise-sunset.org free API to get local sun rise/set time of today. It also takes time zone into consideration as the API only returns times in UTC time zone. It also cache the API result for a day so I’m not abusing the free API.

I have solar power at home however the invertor isn’t API friendly, otherwise it will be best to get solar power output directly from the invertor.

Using this python script I can turn on my Zcash miner when there’s solar power. This saves me money, more importantly the ZEC I mined is carbon free. Here’s a sample bash script to turn on/off the miner according to sun rise/set:

#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
MINER=<miner's IP>
pushd $DIR 
python solar-hours/solar_hours.py
# 0 means solar on, 1 means off
if [ $? -eq 0 ]; then
 ping $MINER -c 1 || wakeonlan <miner's MAC address>
else
 ssh $MINER sleep 1 && ssh -t $MINER 'sudo shutdown -h now'
fi
popd

If you want to try this too please read the Wake On LAN part I’ve done a while ago.

🙂

Play a bit Kubernetes with Minikube

I’ve just played a bit Kubernetes on my Arch Linux laptop, with Minikube. It’s easier than I thought.

Since I’ve already installed VirtualBox from the start, I can use minikube right after I installed it with

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

The command I used to start minikube is

minikube start --cpus 4 --memory 4096 --insecure-registry "10.0.0.0/8"

It’s obvious that I wanted to allocate 4 CPUs and 4GB memory to the Kubernetes cluster. The –insecure-registry option is useful when I want to use a local Docker Registry without SSL.

Check if the cluster is ready with

minikube status

And launch the Kubernetes Dashboard with

minikube dashboard

After all these, it’s time to play with Kubernetes(kubectl command). However the local Kubernetes cluster doesn’t have DNS management like its cloud counterpart does. I wanted to have a load balancer too so I needed to get the IP and then tell kubectl to use the IP for the load balancer service:

minikube ip
192.168.99.104

Then in the yaml file for kubectl:

---
apiVersion: v1
kind: Service
metadata:
...
spec:
  externalIPs:
    - 192.168.99.104
...
  type: LoadBalancer

For now I found this necessary otherwise the service stuck at pending state.

🙂

Mining ZCash on Ubuntu Linux

I didn’t quite believe that mining crypto currencies is viable as an individual, until I saw the news that AMD graphics cards were sold out because they’re good at mining Ethereum. To be convinced I tried to order AMD RX 570 from some online vendors, and they all cancelled my orders and refunded me shortly.

So even if I wanted to mine Ethereum I will have to wait indefinitely for the AMD cards to be re-stocked. At least I can buy some NVidia GTX 1070 cards and mine ZCash instead, before NVidia cards are sold out.

Here’s how to mine ZCash with NVidia cards on Ubuntu.

First, you need a wallet so I can receive payments, if there will be any.  It’s quite easy to install zcash on Arch Linux(because I run Arch on my laptop):

sudo pacman -S zcash
mkdir .zcash
echo "addnode=mainnet.z.cash" >~/.zcash/zcash.conf
echo "rpcuser=<your user>" >>~/.zcash/zcash.conf
echo "rpcpassword=`head -c 32 /dev/urandom | base64`" >>~/.zcash/zcash.conf

For other operating systems, see https://z.cash/download.html

Then you can download the bootstrap data with

zcash-fetch-params

It will download about 800MB, after finished, you can start your wallet with

zcashd

When it’s running, you can use zcash-cli command to create your wallet:

zcash-cli getnewaddress

There will be a long hash started with ‘t’, which is a transparent address, with which you can send and receive zcash. You don’t have to run your wallet and your miner on the same machine, but your miner will use the t address(you will get paid to your wallet).

Now onto your miner machine. You will need to install some dependencies for the miner:

sudo apt-get install nvidia-opencl-dev nvidia-375

System needs to be restarted to load the driver. You can load the driver without restarting too, eg. sudo modprobe nvidia-375. Then you can follow the post below to use the miner:

https://bitcointalk.org/index.php?topic=1707546.0

🙂