Sponsored Content
Full Discussion: Need help on my LED REST API
Top Forums Programming Need help on my LED REST API Post 302910505 by aoiregion on Friday 25th of July 2014 12:41:31 AM
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);

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
RT::Client::REST::Exception(3pm)			User Contributed Perl Documentation			  RT::Client::REST::Exception(3pm)

NAME
RT::Client::REST::Exception -- exceptions thrown by RT::Client::REST methods. DESCRIPTION
These are exceptions that are thrown by various RT::Client::REST methods. EXCEPTION HIERARCHY
RT::Client::REST::Exception This exception is virtual -- it is never thrown. It is used to group all the exceptions in this category. RT::Client::REST::OddNumberOfArgumentsException This means that the method you called wants key-value pairs. RT::Client::REST::InvaildObjectTypeException Thrown when you specify an invalid type to "show()", "edit()", or "search()" methods. RT::Client::REST::RequiredAttributeUnsetException An operation failed because a required attribute was not set in the object. RT::Client::REST::MalformedRTResponseException RT server sent response that we cannot parse. This may very well mean a bug in this client, so if you get this exception, some debug information mailed to the author would be appreciated. RT::Client::REST::InvalidParameterValueException Invalid value for comments, link types, object IDs, etc. RT::Client::REST::CannotReadAttachmentException Cannot read attachment (thrown from methods "comment()" and "correspond"). RT::Client::REST::RTException This is a virtual exception and is never thrown. It is used to group exceptions thrown because RT server returns an error. RT::Client::REST::ObjectNotFoundException One or more of the specified objects was not found. RT::Client::REST::AuthenticationFailureException Incorrect username or password. RT::Client::REST::UpdateException This is a virtual exception. It is used to group exceptions thrown when RT server returns an error trying to update an object. RT::Client::REST::CouldNotSetAttributeException For one or another reason, attribute could not be updated with the new value. RT::Client::REST::InvalidEmailAddressException Invalid e-mail address specified. RT::Client::REST::AlreadyCurrentValueException The attribute you are trying to update already has this value. I do not know why RT insists on treating this as an exception, but since it does so, so should the client. You can probably safely catch and throw away this exception in your code. RT::Client::REST::ImmutableFieldException Trying to update an immutable field (such as "last_updated", for example). RT::Client::REST::IllegalValueException Illegal value for attribute was specified. RT::Client::REST::UnknownCustomFieldException Unknown custom field was specified in the request. RT::Client::REST::InvalidQueryException Server could not parse the search query. RT::Client::REST::UnauthorizedActionException You are not authorized to perform this action. RT::Client::REST::AlreadyTicketOwnerException The owner you are trying to assign to a ticket is already the owner. This exception is usually thrown by methods "take()", "untake", and "steal", if the operation is a noop. RT::Client::REST::RequestTimedOutException Request timed out. RT::Client::REST::UnknownRTException Some other RT exception that the driver cannot recognize. METHODS
_get_exception_class Figure out exception class based on content returned by RT. _rt_content_to_exception Translate error string returned by RT server into an exception object ready to be thrown. SEE ALSO
Exception::Class, RT::Client::REST. AUTHOR
Dmitri Tikhonov <dtikhonov@yahoo.com> perl v5.14.2 2011-12-27 RT::Client::REST::Exception(3pm)
All times are GMT -4. The time now is 12:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy