#Idiots Guide to Using littleBits cloudBit API
##Introduction
- Connect a cloudBit to your network using the instructions at http://control.littlebitscloud.cc/
- Find out your AccessToken
- visit http://control.littlebitscloud.cc/
- on the left hand side select any of your cloudBits
- using the tab bar at the bottom select settings
- scroll down and copy your AccessToken
- Find a REST client to test with; I use either Chrome app REST client or http://apigee.com/console
##Setting Up Headers
- Include an 'Authorization' header 'Bearer XXXX' where XXXX is your AccessToken you need the word Bearer
- Include an 'Accept' header 'application/vnd.littlebits.v2+json'
- Include a 'Content-Type' header 'application/json'
##Current URL 'http://api-http.littlebitscloud.cc/v2/'
##GET All Connected Devices
- Change the request url to = 'http://api-http.littlebitscloud.cc/v2/devices/'
- Ensure you have:
- Authorization header
- Accept Content Type header
- Content Type header
- Click GET
\\\request
POST /v2/devices HTTP/1.1
Authorization: Bearer d64e5f77f9c60f00b4999ca2539ef61394e7b3beef00ce0856cb1aa9976871fa
Host: api-http.littlebitscloud.cc
Content-Length: 46
X-Target-URI: http://api-http.littlebitscloud.cc
Accept: application/vnd.littlebits.v2+json
Content-Type: application/json
Connection: Keep-Alive
\\RESPONSE
[
{
"id": "00e04c2241e8",
"user_id": "20702",
"label": "Oshawott",
"is_connected": true,
"ap": {
"ssid": "BTHub4-JWPJ",
"mac": "CC:33:BB:21:63:30",
"strength": "81"
},
"subscribers": [],
"subscriptions": []
}
]
##POST Data to Connected Device
- Connect a green output bit preferably something you can see numbers on, either a number bit or bargraph.
- Using 'GET all connected devices' request establish which cloudBit you need to talk to - save it's device_id somewhere
- Change the request url to 'http://api-http.littlebitscloud.cc/v2/devices/XXXX/output' where XXXX is the device_id
- In the request payload supply the following json:
{
"percent":50,
"duration_ms":5000
}- percent needs to be a whole number between 0 and 100.
- duration_ms is the number of milliseconds to run, -1 runs forever (or until something interrupts it)
- Ensure you have:
- Authorization header
- Accept Content Type header
- Content Type header
- Click POST
///REQUEST
POST /v2/devices/00e04c2241e8/output HTTP/1.1
Authorization: Bearer d64e5f77f9c60f00b4999ca2539ef61394e7b3beef00ce0856cb1aa9976871fa
Host: api-http.littlebitscloud.cc
Content-Length: 46
X-Target-URI: http://api-http.littlebitscloud.cc
Accept: application/vnd.littlebits.v2+json
Content-Type: application/json
Connection: Keep-Alive
{
"percent": 50,
"duration_ms": 5000
}
///RESPONSE
OK
##Connect 2 CloudBits Together
- Connect a purple input bit before one cloud bit (eg. squirtle)
- Connect a green output bit to after another cloud bit (eg. bulbasaur)
- Using 'GET all connected devices' request establish the device_ids of the 2 cloud bits you want to link together.
- Open the REST API client and set the request url to 'http://api-http.littlebitscloud.cc/v2/subscriptions', and the method to POST.
- Ensure you have:
- Authorization header
- Accept Content Type header
- Content Type header
- In the request payload supply the following json. The publisher_id is the device ID of the sender with the input (squirtle). The subscriber_id is the device ID of the reciver with the output (bulbasaur).
{
"publisher_id":"00e04c035a67",
"subscriber_id":"00e04c037b69"
}-
Click 'Send'.
-
Press on the purple input of squirtle and you should see the output happen on bulbasaur.
\\\request
POST /v2/subscriptions HTTP/1.1
Host: api-http.littlebitscloud.cc
Connection: keep-alive
Content-Length: 71
Accept: application/vnd.littlebits.v2+json
Authorization: Bearer d64e5f77f9c60f00b4999ca2539ef61394e7b3beef00ce0856cb1aa9976871fa
Content-Type: application/json
Accept-Language: en-US,en;q=0.8
\\RESPONSE
{
"publisher_id":"00e04c035a67",
"subscriber_id":"00e04c037b69",
"publisher_events":[
{
"name":"amplitude:delta:ignite"
}
]
}