function xap_sendQueryMsg($msg, $target = '', $source = '', $uid = '') { xap_sendMsg("xAPBSC.query", $msg, $target, $source, $uid); }
function send_data() { global $debug, $minmax; $s = enumerate_w1_sensors(); if (is_array($s)) { foreach ($s as $k => $v) { //$k=xap_id $v=sensor metadata if ($v['AVAILABLE'] == 'YES') { if ($v['TYPE'] == 28) { //1 wire temperature sensor $id = $v['TYPE'] . '-' . $v['SENSOR_ID']; logformat(sprintf("Reading 1 wire temperature sensor with ID: '%s' and NAME: '%s'.\n", $id, $v['NAME'])); $cmd = 'cat ' . SENSORPATH . '/' . $id . '/w1_slave'; $r = explode("\n", `{$cmd}`); if (substr($r[0], -3) == 'YES') { $t = explode("=", $r[1]); $temp = sprintf("%.03f", $t[1] / 1000); $dt = date('YmdHis'); // deal with min and max values and save them if (!isset($minmax[$id])) { $minmax[$id] = array('min' => $temp, 'mintime' => $dt, 'max' => $temp, 'maxtime' => $dt); } if ($temp < $minmax[$id]['min']) { $minmax[$id]['min'] = $temp; $minmax[$id]['mintime'] = $dt; } if ($temp > $minmax[$id]['max']) { $minmax[$id]['max'] = $temp; $minmax[$id]['maxtime'] = $dt; } logformat(sprintf("Id=%s,Name=%s,Data=%s°C\n", $id, $v['NAME'], $temp)); $msg = sprintf("info.temperature\n{\nname=%s\ndatetime=%s\nunit=c\nvalue=%s\nsensorId=%s\n}\n", XAPSOURCE . '.' . $v['NAME'], $dt, $temp, $id); $msg .= sprintf("stats.temperature\n{\nmax=%s\nmaxtime=%s\nmin=%s\nmintime=%s\n}\n", $minmax[$id]['max'], $minmax[$id]['maxtime'], $minmax[$id]['min'], $minmax[$id]['mintime']); xap_sendMsg('xAPTSC.info', $msg, '', xap_make_endpoint_source(XAPSOURCE, $k), xap_make_endpoint_uid(XAPUID, $k)); } } } else { logformat(sprintf("Skipping 1 wire sensor with ID: '%s-%s' and NAME: '%s'.\n", $v['TYPE'], $v['SENSOR_ID'], $v['NAME'])); } } } return 1; }