WhatsMiner API v2.0.5
Summary
This article describes how to use the whatsminer’s API. The intendedaudience is mine management software developers. The mine management
software functions similar to WhatMinerTool can be realized throughtheAPI. The API read permission is granted by default, and the API write permissionneeds to be enabled through the WhatMinerTool, follow these steps:
1.Change the default password(admin);
2.Enable the API by the WhatsMinerTool;
Protocol
The whatsminer API TCP port is 4028.
Notice:
- If no data is received within 10 seconds after the port is connected, theconnection will time out and be closed.
- Miner supports max 16 IP clients, one IP can get 32 tokens, and a tokenkeepalive time is 30 minutes.
JSON API return format:
1 | { |
Message Code:
Code | Message |
---|---|
14 | invalid API command or data |
23 | invalid JSON message |
45 | permission denied |
131 | command OK |
132 | command error |
134 | get token message OK |
135 | check token error |
136 | token over max times |
137 | base64 decode error |
API ciphertext
Notice: the readable API supports two communication modes: plaintext andciphertext; the writable API supports only ciphertext communication
Encryption algorithm:
Ciphertext = aes256(plaintext),ECB mode
Encode text = base64(ciphertext)
Steps as follows:
(1)api_cmd = token,$sign|api_str
(2)enc_str = aes256(api_cmd, $key)
(3)tran_str = base64(enc_str)
api_str is API command plaintext
Generate aeskey step:
(1)Get token from miner: $time $salt $newsalt
(2)Generate key:
key = md5(salt + admin_password)
Reference code:
key = openssl passwd -1 -salt $salt "${admin_password}"
(3)Generate aeskey:
aeskey = sha256($key)
e.g.:
set_led|auto ->
token,$sign|set_led|auto ->
ase256(“token,sign|set_led|auto”, $aeskey) ->
base64(ase256(“token,sign|set_led|auto”, $aeskey) ) ->
enc|base64(ase256(“token,sign|set_led|auto”, $aeskey))
1 | { |
The flow
flowchart TD A[Start] --> B[Get token] B --> C{Return error?} C -->|Yes| D[END] C -->|No| E[Token] E --> F[aes256 api command with sign] F --> G[base64 api command] G --> H[Send API] H --> I[Receive] I --> D
Readable API
Summary
Contains fan speed, power info, etc
1 | { |
retrun
1 | { |
Pools
Contains pool miner information.
1 | { |
return
1 | { |
Edevs/devs
Contains information for each hash board.
1 | { |
return
1 | { |
Devdetails
1 | { |
return
1 | { |
Get PSU
Contains power information
1 | { |
return
1 | { |
Get version
Get miner API version.
1 | { |
return
1 | { |
Get token
Plaintext must be used, and the miner returns plaintext.
1 | { |
return
1 | { |
Status
Get btminer status and firmware version.
1 | { |
return
1 | { |
Get miner info
1 | { |
return
1 | { |
Get error code
You can use this command to obtain the machine error codes.
1 | { |
return
1 | { |
The API command can be used for two joins
eg.
1 | { |
Writable API
Writable API only supports ciphertext.
The writable API must first obtain the token as follows:
1 | client -> miner: |
- time: timestamp, this count starts at the Unix Epoch on January 1st, 1970 at UTC.
- salt: a random salt is generated for each password
- newsalt: new salt for sign
Token calculation method:
Get token from miner: time salt newsalt.
- calculate key use admin’s password and salt.
- time is the last four characters of time.
key = md5(salt + admin_password)
sign = md5(newsalt + key + time)
The reference code in Ubuntu:
First, Get those values from miner: $time $salt $newsalt.
Ubuntu Shell command:
key = openssl passwd -1 -salt $salt "${admin_password}"|cut -f 4 -d'$'
sign=openssl passwd -1 -salt $newsalt "${key}${time:0-4}"|cut -f 4 -d'$'
The default user name and password are admin
Update pools information
This operation updates the pool configuration and switches immediately
1 | { |
Restart btminer
This operation only restarts the btminer process, not the control board.
1 | { |
Power off hashboard
This operation simply stops mining and turns off the power of the hashboard.
1 | { |
Power on hashboard
This operation simply starts mining and turns on the power of the hashboard.
1 | { |
Manage led
Recovery to automatic control:
1 | { |
LED manual setting:
1 | { |
Switch power mode
After the miner power mode is successfully configured, btminer will berestarted.
1 | { |
Firmware upgrading
Upgrade flow:
Client -> miner(text flow): “update_firmware”
1 | { |
Miner -> client(text flow): “ready”
1 | { |
Client -> miner(binary flow): file_size(4Bytes) file_data
file_size: size of upgrade file,send integer to stream as little endian. file_data:file binary flow
Check upgrading by the value of “Firmware Version” returned by summary.
All interactions are one-time TCP connections.
Reboot system
This operation restarts the control board.
1 | { |
Restore to factory setting
This operation restores the network configuration, systempasswords, user
permission, turns off the api switch, web pools set, removes pools, power
mode, power limit, etc.
1 | { |
Modify the password of admin account
The maximum password length is 8 bytes. Notice: the token must be acquired again from miner for encrypted transmission.
1 | { |
Modify network configuration
Notice: after modifying the configuration, miner will restart.
1 | { |
1 | { |
Download logs
This operation exports the miner log files.
Download flow:
Client -> miner(text flow):
1 | { |
Miner -> client(text flow):
1 | { |
Miner -> client(binary flow):
The miner sends the file contents after 10ms delay.
Set target frequency
Set a new target mining frequency, which adjusts a certain percentagebasedon the mining frequency in normal power mode (a percentage of 0 meansnoadjustment). Please note that only water-cooled and liquid-cooled machinessupport overclocking, while fan-cooled machines only support underclocking. After successful setting, the mining service will automatically restart.
1 | { |
Enablebt miner fastboot
Set the mining service to quickly increase power at startup, useful for miningfarm load power situations that require a quick start. Please note that thissetting allows the machine’s power to quickly rise to the target value, not
the hash rate to stabilize quickly, so it has little impact on the time tostabilize hash rate. The setting will take effect upon the next startupof themining service.
1 | { |
Disablebt miner fastboot
Disable the btminer fast boot mode. The setting will take effect uponthenext
startup of the mining service.
1 | { |
Enableweb pools
Allows configuration of pools on web pages with immediate effect.
1 | { |
Disableweb pools
Turn off the configure pools feature on the web page with immediate effect.
1 | { |
Set hostname
This configuration does not take effect until the network is restarted.
1 | { |
Set zone
This configuration does not take effect until the network is restarted.
1 | { |
Load log
Configure the rsyslog log server.
1 | { |
Set power percent(Fastmode)
The dynamic adjustment of the power percentage is based on the initial
stable mining power. The adjustment process is completed within onesecond. Please note that only an approximate power percentage canbeachieved, and the lowest percentage that can maintain stable operationisrelated to the machine’s own characteristics, environmental temperature, and cooling conditions. If the target percentage is too low, it may causethemachine to become unbalanced and automatically restart the miningservice. The maximum percentage cannot exceed 100%. This is recommendedfor
temporary adjustments only, as running for extended periods may leadtoinstability. Compared to Set power percent V2 (Normal mode), it is faster inadjusting power percentage, however, it comes with a greater loss inperformance. If speed of adjustment is not a priority, it is recommendedto
use Set power percent V2 (Normal mode).
1 | { |
Set power percent V2 (Normalmode)
The dynamic adjustment of power percentage is based on the initial stablemining power. This adjustment process will last for a few minutes andmayresult in a slight but not significant loss in hash rate. Please note that onlyanapproximate power percentage can be achieved, and the lowest percentagethat can maintain stable operation is related to the machine’s own
characteristics, environmental temperature, and cooling conditions. If thetarget percentage is too low, it may cause the machine to become
unbalanced and automatically restart the mining service. This functionis
only permitted for fan-cooled machines in normal or low power mode; thereare no power mode restrictions for water-cooled and liquid-cooled machines. The maximum percentage cannot exceed 100% (future versions will allowwater-cooled and liquid-cooled machines to exceed 100%). Althoughits
impact on performance is less than that of Set power percent (Fast mode), the machine is still not in its optimal state in terms of performance andstability. It is suitable for scenarios where power costs frequently changeandpower adjustments are constantly required. If there is no need for frequent
power adjustments and long-term operation at a specific power level is
preferred, it is recommended to use Adjust power limit or Set target
frequency.
1 | { |
Set temp offset
Set the target temperature offset for the machine’s hashboard (range: -30to0℃). This will increase the machine fan speed, reducing the strain onthemining farm’s cooling system. This is only effective for air-cooled machines. The setting will take effect upon the next startup of the mining service
1 | { |
Adjust power limit
Set the upper limit of the miner’s power. Not higher than the ordinary power
of the machine. If the Settings take effect, the machine will restart.
1 | { |
Adjust upfreq speed
Set the startup speed of the mining service (or the speed of the miner
frequency adjustment and stabilization). The faster the speed, the shorter thetime it takes to reach stable hash rate. 0 represents normal speed, while9represents the fastest speed. The faster the speed, the greater the deviationin target hash rate and power, and the greater the impact on performanceand stability. Fast boot mode cannot be used concurrently.
1 | { |
Set poweroff cool
Set whether to cool machine when stopping mining.
1 | { |
Set fan zero speed
Sets whether the fan speed supports the lowest 0 speed.
1 | { |
Set heat mode
The water-cooling miner is set to default anti-icing mode. The power-keeping mode ensures that the miner maintains full power duringnetwork outages.
1 | { |
Disable btminer init
Disable miner startup for mining
1 | { |
Enable btminer init
Enable miner startup for mining.
1 | { |