Developed for a ⧮ Hardware workshop at NodeConf EU 2014
- Have a littleBits account to associate your cloudBit to; Create account.
- Have a Heroku account to host a webhook endpoint for your cloudBit (also, the heroku gem).
- Visit Colin, tell him the email used for your littleBits account, get a cloudBit.
- Get
ACCESS_TOKEN
andCLOUDBIT_ID
from Cloud Control
- Try default output
$ curl -i -XPOST \
-H "Authorization: Bearer ACCESS_TOKEN" \
https://api-http.littlebitscloud.cc/v3/devices/CLOUDBIT_ID/output
- Try 50% output for 5 seconds
$ curl -i -XPOST \
-H "Authorization: Bearer ACCESS_TOKEN" \
https://api-http.littlebitscloud.cc/v3/devices/CLOUDBIT_ID/output \
-d percent=50 \
-d duration_ms=5000
- Investigate the HTTP API docs for how you can send a perpetual output percentage to your cloudBit
- Get the cloudBit's current input voltage
$ curl -i \
-H "Authorization: Bearer ACCESS_TOKEN" \
https://api-http.littlebitscloud.cc/v3/devices/CLOUDBIT_ID/input
This will start a stream of values, you can stop by hitting ctrl-c
. Each value
will be a json
object with a bunch of metadata. The most useful one in most cases being:
data.percent
You will see the percent
value near the end of the response, in the below example, "percent":69
data:{"type":"input","timestamp":1415472471048,"from":{"user":{"id":1323},"device":{"id":"1a2b3c4d5e6f","device":"littlebits-module-cloud","setup_version":"1.0.0","protocol_version":"1.1.0","firmware_version":"1.0.140820b","mac":"1a2b3c4d5e6f","hash":"XXXXXXXXXXXXXXXXXXXXXXXXXXX","ap":{"ssid":"MySuperInternet!","mac":"AA:BB:CC:DD:EE:FF","strength":100}},"server":{"id":"QkZVqqe"}},"percent":69,"absolute":709,"name":"amplitude","payload":{"percent":69,"absolute":709}}
Replace YOUR_APP
with the application name you would like.
- Deploy the demo cloudBit reader app to Heroku
$ git clone [email protected]:littlebits/cloud-api-lessons.git \
&& cd cloud-api-lessons \
&& heroku apps:create YOUR_APP \
&& git push heroku
- Tell the app to read from your cloudBit
$ curl -i -XPOST \
-H "Authorization: Bearer ACCESS_TOKEN" \
https://api-http.littlebitscloud.cc/v2/subscriptions \
-d publisher_id=CLOUDBIT_ID \
-d subscriber_id=http://YOUR_APP.herokuapp.com
- Inspect your cloudBit's current "readers" (AKA subscribers)
$ curl -H \
"Authorization: Bearer ACCESS_TOKEN" \
https://api-http.littlebitscloud.cc/v2/subscriptions?publisher_id=CLOUDBIT_ID
- Stop reading
$ curl -H -XDELETE \
"Authorization: Bearer ACCESS_TOKEN" \
https://api-http.littlebitscloud.cc/v2/subscriptions \
-d publisher_id=CLOUDBIT_ID \
-d subscriber_id=http://YOUR_APP.herokuapp.com
- Investigate the HTTP API docs for how you can make one cloudBit read from another
Ok, not really a lesson. Create an original mashup between your cloudBit and another service that does something awesome. Best mash-up wins some littleBits including a cloudBit :)
- cloudBit Cloud Control app: http://littlebits.cc/cloudstart
- littleBits Cloud HTTP API docs: http://developer.littlebitscloud.cc
- HTTP API library: https://github.com/littlebits/cloud-client-api-http