Introduction
One of the most frustrating thing about mining The Bitcoins is when your rig goes down, and you're not aware of it. I would like to know that my mining rig is running at all times without too much hassle. I've taken an existing open source module and jazzed it up a bit to create what I like to call, Hash Canary (shoutout to illo jones for the name suggestion).Features
- Real time LED status of a mining rig
- Notification on your smart phone if the rig goes down
- Automatic restart of the rig if it is down for more than a specified timeout
- Daily logs of power usage (needs more work)
Overview
The power drawn by the mining rig is monitored by a smart plug. The smart plug is polled by a Raspberry Pi, once every second. If the power drawn by the rig goes below a threshold, a notification will be sent. If the rig goes down for longer than a specified timeout, the entire rig will be power cycled.Implementation
You will need:
1. Raspberry Pi Zero W (or equivalent)2. Unicorn pHAT
3. Soldering iron
4. IFTTT account (ifttt.com)
5. Kasa smart plug HS110 model ( https://www.amazon.com/gp/product/B01DQM4ZC2 )
6. A working mining rig with a motherboard that can automatically start up when power is restored (some motherboards will require a user to hit a switch).
IFTTT steps (optional)
1. Register an account at ifttt.com
2. From there, create two applets for webooks, one for event named 'rig started' and one for 'rig down'. The strings must match exactly as shown.
3. Optionally create an applet to send you an email when any webhooks are triggered (search for the 'notification' applet)
4. Grab your IFTTT API key and copy it somewhere. Go to https://ifttt.com/maker_webhooks then click on the gear icon at the top right corner of the page.
Raspberry Pi steps
0. It's assumed that the user name is 'pi'
1. Solder the Unicorn pHat onto your Raspberry Pi Zero W. You need good soldering here; I've had mine go flaky because of poor soldering.
2. Download Raspbian Buster (Sept 2019).
3. Use Balena Etcher (if on Windows) to load the image to an SD card.
4. Enable WIFI (https://howchoo.com/g/ndy1zte2yjn/how-to-set-up-wifi-on-your-raspberry-pi-without-ethernet).
5. Enable SSH (https://hackernoon.com/raspberry-pi-headless-install-462ccabd75d0).
6. Insert the SD card in the Pi and boot 'er up!
7. You should be able to find the IP address of the Pi by going to your router and checking for any new devices.
8. SSH into the pi. Once in, type
sudo raspi-config
to change the password, and set the locale.
9. Download my forked copy of the Kasa smart plug module
cd ~
git clone https://github.com/boltar/hashcanary
10. Install the required npm modules
cd hashcanary
npm install
11. Install the required python modules for unicorn hat
sudo pip install rpi_ws281x
sudo pip install unicornhat
11a. For the time being, you have to manually update a file in the rpi_ws281x python package to fix a bug. I've submitted a fix for it but it seems like it hasn't made into the distribution chain yet. Edit the file /usr/local/lib/python2.7/dist-packages/rpi_ws281x/rpi_ws281x.py
ws.ws2811_fini(self.leds)
before the call to
ws.delete_ws2811_t(self._leds)
Final function should look like this:
# Clean up memory used by the library when not needed anymore.
if self._leds is not None:
ws.ws2811_fini(self.leds)
ws.delete_ws2811_t(self._leds)
self._leds = None
self._channel = None
12. Create a unix pipe. This will allow you to see the real time power drawn by your rig.
mkfifo ~/poll_pipe
13. Make poll_rig.sh executable. poll_rig.sh is a bash script to launch the poll monitor.
chmod +x poll_rig.sh
14. Edit ~/hashcanary/examples/simple/downstairs.js to meet your needs. Key fields to update:
var smartPlugPowerMonitor = new SmartPlugPowerMonitor({
smartPlugIP: "192.168.1.136", // miner downstairs
iftttMakerChannelKey: "",
pollIntervalSeconds: 1,
startTimeWindowSeconds: 3,
endTimeWindowSeconds: 60*15, // 15 minutes
startEventName: "rig started",
endEventName: "rig down",
pollingCallback: pollingData,
wattsThreshold: 800,
cooldownPeriodSeconds: 60,
eventCallback: eventData
});
- smartPlugIP - This is the IP of your Kasa smart plug. Find it somehow.
- iftttMakerChannelKey - this is the key from IFTTT Step 4
- pollIntervalSeconds: how often to poll
- endTimeWindowSeconds - this is the time to wait before the entire mining rig power cycles.
- wattsThreshold - this is the power threshold in Watts that determines whether your rig is down or up. This requires you knowing what your rig draws during idle and at full mining. example: If your rig typically draws 900-1000 Watts during normal mining, I would set it to 800 (default).
15. Edit /etc/rc.local and add this line at the end (before `exit 0`)
sudo /home/pi/hashcanary/poll_rig.sh
16. Edit ~/hashcanary/equalizer.py to set the Wattage ranges for your rig. The variable is misnamed as voltage, please ignore that. The units are in Watts.
max_voltage = 990
min_voltage = 950
This will set the scaling for the heartbeat led array.
17. Optionally, if you want to change the color, you can edit the same file, around line 51, to default to a different color other than red. Valid colors are "red", "green", "blue", "yellow", "cyan", "purple", "white".
Operation
1. Reboot the Pi and it should automatically start polling.
2. To see current power drawn by the rig:
cat ~/poll_pipe
3. To restart the polling process
sudo pkill node
sudo ~/hashcanary/poll_rig.sh
4. There is rudimentary logging available at ~/hashcanary/examples/simple/power_usage.txt. At the start of the logging script and at around midnight of each day, it will log the current power drawn.
Troubleshooting
In some cases, the LEDs may get stuck. This is due to the python script not quitting fast enough before the next polling cycle. Simply kill the python process
sudo pkill python
And it should pick right back up again.
To do
- Be able to change the color more easily
- More detailed logging of power usage
No comments:
Post a Comment