示例#1
0
if ('cam' == substr($hostname, 0, 3)) {
    $hostname = substr($hostname, 3);
}
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 XRW2G */
$r = array();
/* current value registers */
$r = $r + getModbusRegisters('localhost', 38, 0, 47);
$jd = array();
$jd[$hostname]['sensors'] = array();
$ws = pcwx_anemometer(0.765, 0.35, $r[1]);
$wg = pcwx_anemometer(0.765, 0.35, $r[2]);
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Wind Speed', 'm/s', $ws, 'speed', 'm/s');
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Wind Gust', 'm/s', $wg, 'speed', 'm/s');
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Input Voltage', 'volts', $r[18] * 0.024477);
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Temperature', '°C', $r[30] * 0.001220703 * 39.394 - 30.0, 'temperature', 'c');
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Relative Humidity', '%', $r[33] * 0.001220703 * 30.303);
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Sequence Number', '', $r[42]);
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Ticks', 'seconds', $r[43] * 0.001);
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Uptime', 'minutes', $r[44]);
$jd[$hostname]['sensors'] += pcwx_encodeForBroadcast('Watchdog Timer', 'seconds', $r[45]);
$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);
$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]);
$wg1 = pcwx_anemometer(0.765, 0.35, $r[8]);
$wc1 = $r[6];
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Wind Average (Secondary)', 'm/s', $wa1, 'speed', 'm/s', true);
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Wind Speed (Secondary)', 'm/s', $ws1, 'speed', 'm/s', true);
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Wind Gust (Secondary)', 'm/s', $wg1, 'speed', 'm/s', true);
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Wind Count (Secondary)', '', $wc1, '', '', true);
/* turbine on big tower */
$rpma = pcwx_anemometer_average(12.0, 0.0, $r[12], $r[43] / 100.0);
$rpms = pcwx_anemometer(12.0, 0.0, $r[13]);
$rpmg = pcwx_anemometer(12.0, 0.0, $r[14]);
$rpmc = $r[12];
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Turbine Rotor Average', 'RPM', $rpma, '', '', true);
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Turbine Rotor Speed', 'RPM', $rpms, '', '', true);
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Turbine Rotor Gust', 'RPM', $rpmg, '', '', true);
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Turbine Rotor Count', '', $rpmc, '', '', true);
/* wind vane on big tower */
/* MOD(ROUND((^^analog1Current/4096.0)*360.0+145.0,0),360) AS windDirection */
$wd = ($r[21] * XR2G_VIN_V_PER_BIT * 360.0 + 145.0) % 360;
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Wind Direction', '°', $wd, '', '', true);
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Supply Voltage', 'volts', $r[19] * XR2G_VIN_V_PER_BIT);
$temperatureAmbient = $r[28] * XRW2G_5VOLT_V_PER_BIT * 100.0 - 273.15;
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Ambient Temperature', '°C', $temperatureAmbient, 'temperature', 'c', true);
/* meta data */
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Modbus Host', '', '192.168.8.2:505');
$jd[$dname]['A4258'] += pcwx_encodeForBroadcast('Sequence Number', '', $r[42], '', '', true);
/* 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);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Container Turbine Rotor Speed', 'RPM', $rpm, '', '', true);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Container Turbine Rotor Gust', 'RPM', $rpmGust, '', '', true);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Container Turbine Rotor Average', 'RPM', $rpmAverage, '', '', true);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Container Turbine Rotor Count', '', $r[6], '', '', true);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Supply Voltage', 'volts', $r[19] * XR2G_VIN_V_PER_BIT);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('12V Rectifier 1 Temperature', '°C', $r[28] * XRW2G_5VOLT_V_PER_BIT * 100.0 - 273.15, 'temperature', 'c', true);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Matrix Open Circuit Voltage', 'VDC', $r[31] * XRW2G_5VOLT_V_PER_BIT * 20.0);
/* meta data */
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Modbus Host', '', '192.168.8.2:503');
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Sequence Number', '', $r[42], '', '', true);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Ticks', 'seconds', $r[43] / 100.0, '', '', true);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Uptime', 'minutes', $r[44], '', '', true);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Packet Date', 'UTC', $datetime, '', '', true);
$jd[$dname]['A3458'] += pcwx_encodeForBroadcast('Run Date', '', $_SERVER['REQUEST_TIME_FLOAT'], '', '', true);