From a074bcfd560bcbb9cf3ca980e2357ce70683175f Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Sat, 12 Dec 2015 15:13:15 +0000 Subject: [PATCH] Pi no longer needs root workaround to access gpio (stops PAM logging in Node-RED log under systemd) --- nodes/core/hardware/36-rpi-gpio.html | 1 + nodes/core/hardware/36-rpi-gpio.js | 8 ++++---- nodes/core/hardware/nrgpio.py | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/nodes/core/hardware/36-rpi-gpio.html b/nodes/core/hardware/36-rpi-gpio.html index cfd4ec26d..36b299268 100644 --- a/nodes/core/hardware/36-rpi-gpio.html +++ b/nodes/core/hardware/36-rpi-gpio.html @@ -325,6 +325,7 @@ +
diff --git a/nodes/core/hardware/36-rpi-gpio.js b/nodes/core/hardware/36-rpi-gpio.js index 191b1bc2c..06150cc8a 100644 --- a/nodes/core/hardware/36-rpi-gpio.js +++ b/nodes/core/hardware/36-rpi-gpio.js @@ -1,5 +1,5 @@ /** - * Copyright 2013,2014 IBM Corp. + * Copyright 2013,2015 IBM Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,8 @@ module.exports = function(RED) { var exec = require('child_process').exec; var spawn = require('child_process').spawn; var fs = require('fs'); - - var gpioCommand = __dirname+'/nrgpio'; +s + var gpioCommand = __dirname+'/nrgpio.py'; if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi //RED.log.info(RED._("rpi-gpio.errors.ignorenode")); @@ -231,7 +231,7 @@ module.exports = function(RED) { this.butt = n.butt || 7; var node = this; - node.child = spawn(gpioCommand+".py", ["mouse",node.butt]); + node.child = spawn(gpioCommand, ["mouse",node.butt]); node.status({fill:"green",shape:"dot",text:"common.status.ok"}); node.child.stdout.on('data', function (data) { diff --git a/nodes/core/hardware/nrgpio.py b/nodes/core/hardware/nrgpio.py index 3ef6f5e0f..358869c1a 100755 --- a/nodes/core/hardware/nrgpio.py +++ b/nodes/core/hardware/nrgpio.py @@ -23,7 +23,7 @@ if sys.version_info >= (3,0): print("Sorry - currently only configured to work with python 2.x") sys.exit(1) -if len(sys.argv) > 1: +if len(sys.argv) > 2: cmd = sys.argv[1].lower() pin = int(sys.argv[2]) GPIO.setmode(GPIO.BOARD) @@ -193,5 +193,15 @@ if len(sys.argv) > 1: file.close() sys.exit(0) +elif len(sys.argv) > 1: + cmd = sys.argv[1].lower() + if cmd == "rev": + print GPIO.RPI_REVISION + elif cmd == "ver": + print GPIO.VERSION + else: + print "Bad parameters - in|out|pwm|buzz|byte|borg|mouse|ver {pin} {value|up|down}" + print " only ver (gpio version) and rev (board revision) accept no pin parameter." + else: - print "Bad parameters - {in|out|pwm} {pin} {value|up|down}" + print "Bad parameters - in|out|pwm|buzz|byte|borg|mouse|ver {pin} {value|up|down}"