Last active
August 29, 2015 13:57
-
-
Save mohitathwani/9829480 to your computer and use it in GitHub Desktop.
Sample code for the IoT Blog post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//We first load the express framework and make it available for our script | |
var express = require('express'); | |
//Here we initialize the express framework | |
var app = express(); | |
//We are going to GET the pin number and the state to set the pin to from the URL from the browser | |
//For example http://yourdomain.com/25/1 -----> This turns the state of pin number 25 to HIGH | |
//Similarly: http://yourdomain.com/25/0 -----> This turns the state of pin number 25 to LOW | |
//NOTE: We can also send a json packet to the server as part of this request, but we won't cover that for now ! | |
app.get('/:pin/:state', function(req, res) { | |
res.send({pin:req.params.pin, state: req.params.state}); | |
}); | |
//We start the server on port number 3000 and allow it work on all domains. | |
app.listen(4000, '0.0.0.0'); | |
console.log('Listening on port 4000...'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment