Need help on my LED REST API


 
Thread Tools Search this Thread
Top Forums Programming Need help on my LED REST API
# 1  
Old 07-25-2014
Need help on my LED REST API

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:
Code:
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);

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Face-api.js  JavaScript API for Face Recognition in the Browser with tensorflow.js

Ref: https://itnext.io/face-api-js-javascript-api-for-face-recognition-in-the-browser-with-tensorflow-js-bcc2a6c4cf07 (0 Replies)
Discussion started by: Neo
0 Replies

2. IP Networking

CurL command Rest API call with oauth 2.0 secutity error

Hi I need to get rates for different security form REST API . the API is oauth 2.0 secured. i need to use curl command to get json response from api . token URL - is HTTP data URL is - HTTPS when trigger my command from bash script it passing and failing intermittently with... (0 Replies)
Discussion started by: shobhit.working
0 Replies

3. Shell Programming and Scripting

perl: CURL REST API Query

I have not used cUrl before, but I have noticed that in my Perl script I give a query and it takes the format: URL?query={field;field} But, when I try this with cUrl, it will not query at all: curl: (3) nested braces not supported at pos 88 I have tried moving the braces etc etc, it... (1 Reply)
Discussion started by: 3246251196
1 Replies

4. Shell Programming and Scripting

Need to run an API from a script and extract fields from output of API

Hi, I need to call an API (GetUsageDetails)from inside a shell script which takes an input argument acct_nbr. The output of API will be like : <usageAccum accumId="450" accumCaptn="PM_125" inclUnits="1410.00" inclUnitsUsed="744.00" shared="true" pooled="false" prorated="false"... (1 Reply)
Discussion started by: rkrish
1 Replies

5. AIX

Attention Led on HMC

We use HMC to manage two logical partitions. LPARs don't have any problem but HMC's, itself, attention led is on. :eek: I am not sure if that's going to affect LPARs, but just wanted to be sure.... :confused: Has anyone come across such problem on HMC? Where can you suggest to look for logs... (1 Reply)
Discussion started by: royalliege
1 Replies

6. Solaris

locator led SUN T2000

Hi Guys, I am unable to turn on the locator led light on a SUN T2000 machine # uname -a SunOS node1 5.10 Generic_137137-09 sun4v sparc SUNW,Sun-Fire-T200 when i try to turn it on I have following error. # locator -n 'system' locator not found Although the hardware specfication... (5 Replies)
Discussion started by: Asteroid
5 Replies

7. HP-UX

System LED flashing

hi guys, i have 2 hp-ux servers at my office with flashing system LED. am very new to hp-ux...no much of access directly to the server. how can i check for faults relating to this flashing of this system LED? the DC is pretty far from my office...all i have is an ssh access into the server.... (4 Replies)
Discussion started by: cromohawk
4 Replies

8. AIX

RS/6000 warning led

On my IBM RS/6000 9114-275 a warning led is burning. It's an orange light with an exclamation mark. It started to burn when I did a reset of the system. What does it mean? How can I get it away? (0 Replies)
Discussion started by: rein
0 Replies

9. AIX

LED Code

Anyone know what led code 626 means please. This is on a VIO server running vios 1.3.0.1-FP-8.1 and AIX 5.3 ML5. (8 Replies)
Discussion started by: johnf
8 Replies

10. AIX

LED stops at 406eoch6 help

Hi can anybody help me when i boot up my machine the LED runs until it gets to 406coch6 and it simply stops their noting appears on the screen...? Is their a website that lists all the codes and their meaning Thanks Liam (2 Replies)
Discussion started by: lodonovan
2 Replies
Login or Register to Ask a Question

Featured Tech Videos