<?php
$R=rand(1,8);
$kirim="https://api.thingspeak.com/update?api_key=6AQ86NJXWBFB634521&field1=$R";
//get_content($kirim);
echo"<hr>";
$baca="https://api.thingspeak.com/channels/1089670/feeds.json?api_key=5TW0G96C5T5U9F5R21&results=1";
$hasil= get_content($baca);
//var_dump($hasil);
$array = json_decode($hasil, true);
$x=$array["feeds"][0]["field1"];
echo $x;
echo"<hr>";
//var_dump($array);
function get_content($URL){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $URL);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
?>
API Requests
https://thingspeak.com/channels/1089670/api_keys
Write a Channel Feed
GET https://api.thingspeak.com/update?api_key=6AQ86NJXWBFB634521&field1=0
Read a Channel FeedGET https://api.thingspeak.com/channels/1089670/feeds.json?api_key=5TW0G96C5T5U9F5R21&results=2
Read a Channel FieldGET https://api.thingspeak.com/channels/1089670/fields/1.json?api_key=5TW0G96C5T5U9F5R21&results=2
Read Channel Status UpdatesGET https://api.thingspeak.com/channels/1089670/status.json?api_key=5TW0G96C5T5U9F5R21
https://jonsuh.com/blog/convert-loop-through-json-php-javascript-arrays-objects/#:~:text=Convert%20JSON%20String%20to%20PHP,the%20objects%20as%20associative%20arrays.
Tidak ada komentar:
Posting Komentar