Raspberry Pi + UniPi - Reading inputs

701 views
Skip to first unread message

Matt Conway

unread,
Jun 11, 2015, 10:20:39 AM6/11/15
to node...@googlegroups.com
Hello,

I have connected a button to my UniPi. I've connected it to I04 (Which turns on in the UniPi Control Panel when I am using Pin: 16, GPIO4) and then I've made a simple flow to try and read the state of the input and turn on relay 1 based on the output. The "TestRelay1" injectors both work.
Here is my flow (Exported code at the bottom):


When the flow is deployed to the Pi, the UniPi control panel shows Input 4 as on, but the flow shows it as 0. Neither recognise the button being pressed, even though the led on the UniPi does change state.
Before deployment, the control panel was recognising the button being pressed just fine.

Is there something wrong with my flow? What is the best way for me to read the Digital inputs on my UniPi through node-red?

Any help is greatly appreciated.

Matt

(Sorry if I haven't adhered to this groups posting conventions, let me know if I have done something wrong!)

Export code:

[{"id":"300b989c.e8de08","type":"websocket-client","path":"ws://127.0.0.1/ws","wholemsg":"false"},{"id":"b40c4a71.fbf9a","type":"websocket out","name":"","server":"","client":"300b989c.e8de08","x":883,"y":300,"z":"903f246b.4a7b8","wires":[]},{"id":"bebdaeaf.8b774","type":"function","name":"GetState","func":"state = msg.payload;\nmsg= {};\n\nmsg.payload = {\"dev\":\"relay\",\"circuit\":\"1\",\"value\": state}\n\nreturn msg;","outputs":1,"valid":true,"x":636,"y":300,"z":"903f246b.4a7b8","wires":[["b40c4a71.fbf9a","2af3cdc0.a80f42"]]},{"id":"2af3cdc0.a80f42","type":"debug","name":"","active":false,"console":"false","complete":"payload","x":833,"y":245,"z":"903f246b.4a7b8","wires":[]},{"id":"905700c0.a31b88","type":"debug","name":"","active":true,"console":"false","complete":"false","x":637,"y":193,"z":"903f246b.4a7b8","wires":[]},{"id":"42b06efd.165be","type":"inject","name":"TestRelay1 - On","topic":"","payload":"1","payloadType":"string","repeat":"","crontab":"","once":false,"x":419,"y":389,"z":"903f246b.4a7b8","wires":[["bebdaeaf.8b774"]]},{"id":"8fefce24.ba2368","type":"inject","name":"TestRelay1 - Off","topic":"","payload":"0","payloadType":"string","repeat":"","crontab":"","once":false,"x":418,"y":440,"z":"903f246b.4a7b8","wires":[["bebdaeaf.8b774"]]},{"id":"882a3be.93f3ec8","type":"rpi-gpio in","name":"","pin":"16","intype":"tri","read":false,"x":379,"y":243,"z":"903f246b.4a7b8","wires":[["bebdaeaf.8b774","905700c0.a31b88"]]}]

Mark Setrem

unread,
Jun 11, 2015, 11:59:47 AM6/11/15
to node...@googlegroups.com
I'm guessing the UniPi control panel is a Raspberry PI App?
If so it could be that it is still running and therefore the serial port is locked as only one app can "attach" to a serial port.
What does the node-red console log show?

An alternative approach would be to use the example in the flows library flows.nodered.org (search for UniPi) which appears to connect by some interim software.

Matt Conway

unread,
Jun 11, 2015, 12:08:56 PM6/11/15
to node...@googlegroups.com
Thanks for getting back to me Mark.

The UniPi control panel is essentially a Raspberry Pi app, yes. It runs using the Evok Api.
I followed this tutorial for getting everything setup.

http://unipi.technology/wiki/Controlling_UniPi_over_Node-RED_and_IBM_Bluemix

Console output below:
pi@GPIOTest ~ $ node-red-pi

Welcome to Node-RED
===================

11 Jun 16:05:57 - [info] Node-RED version: v0.10.6
11 Jun 16:05:57 - [info] Node.js  version: v0.10.38
11 Jun 16:05:57 - [info] Loading palette nodes
11 Jun 16:06:03 - [warn] ------------------------------------------
11 Jun 16:06:03 - [warn] Failed to register 3 node types
11 Jun 16:06:03 - [warn] Run with -v for details
11 Jun 16:06:03 - [warn] ------------------------------------------
11 Jun 16:06:03 - [info] User Directory : /home/pi/.node-red
11 Jun 16:06:03 - [info] Flows file     : /home/pi/.node-red/flows_GPIOTest.json
11 Jun 16:06:03 - [info] Server now running at http://127.0.0.1:1880/
11 Jun 16:06:03 - [info] Starting flows
11 Jun 16:06:03 - [info] Started flows

I think the only UniPi flow I could find was the one from the tutorial, I will look again!

Cheers,

Matt


--
http://nodered.org
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/QEhG7GoNQNA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark Setrem

unread,
Jun 11, 2015, 12:30:50 PM6/11/15
to node...@googlegroups.com
To gain any really useful information from the console.log you would need to restart node-red with the -v flag.

Matt Conway

unread,
Jun 12, 2015, 7:42:36 AM6/12/15
to node...@googlegroups.com
Hi again,

I added the -v flag to the command to see what was going on. Perhaps I need to add the modules I'm missing?
Output below


pi@GPIOTest ~ $ node-red-pi -v

Welcome to Node-RED
===================

12 Jun 10:36:52 - [info] Node-RED version: v0.10.6
12 Jun 10:36:52 - [info] Node.js version: v0.10.38
12 Jun 10:36:52 - [info] Loading palette nodes
12 Jun 10:36:58 - [warn] ------------------------------------------
12 Jun 10:36:58 - [warn] [arduino] Error: Cannot find module 'arduino-firmata'
12 Jun 10:36:58 - [warn] [redisout] Error: Cannot find module 'redis'
12 Jun 10:36:58 - [warn] [mongodb] Error: Cannot find module 'mongodb'
12 Jun 10:36:58 - [warn] ------------------------------------------
12 Jun 10:36:58 - [info] User Directory : /home/pi/.node-red
12 Jun 10:36:58 - [info] Flows file : /home/pi/.node-red/flows_GPIOTest.json
12 Jun 10:36:58 - [info] Server now running at http://127.0.0.1:1880/
12 Jun 10:36:58 - [info] Starting flows
12 Jun 10:36:58 - [info] Started flows
12 Jun 10:36:58 - [info] [rpi-gpio in:882a3be.93f3ec8] out: 1 :
12 Jun 10:36:58 - [info] [rpi-gpio in:882a3be.93f3ec8] out: 1 :
12 Jun 10:36:58 - [info] [rpi-gpio in:882a3be.93f3ec8] out: 0 :

Cheers,

Matt

Mark Setrem

unread,
Jun 12, 2015, 11:33:23 AM6/12/15
to node...@googlegroups.com
No you don't need to load the missing modules as you aren't using any of them. 

Your flow appears to be 
"RPI GPIO IN" -> "Function" -> etc   with the stated aim of detecting an change (button press) on the UniPi board.

Where as the tutorial you linked to has this diagram:

 

So you would appear to need a "WEBSOCKET IN" node rather than your "RPI GPIO IN" node. 


So start by linking "WEBSOCKET IN" -> "DEBUG"  configure the debug node to output "Complete msg object", deploy and see if that works.

Reply all
Reply to author
Forward
0 new messages