HatSpin: Connecting LittleBits and the cloud with node.js
MIT License
HatSpin is an example of using the LittleBits CloudKit and node.js to bridge the web and physical devices.
This sample does require the LittleBits CloudKit. After cloning the repository, you need to need to get a few keys in place. Start by renaming _secrets.json
to secrets.json
.
Log into the LittleBits Cloud Console. Click on the settings
tab, and copy your Device ID
and AccessToken
into secrets.json
:
Now the circuit. I'm using the w20 cloud bit, and a simple dc motor to create some spin. You could really use any output circuit here. Play around with it, and so something fun!
The code uses redis to store the number of clicks, working towards 100 to set off the device. I used a free RedisLabs database. After you have that setup, copy the host and port into secrets.json
.
The code uses PubNub to provide scalable realtime communication between clients and the server. This is convenient if your web host does not support websockets natively. You need the publish key and subscribe key in your secrets.json
:
After secrets.json
is in good shape, just run with:
npm start
Next, hit http://localhost:8080 in your browser. Keep on clicking the button! Once you hit 100 clicks, the circuit will start to go.
This code is built as a demo for running Node.js on Google Cloud, but you can run it anywhere that node.js works.
gcloud preview app deploy
Feel free to submit an issue on the repository, or find me at @JustinBeckwith