Skip to content

Instantly share code, notes, and snippets.

@daniellevass
Last active January 20, 2016 20:11
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 daniellevass/f7bb5076d412b6336ed8 to your computer and use it in GitHub Desktop.
Save daniellevass/f7bb5076d412b6336ed8 to your computer and use it in GitHub Desktop.
Sending data to LittleBits

Sending Data to LittleBits 🎁

1. JSFiddle

Start a new JSFiddle

2. JQuery

Add in jQuery by clicking the little cog in the JavaScript square

3. Cloud Control

Log into the cloud control website at - - the username and password will be somewhere visible in real life!

Imgur

4. Testing

Find the pokemon that matches the picture on your cloudbit on the left hand side - and try pressing the big button. What happens?

5. Settings

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!

6. Copy paste

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/

7. More testing

Do you see the word percent and then a number? try changing that number - what happens?

8. Functions

We could put this into a function so we can programmatically change the number. If you get stuck here, ask us for some help!

9. Further!

How about combining this with the the christmas countdown? Could you send how many days until christmas there are?

@jonalling
Copy link

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.

@daniellevass
Copy link
Author

haha no problem! What're you working on with the cloudbits out of interest?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment