hatspin

HatSpin: Connecting LittleBits and the cloud with node.js

MIT License

Stars
9

HatSpin: LittleBits + node.js

HatSpin is an example of using the LittleBits CloudKit and node.js to bridge the web and physical devices.

Setup

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.

Littlebits

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!

Redis

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.

PubNub

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:

Running the code

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.

Deployment

This code is built as a demo for running Node.js on Google Cloud, but you can run it anywhere that node.js works.

  1. Create a project in the Google Cloud Platform Console.
  2. Enable billing for your project.
  3. Install the Google Cloud SDK.
  4. Deploy it with gcloud preview app deploy

License

MIT License

Questions?

Feel free to submit an issue on the repository, or find me at @JustinBeckwith