Hi guys, I would like to seek help on my LED REST API. I have finished 
constructed my basic REST API for my Raspberry PI. What I'm trying to do 
now is allow my LED to light up whenever I key localhost:3000/7/1 and key 
localhost:3000/7/0 to switch off. But my problem now is my REST API can't 
works and hope you guys could help me out with it as soon as possible, 
thanks in advance, guys.

*This is my led_rest_api.js:*
*var express = require('express');*
*var bodyParser = require('body-parser');*
*var gpio = require('pi-gpio');*
*var app = express();*

*app.use(bodyParser.json());*
*app.set('port', process.env.PORT || 3030);*

*app.post('/:pin/1', function(req, res)*
*{*
*  var pin = req.params.pin;*

*  gpio.open(pin, 'output', function(err){*
* if (pin === 7){*
* //Set pin 7 high (1)*
*    gpio.write(7, 1, function() *
* { *
*        gpio.close(7);*
*  }*
* return gpio;*
* } if (pin === 11){*
* //Set pin 11 high (1)*
*    gpio.write(11, 1, function() *
* { *
*        gpio.close(11);*
*  }*
* return gpio;*
* } if (pin === 16){*
* //Set pin 16 high (1)*
*    gpio.write(16, 1, function() *
* { *
*        gpio.close(16);*
*  }*
* return gpio;*
* }*
*  }*
*});*

*app.post('/:pin/0', function(req, res)*
*{*
*  var pin = req.params.pin;*

*  gpio.open(pin, 'output', function(err){*
* if (pin === 7){*
* //Set pin 7 low (0)*
*    gpio.write(7, 0, function() *
* { *
*        gpio.close(7);*
*  }*
* return gpio;*
* } if (pin === 11){*
* //Set pin 11 low (0)*
*    gpio.write(11, 0, function() *
* { *
*        gpio.close(11);*
*  }*
* return gpio;*
* } if (pin === 16){*
* //Set pin 16 low (0)*
*    gpio.write(16, 0, function() *
* { *
*        gpio.close(16);*
*  }*
* return gpio;*
* }*
*  }*
*});*


*var server = app.listen(app.get('port'), function() {*
*  console.log('Listening on port %d', server.address().port);*



-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/de5768e0-a6ed-4e01-a339-74eadb372ada%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to