I'm using Raspberry Pi model B Type 2 with ARM6 and Type 3 with ARM7. I have tested this code several times and after a week, when I tried, it is not working.

Below is my node js program:

var express = require('express')
var app = express()
var bodyParser = require('body-parser')
var gpio = require("gpio")
var ip_add = require('./getip.js')

app.use(bodyParser.urlencoded({ extended: false }))

// parse application/json

app.get('/', function (req, res) {
  res.send('Hello World!')

app.post('/status', function(req, res){
    var status = req.query.status;
    var direction = req.body.status;
    var actionMap = {
        north: 11,
        east: 12,
        south: 7,
        west: 13,
        test: 5

    setgpio = gpio.export(actionMap[direction], {
    ready: function() {
//          intervalTimer = setInterval(function() {
         setTimeout(function() { setgpio.reset(); }, 3000);
//      }, 1000);


app.listen(3000, function () {

  console.log('Example app listening on port 3000!')

var http = require('http');

var options = {
    host: '',
    port: 8080,
    path: '/sample/ip_pi.jsp?myip=' + ip_add

    console.log("chunk:" + chunk);
}).on("error", function(e){
    console.log("error:" + e.message);


Then I have tried the sample program from npmjs.com which was working before. I have to light four LEDs alternatively depending up on the status received from another host, all other parts of the code is working fine except glowing LEDs connected to GPIO.

What would be the possible reason?

What is the possible solution?

As suggested by joan, i have carried out the test as below,

GPIO Test:

1) test the GPIO with nothing connected:

Test Method: using pigpio library of joan, from the stack exchange answer

a) ./x_pigpiod_if2 : pigpio version 58 Mode/PUD/read/write tests. Test 1.1 to Test 9.4 :Pass

b) ./x_pigpio.py

Python module 1.34 Python 2.7.9 Test 1.1 to Test 13.13 Pass

c) ./x_pigs : all ok

d) ./x_pipw : all ok

2) testing LED using command-line

sudo -i

echo "23" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio23/direction

echo "1" > /sys/class/gpio/gpio23/value
echo "0" > /sys/class/gpio/gpio23/value

echo "23" > /sys/class/gpio/unexport

result: Sucess

3)test the LED using python program:

using RPi.GPIO package and simple python program

Test result: Failed!!!

I have also tried to install npm on off and rpi-gpio as an alternative for the current library npm gpio it failed, my stack exchange question

Now it is clear the hardware is ok, What could be the reason which stops my program/package accessing GPIO?

  • I'm not sure why you show the program if you claim no software has changed. That would suggest the hardware has changed.
    – joan
    Commented Dec 19, 2016 at 10:07
  • @joan Sounds Brilliant. When program failed with RPi 2 i tried the same with RPi 3 result was same. I'm a beginner in node js & pi, hence i'm not sure this code have damaged the GPIO pins, etc..
    – jasim
    Commented Dec 19, 2016 at 10:10
  • Dear Programmers, Any sugession, piece of code, alternative methods, etc.. are highly appreciated and Thanks in advance!
    – jasim
    Commented Dec 19, 2016 at 10:19
  • I suggest you do three things. 1) test the GPIO with nothing connected. Google for how. 2) test the LEDs are okay by sending commands from the command line. Google for how. 3) Edit your question and add the results of tests 1) and 2).
    – joan
    Commented Dec 19, 2016 at 11:11
  • @joan I had done the 1,2 & 3. 1,2 Tests passed. Now, what to do joan? kindly help.
    – jasim
    Commented Dec 21, 2016 at 7:31


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.