Čtvrtek, Duben 27, 2017

Plugin teploměr

Zobrazuje data z wifi teploměru

Naměřené hodnoty jsou ukládány do free cloudu na tmep.cz

lze tedy zobrazovat historii naměřených hodnot, např. rouchovany.tmep.cz

Zobrazení posledního měření:

function plugin_thermometer_widget() {

$url = "http://tmep.cz/vystup-json.php?id=658&export_key=t6e3c5wbrj";

$quote = file_get_contents($url);

$json ='[ '.$quote.' ]';

$data = json_decode($json, TRUE);

$rate = $data[0]["teplota"]; 

$rate1 = $data[0]["vlhkost"]; 

$rate2 = $data[0]["cas"]; 

$rate2=substr($rate2,0,(strlen($rate2)-3)); // zkrácení o sekundy

$rate3 = $data[0]["umisteni"]; 

  $content='<div><p style="font: normal 9pt Arial, Helvetica, sans-serif; color: red; font-weight: bold; margin: 5px 0 0 0px; padding: 0;">';

  $content=$content.'<a href="http://rouchovany.tmep.cz" target="_blank">Teplota:</a>&nbsp'.$rate.'°C'.'&nbsp&nbsp<a href="http://rouchovany.tmep.cz" target="_blank">Vlhkost:</a>&nbsp'.$rate1.'%';

  $content=$content.'<br><a href="https://tmep.cz/mapa/" target="_blank">'.$rate3.'</a>&nbsp'.$rate2;

  $content=$content.'</p></div>';

  	$entry['subject'] = "";

	$entry['content'] = $content;

	return $entry;

}

register_widget('thermometer', 'thermometer', 'plugin_thermometer_widget');

?>

Widget pro android cz.monkeytech

Pokud adresa začíná protokolem https:// zakažte kontrolu certifikátu:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

	function get_data($url) {

	$ch = curl_init();

	$timeout = 5;

	curl_setopt($ch, CURLOPT_URL, $url);

	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_USERAGENT, "My User Agent Name");

	$data = curl_exec($ch);

	curl_close($ch);

	return $data;

}

        $details = json_decode($data);

        echo $details->teplota;