Created
October 2, 2015 14:02
-
-
Save stresslimit/5d73b7f06b0607c926ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$access_token = 'YOUR_TOKEN'; | |
$cloudBit_ID = 'YOUR_CLOUDBIT_ID'; | |
init_api_request($access_token, $cloudBit_ID); | |
function handle_input($ch, $data) { | |
// remove "data:" from beginning of SSE data to leave just json | |
$data = preg_replace('/^data:(.*)$/mi', '$1', $data); | |
// decode json to get php object | |
$data = json_decode( $data ); | |
// this is the value of the input signal of our cloudBit: | |
echo $data->percent; | |
} | |
function init_api_request($access_token, $cloudBit_ID) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, 'https://api-http.littlebitscloud.cc/devices/' | |
.$cloudBit_ID | |
.'/input?access_token=' | |
.$access_token); | |
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'handle_input'); | |
curl_exec($ch); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment