GitGab19 / bitcoin-mining-custom-RMM

Repo contains a personal implementation of a custom Remote Monitoring and Management system for Bitcoin mining, which I developed during a prototyping phase project, with a single ASIC miner. Monitoring of the activity is managed through different tools like Docker, Grafana, InfluxDB, Telegraf, Mosquitto, Raspberry PI, ESP32 and various sensors.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bitcoin Mining Custom RMM (Remote Monitoring and Management) System

Introduction

Repo contains a personal implementation of a custom Remote Monitoring and Management system for Bitcoin mining, which I developed during a prototyping phase project, with a single ASIC miner. Monitoring of the activity is managed through different tools like Docker, Grafana, InfluxDB, Telegraf, Mosquitto, Raspberry PI, ESP32 and various sensors.

Functional requirements

These are the requirements that I had for my project: they can be useful in order to have a generic idea of what the RMM system can do and how it's built.

Functionality Component used Role Status
Remote switch on/off Sonoff powr2 (tasmotized) Smart switch
Remote access to RMM system Raspberry PI 4 VNC server
Power consumption and data(voltage/current) monitoring Sonoff powr2 (tasmotized) Power meter
Temp/Hum measurement (environmental) DHT22 Temp/Hum sensor
Smoke detection MQ2 Gas sensor
Sensors data management ESP32 Sensors control board and MQTT client
Hashrate visualization miner_stats.py script Socket reader

System Design

In order to understand in a better way the RMM system architecture, you can have a look at the system design that I've chosen to use in my context.

Repository structure

Repo is divided into 3 subfolders:

  • /miner-RMM          
    It contains the core part of this project, including all the docker containers and their relative configuration files.
    Every env variable used in the initial setup of the containers are placed in the .env file, such as Grafana initial username and password, InfluxDB admin credentials, etc.

    Warning You need to edit the .env file to setup the default credentials/configurations that you prefer.

    In order to give a general explanation about the behaviour of the services wrapped into docker-compose.yml and the interaction between each other, have a look at the schema below.

    More details about the subfolder contents are explained in a deeper way into its relative README.

  • /sensors    
    It contains sensors_management.ino: this is the file that needs to be flashed into the ESP32 in order to let it communicating sensors measurements by MQTT messages to the MQTT broker (mosquitto) that is running into Raspberry PI.

    Warning Before flashing it, you need to change some lines of code, such as:

    #define WIFI_SSID "PUT HERE YOUR WIFI SSID"     // line 7
    #define WIFI_PASSWORD "PUT HERE YOUR WIFI PASSWORD"   // line 8
    
    #define MQTT_HOST IPAddress(192, 168, 1, 170)   // line 14
    

    Other specific settings can be customized directly into code, in which there are already comments to better understand it.
    In order to flash the ESP32 with this code, you can do it using the Arduino IDE, following this guide.

  • /tasmota_custom_firmware    
    It contains my custom Tasmota firmware binary, customized by me in order to add the Telegram functionality to the original firmware version. This customization, once firmware is flashed into the Sonoff, permits to link a personal Telegram bot to the smart switch, and power on/off the miner connected to it, remotely, using your smartphone.

    In order to not trusting me and my customized firmware, if you want to enable the above descripted functionality, have a look at https://github.com/benzino77/tasmocompiler for compiling your customized version of the firmware to install into your Sonoff switch.
    All you have to do is to add the following strings in the "Custom parameters" section (4) of Tasmocompiler (or directly into user_config_override.h file if you want to compile it by hand):

    #define USE_TELEGRAM 
    #define USE_MQTT_TLS_CA_CERT   
    

    If you want to read more about compiling tools for Tasmota firmware, you can find it at https://tasmota.github.io/docs/Compile-your-build/.
    Flashing the customized Tasmota firmware into Sonoff it's not a trivial operation, pay attention in this phase. Different flashing solutions are available at https://tasmota.github.io/docs/Getting-Started/#hardware-preparation, depending on platform you use to flash your Sonoff.
    In order to create the Telegram bot and configure it to talk with your "tasmotized" Sonoff, you can follow this guide.

Project setup

First of all, depending on the Bitcoin miner that you chose to buy, pay attention to the specifics about energy requirements of the miner, such as power on wall (kW), input current (Amp) and input voltage (V).
Once you got these specifics, you have to setup the correct power supply infrastructure, such as power supply cables (oversized) and safety breaker switches.

After having the energy system correctly managed, once you obtained the hardware components needed for this project, you can finally start following the steps to replicate my own RMM system:

1. Raspberry setup

Warning
In my project I decided to use a Raspberry PI 4, but I'd like to underline that every other device can be good as well, such as a normal notebook or a generic server. The important thing is that it can be reached someway remotely (through VNC, VPN, etc.), so it needs to support one of these methods.

  • Assuming to use a Raspberry PI, first of all you have to assemble its components (cover, fans, etc.)

  • Flash the SD card with the standard OS (you can follow this guide)

  • Plug in a monitor, keyboard and mouse to the Raspberry and boot it

  • Set a static local IP for your Raspberry PI: it's important that it doesn't change because both the Sonoff and the sensors board will be setup later in order to find the MQTT broker at this fixed IP address

    Warning the default IP address that I used in the configuration of the services that are composing the RMM system is 192.168.1.170: if it's available in your local network, I really suggest to use this address for your Raspberry PI. In this case you will not need to change anything to make the whole system work perfectly.
    If you set a different from 192.168.1.170, have a look at this readme in order to make everything work correctly!

  • Install the software requirements for the RMM system:

  • Clone the repository locally:

    git clone https://github.com/GitGab19/bitcoin-mining-custom-RMM 
    
  • Enter the miner-RMM folder:

    cd miner-RMM 
    
  • Once docker is running, launch this command from terminal:

    docker-compose up -d
    
  • Open a new browser window and go to localhost:3000

  • You should be redirected to the Grafana welcome screen, like this one:

  • Enter Grafana default credentials (which are set in .env file):

    • username: admin
    • password: admin
  • Set the new password in the following step

  • You'll be redirected to the Grafana home screen, where you'll find the already created dashboard, called "ASIC":

  • Open that dashboard, you'll enter this screen:

  • The ON/OFF button on the top-left corner of the dashboard will be able to power on/off your miner (once correctly setup with your Sonoff!)

    • In order to setup this button to work properly with the Sonoff, you can find more helpful info here
  • All the other panels are already setup in order to show measurements data that will come from the Sonoff power meter, environental sensors, and miner itself!

Warning
In case you chose to set 192.168.1.170 as static local IP address for your Raspberry, everything will be working. In other cases, as said before, go to this readme to learn how to fix the configuration of some services.

2. Sonoff setup

  • Prepare the Tasmota firmware that needs to be flashed into Sonoff:
    • if you want to add the Telegram functionality, which permits to control the Sonoff switch by sending a simple message, you can:
      • directly download the version already customized by me here;
      • add the functionality and compile the firmware by your own, following the advices which I already mentioned above in the tasmota_custom_firmware section;
    • if you don't want to enable the Telegram functionality, you can go directly to the official Tasmota guide from here and follow it.
  • In both cases, in order to flash the firmware into the Sonoff, you need to buy a Serial-to-USB adapter (you can read more about it here).
  • Once Tasmota custom firmware is flashed, your Sonoff is ready to be configured:
    • if it's already connected to your wi-fi router, scan your local network, find its IP address and open a browser that points to it
    • if it's not, do a rapid triple-click onto the unique physical button present on Sonoff, entering its pairing mode
      • at this point you can find the "TASMOTA-xxx" wifi network from your computer, click on it to connect. This will take you to the configuration page of Tasmota, in which you can set the wifi parameters;
    • go to Configuration->Configure MQTT and:
      • set the MQTT host (broker) to connect with, entering the Raspberry local IP address;
      • leave all the other fields as they are (make sure the topic field is filled with "tasmota");
  • Now your Sonoff is completely configured, and you can start using it:
    • if you decided to add the Telegram functionality, my advice is to connect the Sonoff to a very basic object that can be controlled by a switch, such as a simple lamp, in order to setup and test the Telegram interaction in a safer way.
      To setup the Telegram bot and configure it with the "tasmotized" Sonoff, you can follow this guide.
  • If you didn't want the Telegram functionality, or after having tested the Telegram functionality, you can directly start plugging the power cables between the wall, Sonoff and your miner.

If you don't know MQTT protocol and want to know more, you can start by reading the Tasmota documentation and follow its relative links: https://tasmota.github.io/docs/MQTT/#topic

3. ESP32 and sensors setup

  • Prepare the firmware that needs to be flashed into ESP32, which is responsible of letting ESP32 send MQTT messages containing the sensors measurements:
    • have a look at the sensors_management.ino file, and change the lines of code cited here, in order to tell to the ESP32 the corrrect credentials of your wifi router and the local IP address of the MQTT broker (which is the local IP address that you chose to set to your raspberry PI);
    • if you have similar but not equal sensors to the ones specified (DHT22 and MQ2), you could have to modify some other parts, uncommenting or adding some lines of code;
  • Flash the firmware to ESP32, following these advices.
  • Insert the ESP32 into the board and connect it with the sensors above listed using different jumpers and wires. You can follow different guides present on Internet, such as https://www.hackster.io/ricky-wijaya/temperature-humidity-and-air-quality-control-3fc819.
  • Connect the ESP32 with your computer and verify from the Arduino IDE that everything is good, looking for the debug messages sent to the serial monitor tool of the IDE.
  • At this point your ESP32 is correctly setup and it's ready to be plugged into the experimental location (as near as possible to the miner) with a generic power adapter.

4. Boot up the system

Once you have configured everything up, you just need to do a last thing:

  • set a STATIC local IP address to your miner
  • write this static IP in this cron file, subtituting the current 192.168.1.192

Everything should be ready, restart everything and enjoy the RMM system!

Conclusion

I've decided to publish my personal project for anyone who is interested in experimenting with mining, especially for the ones who are willing to try starting with just a single miner. As illustrated in the system design, my solution was built around an Antminer S19J pro, but it can be easily adapted for any other miner on the market.

Feel free to open issues, comment it or contribute to the project!

About

Repo contains a personal implementation of a custom Remote Monitoring and Management system for Bitcoin mining, which I developed during a prototyping phase project, with a single ASIC miner. Monitoring of the activity is managed through different tools like Docker, Grafana, InfluxDB, Telegraf, Mosquitto, Raspberry PI, ESP32 and various sensors.

License:MIT License


Languages

Language:C++ 60.7%Language:Python 18.4%Language:Shell 15.0%Language:Dockerfile 5.9%