$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]);
$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 */
$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);
/* send data to broadcast server(s) */