Post
Topic
Board Mining support
Merits 12 from 3 users
Re: [Reference] May 2019 "Multi-Level" menu values
by
s3binator
on 03/08/2019, 16:15:13 UTC
⭐ Merited by frodocooper (10) ,tim-bc (1) ,BitMaxz (1)
So I wanted to contribute by showing how I did this using requests, but I have a little snag EDIT: FIXED. Everything works except for the working mode never updates. The config file that is loaded when loading the configuration page gives

Code:
"bitmain-low-vol" : "",

No matter what I place into the '_ant_multi_level' field, it's always blank, and this forces Working Mode to be set to Normal via the get_miner_conf javascript function.

I unpacked the newest firmware, and found the set_miner_config.cgi file. It looks like this:

Code:
#!/bin/sh
#set -x

ant_pool1url=
ant_pool1user=
ant_pool1pw=
ant_pool2url=
ant_pool2user=
ant_pool2pw=
ant_pool3url=
ant_pool3user=
ant_pool3pw=
ant_nobeeper=
ant_notempoverctrl=
ant_fan_customize_value=
ant_fan_customize_switch=
ant_freq=
ant_voltage=
ant_asic_boost=
ant_low_vol_freq=
ant_economic_mode=
ant_low_vol=


ant_input=`cat /dev/stdin`
ant_tmp=${ant_input//&/ }
i=0
for ant_var in ${ant_tmp}
do
ant_var=${ant_var//+/ }
ant_var=${ant_var//%23/#}
ant_var=${ant_var//%24/$}
ant_var=${ant_var//%25/%}
ant_var=${ant_var//%26/&}
ant_var=${ant_var//%2C/,}
ant_var=${ant_var//%2B/+}
ant_var=${ant_var//%3A/:}
ant_var=${ant_var//%3B/;}
ant_var=${ant_var//%3C/<}
ant_var=${ant_var//%3D/=}
ant_var=${ant_var//%3E/>}
ant_var=${ant_var//%3F/?}
ant_var=${ant_var//%40/@}
ant_var=${ant_var//%5B/[}
ant_var=${ant_var//%5D/]}
ant_var=${ant_var//%5E/^}
ant_var=${ant_var//%7B/\{}
ant_var=${ant_var//%7C/|}
ant_var=${ant_var//%7D/\}}
ant_var=${ant_var//%2F/\/}
#ant_var=${ant_var//%22/\"}
#ant_var=${ant_var//%5C/\\}
case ${i} in
0 )
ant_pool1url=${ant_var/_ant_pool1url=/}
;;
1 )
ant_pool1user=${ant_var/_ant_pool1user=/}
;;
2 )
ant_pool1pw=${ant_var/_ant_pool1pw=/}
;;
3 )
ant_pool2url=${ant_var/_ant_pool2url=/}
;;
4 )
ant_pool2user=${ant_var/_ant_pool2user=/}
;;
5 )
ant_pool2pw=${ant_var/_ant_pool2pw=/}
;;
6 )
ant_pool3url=${ant_var/_ant_pool3url=/}
;;
7 )
ant_pool3user=${ant_var/_ant_pool3user=/}
;;
8 )
ant_pool3pw=${ant_var/_ant_pool3pw=/}
;;
9 )
ant_nobeeper=${ant_var/_ant_nobeeper=/}
;;
10 )
ant_notempoverctrl=${ant_var/_ant_notempoverctrl=/}
;;
11 )
ant_fan_customize_switch=${ant_var/_ant_fan_customize_switch=/}
;;
12 )
ant_fan_customize_value=${ant_var/_ant_fan_customize_value=/}
;;
13 )
ant_freq=${ant_var/_ant_freq=/}
;;
14 )
ant_voltage=${ant_var/_ant_voltage=/}
;;
15 )
ant_asic_boost=${ant_var/_ant_asic_boost=/}
;;
16 )
ant_low_vol_freq=${ant_var/_ant_low_vol_freq=/}
;;
17 )
ant_economic_mode=${ant_var/_ant_economic_mode=/}
;;
18 )
ant_low_vol=${ant_var/_ant_multi_level=/}
;;
esac
i=`expr $i + 1`
done

echo "{" >  /config/bmminer.conf
echo "\"pools\" : [" >> /config/bmminer.conf
echo "{" >> /config/bmminer.conf
echo "\"url\" : \"${ant_pool1url}\"," >> /config/bmminer.conf
echo "\"user\" : \"${ant_pool1user}\"," >> /config/bmminer.conf
echo "\"pass\" : \"${ant_pool1pw}\"" >> /config/bmminer.conf
echo "}," >> /config/bmminer.conf
echo "{" >> /config/bmminer.conf
echo "\"url\" : \"${ant_pool2url}\"," >> /config/bmminer.conf
echo "\"user\" : \"${ant_pool2user}\"," >> /config/bmminer.conf
echo "\"pass\" : \"${ant_pool2pw}\"" >> /config/bmminer.conf
echo "}," >> /config/bmminer.conf
echo "{" >> /config/bmminer.conf
echo "\"url\" : \"${ant_pool3url}\"," >> /config/bmminer.conf
echo "\"user\" : \"${ant_pool3user}\"," >> /config/bmminer.conf
echo "\"pass\" : \"${ant_pool3pw}\"" >> /config/bmminer.conf
echo "}" >> /config/bmminer.conf
echo "]" >> /config/bmminer.conf
echo "," >> /config/bmminer.conf
echo "\"api-listen\" : true," >> /config/bmminer.conf
echo "\"api-network\" : true," >> /config/bmminer.conf
echo "\"api-groups\" : \"A:stats:pools:devs:summary:version\","                          >> /config/bmminer.conf
echo "\"api-allow\" : \"A:0/0,W:*\","                       >> /config/bmminer.conf
if [ "${ant_nobeeper}" = "true" ]; then
echo "\"bitmain-nobeeper\" : "true"," >> /config/bmminer.conf
fi
if [ "${ant_notempoverctrl}" = "true" ]; then
echo "\"bitmain-notempoverctrl\" : "true"," >> /config/bmminer.conf
fi

if [ "${ant_fan_customize_switch}" = "true" ]; then
echo "\"bitmain-fan-ctrl\" : "true"," >> /config/bmminer.conf
echo "\"bitmain-fan-pwm\" : \"${ant_fan_customize_value}\"," >> /config/bmminer.conf

fi
echo "\"bitmain-use-vil\" : "true"," >> /config/bmminer.conf
echo "\"bitmain-freq\" : \"${ant_freq}\"," >> /config/bmminer.conf
#if [ "${ant_asic_boost}" = "true" ]; then
#    echo "\"bitmain-close-asic-boost\" : true," >> /config/bmminer.conf
#fi
if [ "${ant_low_vol_freq}" = "true" ]; then
    echo "\"bitmain-close-low-vol-freq\" : true," >> /config/bmminer.conf
fi
if [ "${ant_economic_mode}" = "true" ]; then
    echo "\"bitmain-economic-mode\" : true," >> /config/bmminer.conf
fi

echo "\"bitmain-low-vol\" : \"${ant_low_vol}\"," >> /config/bmminer.conf

echo "\"bitmain-voltage\" : \"0706\"" >> /config/bmminer.conf
echo "}"        >> /config/bmminer.conf
sync &
sleep 1s

# cp /www/pages/cgi-bin/minerConfiguration2.cgi /www/pages/cgi-bin/minerConfiguration.cgi -f
sync

/etc/init.d/bmminer.sh restart >/dev/null 2>&1

sleep 5s

echo "ok"

It seems like the code I provide below should work. Are there any suggestions or thoughts? Note: The URLEncode line below my dictionary converts the dictionary into the same format as Tim's data.

EDIT: There was one field missing '_ant_voltage', in both Tim's and my data payload. This missing field caused the set_miner_conf.cgi bash script to improperly read what was sent after the '_ant_freq' field. I have updated the code below to working code, along with a working payload for curl.

Code:
from requests.auth import HTTPDigestAuth
import requests
import urllib.parse

ip = 'ip'
url = 'http://' + ip + '/cgi-bin/set_miner_conf.cgi'
data = {}
data['_ant_pool1url'] = 'url1'
data['_ant_pool1user'] = 'user1'
data['_ant_pool1pw'] = 'x'
data['_ant_pool2url'] = 'url2'
data['_ant_pool2user'] = 'user2'
data['_ant_pool2pw'] = 'x'
data['_ant_pool3url'] = 'url3'
data['_ant_pool3user'] = 'user3'
data['_ant_pool3pw'] = 'x'
data['_ant_nobeeper'] = 'false'
data['_ant_notempoverctrl'] = 'false'
data['_ant_fan_customize_switch'] = 'false'
data['_ant_fan_customize_value'] = ''
data['_ant_freq'] = ''
data['_ant_voltage'] = ''
data['_ant_asic_boost'] = 'false'
data['_ant_low_vol_freq'] = 'false'
data['_ant_economic_mode'] = 'false'
data['_ant_multi_level'] = '240'
payload = urllib.parse.urlencode(data)
r = requests.post(url, auth=HTTPDigestAuth('root', 'root'), data=payload)

The payload is the string:

Code:
_ant_pool1url=url1&_ant_pool1user=user1&_ant_pool1pw=x&_ant_pool2url=url2&_ant_pool2user=user2&_ant_pool2pw=x&_ant_pool3url=url3&_ant_pool3user=user3&_ant_pool3pw=x&_ant_nobeeper=false&_ant_notempoverctrl=false&_ant_fan_customize_switch=false&_ant_fan_customize_value=&_ant_freq=&_ant_voltage=&_ant_asic_boost=false&_ant_low_vol_freq=true&_ant_economic_mode=false&_ant_multi_level=240

The above string can be used with curl, as shown by Tim in the original post.