I'm using raspberry pi with jmordica cgminer.
sometimes one off the blade Off. it's happen for any freq, 83x,850,86x.
I just need to restart the cgminer to make it hashing again.
Is there anyway to automatically restart cgminer when the blade off ?
little quick and dirty php code to restart cgminer when one or all blade off.
run this using php cli
#
# Sample Socket I/O to CGMiner API
#
function getsock($addr, $port)
{
$socket = null;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false || $socket === null)
{
$error = socket_strerror(socket_last_error());
$msg = "socket create(TCP) failed";
echo "ERR: $msg '$error'\n";
return null;
}
$res = socket_connect($socket, $addr, $port);
if ($res === false)
{
$error = socket_strerror(socket_last_error());
$msg = "socket connect($addr,$port) failed";
echo "ERR: $msg '$error'\n";
socket_close($socket);
return null;
}
return $socket;
}
#
# Slow ...
function readsockline($socket)
{
$line = '';
while (true)
{
$byte = socket_read($socket, 1);
if ($byte === false || $byte === '')
break;
if ($byte === "�")
break;
$line .= $byte;
}
return $line;
}
#
function request($cmd)
{
$socket = getsock('127.0.0.1', 4001);
if ($socket != null)
{
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec'=>2, 'usec'=>2000));
socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec'=>2, 'usec'=>2000));
socket_write($socket, $cmd, strlen($cmd));
$line = readsockline($socket);
socket_close($socket);
if (strlen($line) == 0)
{
echo "WARN: '$cmd' returned nothing\n";
return $line;
}
// print "$cmd returned '$line'\n";
if (substr($line,0,1) == '{')
{
echo "tes\n";
return json_decode($line, true);
}
$data = array();
$objs = explode('|', $line);
foreach ($objs as $obj)
{
if (strlen($obj) > 0)
{
$items = explode(',', $obj);
$item = $items[0];
$id = explode('=', $items[0], 2);
if (count($id) == 1 or !ctype_digit($id[1]))
$name = $id[0];
else
$name = $id[0].$id[1];
if (strlen($name) == 0)
$name = 'null';
if (isset($data[$name]))
{
$num = 1;
while (isset($data[$name.$num]))
$num++;
$name .= $num;
}
$counter = 0;
foreach ($items as $item)
{
$id = explode('=', $item, 2);
if (count($id) == 2)
$data[$name][$id[0]] = $id[1];
else
$data[$name][$counter] = $id[0];
$counter++;
}
}
}
return $data;
}
return null;
}
while(true) {
if (isset($argv) and count($argv) > 1)
$r = request($argv[1]);
else
$r = request('notify');
#echo print_r($r, true);
$bl0 = $r["NOTIFY0"]["Last Not Well"];
$bl1 = $r["NOTIFY1"]["Last Not Well"];
if ( $bl0 or $bl1 )
exec("killall cgminer");
echo date("YmdHis") . " : $bl0 dan $bl1\n";
#echo intval($st) - 4 ;
sleep(60);
}
?>