Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save daniellevass/67a13943be883e88df39 to your computer and use it in GitHub Desktop.
Save daniellevass/67a13943be883e88df39 to your computer and use it in GitHub Desktop.
Idiots Guide to Using littleBits cloudBit API

#Idiots Guide to Using littleBits cloudBit API

##Introduction

  1. Connect a cloudBit to your network using the instructions at http://control.littlebitscloud.cc/
  2. 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
  1. Find a REST client to test with; I use either Chrome app REST client or http://apigee.com/console

##Setting Up Headers

  1. Include an 'Authorization' header 'Bearer XXXX' where XXXX is your AccessToken you need the word Bearer
  2. Include an 'Accept' header 'application/vnd.littlebits.v2+json'
  3. Include a 'Content-Type' header 'application/json'

##Current URL 'http://api-http.littlebitscloud.cc/v2/'

##GET All Connected Devices

  1. Change the request url to = 'http://api-http.littlebitscloud.cc/v2/devices/'
  2. Ensure you have:
  • Authorization header
  • Accept Content Type header
  • Content Type header
  1. 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

  1. Connect a green output bit preferably something you can see numbers on, either a number bit or bargraph.
  2. Using 'GET all connected devices' request establish which cloudBit you need to talk to - save it's device_id somewhere
  3. Change the request url to 'http://api-http.littlebitscloud.cc/v2/devices/XXXX/output' where XXXX is the device_id
  4. 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)
  1. Ensure you have:
  • Authorization header
  • Accept Content Type header
  • Content Type header
  1. 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
@damiththa
Copy link

Thanks for the post ,exactly what I was looking for.
One small comment,
I only have one cloudbit, so to GET connected device I pass the request URL as 'https://api-http.littlebitscloud.cc/devices/DEVICE_ID'

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