Start a new JSFiddle
Add in jQuery by clicking the little cog in the JavaScript square
Log into the cloud control website at - - the username and password will be somewhere visible in real life!
Find the pokemon that matches the picture on your cloudbit on the left hand side - and try pressing the big button. What happens?
Head over to the settings tab at the bottom of the page - the important pieces of information here are the device id and authorisation token. We're going to need those in just a minute!
var token = "xx";
var device ="00e04c039efe"
$.ajax({
url: 'http://api-http.littlebitscloud.cc/v2/devices/'+device+'/output',
type: 'post',
data:
JSON.stringify({
"percent": 20,
"duration_ms": 1000
}),
headers: {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json',
},
success: function(data) {
console.log(data);
},
error: function(data){
console.log(data);
}
});
Make sure you change the token
and device
before you try to play it!
You can use this JSFiddle if you like - http://jsfiddle.net/9hypen62/
Do you see the word percent and then a number? try changing that number - what happens?
We could put this into a function so we can programmatically change the number. If you get stuck here, ask us for some help!
How about combining this with the the christmas countdown? Could you send how many days until christmas there are?
Thank you for this. Finally someone with some Javascript documentation that was useful! I'm writing in AngularJS and was able to make it work.