Skip to content

Instantly share code, notes, and snippets.

@danielset
Last active May 29, 2016 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielset/c337769795c6c68febe9ce30d9d0f9da to your computer and use it in GitHub Desktop.
Save danielset/c337769795c6c68febe9ce30d9d0f9da to your computer and use it in GitHub Desktop.
API Connect cloudBit PHP
<?php
// Place other API connects e.g. the one to Google here
// Your ID and token of your cloudBit
$deviceID = 'DEVICE_ID';
$authToken = 'AUTH_TOKEN';
// The data to send to the API
$cloudData = array(
'percent' => 80,
'duration_ms' => -1
);
// Setup cURL
$ch = curl_init('https://api-http.littlebitscloud.cc/devices/'.$deviceID.'/output');
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.$authToken,
'Content-Type: application/json'
),
CURLOPT_POSTFIELDS => json_encode($cloudData)
));
// Send the request
$response = curl_exec($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment