1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

let python sub processes use python3

This commit is contained in:
Dave Conway-Jones 2018-07-07 19:24:35 +01:00
parent 88f7f52f99
commit b4fca36ab6
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
12 changed files with 62 additions and 74 deletions

View File

@ -6,10 +6,6 @@ import sys
bounce = 20 # bounce time in mS to apply bounce = 20 # bounce time in mS to apply
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) > 1:
cmd = sys.argv[1].lower() cmd = sys.argv[1].lower()
pin = int(sys.argv[2]) pin = int(sys.argv[2])
@ -17,7 +13,7 @@ if len(sys.argv) > 1:
GPIO.setwarnings(False) GPIO.setwarnings(False)
if cmd == "pwm": if cmd == "pwm":
#print "Initialised pin "+str(pin)+" to PWM" #print("Initialised pin "+str(pin)+" to PWM")
GPIO.setup(pin,GPIO.OUT) GPIO.setup(pin,GPIO.OUT)
p = GPIO.PWM(pin, 100) p = GPIO.PWM(pin, 100)
p.start(0) p.start(0)
@ -32,10 +28,10 @@ if len(sys.argv) > 1:
GPIO.cleanup(pin) GPIO.cleanup(pin)
sys.exit(0) sys.exit(0)
except Exception as ex: except Exception as ex:
print "bad data: "+data print("bad data: "+data)
elif cmd == "buzz": elif cmd == "buzz":
#print "Initialised pin "+str(pin)+" to Buzz" #print("Initialised pin "+str(pin)+" to Buzz")
GPIO.setup(pin,GPIO.OUT) GPIO.setup(pin,GPIO.OUT)
p = GPIO.PWM(pin, 100) p = GPIO.PWM(pin, 100)
p.stop() p.stop()
@ -54,10 +50,10 @@ if len(sys.argv) > 1:
GPIO.cleanup(pin) GPIO.cleanup(pin)
sys.exit(0) sys.exit(0)
except Exception as ex: except Exception as ex:
print "bad data: "+data print("bad data: "+data)
elif cmd == "out": elif cmd == "out":
#print "Initialised pin "+str(pin)+" to OUT" #print("Initialised pin "+str(pin)+" to OUT")
GPIO.setup(pin,GPIO.OUT) GPIO.setup(pin,GPIO.OUT)
if len(sys.argv) == 4: if len(sys.argv) == 4:
GPIO.output(pin,int(sys.argv[3])) GPIO.output(pin,int(sys.argv[3]))
@ -78,9 +74,9 @@ if len(sys.argv) > 1:
GPIO.output(pin,data) GPIO.output(pin,data)
elif cmd == "in": elif cmd == "in":
#print "Initialised pin "+str(pin)+" to IN" #print("Initialised pin "+str(pin)+" to IN")
def handle_callback(chan): def handle_callback(chan):
print GPIO.input(chan) print(GPIO.input(chan))
if len(sys.argv) == 4: if len(sys.argv) == 4:
if sys.argv[3].lower() == "up": if sys.argv[3].lower() == "up":
@ -91,7 +87,7 @@ if len(sys.argv) > 1:
GPIO.setup(pin,GPIO.IN) GPIO.setup(pin,GPIO.IN)
else: else:
GPIO.setup(pin,GPIO.IN) GPIO.setup(pin,GPIO.IN)
print GPIO.input(pin) print(GPIO.input(pin))
GPIO.add_event_detect(pin, GPIO.BOTH, callback=handle_callback, bouncetime=bounce) GPIO.add_event_detect(pin, GPIO.BOTH, callback=handle_callback, bouncetime=bounce)
while True: while True:
@ -104,7 +100,7 @@ if len(sys.argv) > 1:
sys.exit(0) sys.exit(0)
elif cmd == "byte": elif cmd == "byte":
#print "Initialised BYTE mode - "+str(pin)+ #print("Initialised BYTE mode - "+str(pin)+)
list = [7,11,13,12,15,16,18,22] list = [7,11,13,12,15,16,18,22]
GPIO.setup(list,GPIO.OUT) GPIO.setup(list,GPIO.OUT)
@ -127,7 +123,7 @@ if len(sys.argv) > 1:
GPIO.output(list[bit], data & mask) GPIO.output(list[bit], data & mask)
elif cmd == "borg": elif cmd == "borg":
#print "Initialised BORG mode - "+str(pin)+ #print("Initialised BORG mode - "+str(pin)+)
GPIO.setup(11,GPIO.OUT) GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT) GPIO.setup(13,GPIO.OUT)
GPIO.setup(15,GPIO.OUT) GPIO.setup(15,GPIO.OUT)
@ -154,10 +150,10 @@ if len(sys.argv) > 1:
data = 0 data = 0
elif cmd == "rev": elif cmd == "rev":
print GPIO.RPI_REVISION print(GPIO.RPI_REVISION)
elif cmd == "ver": elif cmd == "ver":
print GPIO.VERSION print(GPIO.VERSION)
elif cmd == "mouse": # catch mice button events elif cmd == "mouse": # catch mice button events
file = open( "/dev/input/mice", "rb" ) file = open( "/dev/input/mice", "rb" )
@ -171,7 +167,7 @@ if len(sys.argv) > 1:
button = ord( buf[0] ) & pin # mask out just the required button(s) button = ord( buf[0] ) & pin # mask out just the required button(s)
if button != oldbutt: # only send if changed if button != oldbutt: # only send if changed
oldbutt = button oldbutt = button
print button print(button)
while True: while True:
try: try:
@ -181,4 +177,4 @@ if len(sys.argv) > 1:
sys.exit(0) sys.exit(0)
else: else:
print "Bad parameters - in|out|pwm|buzz|byte|borg|mouse|ver pin {value|up|down}" print("Bad parameters - in|out|pwm|buzz|byte|borg|mouse|ver pin {value|up|down}")

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-ledborg", "name" : "node-red-node-ledborg",
"version" : "0.0.19", "version" : "0.0.20",
"description" : "A Node-RED node to control a PiBorg LedBorg board for a Raspberry Pi.", "description" : "A Node-RED node to control a PiBorg LedBorg board for a Raspberry Pi.",
"dependencies" : { "dependencies" : {
}, },

View File

@ -107,8 +107,8 @@ def lcd_byte(bits, mode):
if len(sys.argv) > 1: if len(sys.argv) > 1:
pins = sys.argv[1].lower().split(',') pins = sys.argv[1].lower().split(',')
if len(pins) != 6: if len(pins) != 6:
print "Bad number of pins supplied" print("Bad number of pins supplied")
print " "+pins print(" "+pins)
sys.exit(0) sys.exit(0)
LCD_RS = int(pins[0]) LCD_RS = int(pins[0])
@ -181,6 +181,6 @@ if len(sys.argv) > 1:
sys.exit(0) sys.exit(0)
else: else:
print "Bad params" print("Bad params")
print " sudo nrlcd.py RS,E,D4,D5,D6,D7" print(" sudo nrlcd.py RS,E,D4,D5,D6,D7")
sys.exit(0) sys.exit(0)

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-pilcd", "name" : "node-red-node-pilcd",
"version" : "0.0.9", "version" : "0.0.10",
"description" : "A Node-RED node for Raspberry Pi to write to HD44780 style LCD panels.", "description" : "A Node-RED node for Raspberry Pi to write to HD44780 style LCD panels.",
"dependencies" : { "dependencies" : {
}, },

View File

@ -6,10 +6,6 @@ import sys
bounce = 20 # bounce time in mS to apply bounce = 20 # bounce time in mS to apply
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) > 1:
cmd = sys.argv[1].lower() cmd = sys.argv[1].lower()
pin = int(sys.argv[2]) pin = int(sys.argv[2])
@ -17,7 +13,7 @@ if len(sys.argv) > 1:
GPIO.setwarnings(False) GPIO.setwarnings(False)
if cmd == "pwm": if cmd == "pwm":
#print "Initialised pin "+str(pin)+" to PWM" #print("Initialised pin "+str(pin)+" to PWM")
GPIO.setup(pin,GPIO.OUT) GPIO.setup(pin,GPIO.OUT)
p = GPIO.PWM(pin, 100) p = GPIO.PWM(pin, 100)
p.start(0) p.start(0)
@ -32,10 +28,10 @@ if len(sys.argv) > 1:
GPIO.cleanup(pin) GPIO.cleanup(pin)
sys.exit(0) sys.exit(0)
except Exception as ex: except Exception as ex:
print "bad data: "+data print("bad data: "+data)
elif cmd == "buzz": elif cmd == "buzz":
#print "Initialised pin "+str(pin)+" to Buzz" #print("Initialised pin "+str(pin)+" to Buzz")
GPIO.setup(pin,GPIO.OUT) GPIO.setup(pin,GPIO.OUT)
p = GPIO.PWM(pin, 100) p = GPIO.PWM(pin, 100)
p.stop() p.stop()
@ -54,10 +50,10 @@ if len(sys.argv) > 1:
GPIO.cleanup(pin) GPIO.cleanup(pin)
sys.exit(0) sys.exit(0)
except Exception as ex: except Exception as ex:
print "bad data: "+data print("bad data: "+data)
elif cmd == "out": elif cmd == "out":
#print "Initialised pin "+str(pin)+" to OUT" #print("Initialised pin "+str(pin)+" to OUT")
GPIO.setup(pin,GPIO.OUT) GPIO.setup(pin,GPIO.OUT)
if len(sys.argv) == 4: if len(sys.argv) == 4:
GPIO.output(pin,int(sys.argv[3])) GPIO.output(pin,int(sys.argv[3]))
@ -78,9 +74,9 @@ if len(sys.argv) > 1:
GPIO.output(pin,data) GPIO.output(pin,data)
elif cmd == "in": elif cmd == "in":
#print "Initialised pin "+str(pin)+" to IN" #print("Initialised pin "+str(pin)+" to IN")
def handle_callback(chan): def handle_callback(chan):
print GPIO.input(chan) print(GPIO.input(chan))
if len(sys.argv) == 4: if len(sys.argv) == 4:
if sys.argv[3].lower() == "up": if sys.argv[3].lower() == "up":
@ -91,7 +87,7 @@ if len(sys.argv) > 1:
GPIO.setup(pin,GPIO.IN) GPIO.setup(pin,GPIO.IN)
else: else:
GPIO.setup(pin,GPIO.IN) GPIO.setup(pin,GPIO.IN)
print GPIO.input(pin) print(GPIO.input(pin))
GPIO.add_event_detect(pin, GPIO.BOTH, callback=handle_callback, bouncetime=bounce) GPIO.add_event_detect(pin, GPIO.BOTH, callback=handle_callback, bouncetime=bounce)
while True: while True:
@ -104,7 +100,7 @@ if len(sys.argv) > 1:
sys.exit(0) sys.exit(0)
elif cmd == "byte": elif cmd == "byte":
#print "Initialised BYTE mode - "+str(pin)+ #print("Initialised BYTE mode - "+str(pin)+)
list = [7,11,13,12,15,16,18,22] list = [7,11,13,12,15,16,18,22]
GPIO.setup(list,GPIO.OUT) GPIO.setup(list,GPIO.OUT)
@ -127,7 +123,7 @@ if len(sys.argv) > 1:
GPIO.output(list[bit], data & mask) GPIO.output(list[bit], data & mask)
elif cmd == "borg": elif cmd == "borg":
#print "Initialised BORG mode - "+str(pin)+ #print("Initialised BORG mode - "+str(pin)+)
GPIO.setup(11,GPIO.OUT) GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT) GPIO.setup(13,GPIO.OUT)
GPIO.setup(15,GPIO.OUT) GPIO.setup(15,GPIO.OUT)
@ -154,10 +150,10 @@ if len(sys.argv) > 1:
data = 0 data = 0
elif cmd == "rev": elif cmd == "rev":
print GPIO.RPI_REVISION print(GPIO.RPI_REVISION)
elif cmd == "ver": elif cmd == "ver":
print GPIO.VERSION print(GPIO.VERSION)
elif cmd == "mouse": # catch mice button events elif cmd == "mouse": # catch mice button events
file = open( "/dev/input/mice", "rb" ) file = open( "/dev/input/mice", "rb" )
@ -171,7 +167,7 @@ if len(sys.argv) > 1:
button = ord( buf[0] ) & pin # mask out just the required button(s) button = ord( buf[0] ) & pin # mask out just the required button(s)
if button != oldbutt: # only send if changed if button != oldbutt: # only send if changed
oldbutt = button oldbutt = button
print button print(button)
while True: while True:
try: try:
@ -181,4 +177,4 @@ if len(sys.argv) > 1:
sys.exit(0) sys.exit(0)
else: else:
print "Bad parameters - in|out|pwm|buzz|byte|borg|mouse|ver pin {value|up|down}" print("Bad parameters - in|out|pwm|buzz|byte|borg|mouse|ver pin {value|up|down}")

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-piliter", "name" : "node-red-node-piliter",
"version" : "0.0.12", "version" : "0.0.13",
"description" : "A Node-RED node to drive a Raspberry Pi Pi-LITEr 8 LED board.", "description" : "A Node-RED node to drive a Raspberry Pi Pi-LITEr 8 LED board.",
"dependencies" : { "dependencies" : {
}, },

View File

@ -62,8 +62,8 @@ def restart():
if len(sys.argv) > 1: if len(sys.argv) > 1:
pins = sys.argv[1].lower().split(',') pins = sys.argv[1].lower().split(',')
if len(pins) != 3: if len(pins) != 3:
print "Bad parameters supplied" print("Bad parameters supplied")
print pins print(pins)
sys.exit(0) sys.exit(0)
TRIGGER = int(pins[0]) TRIGGER = int(pins[0])
@ -91,6 +91,6 @@ if len(sys.argv) > 1:
sys.exit(0) sys.exit(0)
else: else:
print "Bad params" print("Bad params")
print " sudo nrsrf.py trigger_pin,echo_pin,rate_in_seconds" print(" sudo nrsrf.py trigger_pin,echo_pin,rate_in_seconds")
sys.exit(0) sys.exit(0)

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-pisrf", "name" : "node-red-node-pisrf",
"version" : "0.1.1", "version" : "0.1.2",
"description" : "A Node-RED node for a Raspberry Pi to use a SRF04 or SRF05 range finder", "description" : "A Node-RED node for a Raspberry Pi to use a SRF04 or SRF05 range finder",
"dependencies" : { "dependencies" : {
}, },

View File

@ -10,10 +10,6 @@ from time import sleep
bounce = 25; bounce = 25;
if sys.version_info >= (3,0):
print("Sorry - currently only configured to work with python 2.x")
sys.exit(1)
if len(sys.argv) > 2: if len(sys.argv) > 2:
cmd = sys.argv[1].lower() cmd = sys.argv[1].lower()
pin = int(sys.argv[2]) pin = int(sys.argv[2])
@ -21,7 +17,7 @@ if len(sys.argv) > 2:
GPIO.setwarnings(False) GPIO.setwarnings(False)
if cmd == "pwm": if cmd == "pwm":
#print "Initialised pin "+str(pin)+" to PWM" #print("Initialised pin "+str(pin)+" to PWM")
GPIO.setup(pin,GPIO.OUT) GPIO.setup(pin,GPIO.OUT)
p = GPIO.PWM(pin, 100) p = GPIO.PWM(pin, 100)
p.start(0) p.start(0)
@ -36,10 +32,10 @@ if len(sys.argv) > 2:
GPIO.cleanup(pin) GPIO.cleanup(pin)
sys.exit(0) sys.exit(0)
except Exception as ex: except Exception as ex:
print "bad data: "+data print("bad data: "+data)
elif cmd == "buzz": elif cmd == "buzz":
#print "Initialised pin "+str(pin)+" to Buzz" #print("Initialised pin "+str(pin)+" to Buzz")
GPIO.setup(pin,GPIO.OUT) GPIO.setup(pin,GPIO.OUT)
p = GPIO.PWM(pin, 100) p = GPIO.PWM(pin, 100)
p.stop() p.stop()
@ -58,10 +54,10 @@ if len(sys.argv) > 2:
GPIO.cleanup(pin) GPIO.cleanup(pin)
sys.exit(0) sys.exit(0)
except Exception as ex: except Exception as ex:
print "bad data: "+data print("bad data: "+data)
elif cmd == "out": elif cmd == "out":
#print "Initialised pin "+str(pin)+" to OUT" #print("Initialised pin "+str(pin)+" to OUT")
GPIO.setup(pin,GPIO.OUT) GPIO.setup(pin,GPIO.OUT)
if len(sys.argv) == 4: if len(sys.argv) == 4:
GPIO.output(pin,int(sys.argv[3])) GPIO.output(pin,int(sys.argv[3]))
@ -82,11 +78,11 @@ if len(sys.argv) > 2:
GPIO.output(pin,data) GPIO.output(pin,data)
elif cmd == "in": elif cmd == "in":
#print "Initialised pin "+str(pin)+" to IN" #print("Initialised pin "+str(pin)+" to IN")
bounce = int(sys.argv[4]) bounce = int(sys.argv[4])
def handle_callback(chan): def handle_callback(chan):
sleep(bounce/1000) sleep(bounce/1000)
print GPIO.input(chan) print(GPIO.input(chan))
if sys.argv[3].lower() == "up": if sys.argv[3].lower() == "up":
GPIO.setup(pin,GPIO.IN,GPIO.PUD_UP) GPIO.setup(pin,GPIO.IN,GPIO.PUD_UP)
@ -95,7 +91,7 @@ if len(sys.argv) > 2:
else: else:
GPIO.setup(pin,GPIO.IN) GPIO.setup(pin,GPIO.IN)
print GPIO.input(pin) print(GPIO.input(pin))
GPIO.add_event_detect(pin, GPIO.BOTH, callback=handle_callback, bouncetime=bounce) GPIO.add_event_detect(pin, GPIO.BOTH, callback=handle_callback, bouncetime=bounce)
while True: while True:
@ -108,7 +104,7 @@ if len(sys.argv) > 2:
sys.exit(0) sys.exit(0)
elif cmd == "byte": elif cmd == "byte":
#print "Initialised BYTE mode - "+str(pin)+ #print("Initialised BYTE mode - "+str(pin)+)
list = [7,11,13,12,15,16,18,22] list = [7,11,13,12,15,16,18,22]
GPIO.setup(list,GPIO.OUT) GPIO.setup(list,GPIO.OUT)
@ -131,7 +127,7 @@ if len(sys.argv) > 2:
GPIO.output(list[bit], data & mask) GPIO.output(list[bit], data & mask)
elif cmd == "borg": elif cmd == "borg":
#print "Initialised BORG mode - "+str(pin)+ #print("Initialised BORG mode - "+str(pin)+)
GPIO.setup(11,GPIO.OUT) GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT) GPIO.setup(13,GPIO.OUT)
GPIO.setup(15,GPIO.OUT) GPIO.setup(15,GPIO.OUT)
@ -169,7 +165,7 @@ if len(sys.argv) > 2:
button = ord( buf[0] ) & pin # mask out just the required button(s) button = ord( buf[0] ) & pin # mask out just the required button(s)
if button != oldbutt: # only send if changed if button != oldbutt: # only send if changed
oldbutt = button oldbutt = button
print button print(button)
while True: while True:
try: try:
@ -194,7 +190,7 @@ if len(sys.argv) > 2:
# type,code,value # type,code,value
print("%u,%u" % (code, value)) print("%u,%u" % (code, value))
event = file.read(EVENT_SIZE) event = file.read(EVENT_SIZE)
print "0,0" print("0,0")
file.close() file.close()
sys.exit(0) sys.exit(0)
except: except:
@ -204,14 +200,14 @@ if len(sys.argv) > 2:
elif len(sys.argv) > 1: elif len(sys.argv) > 1:
cmd = sys.argv[1].lower() cmd = sys.argv[1].lower()
if cmd == "rev": if cmd == "rev":
print GPIO.RPI_REVISION print(GPIO.RPI_REVISION)
elif cmd == "ver": elif cmd == "ver":
print GPIO.VERSION print(GPIO.VERSION)
elif cmd == "info": elif cmd == "info":
print GPIO.RPI_INFO print(GPIO.RPI_INFO)
else: else:
print "Bad parameters - in|out|pwm|buzz|byte|borg|mouse|kbd|ver|info {pin} {value|up|down}" print("Bad parameters - in|out|pwm|buzz|byte|borg|mouse|kbd|ver|info {pin} {value|up|down}")
print " only ver (gpio version) and info (board information) accept no pin parameter." print(" only ver (gpio version) and info (board information) accept no pin parameter.")
else: else:
print "Bad parameters - in|out|pwm|buzz|byte|borg|mouse|kbd|ver|info {pin} {value|up|down}" print("Bad parameters - in|out|pwm|buzz|byte|borg|mouse|kbd|ver|info {pin} {value|up|down}")

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-pibrella", "name" : "node-red-node-pibrella",
"version" : "0.0.12", "version" : "0.0.13",
"description" : "A Node-RED node to read from and write to a Pibrella Raspberry Pi add-on board", "description" : "A Node-RED node to read from and write to a Pibrella Raspberry Pi add-on board",
"dependencies" : { "dependencies" : {
}, },

View File

@ -171,5 +171,5 @@ if __name__ == '__main__':
except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program except (EOFError, SystemExit): # hopefully always caused by us sigint'ing the program
sys.exit(0) sys.exit(0)
except Exception as ex: except Exception as ex:
print "bad data: "+data print("bad data: "+data)
print ex print(ex)

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-pi-neopixel", "name" : "node-red-node-pi-neopixel",
"version" : "0.0.19", "version" : "0.0.20",
"description" : "A Node-RED node to output to a neopixel (ws2812) string of LEDS from a Raspberry Pi.", "description" : "A Node-RED node to output to a neopixel (ws2812) string of LEDS from a Raspberry Pi.",
"dependencies" : { "dependencies" : {
}, },