Prerequisites
- You will need node.js and npm installed , and should have at least some knowledge when it comes to node, if you do not , I suggest you try some example code in node before diving into controlling hardware with it.
- You must have the Arduino IDE installed on your machine
- You must know how to get an LED working on pin 13 of an Arduino
Set up the Arduino
Wire up an LED to the Arduino on pin 13 and plug it into your development machine. Now we need to get it ready to talk to johnny-five. To do this simply follow the instructions under johnny-five's readme
Set up the project
Create a folder on your development machine for the project , in this folder create the server.js and index.html files. Copy the code from the files in this gist to the respective files.
Loading ....
We aren't done yet , we need johnny-five and the narf for this to work. In your project directory run the following command:
npm install narf johnny-five
If that succeeded we now have the johnny-five library and narf installed , the server should be ready to go, so lets run it:
node server.js
You should now be able to browse to the page and control the light.
http://localhost:8079/index.html
We are now in business , if you wish to control the light from another machine you will have to edit the urls in index.html and replace localhost with the IP address of the server. Other than that we are pretty much done, an LED controlled over HTTP. If you want to understand more you should just read through the code(its quite simple) and through the documentation for johnny-five. Don't worry too much about the index.html if thats not your cup of tea, it just makes http requests to the server and serves as a nice interface , the meaty bit is in server.js
An early prototype of the HTTP LED that I hacked together in five minutes , the code has been updated since then to make it slightly more solid |
Comments
Post a Comment