コード例 #1
0
ファイル: lib.modbus.php プロジェクト: aprsworld/pmodbusq
function getModbusRegistersPackedAsString($modbusHostname, $slaveAddress, $startRegister, $nRegisters)
{
    $r = getModbusRegisters($modbusHostname, $slaveAddress, $startRegister, $nRegisters);
    $s = '';
    foreach ($r as $val) {
        $hb = $val >> 8 & 0xff;
        $lb = $val & 0xff;
        $s .= chr($hb);
        $s .= chr($lb);
    }
    return $s;
}
コード例 #2
0
require_once dirname(__FILE__) . '/../pmodbusq.php';
require_once 'lib/lib.modbus.php';
require_once 'lib/lib.pcwx.php';
require_once 'lib/lib.xrw2g.php';
require_once 'lib/lib.senddata.php';
$dname = 'A3351';
if ($_SERVER['argc'] != 3 || false === strpos($_SERVER['argv'][2], ':')) {
    printf("usage: %s datetime hostname:destination[,hostname1:port1,...hostnameN:portN]\n", $_SERVER['argv'][0]);
    return 1;
}
$datetime = $_SERVER['argv'][1];
$dest = $_SERVER['argv'][2];
/* modbus registers read from XRW2G */
$r = array();
/* current value registers */
$r = $r + getModbusRegisters('192.168.8.2:505', 24, 0, 46);
print_r($r);
$jd = array();
$jd[$dname]['A4258'] = array();
/* first class anemometer on big tower */
$wa0 = pcwx_anemometer_average(0.0462, 0.21, $r[0], $r[43] / 100.0);
$ws0 = pcwx_anemometer(0.0462, 0.21, $r[1]);
$wg0 = pcwx_anemometer(0.0462, 0.21, $r[2]);
$wc0 = $r[0];
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Wind Average (Primary)', 'm/s', $wa0, 'speed', 'm/s', true);
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Wind Speed (Primary)', 'm/s', $ws0, 'speed', 'm/s', true);
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Wind Gust (Primary)', 'm/s', $wg0, 'speed', 'm/s', true);
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Wind Count (Primary)', '', $wc0, '', '', true);
/* NRG #40HC on big tower */
$wa1 = pcwx_anemometer_average(0.765, 0.35, $r[6], $r[43] / 100.0);
$ws1 = pcwx_anemometer(0.765, 0.35, $r[7]);
コード例 #3
0
    $hostname = substr($hostname, 3);
}
/* allow overriding hostname */
if ($_SERVER['argc'] == 3) {
    $hostname = $_SERVER['argv'][2];
    $_SERVER['argc']--;
}
if ($_SERVER['argc'] != 2 || false === strpos($_SERVER['argv'][1], ':')) {
    printf("usage: %s hostname:destination[,hostname1:port1,...hostnameN:portN]\n", $_SERVER['argv'][0]);
    return 1;
}
$dest = $_SERVER['argv'][1];
/* modbus registers read from pcp board */
$r = array();
/* current value registers */
$r = $r + getModbusRegisters('localhost', 38, 0, 20);
$jd = array();
$jd[$hostname]['sensors'] = array();
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Input Voltage', 'volts', $r[1] * 0.03418);
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Magnetic Switch State', '', $r[6]);
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Magnetic Switch Latch', '', $r[7]);
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Sequence Number', '', $r[10]);
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Ticks', 'seconds', $r[11] * 0.001);
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Uptime', 'minutes', $r[12]);
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Watchdog Timer', 'seconds', $r[13]);
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Packet Date', 'UTC', date("Y-m-d H:i:s"));
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Linux Uptime', '', exec("uptime"));
//$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('802.11 Signal','',exec('iwconfig wlan0 | grep Quality | cut -c 11-'));
/* send data to broadcast server(s) */
print_r($jd);
sendDataTCP($dest, $jd);
コード例 #4
0
require_once dirname(__FILE__) . '/../pmodbusq.php';
require_once 'lib/lib.modbus.php';
require_once 'lib/lib.pcwx.php';
require_once 'lib/lib.xrw2g.php';
require_once 'lib/lib.senddata.php';
$dname = 'A3351';
if ($_SERVER['argc'] != 3 || false === strpos($_SERVER['argv'][2], ':')) {
    printf("usage: %s datetime hostname:destination[,hostname1:port1,...hostnameN:portN]\n", $_SERVER['argv'][0]);
    return 1;
}
$datetime = $_SERVER['argv'][1];
$dest = $_SERVER['argv'][2];
/* modbus registers read from XRW2G */
$r = array();
/* current value registers */
$r = $r + getModbusRegisters('192.168.8.2:503', 90, 0, 46);
print_r($r);
$jd = array();
$jd[$dname]['A3458'] = array();
/* anemometer on top of container */
$ws = pcwx_anemometer(0.765, 0.35, $r[1]);
$wg = pcwx_anemometer(0.765, 0.35, $r[2]);
$wa = pcwx_anemometer_average(0.765, 0.35, $r[0], $r[43] / 100.0);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Wind Speed', 'm/s', $ws, 'speed', 'm/s', true);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Wind Gust', 'm/s', $wg, 'speed', 'm/s', true);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Wind Average', 'm/s', $wa, 'speed', 'm/s', true);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Wind Count', '', $r[0], '', '', true);
/* top of container / purple wires wind turbine */
$rpm = pcwx_anemometer(12.0, 0.0, $r[7]);
$rpmGust = pcwx_anemometer(12.0, 0.0, $r[8]);
$rpmAverage = pcwx_anemometer_average(12.0, 0.0, $r[6], $r[43] / 100.0);
コード例 #5
0
require_once dirname(__FILE__) . '/../pmodbusq.php';
require_once 'lib/lib.modbus.php';
require_once 'lib/lib.pcwx.php';
require_once 'lib/lib.xrw2g.php';
require_once 'lib/lib.senddata.php';
$dname = 'A3351';
if ($_SERVER['argc'] != 3 || false === strpos($_SERVER['argv'][2], ':')) {
    printf("usage: %s datetime hostname:destination[,hostname1:port1,...hostnameN:portN]\n", $_SERVER['argv'][0]);
    return 1;
}
$datetime = $_SERVER['argv'][1];
$dest = $_SERVER['argv'][2];
/* modbus registers read from XRW2G */
$r = array();
/* current value registers */
$r = $r + getModbusRegisters('192.168.8.2:504', 1, 0, 8);
//print_r($r);
$jd = array();
$jd[$dname]['ADAM0'] = array();
/* ROUND((5/65536)*(^^analog0-1)*19.99663-0.00161,2) AS vBatt12 */
$vBatt12 = 5 / 65536 * ($r[0] - 1) * 19.99663 - 0.00161;
$jd[$dname]['ADAM0'] += pcwx_encodeForBroadcast('vBatt12', 'VDC', $vBatt12, '', '', true);
/* ROUND((5/65536)*(^^analog1-1)*19.99813-0.00832,2) AS vBatt24 */
$vBatt24 = 5 / 65536 * ($r[1] - 1) * 19.99813 - 0.008319999999999999;
$jd[$dname]['ADAM0'] += pcwx_encodeForBroadcast('vBatt24', 'VDC', $vBatt24, '', '', true);
/* ROUND((5/65536)*(^^analog2-1)*20.00126-0.00182,2) AS vBatt48 */
$vBatt48 = 5 / 65536 * ($r[2] - 1) * 20.00126 - 0.00182;
$jd[$dname]['ADAM0'] += pcwx_encodeForBroadcast('vBatt48', 'VDC', $vBatt48, '', '', true);
/* ROUND(((10/65535)*(^^analog3-32768))*10.9375,3) AS iRectifier24_1 */
$iRectifier24_1 = 10 / 65535 * ($r[3] - 32768) * 10.9375;
$jd[$dname]['ADAM0'] += pcwx_encodeForBroadcast('iRectifier24_1', 'amps', $iRectifier24_1, '', '', true);
コード例 #6
0
$t_hs = $r[0xe];
if ($t_hs > 32767) {
    $t_hs = $t_hs - 65536;
}
$jd[$hostname]['TriStar'] += pcwx_encodeForBroadcast('Heatsink Temperature', '°C', $t_hs, 'temperature', 'c');
$t_batt = $r[0xf];
if ($t_batt > 32767) {
    $t_batt = $t_batt - 65536;
}
$jd[$hostname]['TriStar'] += pcwx_encodeForBroadcast('Battery Temperature', '°C', $t_batt, 'temperature', 'c');
$jd[$hostname]['TriStar'] += pcwx_encodeForBroadcast('Reference Voltage', 'VDC', $r[0x10] * 96.667 * pow(2, -15));
$jd[$hostname]['TriStar'] += pcwx_encodeForBroadcast('Duty Cycle', '%', $r[0x1c]);
/* SunSaver MPPT on modbus, device ID=2 */
/* current value registers */
printf("Querying SunSaver MPPT\n");
$r = getModbusRegisters('localhost', 2, 8, 20);
print_r($r);
$jd[$hostname]['SunSaverMPPT'] = array();
$jd[$hostname]['SunSaverMPPT'] += pcwx_encodeForBroadcast('Packet Date', 'UTC', date("Y-m-d H:i:s"));
/* sunsaver MPPT */
$jd[$hostname]['SunSaverMPPT'] += pcwx_encodeForBroadcast('Battery Voltage', 'VDC', $r[8] * 100 * pow(2, -15));
$jd[$hostname]['SunSaverMPPT'] += pcwx_encodeForBroadcast('Array Voltage', 'VDC', $r[9] * 100 * pow(2, -15));
$jd[$hostname]['SunSaverMPPT'] += pcwx_encodeForBroadcast('Load Voltage', 'VDC', $r[10] * 100 * pow(2, -15));
$jd[$hostname]['SunSaverMPPT'] += pcwx_encodeForBroadcast('Charging Current', 'A', $r[11] * 79.16 * pow(2, -15));
$jd[$hostname]['SunSaverMPPT'] += pcwx_encodeForBroadcast('Load Current', 'A', $r[12] * 79.16 * pow(2, -15));
/* signed temperatures */
if ($r[13] > 32767) {
    $r[13] -= 65536;
}
$jd[$hostname]['SunSaverMPPT'] += pcwx_encodeForBroadcast('Heatsink Temperature', '°C', $r[13], 'temperature', 'c');
if ($r[14] > 32767) {