Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

feat/mobile-miner

First build of mobile miner support. Need to add START and STOP
commands.
  • Loading branch information...
Stoyvo committed Mar 31, 2015
1 parent bb04737 commit c86d2b9a94c3c29e8292be2858aafe0430390dc5
Showing with 194 additions and 27 deletions.
  1. +111 −17 includes/classes/mobileminer.php
  2. +2 −2 includes/head.php
  3. +8 −8 index.php
  4. +61 −0 js/dashboard/MobileMiner.js
  5. +12 −0 js/dashboard/script.js
@@ -13,65 +13,159 @@
class MobileMiner {
// Settings
protected $_url = 'https://api.mobileminerapp.com';
protected $_username = '';
protected $_apiKey = '';
// cryptoGlance Specific
protected $_appKey = 'ozhjiY941gooFo';
protected $_appKey = 'VEdP-Tmom-kiDA';
// API Specific
protected $_url = 'https://api.mobileminerapp.com/';
protected $_urlParams = '';
// Rig Data
protected $_rigs = array();
public function __construct() {
$this->_username = $GLOBALS['settings']['general']['mobileminer']['username'];
$this->_apiKey = $GLOBALS['settings']['general']['mobileminer']['apikey'];
$this->_urlParams = '?apiKey='.$this->_apiKey . '&emailAddress='.$this->_username . '&applicationKey='.$this->_appKey;
$this->_rigs = new Rigs();
}
// The app will simply update all the device data to the mobileminer api
public function getUpdate() {
$data = curlCall('https://api.mobileminerapp.com/MiningStatisticsInput?emailAddress=email@address.com&applicationKey=appkey&apiKey=apikey');
echo "<pre>";
print_r($data);
echo "</pre>";
die();
// Do nothing if it's not enabled
if (!$GLOBALS['settings']['general']['mobileminer']['enabled']) {
return;
}
// Post Pools
$this->_postPools();
// Listen for response from server
$this->_listen();
// Get all device data
$rigData = $this->_rigs->getUpdate();
// Start building request
// $this->_postStatistics();
// $this->_postPools();
// $this->_postNotifications();
// Post Stats
$this->_postStatistics();
// Done.
return;
}
protected function _listen() {
// call server for any changes
foreach ($this->_rigs->getSettings() as $rigId => $rig) {
$data = curlCall($this->_url . 'RemoteCommands' . $this->_urlParams . '&machineName=' . urlencode($rig['name']));
if (!empty($data) && !empty($data[0])) {
$command = explode('|', $data[0]['CommandText']);
$value = null;
if (is_array($command)) {
$value = $command[1];
$command = $command[0];
}
switch ($command) {
case 'SWITCH':
$poolId = $this->_findPoolIdFromName($this->_rigs->_objs[$rigId]->pools(), $value);
if (!is_null($poolId)) {
$this->_rigs->_objs[$rigId]->switchPool($poolId);
}
break;
case 'RESTART':
$this->_rigs->_objs[$rigId]->restart();
break;
case 'START':
// $this->_rigs->_objs[$rigId]->restart();
break;
case 'STOP':
// $this->_rigs->_objs[$rigId]->restart();
break;
}
curlCall($this->_url .'RemoteCommands'. $this->_urlParams .'&machineName='. urlencode($rig['name']) .'&commandId='. $data[0]['Id']);
}
}
}
protected function _postStatistics() {
// build out machine statistics
$postData = array();
foreach ($this->_rigs->getUpdate() as $rigId => $rig) {
// Each device needs to be posted as a whole different machine.
foreach ($rig['devs'] as $devId => $dev) {
$rigData = array();
$rigData['MachineName'] = $rig['overview']['name'];
$rigData['MinerName'] = 'CryptoGlance';
$rigData['CoinSymbol'] = '';
$rigData['CoinName'] = '';
$rigData['Algorithm'] = $rig['overview']['algorithm'];
// Device Specific
$rigData['Kind'] = $dev['type'];
$rigData['Name'] = $dev['name'];
$rigData['FullName'] = $dev['name'] . ' ' . $dev['id'];
$rigData['PoolIndex'] = $rig['summary']['active_pool']['id'];
$rigData['PoolName'] = $rig['summary']['active_pool']['url'];
$rigData['Index'] = $devId;
$rigData['DeviceID'] = $dev['id'];
$rigData['Enabled'] = ($dev['enabled'] == 'Y') ? 'true':'false';
$rigData['Status'] = $dev['health'];
$rigData['Temperature'] = $dev['temperature']['celsius'];
// GPU STUFF
$rigData['FanSpeed'] = $dev['fan_speed']['raw'];
$rigData['FanPercent'] = $dev['fan_speed']['percent'];
$rigData['GpuClock'] = $dev['engine_clock'];
$rigData['MemoryClock'] = $dev['memory_clock'];
$rigData['GpuVoltage'] = $dev['gpu_voltage'];
$rigData['GpuActivity'] = 0;
$rigData['PowerTune'] = $dev['powertune'];
// END GPU STUFF
$rigData['AverageHashrate'] = $dev['hashrate_avg']*1000;
$rigData['CurrentHashrate'] = $dev['hashrate_5s']*1000;
$rigData['AcceptedShares'] = $dev['accepted']['raw'];
$rigData['RejectedShares'] = $dev['rejected']['raw'];
$rigData['HardwareErrors'] = $dev['hw_errors']['raw'];
$rigData['Utility'] = $dev['utility'];
$rigData['Intensity'] = null;
// $rigData['AcceptedSharesPercent'] = $dev['accepted']['percent'];
$rigData['RejectedSharesPercent'] = $dev['rejected']['percent'];
$rigData['HardwareErrorsPercent'] = $dev['hw_errors']['percent'];
$postData[] = $rigData;
unset($rigData);
}
}
$url = $this->_url . 'MiningStatisticsInput' . $this->_urlParams;
curlCall($url, json_encode($postData));
}
protected function _postPools() {
// Post all the pools for each machine
foreach ($this->_rigs->getSettings() as $rigId => $rig) {
$url = $this->_url . 'PoolsInput' . $this->_urlParams . '&machineName=' . urlencode($rig['name']);
$pools = $this->_rigs->_objs[$rigId]->pools();
$poolData = array();
foreach ($pools as $pool) {
$poolData[] = substr($pool['url'], strpos($pool['url'], '//') + 2);
}
curlCall($url, json_encode($poolData));
}
}
protected function _postNotifications() {
// If anything serious has happened, post notifications to the API
}
protected function _findPoolIdFromName($pools, $name) {
$poolId = null;
foreach ($pools as $pool) {
if (strpos($pool['url'], $name) !== false) {
return $pool['id'];
}
}
return $poolId;
}
}
@@ -32,7 +32,7 @@
<!-- Custom cryptoGlance styles -->
<link href="css/cryptoglance-base.css?v=<?php echo CURRENT_VERSION; ?>" rel="stylesheet">
<!--/build-->

<script type="text/javascript" src="js/packages/jquery-1.10.2.min.js?v=<?php echo CURRENT_VERSION; ?>"></script>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
@@ -49,7 +49,7 @@
var rigUpdateTime = <?php echo $settings['general']['updateTimes']['rig'] ?>;
var poolUpdateTime = <?php echo $settings['general']['updateTimes']['pool'] ?>;
var walletUpdateTime = <?php echo $settings['general']['updateTimes']['wallet'] ?>;
<?php if (isset($_SERVER['PHPDESKTOP_VERSION']) && floatval($_SERVER['PHPDESKTOP_VERSION']) < 31.9) { ?>
$(document).ready(function() {
$().toastmessage('showToast', {
@@ -16,9 +16,15 @@
'dashboard/PoolCollection',
'dashboard/Pool',
'dashboard/WalletCollection',
'dashboard/Wallet',
'dashboard/script'
'dashboard/Wallet'
);
// If MobileMiner is enabled, load the JS
if (isset($settings['general']['mobileminer']['enabled']) && $settings['general']['mobileminer']['enabled'] == 1) {
$jsArray[] = 'dashboard/MobileMiner';
}
// Load Last
$jsArray[] = 'dashboard/script';
include("includes/header.php");
?>
@@ -42,7 +48,6 @@
}
include("templates/modals/switch-pool.php");
}
?>

<?php
@@ -78,11 +83,6 @@
</div>
<!-- /page-container -->


<?php //require_once("templates/modals/switch_pool.php"); ?>

<?php //require_once("templates/modals/delete_prompt.php"); ?>

<?php require_once("includes/scripts.php"); ?>
</body>
</html>
@@ -0,0 +1,61 @@
!function (root, $) {

/*===============================================================
= MobileMiner Class/Object/Constructor =
===============================================================*/

var MobileMiner = function () {
this.apiData = { type: 'mobile-miner', action: 'update' }
}

/*----- End of MobileMiner Class/Object/Constructor ------*/


/*=====================================================
= MobileMiner Public Methods =
=====================================================*/

MobileMiner.prototype.start = function () {
var _self = this;

/*========== Initial Poll ==========*/
_self._getData();

/*========== Setup polling ==========*/
setInterval(function () {
_self._getData();
}, 40000); // every 40 seconds
}

/*----- End of MobileMiner Public Methods ------*/


/*======================================================
= MobileMiner Private Methods =
======================================================*/

MobileMiner.prototype._getData = function () {
var _self = this;

$.ajax({
url: 'ajax.php',
data: _self.apiData,
dataType: 'json'
})
.fail(function (xhr, status, message) {
//console.error(message)
})
}

/*----- End of MobileMiner Private Methods ------*/


/*=============================================
= Export MobileMiner =
=============================================*/

root.MobileMiner = MobileMiner

/*----- End of Export MobileMiner ------*/

}(window, window.jQuery)
@@ -230,6 +230,18 @@
/*----- End of The Wallets ------*/


/*===================================
= MobileMiner =
===================================*/

if (typeof MobileMiner != 'undefined') {
var mobileMiner = new MobileMiner();
mobileMiner.start();
}

/*----- End of MobileMiner ------*/


/*=============================================
= Global Event Handling =
=============================================*/

0 comments on commit c86d2b9

Please sign in to comment.
You can’t perform that action at this time.