Keep the Ethereum mining going steady

in #ethereum7 years ago (edited)

As I noted in the earlier post, about my setup for the single GPU ethereum mining rig, I’d like to take it forward, with some additional updates to keep it running smooth and steady. A number of additional works has gone into, ever since I wrote the last post.

Firstly, the GPU once went dead suddenly, and wouldn’t mine any more. I figured it’s just going way too hot despite all the fans attached around it, in the casing. First I found that one of the casing fan wasn’t really blowing enough air to cool down anything. So changed it to a new cooler-master 120mm fan. This did help to manage a tiny bit better air flow out of the cabinet. However, the GPU wasn’t able to sustain still. Thus, the next step was to open up the heat-sink fan of the GPU and check. Indeed, the thermal paste has gone completely dry and brittle. Thus I got a new paste with thermal paste cleaner. Cleaned up the old dried up paste, replaced with a generous coat of the new paste, before sticking up the heat-sink fan back again. And walla, the machine was up and running once again, with a renewed vigour. It became so good, that now the same old GPU started to churn out new faster hashrate of 24.3 MH/s.

That was awesome. But after a month, came a second jolt. The used gigabyte motherboard went kaput, and the system was dead again. After testing it with another PSU, I made sure that the issue was indeed the motherboard and not the PSU. Thus I had to spend another $74 for a “newer" used motherboard, this time I got an MSI 970A-G43 AM3+ socket, so that my existing Athlon 2 X2 CPU can continue working on it.

Now the system is stable enough with the new motherboard and refreshed GPU, with a steady hashrate as above. Meanwhile, I read on various internet forums, that the ethermine.org pool performs better than nanopool, and also the phoenix miner has a better hashrates with more stability than the claymore miner, with lower dev fee as well. So I shifted both the mining software, as well as, the pool. Indeed, my throughput got enhanced now to a steady 25.1 MH/s, with more frequent and higher payouts. Yippee!

With this, it was time to tackle another annoyance of the Windows OS. BSoD and just plain hanging windows randomly. I needed to not only keep track of these windows hangs, but also make sure the system is hard-rebooted quickly to continue mining.

To make this system work, I did some DIY using an old Raspberry Pi 1 lying around at home. Here’s a detailed setup I came up with, to make my rig self sufficient.

My parts list for this project:

  • Raspberry Pi, with updated Raspbian Stretch on an SD-card.
  • As this RasPi doesn’t have wifi of it’s own, I used this comfast wifi dongle lying around with me
  • 5V dual relay module
  • An old USB charger cable
  • Some spare 2561 one-way wire connectors like these
  • A spare LAN cable

So, first thing required was to get the RaspPi controlling the dual relay module. I used simple python script to achieve this. The wiring diagram for it looks like this:
RaspRelay_bb.png

Next, was the Python code to operate the relays.

#!/usr/bin/python

import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)
relay1Pin = 17
relay2Pin = 4
#GPIO.setup(relayPin, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setwarnings(False)

def switch(rPin, onoff):
    if (onoff == True):
        GPIO.setup(rPin, GPIO.OUT, initial=GPIO.HIGH)
        GPIO.output(rPin, GPIO.LOW)
    else:
        #GPIO.output(relayPin, GPIO.HIGH)
        GPIO.setup(rPin, GPIO.IN)
        
def reboot(rpin):
    switch(rpin, True)
    sleep(0.5) 
    switch(rpin, False)
    sleep(0.5)
    print("Restarted")
    
def hardboot():
    switch(True)
    sleep(4)
    switch(False)
    print("Hard Shutdown")
    sleep(25)
    switch(True)
    sleep(0.5)
    switch(False)
    print("Hard Rebooted")
    
def main():
    #print(GPIO.RPI_INFO)
    reboot(relay1Pin)
    reboot(relay2Pin)
    #hardboot()
    #GPIO.cleanup()
    
if __name__ == '__main__':
    main()

Now that the relays are working, we write the code to check if the windows has hanged. To achieve this, I used the LAN cable connected directly between the PC and the RPi as a peer-to-peer connection.

IMG_20180620_121027.jpg

Then I ping the PC from the RPi. To be reliable always, I modify the LAN adapter settings and entered a fixed IP address at the IPv4 settings as shown in the pictures below.

LAN1.PNGLAN2.PNG

However, this is not enough to be able to ping to windows PC due to a default setting in windows. To enable this, we need to go to the firewall setting through the windows defender. Then open the Incoming connections -> File and printer sharing (Echo Request - ICMPv4-In) and enable the same. Then press Ok, and close the window. Now you should be able to ping the IP address set earlier.

fw1.PNGfw2.PNGfw3.PNGfw4.PNGfw5.PNG

For ease of programming in RPi, I also installed a simple program called fping, (sudo apt-get fping -y).

Now the python program can be written as follows:

#!/usr/bin/python

import RPi.GPIO as GPIO
from time import sleep
import socket
import subprocess
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

GPIO.setmode(GPIO.BCM)
relayPin = 4
GPIO.setwarnings(False)

def sendmail():
    fromaddr = "<My sending email>"
    frompwd = "<My passwd>"
    toaddr = "<My recieving mail ID>"
    msg = MIMEMultipart()
    msg['From'] = fromaddr
    msg['To'] = toaddr
    msg['Subject'] = "Windows is Hanged"
     
    body = "Restarting PC!"
    msg.attach(MIMEText(body, 'plain'))
    try:
        server = smtplib.SMTP('<server id>', 587)
        server.starttls()
        server.login(fromaddr, frompwd)
        text = msg.as_string()
        server.sendmail(fromaddr, toaddr, text)
        print("Mail Sent")
        server.quit()
    except:
        print("Error sending mail")

def switch(relayPin, onoff):
    if (onoff == True):
        GPIO.setup(relayPin, GPIO.OUT, initial=GPIO.HIGH)
        GPIO.output(relayPin, GPIO.LOW)
    else:
        GPIO.setup(relayPin, GPIO.IN)
        
def reboot(rpin):
    switch(rpin, True)
    sleep(0.5) 
    switch(rpin, False)
    sleep(0.5)
    print("Restarted")
    
def main():
    winpc = "<PC's IP address>"
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  #Create a TCP/IP socket
    proc = subprocess.Popen(['fping', '-a', winpc],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    rep, err = proc.communicate()
    if (len(err) > 0):
        sendmail()
        reboot(relayPin)
    else:
        print('Running fine')
    GPIO.cleanup()
    
if __name__ == '__main__':
    main()

This program would check the ping to the PC’s IP address. If this ping returns successfully, then nothing happens and the program would exit. However, if this ping fails, the program sends an email to me, and also triggers the relay for the reset switch, for half a second before switching off again. This is to simulate tje pressing and releasing the reset switch on the PC.

Additionally, I also modified the spare USB cable, with the 2561 connectors, to have a bypass for the reset and power switch connectors in the PC, as you can see below. So these cables now make an alternative for the power and reset switches in the PC.

IMG_20180127_132731.jpg
IMG_20180127_134653.jpgIMG_20180127_134931.jpg

This program is then included in a cron job to run every 10 mins, as follows:
/10 * * * * python /home/pi/Desktop/checkwin.py >/dev/null 2>&1

The RPi is just kept on top of the PC casing as you can see in the pics here.

IMG_20180620_120931.jpgIMG_20180620_120954.jpg

Additionally, I wrote another program to run in a similar fashion, but to trigger the other relay, for the power switch instead of the restart switch, if the ping fails.

#!/usr/bin/python

import RPi.GPIO as GPIO
from time import sleep
import socket
import subprocess
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

GPIO.setmode(GPIO.BCM)
relayPin = 17
GPIO.setwarnings(False)

def sendmail():
    fromaddr = "<my sender email>"
    frompwd = "<email passwd>"
    toaddr = "<my receiver email>"
    msg = MIMEMultipart()
    msg['From'] = fromaddr
    msg['To'] = toaddr
    msg['Subject'] = "Windows is Off"
     
    body = "Switching it On!"
    msg.attach(MIMEText(body, 'plain'))
    try:
        server = smtplib.SMTP('<mail server>', 587)
        server.starttls()
        server.login(fromaddr, frompwd)
        text = msg.as_string()
        server.sendmail(fromaddr, toaddr, text)
        print("Mail Sent")
        server.quit()
    except:
        print("Error sending mail")

def switch(relayPin, onoff):
    if (onoff == True):
        GPIO.setup(relayPin, GPIO.OUT, initial=GPIO.HIGH)
        GPIO.output(relayPin, GPIO.LOW)
    else:
        GPIO.setup(relayPin, GPIO.IN)
        
def boot(rpin):
    switch(rpin, True)
    sleep(0.5) 
    switch(rpin, False)
    print("Switched On")
    
def main():
    winpc = "<PC's IP>"
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  #Create a TCP/IP socket
    proc = subprocess.Popen(['fping', '-a', winpc],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    rep, err = proc.communicate()
    if (len(err) > 0):
        sendmail()
        boot(relayPin)
    else:
        print('Running fine')
    GPIO.cleanup()
    
if __name__ == '__main__':
    main()

This program is set to run once, when the RPi boots up, by editing the /etc/rc.local file, and adding the following line to it.

sudo python /home/pi/Desktop/startwin.py & >/home/pi/Desktop/starting.log 2>&1

This is useful in a scenario like this. If there’s an unexpected power failure, then when the power returns, the RPi would boot off as usual, and then switches on the PC. The mining bat file is already setup to run at startup in the PC. So, with all these systems running smoothly, the mining rig is now fully autonomous, to do mining non-stop, at the highest speed attainable with this hardware.

Thank you for reading it through. I’m open to any queries you have in this regard, or any further suggestions to improve this setup in better ways.

Sort:  

Check it out @originalworks.
Thanks

Congratulations @picsnapr! You received a personal award!

1 Year on Steemit

Click here to view your Board

Do not miss the last post from @steemitboard:

SteemWhales has officially moved to SteemitBoard Ranking
SteemitBoard - Witness Update

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @picsnapr! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!