Pimp my miner

For a while now, I thought about mounting a simple display somewhere that shows the most important parameters of my BitCoin miner. First I started with an AtMega equipped with an Ethernet module. But parsing json without any library support became too cumbersome quickly. So I copy pasted together a small python script, and used a nokia display that I already equipped with an i2c interface. If I knew how easy it is, to use those json interfaces, I would have implemented this display project earlier. The code is at the bottom. It is specific to my setup with p2pool and CHF, but it is so easy to change that you can adapt it to whatever your setting is. The python script now runs on an Alix on the same i2c bus as my simple home automation transmitter. Now all that is left to do, is adding a line to /etc/crontab to execute the script once a minute.

As you can see on the image below, the hash rate is too hight for a stock Saturn. That is because I recently added an extension module. So it has now three instead of two hashing modules. All of a sudden, KncMiner announced they had 200 extension modules for the October batch, and that future modules would be incompatible. So, that was pretty much the only chance for an upgrade. My existing power supply should have room for one more module, and they were moderately priced. The demand was high enough that they were sold out in three minutes. The i30 cooler that was recommended was not available at the time, so I had to use an Xtreme rev2. I had a fun time finding out how to correctly mount it. Even for the original, there was no manual or description how to mount it. Just look at the existing modules said someone in the forum.

#! /usr/bin/python
# Show the current hashrate of my bitcoin miner on a nokia display

import httplib2
import json
import time
from nokia_display import NokiaDisplay

class p2pool:
	def __init__(self, url, payout_addr):
		self.baseurl = url
		self.payout_addr = payout_addr

	def poolHashrate(self): # in GH/s
		h = httplib2.Http(".cache")
		h.debuglevel = 2
		url = "%s/rate" % (self.baseurl)
		resp, content = h.request(url, "GET")
		ghash = float(content) / 1024.0 / 1024.0 / 1024.0
		return ghash

	def localHashrate(self):
		h = httplib2.Http(".cache")
		h.debuglevel = 2
		url = "%s/local_stats" % (self.baseurl)
		resp, content = h.request(url, "GET")
		jj = json.loads(content)
		ghash = float(jj['miner_hash_rates'][self.payout_addr]) / 1024.0 / 1024.0 / 1024.0
		return ghash

	def shares(self):
		h = httplib2.Http(".cache")
		h.debuglevel = 2
		url = "%s/local_stats" % (self.baseurl)
		resp, content = h.request(url, "GET")
		jj = json.loads(content)
		shares = int(jj['shares']['total'])
		return shares

	def current_payout(self):
		h = httplib2.Http(".cache")
		h.debuglevel = 2
		url = "%s/current_payouts" % (self.baseurl)
		resp, content = h.request(url, "GET")
		jj = json.loads(content)
		payout = float(jj[self.payout_addr])
		return payout

class bitcoincharts:
	def __init__(self, symb):
		self.baseurl = 'http://api.bitcoincharts.com/v1/markets.json'
		h = httplib2.Http(".cache")
		h.debuglevel = 2
		resp, content = h.request(self.baseurl, "GET")
		jj = json.loads(content)
		for i in range(len(jj)):
			market = jj[i]
			if market['symbol'] == symb:
				self.market = market

	def last_close(self):
		price = float(self.market['close'])
		return price

	def ask(self):
		price = float(self.market['ask'])
		return price

	def bid(self):
		price = float(self.market['bid'])
		return price

class blockchain:
	def __init__(self, addr):
		self.baseurl = 'https://blockchain.info/address'
		h = httplib2.Http(".cache")
		h.debuglevel = 2
		url = '%s/%s?format=json&limit=0' % (self.baseurl, addr)
		resp, content = h.request(url, "GET")
		self.jj = json.loads(content)

	def total_received(self):
		ammount = float(self.jj['total_received']) / 100000000
		return ammount

	def balance(self):
		ammount = float(self.jj['"final_balance']) / 100000000
		return ammount

# test code
if __name__ == "__main__":
	payout = 'putYourBitCoinAddressHere'
	p2p = p2pool('http://TheMachineWhereYourP2PoolNodeRuns:9332', payout)
	btcch = bitcoincharts('mtgoxCHF')
	blkch = blockchain(payout)

	txtHash   = 'GHash %f'   % p2p.localHashrate()
	txtShares = 'Shares %d'  % p2p.shares()
	txtPay    = 'Pay/blk %f' % p2p.current_payout()
	txtPrice  = 'CHFgox %f'  % btcch.bid()
	txtRecv   = 'Recv %f'    % blkch.total_received()
	txtTime   = time.strftime('%x %X')[0:14]

	print 'pool  hashrate : ', p2p.poolHashrate()
	print 'local hashrate : ', txtHash
	print 'shares         : ', txtShares
	print 'current payout : ', txtPay
	print 'total mined    : ', txtRecv
	print 'mtGoxCHF latest: ', txtPrice
	print 'time           : ', txtTime

	disp = NokiaDisplay(0x19, 0)
	disp.TextOut(1, 1, txtHash)
	disp.TextOut(1, 2, txtShares)
	disp.TextOut(1, 3, txtPay)
	disp.TextOut(1, 4, txtRecv)
	disp.TextOut(1, 5, txtPrice)
	disp.TextOut(1, 6, txtTime)

Leave a Reply

Your email address will not be published. Required fields are marked *