pyasic
BTMinerAPI
Bases: BaseMinerAPI
An abstraction of the API for MicroBT Whatsminers, BTMiner.
Each method corresponds to an API command in BMMiner.
This class abstracts use of the BTMiner API, as well as the
methods for sending commands to it. The self.send_command()
function handles sending a command to the miner asynchronously, and
as such is the base for many of the functions in this class, which
rely on it to send the command for them.
All privileged commands for BTMiner's API require that you change the password of the miners using the Whatsminer tool, and it can be changed back to admin with this tool after. Set the new password either by passing it to the init method, or changing it in settings.toml.
Additionally, the API commands for the privileged API must be encoded using a token from the miner, all privileged commands do this automatically for you and will decode the output to look like a normal output from a miner API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ip |
str
|
The IP of the miner to reference the API on. |
required |
port |
int
|
The port to reference the API on. Default is 4028. |
4028
|
pwd |
str
|
The admin password of the miner. Default is admin. |
global_whatsminer_password
|
Source code in pyasic/API/btminer.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 |
|
adjust_power_limit(power_limit)
async
Set the upper limit of the miner's power. Cannot be higher than the ordinary power of the machine.
Expand
Set the upper limit of the miner's power, only works after changing the password of the miner using the Whatsminer tool. The miner will reboot after this is set.Parameters:
Name | Type | Description | Default |
---|---|---|---|
power_limit |
int
|
New power limit. |
required |
Returns: A reply informing of the status of setting power limit.
Source code in pyasic/API/btminer.py
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 |
|
adjust_upfreq_speed(upfreq_speed)
async
Set the upfreq speed, 0 is the normal speed, 9 is the fastest speed.
Expand
Set the upfreq speed, 0 is the normal speed, 9 is the fastest speed, only works after changing the password of the miner using the Whatsminer tool. The faster the speed, the greater the final hash rate and power deviation, and the stability may be impacted. Fast boot mode cannot be used at the same time.Parameters:
Name | Type | Description | Default |
---|---|---|---|
upfreq_speed |
int
|
New upfreq speed. |
required |
Returns: A reply informing of the status of setting upfreq speed.
Source code in pyasic/API/btminer.py
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 |
|
devdetails()
async
Get data on all devices with their static details.
Expand
Returns:
Type | Description |
---|---|
dict
|
Data on all devices with their static details. |
Source code in pyasic/API/btminer.py
904 905 906 907 908 909 910 911 912 913 |
|
devs()
async
Get data on each PGA/ASC with their details.
Expand
Returns:
Type | Description |
---|---|
dict
|
Data on each PGA/ASC with their details. |
Source code in pyasic/API/btminer.py
882 883 884 885 886 887 888 889 890 891 |
|
disable_fast_boot()
async
Turn off fast boot.
Expand
Turn off fast boot, only works after changing the password of the miner using the Whatsminer tool.Returns:
Type | Description |
---|---|
dict
|
A reply informing of the status of disabling fast boot. |
Source code in pyasic/API/btminer.py
616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
|
disable_web_pools()
async
Turn off web pool updates.
Expand
Turn off web pool updates, only works after changing the password of the miner using the Whatsminer tool.Returns:
Type | Description |
---|---|
dict
|
A reply informing of the status of disabling web pools. |
Source code in pyasic/API/btminer.py
646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
|
edevs()
async
Get data on each PGA/ASC with their details, ignoring blacklisted and zombie devices.
Expand
Returns:
Type | Description |
---|---|
dict
|
Data on each PGA/ASC with their details. |
Source code in pyasic/API/btminer.py
893 894 895 896 897 898 899 900 901 902 |
|
enable_fast_boot()
async
Turn on fast boot.
Expand
Turn on fast boot, only works after changing the password of the miner using the Whatsminer tool.Returns:
Type | Description |
---|---|
dict
|
A reply informing of the status of enabling fast boot. |
Source code in pyasic/API/btminer.py
601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
|
enable_web_pools()
async
Turn on web pool updates.
Expand
Turn on web pool updates, only works after changing the password of the miner using the Whatsminer tool.Returns:
Type | Description |
---|---|
dict
|
A reply informing of the status of enabling web pools. |
Source code in pyasic/API/btminer.py
631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
|
factory_reset()
async
Reset the miner to factory defaults.
Expand
Returns:
Type | Description |
---|---|
dict
|
A reply informing of the status of the reset. |
Source code in pyasic/API/btminer.py
514 515 516 517 518 519 520 521 522 523 |
|
get_error_code()
async
Get a list of error codes from the miner.
Expand
Get a list of error codes from the miner. Replaced `summary` as the location of error codes with API version 2.0.4.Returns:
Type | Description |
---|---|
dict
|
A list of error codes on the miner. |
Source code in pyasic/API/btminer.py
974 975 976 977 978 979 980 981 982 983 984 985 986 |
|
get_miner_info()
async
Get general miner info.
Expand
Returns:
Type | Description |
---|---|
dict
|
General miner info. |
Source code in pyasic/API/btminer.py
963 964 965 966 967 968 969 970 971 972 |
|
get_psu()
async
Get data on the PSU and power information.
Expand
Returns:
Type | Description |
---|---|
dict
|
Data on the PSU and power information. |
Source code in pyasic/API/btminer.py
915 916 917 918 919 920 921 922 923 924 |
|
get_token()
async
Gets token information from the API.
Expand
Returns:
Type | Description |
---|---|
dict
|
An encoded token and md5 password, which are used for the privileged API. |
Source code in pyasic/API/btminer.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
get_version()
async
Get version data for the miner.
Expand
Returns:
Type | Description |
---|---|
dict
|
Version data for the miner. |
Source code in pyasic/API/btminer.py
941 942 943 944 945 946 947 948 949 950 |
|
multicommand(*commands, allow_warning=True)
async
Creates and sends multiple commands as one command to the miner.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*commands |
str
|
The commands to send as a multicommand to the miner. |
()
|
allow_warning |
bool
|
A boolean to supress APIWarnings. |
True
|
Source code in pyasic/API/btminer.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
pools()
async
Get the pool status from the miner.
Expand
Returns:
Type | Description |
---|---|
dict
|
Pool status of the miner. |
Source code in pyasic/API/btminer.py
871 872 873 874 875 876 877 878 879 880 |
|
power_off(respbefore=True)
async
Power off the miner using the API.
Expand
Power off the miner using the API, only works after changing the password of the miner using the Whatsminer tool.Parameters:
Name | Type | Description | Default |
---|---|---|---|
respbefore |
bool
|
Whether to respond before powering off. |
True
|
Returns: A reply informing of the status of powering off.
Source code in pyasic/API/btminer.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
|
power_on()
async
Power on the miner using the API.
Expand
Power on the miner using the API, only works after changing the password of the miner using the Whatsminer tool.Returns:
Type | Description |
---|---|
dict
|
A reply informing of the status of powering on. |
Source code in pyasic/API/btminer.py
417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
pre_power_on(complete, msg)
async
Configure or check status of pre power on.
Expand
Configure or check status of pre power on, only works after changing the password of the miner using the Whatsminer tool.Parameters:
Name | Type | Description | Default |
---|---|---|---|
complete |
bool
|
check whether pre power on is complete. |
required |
msg |
PrePowerOnMessage
|
the message to check.
|
required |
Returns: A reply informing of the status of pre power on.
Source code in pyasic/API/btminer.py
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 |
|
reboot(timeout=10)
async
Reboot the miner using the API.
Expand
Returns:
Type | Description |
---|---|
dict
|
A reply informing of the status of the reboot. |
Source code in pyasic/API/btminer.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
|
reset_led()
async
Reset the LED on the miner using the API.
Expand
Reset the LED on the miner using the API, only works after changing the password of the miner using the Whatsminer tool.Returns:
Type | Description |
---|---|
dict
|
A reply informing of the status of resetting the LED. |
Source code in pyasic/API/btminer.py
431 432 433 434 435 436 437 438 439 440 441 442 443 |
|
restart()
async
Restart BTMiner using the API.
Expand
Restart BTMiner using the API, only works after changing the password of the miner using the Whatsminer tool.Returns:
Type | Description |
---|---|
dict
|
A reply informing of the restart. |
Source code in pyasic/API/btminer.py
385 386 387 388 389 390 391 392 393 394 395 396 397 |
|
set_fan_zero_speed(fan_zero_speed)
async
Sets whether the fan speed supports the lowest 0 speed.
Expand
Sets whether the fan speed supports the lowest 0 speed, only works after changing the password of the miner using the Whatsminer tool.Parameters:
Name | Type | Description | Default |
---|---|---|---|
fan_zero_speed |
bool
|
Whether the fan is allowed to support 0 speed. |
required |
Returns: A reply informing of the status of setting fan minimum speed.
Source code in pyasic/API/btminer.py
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 |
|
set_hostname(hostname)
async
Set the hostname of the miner.
Expand
Set the hostname of the miner, only works after changing the password of the miner using the Whatsminer tool.Parameters:
Name | Type | Description | Default |
---|---|---|---|
hostname |
str
|
The new hostname to use. |
required |
Returns: A reply informing of the status of setting the hostname.
Source code in pyasic/API/btminer.py
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 |
|
set_led(auto=True, color='red', period=60, duration=20, start=0)
async
Set the LED on the miner using the API.
Expand
Set the LED on the miner using the API, only works after changing the password of the miner using the Whatsminer tool.Parameters:
Name | Type | Description | Default |
---|---|---|---|
auto |
bool
|
Whether or not to reset the LED to auto mode. |
True
|
color |
str
|
The LED color to set, either 'red' or 'green'. |
'red'
|
period |
int
|
The flash cycle in ms. |
60
|
duration |
int
|
LED on time in the cycle in ms. |
20
|
start |
int
|
LED on time offset in the cycle in ms. |
0
|
Returns: A reply informing of the status of setting the LED.
Source code in pyasic/API/btminer.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
|
set_low_power()
async
Set low power mode on the miner using the API.
Expand
Set low power mode on the miner using the API, only works after changing the password of the miner using the Whatsminer tool.Returns:
Type | Description |
---|---|
dict
|
A reply informing of the status of setting low power mode. |
Source code in pyasic/API/btminer.py
476 477 478 479 480 481 482 483 484 485 486 487 488 |
|
set_power_pct(percent)
async
Set the power percentage of the miner based on current power. Used for temporary adjustment.
Expand
Set the power percentage of the miner, only works after changing the password of the miner using the Whatsminer tool.Parameters:
Name | Type | Description | Default |
---|---|---|---|
percent |
int
|
The power percentage to set. |
required |
Returns: A reply informing of the status of setting the power percentage.
Source code in pyasic/API/btminer.py
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
|
set_poweroff_cool(poweroff_cool)
async
Set whether to cool the machine when mining is stopped.
Expand
Set whether to cool the machine when mining is stopped, only works after changing the password of the miner using the Whatsminer tool.Parameters:
Name | Type | Description | Default |
---|---|---|---|
poweroff_cool |
bool
|
Whether to cool the miner during power off mode. |
required |
Returns: A reply informing of the status of setting power off cooling mode.
Source code in pyasic/API/btminer.py
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 |
|
set_target_freq(percent)
async
Update the target frequency.
Expand
Update the target frequency, only works after changing the password of the miner using the Whatsminer tool. The new frequency must be between -10% and 100%.Parameters:
Name | Type | Description | Default |
---|---|---|---|
percent |
int
|
The frequency % to set. |
required |
Returns: A reply informing of the status of setting the frequency.
Source code in pyasic/API/btminer.py
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
|
set_temp_offset(temp_offset)
async
Set the offset of miner hash board target temperature.
Expand
Set the offset of miner hash board target temperature, only works after changing the password of the miner using the Whatsminer tool.Parameters:
Name | Type | Description | Default |
---|---|---|---|
temp_offset |
int
|
Target temperature offset. |
required |
Returns: A reply informing of the status of setting temp offset.
Source code in pyasic/API/btminer.py
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 |
|
status()
async
Get BTMiner status and firmware version.
Expand
Returns:
Type | Description |
---|---|
dict
|
BTMiner status and firmware version. |
Source code in pyasic/API/btminer.py
952 953 954 955 956 957 958 959 960 961 |
|
summary()
async
Get the summary status from the miner.
Expand
Returns:
Type | Description |
---|---|
dict
|
Summary status of the miner. |
Source code in pyasic/API/btminer.py
860 861 862 863 864 865 866 867 868 869 |
|
update_firmware()
async
Not implemented.
Source code in pyasic/API/btminer.py
490 491 492 493 494 |
|
update_pools(pool_1, worker_1, passwd_1, pool_2=None, worker_2=None, passwd_2=None, pool_3=None, worker_3=None, passwd_3=None)
async
Update the pools of the miner using the API.
Expand
Update the pools of the miner using the API, only works after changing the password of the miner using the Whatsminer tool.Parameters:
Name | Type | Description | Default |
---|---|---|---|
pool_1 |
str
|
The URL to update pool 1 to. |
required |
worker_1 |
str
|
The worker name for pool 1 to update to. |
required |
passwd_1 |
str
|
The password for pool 1 to update to. |
required |
pool_2 |
str
|
The URL to update pool 2 to. |
None
|
worker_2 |
str
|
The worker name for pool 2 to update to. |
None
|
passwd_2 |
str
|
The password for pool 2 to update to. |
None
|
pool_3 |
str
|
The URL to update pool 3 to. |
None
|
worker_3 |
str
|
The worker name for pool 3 to update to. |
None
|
passwd_3 |
str
|
The password for pool 3 to update to. |
None
|
Returns:
Type | Description |
---|---|
dict
|
A dict from the API to confirm the pools were updated. |
Source code in pyasic/API/btminer.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
|
update_pwd(old_pwd, new_pwd)
async
Update the admin user's password.
Expand
Update the admin user's password, only works after changing the password of the miner using the Whatsminer tool. New password has a max length of 8 bytes, using letters, numbers, and underscores.Parameters:
Name | Type | Description | Default |
---|---|---|---|
old_pwd |
str
|
The old admin password. |
required |
new_pwd |
str
|
The new password to set. |
required |
Returns: A reply informing of the status of setting the password.
Source code in pyasic/API/btminer.py
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
|
version()
async
Get version data for the miner. Wraps self.get_version()
.
Expand
Get version data for the miner. This calls another function, self.get_version(), but is named version to stay consistent with the other miner APIs.Returns:
Type | Description |
---|---|
dict
|
Version data for the miner. |
Source code in pyasic/API/btminer.py
926 927 928 929 930 931 932 933 934 935 936 937 938 939 |
|