UpstreamData / pyasic

A simplified and standardized interface for Bitcoin ASICs.
https://docs.pyasic.org
Apache License 2.0
90 stars 45 forks source link

[Feature Request] Add Bitaxe Miner Support (esp-miner) #165

Open pixeldoc2000 opened 3 days ago

pixeldoc2000 commented 3 days ago

Please add (basic) Support for Bitaxe Miner (esp-miner firmware).

The bitaxe is a fully open source ASIC bitcoin miner.

Project: https://www.bitaxe.org/ Firmware: https://github.com/skot/ESP-Miner/

Firmware API: https://github.com/skot/ESP-Miner?tab=readme-ov-file#api

b-rowan commented 2 days ago

This is a great idea, I wasn't even aware that the bitaxe had much in the way of API, but its nice to see some docs for it. Not sure if you have one, but if you do, would you mind hitting those web endpoints in a browser and sending some results here?

jpcomps commented 2 days ago

This was on my wish list to find time to add as well, glad someone pushed a issue for this. Going to tag @skot here if I can in case we need some additional help, but sure we can find many people willing to dump anything we need. I am looking to have one ordered as well so can also help once we put the framework in

b-rowan commented 2 days ago

This was on my wish list to find time to add as well, glad someone pushed a issue for this. Going to tag @skot here if I can in case we need some additional help, but sure we can find many people willing to dump anything we need. I am looking to have one ordered as well so can also help once we put the framework in

NGL, im in the middle of doing this right now. My biggest issue is always that I dont have one haha. Ill push up something to dev_bitaxe shortly once I finish the factory implementation.

b-rowan commented 2 days ago

Done. I've done very basic support for it one the dev_bitaxe branch, now it just needs testing.

skot commented 2 days ago

Dang you guys are quick! I'll test this out asap.

b-rowan commented 2 days ago

Dang you guys are quick! I'll test this out asap.

Having source code makes things much easier. Thanks for all your contributions to open source in the space!

jpcomps commented 2 days ago

{ "power": 10.869999885559082, "voltage": 5042.5, "current": 2156.25, "fanSpeedRpm": 3827, "temp": 55, "hashRate": 435.77643357785956, "bestDiff": "274M", "bestSessionDiff": "1.71M", "freeHeap": 164292, "coreVoltage": 1200, "coreVoltageActual": 1234, "frequency": 485, "ssid": "KH", "hostname": "espressif", "wifiStatus": "Connected!", "sharesAccepted": 63, "sharesRejected": 1, "uptimeSeconds": 3033, "ASICModel": "BM1366", "stratumURL": "public-pool.io", "stratumPort": 21496, "stratumUser": ".office", "version": "v2.1.8", "boardVersion": "0.11", "runningPartition": "ota_1", "flipscreen": 1, "invertscreen": 0, "invertfanpolarity": 1, "autofanspeed": 1, "fanspeed": 100 }

api/system/info^^

Thanks to gary_mara in discord!

pixeldoc2000 commented 14 hours ago

First test with dev_bitaxe branche

esp-miner API System Info

http://192.168.0.202/api/system/info

{
    "power":    19.049999237060547,
    "voltage":  5036.25,
    "current":  3775,
    "fanSpeedRpm":  5341,
    "temp": 51,
    "hashRate": 516.40948791849462,
    "bestDiff": "635M",
    "bestSessionDiff":  "39.5k",
    "freeHeap": 164456,
    "coreVoltage":  1300,
    "coreVoltageActual":    1309,
    "frequency":    650,
    "ssid": "xxx",
    "hostname": "xxx",
    "wifiStatus":   "Connected!",
    "sharesAccepted":   19,
    "sharesRejected":   0,
    "uptimeSeconds":    201,
    "ASICModel":    "BM1366",
    "stratumURL":   "xxx",
    "stratumPort":  3333,
    "stratumUser":  "BTC:bc1qxxx",
    "version":  "v2.1.7",
    "boardVersion": "0.11",
    "runningPartition": "ota_1",
    "flipscreen":   1,
    "invertscreen": 0,
    "invertfanpolarity":    1,
    "autofanspeed": 1,
    "fanspeed": 100
}

Test MinerData

Source: https://github.com/UpstreamData/pyasic#data-gathering

MinerData(ip='192.168.0.202', datetime='2024-06-30T22:13:36.714119+02:00', timestamp=1719778416, device_info=DeviceInfo(make=None, model=None, firmware=None, algo=SHA256Algo), make=None, model=None, firmware=None, algo='SHA256', mac=None, api_ver='v2.1.7', fw_ver='v2.1.7', hostname='xxx', hashrate=0.595494584964798 TH/s, expected_hashrate=None, expected_hashboards=3, expected_chips=0, expected_fans=2, percent_expected_chips=None, percent_expected_hashrate=None, percent_expected_wattage=None, temperature_avg=None, env_temp=None, wattage=19, wattage_limit=None, voltage=None, fans=[], fan_psu=None, hashboards=[HashBoard(slot=0, hashrate=0.595494584964798 TH/s, temp=None, chip_temp=51, chips=None, expected_chips=None, serial_number=None, missing=False, tuned=None, active=True, voltage=5027.5)], total_chips=None, nominal=None, config=MinerConfig(pools=PoolConfig(groups=[PoolGroup(pools=[Pool(url='stratum+tcp://xxx:3333', user='BTC:bc1qxxx', password='x')], quota=1, name='N2B4L3')]), fan_mode=FanModeNormal(mode='normal', minimum_fans=1, minimum_speed=0), temperature=TemperatureConfig(target=None, hot=None, danger=None), mining_mode=MiningModeNormal(mode='normal')), fault_light=None, errors=[], is_mining=True, uptime=3537, efficiency=32, pools=[])
0.595494584964798 TH/s

Not all MinerData is populated, but query some data with miner_data and miner_data.hashrate is working.

Looking at the source and MinerDate, I am wondering why "expected_hashboards=3, expected_chips=0, expected_fans=2" is returned wrong -> "ASICModel": "BM1366",

It looks like the wrong json object is parsed for bitaxe model, made a comment about it: https://github.com/UpstreamData/pyasic/commit/923e96336916d43abc85defd93b53772ff7a4f0e#r143697922

Test restart

import asyncio
from pyasic import get_miner

async def do_restart():
    miner = await get_miner("192.168.0.202")

    # call control function
    result = await miner.restart()

if __name__ == "__main__":
    asyncio.run(do_restart())
Traceback (most recent call last):
  File "D:\git\pyasic\test_bitaxe_02.py", line 11, in <module>
    asyncio.run(do_restart())
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "D:\git\pyasic\test_bitaxe_02.py", line 8, in do_restart
    result = await miner.restart()
                   ^^^^^^^^^^^^^
AttributeError: 'BitAxe' object has no attribute 'restart'
b-rowan commented 12 hours ago

For reference, the model is parsed in MinerFactory via the MINER_CLASSES dict, the keys are miner type, then model, here is the bitaxe models - https://github.com/UpstreamData/pyasic/blob/ee1eece181798e9ee47e6f23495532b9b6a4eae5/pyasic/miners/factory.py#L444-L449

That uses the result of this function, converted into uppercase - https://github.com/UpstreamData/pyasic/blob/ee1eece181798e9ee47e6f23495532b9b6a4eae5/pyasic/miners/factory.py#L1023-L1033

This means I expect web_system_info["devicemodel'].upper() to be one of the values above, which would parse it directly into one of those miner types. On the bright side, it seems to know that it is a BitAxe model of some kind, so the initial layer of discovery is working, but it seems this one is failing. The problem in this case seems to be that your device contains no devicemodel key, which from what I can see has to be set in the inital configuration. Ill make changes to have it use the asicmodel instead, and that should fix it, although I could actually have it check for either or if needed.

Also, regarding the restart function, the function is not called restart, there are 2 different functions for "restarting" in pyasic, restart_backend, which usually is used to retsart the mining process, such as cgminer, and not the whole device, and reboot, which is used to restart the whole device (https://docs.pyasic.org/en/latest/#miner-control).

b-rowan commented 12 hours ago

Should be fixed on master, just pushed a commit that uses asic model instead, see https://github.com/UpstreamData/pyasic/commit/7a9c9237a3688ad3b9bd4c2a3ec3a1acba38691c