Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shows vcgenmod throttle status of raspberry pi #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions conf/esm.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"enable": true,
"max": 5
},
"pistatus": {
"enable": false
},
"services": {
"show_port": true,
"list": [
Expand Down
17 changes: 17 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,24 @@
</div>
</div>

<div class="box column-left column-33" id="esm-pistatus">
<div class="box-header">
<h1>Pi status</h1>
<ul>
<li><a href="#" class="reload" onclick="esm.reloadBlock('pistatus');"><span class="icon-cycle"></span></a></li>
</ul>
</div>

<div class="box-content">
<?php if ($Config->get('pistatus:enable') == true): ?>
<table>
<tbody></tbody>
</table>
<?php else: ?>
<p>Disabled</p>
<?php endif; ?>
</div>
</div>

<div class="box column-right column-33" id="esm-services">
<div class="box-header">
Expand Down
35 changes: 34 additions & 1 deletion js/esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,37 @@ esm.getPing = function() {

}

esm.getPiStatus = function() {

var module = 'pistatus';

esm.reloadBlock_spin(module);

$.get('libs/'+module+'.php', function(data) {

var $box = $('.box#esm-'+module+' .box-content tbody');
$box.empty();

for (var line in data)
{
var label_color = data[line].status == 1 ? 'error' : 'success';
var label_status = data[line].status == 1 ? 'on' : 'off';

var html = '';
html += '<tr>';
html += '<td class="w5p"><span class="label '+label_color+'">'+label_status+'</span></td>';
html += '<td>'+data[line].name+'</td>';
html += '</tr>';

$box.append(html);
}

esm.reloadBlock_spin(module);

}, 'json');

}


esm.getServices = function() {

Expand Down Expand Up @@ -305,6 +336,7 @@ esm.getAll = function() {
esm.getLast_login();
esm.getNetwork();
esm.getPing();
esm.getPiStatus();
esm.getServices();
}

Expand Down Expand Up @@ -367,5 +399,6 @@ esm.mapping = {
last_login: esm.getLast_login,
network: esm.getNetwork,
ping: esm.getPing,
pistatus: esm.getPiStatus,
services: esm.getServices
};
};
51 changes: 51 additions & 0 deletions libs/pistatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
require '../autoload.php';

const Under_Voltage_Detected = 0b00000000000000000001;
const ARM_Frequency_Capped = 0b00000000000000000010;
const Currently_Throttled = 0b00000000000000000100;
const Soft_Temperature_Limit_Active = 0b00000000000000001000;
const Under_Voltage_Has_Occurred = 0b00010000000000000000;
const ARM_Frequency_Capping_Has_Occurred = 0b00100000000000000000;
const Throttling_Has_Occurred = 0b01000000000000000000;
const Soft_Temperature_Limit_Has_Occurred = 0b10000000000000000000;


$Config = new Config();


$datas = array();

if ($Config->get('pistatus:enable'))
{


$vcgencmd_output = hexdec(trim(shell_exec('vcgencmd get_throttled'), 'throttled='));

if ($vcgencmd_output & Under_Voltage_Detected) { $datas[] = array( 'name' => "Under voltage detected" , 'status' => 1 ); }
else { $datas[] = array( 'name' => "Under Voltage detected" , 'status' => 0 ); }

if ($vcgencmd_output & ARM_Frequency_Capped) { $datas[] = array( 'name' => "ARM frequency capped" , 'status' => 1 ); }
else { $datas[] = array( 'name' => "ARM frequency capped" , 'status' => 0 ); }

if ($vcgencmd_output & Currently_Throttled) { $datas[] = array( 'name' => "Currently throttled" , 'status' => 1 ); }
else { $datas[] = array( 'name' => "Currently throttled" , 'status' => 0 ); }

if ($vcgencmd_output & Soft_Temperature_Limit_Active) { $datas[] = array( 'name' => "Soft temperature limit active" , 'status' => 1 ); }
else { $datas[] = array( 'name' => "Soft temperature limit active" , 'status' => 0 ); }

if ($vcgencmd_output & Under_Voltage_Has_Occurred) { $datas[] = array( 'name' => "Under voltage has occurred" , 'status' => 1 ); }
else { $datas[] = array( 'name' => "Under voltage has occurred" , 'status' => 0 ); }

if ($vcgencmd_output & ARM_Frequency_Capping_Has_Occurred) { $datas[] = array( 'name' => "ARM frequency capping has occurred" , 'status' => 1 ); }
else { $datas[] = array( 'name' => "ARM frequency capping has occurred" , 'status' => 0 ); }

if ($vcgencmd_output & Throttling_Has_Occurred) { $datas[] = array( 'name' => "Throttling has occurred" , 'status' => 1 ); }
else { $datas[] = array( 'name' => "Throttling has occurred" , 'status' => 0 ); }

if ($vcgencmd_output & Soft_Temperature_Limit_Has_Occurred) { $datas[] = array( 'name' => "Soft temperature limit has occurred" , 'status' => 1 ); }
else { $datas[] = array( 'name' => "Soft temperature limit has occurred" , 'status' => 0 ); }
}

echo json_encode($datas);