$value) { // looking for suffixes and redirecting them /* Weatherunderground format looks like this: * ID ID (configuratble in the App) * PASSWORD KEY (configurable in the App) * indoortempf in Fahrenheit * windchillf in Fahrenheit * indoorhumidity in percent * humidity in pfpro_cleanup * windspeedmph in mp/h * windgustmph in mp/h * winddir in degrees * absbaromin in inch of mercury * baromin in inch of mercury * rainin in inch * dailyrainin in inch * weeklyrainin in inch * monthlyrainin in inch * solarradiation in W/m2 * UV in index (0 - 11) * dateutc current date (UTC) * softwaretype used software * action usually "updateraw" * realtime using real-time updates (0/1) * rtfreq update frequency (configurable in the App) as seen here, with the last character(s) of a attribute you can tell, which unit is used */ switch (substr($key, -3)) { case "mpf": // unit is in Fahrenheit (remove "f") sendOH2Command($weatherprefix.str_replace("mpf", "mp", $key), f2c($value)); break; case "ptf": // unit is in Fahrenheit also (remove "f") sendOH2Command($weatherprefix.str_replace("ptf", "pt", $key), f2c($value)); break; case "llf": // unit is in Fahrenheit also (remove "f") sendOH2Command($weatherprefix.str_replace("llf", "ll", $key), f2c($value)); break; case "min": // unit is in inHg (remove "min") sendOH2Command($weatherprefix.str_replace("min", "", $key), inHG2hPa($value)); break; case "nin": // unit is in inch (remove "in") sendOH2Command($weatherprefix.str_replace("nin", "n", $key), in2cm($value)); break; case "mph": // unit is in mph (remove "mph") sendOH2Command($weatherprefix.str_replace("mph", "", $key), mph2kmh($value)); break; case "utc": // unit is in UTC sendOH2Command($weatherprefix.$key, str2UTC($value).""); break; default: // everything else: not a unit, or percent or string sendOH2Command($weatherprefix.$key, $value); } } function sendOH2Command($item, $data) { $url = "http://192.168.1.100:8080/rest/items/" . $item; $options = array( 'http' => array( 'header' => "Content-type: text/plain\r\n", 'method' => 'POST', 'content' => '' . $data //http_build_query($data), ), ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); return $result; } function str2UTC($given_value) { return str_replace(" ", "T", $given_value); } function mph2kmh($given_value) { return '' . round( floatval($given_value) * 1.60934, 1); } function in2cm($given_value) { return '' . round( floatval($given_value) * 2.54, 1); } function inHG2hPa($given_value) { return '' . round( floatval($given_value) * 33.8639 , 1); //1 inHG = 3386,39 Pa, Bespielwert: 29.064 sollte ca 985 sein } function f2c($given_value) { return '' . round( (5.0 / 9 * (floatval($given_value) - 32 )), 1); } ?>