# Node-RED Dashboard: Some simple questions

**URL:** <https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538>\
**Category:** Dashboard\
**Created:** [20 August 2019 09:29 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538 "2019-08-20T09:29:39Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Minz](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@Minz](https://discourse.nodered.org/u/Minz)\
**Post date:** [28 August 2019 12:24 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/21 "2019-08-28T12:24:07Z")

</div>

Because its a really big program and it would cost weeks to implement this into node-red completely

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [28 August 2019 14:09 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/22 "2019-08-28T14:09:03Z")

</div>

I know of no way of doing that but maybe someone else will have an idea

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [28 August 2019 16:25 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/23 "2019-08-28T16:25:31Z")

</div>

Sure you can. The code you provided is asking the user for an input. This means you run it on a display if I have understood correctly???

Then you have to start the python program in such way so it runs on the display. My example, test.py, with your code, works fine running in a RPi as you can see on the screen shot below. I added a short delay to allow you to see the result since the program closes otherwise when the execution is finished

If you want to give the program the input from NR and see the result returned back, you have to introduce communication with your python program. Inputs can be sent as arguments and return of the result, well I would use MQTT

```auto
import time

def main():
	user_input = input('Hello User, please write a number: ')
	print('Your input was ' + user_input)
        

if __name__ == ' __main__':
    main()

time.sleep(5)

```

```auto
[{"id":"1ad354d8.5ea0cb","type":"exec","z":"797a7c58.e82134","command":"export DISPLAY=:0 && lxterminal -e python3 /home/pi/test.py","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":760,"y":450,"wires":[[],[],[]]},{"id":"65c511f.996e8f","type":"inject","z":"797a7c58.e82134","name":"Go","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":290,"y":450,"wires":[["1ad354d8.5ea0cb"]]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9423eabbaebba08a8e1c821768f0b17fc4e3ec3a.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [28 August 2019 17:31 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/24 "2019-08-28T17:31:02Z")

</div>

@krambriw Walter, what if NR is running on the Pi, but you are connected to on a browser from device B? Won't it open the window on the Pi and not in the dashboard of the browser B?

If I understand the OP he wants the questions to show up in the node-RED Dashboard.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [28 August 2019 18:01 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/25 "2019-08-28T18:01:10Z")

</div>

> [@zenofmud](#):
>
> If I understand the OP he wants the questions to show up in the node-RED Dashboard

Well, if that's the case, sure is possible, then there has to be two-way communication between the Python program and NR. I would then extend the Python program to use MQTT for this purpose

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [28 August 2019 18:13 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/26 "2019-08-28T18:13:53Z")

</div>

Well the node-red-node-daemon may be better suited as it provides stdin and stdout so you can both listen and reply to a long running process.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [29 August 2019 07:47 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/27 "2019-08-29T07:47:35Z")

</div>

This is a little xample with NR communicating with a python script using mqtt

With "Go" you start the python script, then visible on the display

From the dashboard you pick a number that is sent to the script, returned back and displayed as the result

With "abort" you terminate the python script

```auto
[{"id":"ea37930f.f3f81","type":"exec","z":"8627eb61.169ee8","command":"export DISPLAY=:0 && lxterminal -e python3 /home/pi/test.py","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":550,"y":1280,"wires":[[],[],[]]},{"id":"c8a452e7.c8ba7","type":"mqtt in","z":"8627eb61.169ee8","name":"","topic":"from_python","qos":"2","datatype":"auto","broker":"75eba16c.094f9","x":150,"y":1500,"wires":[["e677846b.f968e8","fcc16d87.c21e1"]]},{"id":"1c4bbd7b.ee5dc3","type":"inject","z":"8627eb61.169ee8","name":"Go","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1280,"wires":[["ea37930f.f3f81"]]},{"id":"e677846b.f968e8","type":"debug","z":"8627eb61.169ee8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":370,"y":1560,"wires":[]},{"id":"9bbac985.bba978","type":"mqtt out","z":"8627eb61.169ee8","name":"","topic":"to_python","qos":"","retain":"","broker":"75eba16c.094f9","x":380,"y":1360,"wires":[]},{"id":"b90a472b.2d32f8","type":"ui_numeric","z":"8627eb61.169ee8","name":"","label":"pick a number","tooltip":"","group":"b367811d.6667b","order":1,"width":0,"height":0,"passthru":true,"topic":"","format":"{{value}}","min":0,"max":10,"step":1,"x":160,"y":1360,"wires":[["9bbac985.bba978"]]},{"id":"fcc16d87.c21e1","type":"ui_text","z":"8627eb61.169ee8","group":"b367811d.6667b","order":2,"width":0,"height":0,"name":"","label":"result","format":"{{msg.payload}}","layout":"row-spread","x":370,"y":1500,"wires":[]},{"id":"ad31a88a.314728","type":"inject","z":"8627eb61.169ee8","name":"","topic":"","payload":"abort","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1430,"wires":[["9bbac985.bba978"]]},{"id":"75eba16c.094f9","type":"mqtt-broker","z":"","name":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"b367811d.6667b","type":"ui_group","z":"","name":"User inputs & results","tab":"f1725e1b.29ba","disp":true,"width":"8","collapse":false},{"id":"f1725e1b.29ba","type":"ui_tab","z":"","name":"NR to Python","icon":"dashboard","disabled":false,"hidden":false}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7abad2daa4c145f8da65cb68c18da63e2ec27be3.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/ec7146d329c8f37e810f77d5bb22d144adbb652e.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/ac18973acc9da60b483a11846d47e5267f7e65de.jpeg)

And the script....

```auto
import time
import paho.mqtt.client as mqtt
abort = False

def on_connect(client, obj, flags, rc):
    client.subscribe("to_python", 0)

def on_subscribe(client, userdata, mid, granted_qos):
    print ('Subscribed:', userdata, mid, granted_qos)
    print ('We are here, waiting for commands...')

def on_message(client, obj, msg):
    global abort
    print (msg.payload)
    if msg.payload.decode("utf-8") == "abort":
        abort = True
        return
    client.publish("from_python", 'Your input was '+str(msg.payload.decode("utf-8")), 1, False)

def main():
    client = mqtt.Mosquitto()
    client.on_connect = on_connect
    client.on_message = on_message
    client.on_subscribe = on_subscribe
    client.connect("127.0.0.1", 1883, 60)
    client.loop_start()
    client.publish("from_python", 'Hello user, please pick a number: ', 1, False)
        
    while abort == False:
        time.sleep(1)

    client.loop_stop()
    client.disconnect()
    del client
    exit(0)

if __name__ == ' __main__':
    main()

```

---

<div class="post-metadata">

**Author:** ![georgey11](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@georgey11](https://discourse.nodered.org/u/georgey11)\
**Post date:** [27 January 2021 16:52 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/28 "2021-01-27T16:52:27Z")

</div>

This is helping me understand a lot , its been really helpfull.

So what i need to do is tell NR to start my Python Script, from that script i need to be able to extract who was recognised (as its facial recognition). And get that sent back to NR.

Still figuring it out but feel like im making progress

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [27 January 2021 17:05 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/29 "2021-01-27T17:05:09Z")

</div>

the "other" way - is for your python script to be running separately all the time (but alongside) ... waiting for an mqtt message to arrive (containing and image buffer) in the on\_Message call above - process it and send the answer back (using client.publish) ... And likewise for Node-RED to publish the image out to the required topic and subscribe to the answer topic coming back.

---

<div class="post-metadata">

**Author:** ![georgey11](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@georgey11](https://discourse.nodered.org/u/georgey11)\
**Post date:** [27 January 2021 17:32 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/30 "2021-01-27T17:32:24Z")

</div>

Do you know of any exmaples like this?

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [27 January 2021 17:39 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/31 "2021-01-27T17:39:23Z")

</div>

Maybe misunderstood, but is this for a lesson you have at college? Or is it for the monitoring of vechiles arriving at he college?

---

<div class="post-metadata">

**Author:** ![georgey11](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@georgey11](https://discourse.nodered.org/u/georgey11)\
**Post date:** [27 January 2021 17:41 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/32 "2021-01-27T17:41:26Z")

</div>

Its a project im doing for college, essentially only allowing authorized persons enter through the barrier

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [27 January 2021 17:50 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/33 "2021-01-27T17:50:05Z")

</div>

OK understood. If you take the script above, it is a script that will run continously until you "kill it" (if you send a mqtt message "abort" to it, it will terminate gracefully)

Now you can combine this script with the functionality of yours. In your script you read frames from your camera and detects and checks faces. If you get a match you just publish that back to NR via mqtt

What you also could do, I think this is what @dceejay meant, is to feed the script with image data from other sources. You then convert the image data into a buffer in NR and sends it to the script via mqtt. It will arrive in the "on\_message" callback function where you could add necessary code or another function call to do the checkup

---

<div class="post-metadata">

**Author:** ![georgey11](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@georgey11](https://discourse.nodered.org/u/georgey11)\
**Post date:** [27 January 2021 18:04 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/34 "2021-01-27T18:04:11Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/2/c2e07a3fc36373ac92758787f5aca34a2c837811.png)

I wont run my script, only bring me to my script, iv tried "\_run" after geany and just get a blank terminal

---

<div class="post-metadata">

**Author:** ![georgey11](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@georgey11](https://discourse.nodered.org/u/georgey11)\
**Post date:** [27 January 2021 18:05 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/35 "2021-01-27T18:05:55Z")

</div>

How would do i run a python script all of the time?

Please understand i am new to all of this

---

<div class="post-metadata">

**Author:** ![georgey11](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@georgey11](https://discourse.nodered.org/u/georgey11)\
**Post date:** [27 January 2021 18:06 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/36 "2021-01-27T18:06:38Z")

</div>

How would do i run a python script all of the time?

Please understand i am new to all of this

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [27 January 2021 18:14 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/37 "2021-01-27T18:14:29Z")

</div>

My script above will run until you abort it by sending a mqtt message ''abort" (or kill it). Read the python code and you will see, there is a loop at the end

```auto
while abort == False:
        time.sleep(1)

```

---

<div class="post-metadata">

**Author:** ![georgey11](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@georgey11](https://discourse.nodered.org/u/georgey11)\
**Post date:** [27 January 2021 18:19 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/38 "2021-01-27T18:19:29Z")

</div>

Ah yes i see that.  
But my script wont run, it just brings me to my script in Geany. Im obviously missing something to run it

---

<div class="post-metadata">

**Author:** ![georgey11](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@georgey11](https://discourse.nodered.org/u/georgey11)\
**Post date:** [27 January 2021 18:22 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/39 "2021-01-27T18:22:24Z")

</div>

I need to be able to get it running in the background before i link the python and NR with mqtt

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [27 January 2021 18:23 UTC](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538/40 "2021-01-27T18:23:52Z")

</div>

Are you good at python? You'll fix it 😉

[Previous page](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538.md?page=1)

[Next page](https://discourse.nodered.org/t/node-red-dashboard-some-simple-questions/14538.md?page=3)
