Hello miners! Today we’re going to start our multi-part series on using the programming language Python to communicate and manage miners running cgminer. As cgminer is a popular open-source mining software program this tutorial can be used to manage a variety of devices.
I’ll put together I’ve put together a list of mining hardware we know runs cgminer.
Now that’s out of the way, I want to voice a shameful caveat before we begin. I’m a self-taught Python programmer, and although the code we create will run great it may not be the prettiest girl at the party. My plan is to create a Github repository to archive all our work, so maybe a coding wizard can take a look and help me tighten it up. I’m not proud!
Finally, I’m going to point everyone to a number of guides on the internet that will walk you through installing Python 3 and PyCharm, my IDE of choice. I’m happy to answer any questions fielded in the comments but I figure smarter people than me can walk you through the basics. For this series I’ll be using a Linux machine for the walkthrough screens, but PyCharm runs exactly the same on all operating systems. For those of us born after the new millennium, here’s a video:
What is Cgminer?
Before we continue let’s take a minute to talk cgminer. It was created by Con Kolivas and is an open source project that anyone can download, modify and use. Originally designed for Bitcoin mining, cgminer has become the standard built-in software for a majority of ASIC miners on the market. The software itself plays a middle-man function. It takes work from a mining pool, delivers it to the mining hardware and finally returns the completed work back to the mining pool. That’s a super-simple overview, but we just need the basics to get started.
The software also has a very robust API which is what we’re going to use to communicate with the miner in Python. This API allows us to send commands to the miners and receive the response back. Don’t let the lengthy command list frighten you, we’ll just be using the one “summary” command to get started.
I’ve got a few Avalon 741s in my lab that we’ll be using in this guide, but this code should talk to any cgminer based hardware with no modification. If you’re having problems getting things working in your setup, feel free to drop me a line in the comments and we can troubleshoot it together! My network setup is as straight forward as it comes: each miner has a static IP address and the computer we’ll use to run our code is connected to the same network. I’ve got a standard cable modem connected to the internet with a residential account from my ISP.
We’ll be writing the Python code on my laptop, then I’ll upload the code to my Raspberry Pi device that I use to run all my little scripts. If you want to follow along with every step, prepare your Raspberry Pi on the same network as your miner and grab a (free) copy of FileZilla for the platform of your choice.
Next week in Part 1 of our walk-through we’re going to jump straight into the code. We’ll learn how to request the current status of your miner and store that information in a simple database. If you’ve never used Python before, take a few minutes out of your day and run your fresh copy of PyCharm through a tutorial or two. I’ll see you soon!