Node-RED Dashboard: Some simple questions

Dear Users,

I´m very new to Node-RED, and also pretty new to programming also, so please excuse my simple questions.

I wrote a script that charges or discharges batteries, the User can choose the End-Off-Charge voltage and other things beforehand. Up till now, I was running the script from my laptop via PuTTY on the raspberry console. Now I would like to use the Node-RED Dashboard instead. The Dashboard is running, everything installed just fine, I can start the program on my dashboard via a START Button. Now i have some problems:

The program begins by asking the user, what he wants to do: Charge or discharge, and then waits for user input (1 for charge, 2 for discharge). I can see the text on my dashboard, and I also have an input node right under, but whatever I Type in, nothing happens. I wrote the script so that wrong inputs should be detected and the user has to try again, but actually, nothing happens... Here is how it looks:

node%20red

You can also see another problem: the Text displayed is not formatted as I formatted it for the console display. But that's not too problematic, I will just erase the formatting and format in Node-RED

I have noticed that when I run a script like "Hello world" printed first, then sleeps for 10 seconds, and then a "Bye world" printed, it doesn't show live on the display, but both prints at once. How can outputs be displayed live?

In my script, the user can always cancel by keyboard interrupt (strg + c). By doing so, safety measures like deactivating all relais, for example, are handled. I would like to implement this in my dashboard, like a "STOP NOW" button that is just like strg + c.

Thanks for your help!

Start by adding debug nodes to your flow so you can “see” what is happening

In a case like this, you should provide your flow. No one can determine what you are doing from an image. That said, it looks like you are using an exec node, are the input's connected to the node passing information to it that needs to be sent to the script? What settings do you have used in the exec node?

Im sorry, i don´t know how to provide a flow... Yes, i use an exec node that looks like "sudo python3 /home/pi/testbench/main.py"

msg.payload is ticked.
output is on (spawn)

thats basically it.

I dont know what you mean by your "connected to the node passing information" questions. why are you talking about multiple inputs?

If i put a debug after the Main, and i type "1" into the input, the debug window shows:

node%20red%203

not sure how this helps...

hamburger
export
clipboard
allflows

And go read this post: How to share code or flow json

[{"id":"e4a4769c.0fab78","type":"exec","z":"40877b32.de1774","command":"sudo python3 /home/pi/Teststand/main.py","addpay":true,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"Main","x":381,"y":225,"wires":[["39fe0e69.cc0352"],[],[]]},{"id":"39fe0e69.cc0352","type":"ui_text","z":"40877b32.de1774","group":"f9561567.9c4328","order":1,"width":"6","height":"4","name":"output","label":"","format":"{{msg.payload}}","layout":"col-center","x":691,"y":212.5,"wires":[]},{"id":"8721a4b5.704418","type":"ui_button","z":"40877b32.de1774","name":"","group":"7b1c3c0.d43a6c4","order":1,"width":"6","height":"1","passthru":false,"label":"Start","tooltip":"","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"str","topic":"","x":171,"y":332.5,"wires":[["e4a4769c.0fab78"]]},{"id":"f53b7b50.e93ef8","type":"ui_text_input","z":"40877b32.de1774","name":"input","label":"input","tooltip":"","group":"f9561567.9c4328","order":2,"width":0,"height":0,"passthru":true,"mode":"text","delay":"0","topic":"","x":172,"y":145.5,"wires":[["e4a4769c.0fab78"]]},{"id":"f9561567.9c4328","type":"ui_group","z":"","name":"Display","tab":"50487181.35e13","order":2,"disp":true,"width":"6","collapse":false},{"id":"7b1c3c0.d43a6c4","type":"ui_group","z":"","name":"Teststand","tab":"50487181.35e13","order":1,"disp":true,"width":"6","collapse":false},{"id":"50487181.35e13","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

As a new user, i can´t attach the .json file...

Given your answers, it might be worth stepping back and starting by going through one of the tutorials for how to use Node-RED

This will give you an understanding of the fundamentals such as if you have two wires
going into a node the node will see two separate messages.

Your python also outputs a buffer (as you can see in the debug) whereas you need to output a string (text) if you want to display it

Your python also outputs a buffer (as you can see in the debug) whereas you need to output a string (text) if you want to display it

But as you see in the first post: I get a string displayed.

Please add a debug node to both the text-in node and the button node. Next press the button and enter some text.

Now look at your debug output, what do you see?

What are you doing with them?

Also you should attach a debug node to the other two outputs of the exec node so you can see if anything is coming out from them.

Hello zeno,

first thanks for your help, i am slowly getting to the root of my problem i guess. This is my current setup:

and this is what happens with the debugs, when i click the "START" button and send "1" via the input in the dashboard:

i unfolded one of the massages by debug output 1 and you can see: its the string that i get displayed in the output. Strange thing is, that the "1" gets send multiple times, in fact also every time i switch to the dashboard tab, ALTHOUGH I put the Delay to 0, which says, that 0 waits for Enter to send the input, but looks like it doesnt.

If I open the command on my raspberry at the same time and take a look at all processes called "main.py", i see this: (see next post)

I am not completely getting what i can see there, but it looks like i open more and more main.py by typing 1 into the input, or even just changing between tabs as i said.
Also, it looks like my Kill button does´nt work properly: It´s set to send "Kill" when clicked (i also tried msg.kill), but nothing happens.

Here is the json:

[{"id":"fc6a00f1.e87c3","type":"exec","z":"af93aff9.41f0e","command":"sudo python3 /home/pi/Teststand/main.py","addpay":true,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"Main","x":375.5,"y":169.5,"wires":[["8057f89e.611e18","f8cf3753.2039b8"],["d404f4db.ca5998"],["3dff16e7.01fdaa"]]},{"id":"8057f89e.611e18","type":"ui_text","z":"af93aff9.41f0e","group":"f9561567.9c4328","order":1,"width":"6","height":"4","name":"output","label":"","format":"{{msg.payload}}","layout":"col-center","x":825.5,"y":21,"wires":[]},{"id":"d83c3d26.fb445","type":"ui_button","z":"af93aff9.41f0e","name":"","group":"7b1c3c0.d43a6c4","order":1,"width":"6","height":"1","passthru":false,"label":"Start","tooltip":"","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"str","topic":"","x":130.5,"y":233,"wires":[["fc6a00f1.e87c3","b001e15f.dfd9c"]]},{"id":"a22755a7.1b15d8","type":"ui_text_input","z":"af93aff9.41f0e","name":"input","label":"input","tooltip":"","group":"f9561567.9c4328","order":2,"width":0,"height":0,"passthru":true,"mode":"text","delay":"0","topic":"","x":164.5,"y":120,"wires":[["fc6a00f1.e87c3","cb129418.0a2178"]]},{"id":"cb129418.0a2178","type":"debug","z":"af93aff9.41f0e","name":"input debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":358.5,"y":71,"wires":[]},{"id":"f8cf3753.2039b8","type":"debug","z":"af93aff9.41f0e","name":"exec output 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":890.5,"y":141,"wires":[]},{"id":"b001e15f.dfd9c","type":"debug","z":"af93aff9.41f0e","name":"button debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":395.5,"y":297,"wires":[]},{"id":"d404f4db.ca5998","type":"debug","z":"af93aff9.41f0e","name":"exec output 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":888.5,"y":208,"wires":[]},{"id":"3dff16e7.01fdaa","type":"debug","z":"af93aff9.41f0e","name":"exec output 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":894.5,"y":262,"wires":[]},{"id":"64934527.f1343c","type":"ui_button","z":"af93aff9.41f0e","name":"Kill","group":"7b1c3c0.d43a6c4","order":1,"width":"6","height":"1","passthru":true,"label":"Kill","tooltip":"","color":"","bgcolor":"","icon":"","payload":"msg.kill","payloadType":"str","topic":"","x":138,"y":321,"wires":[["fc6a00f1.e87c3"]]},{"id":"f9561567.9c4328","type":"ui_group","z":"","name":"Display","tab":"50487181.35e13","order":2,"disp":true,"width":"6","collapse":false},{"id":"7b1c3c0.d43a6c4","type":"ui_group","z":"","name":"Teststand","tab":"50487181.35e13","order":1,"disp":true,"width":"6","collapse":false},{"id":"50487181.35e13","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

in addition:

it certainly looks to me that when you press 'START' you are sending a boolean true not the number 1 and the input text is what ever is typed.

So both of those will be sent to the exec node and appended to the command that is executed

maybe i have to simplify my problem:

Lets say i have following code:

def main():

	user_input = input('Hello User, please write a number: ')

	print('Your input was ' + user_input)


if __name__ == '__main__':
    main()

and i want the node-red-dashboard to function as my command window, so that i have an output window for the script telling me to write a number, and an input window that gives the script back my written number and than again getting an output (in the same output window as before) telling me which number i typed in.

Because as it looks from the grep functions, as you said: I´m sending my input to the exec, but not within the exec.

The boolean 'true' comes from the Start button, as i thought sending a true to an exec would mean starting it...

Have you read the info tab of the exec node?

yes i did. What ae you trying to tell me? Let´s not focus on the start button problem, but on the problem of sending input within the exec please

payload string

if configured to do so, will be appended to the executed command.

The command that is run is defined within the node, with an option to append msg.payload and a further set of parameters.

As the node info tab says, you can add additional parameters to what ever program/command/script you are calling from the exec node. The extra parameters can be hard coded in the node or passed to the exec node via msg.payload

Why is there a need to do this in python and not just in node-red ?

Thanks, i did figure that out after seeing what the grep main.py showed me in the command.

But getting back to my simplified question:

maybe i have to simplify my problem:

Lets say i have following code:

def main():

	user_input = input('Hello User, please write a number: ')

	print('Your input was ' + user_input)


if __name__ == '__main__':
    main()

and i want the node-red-dashboard to function as my command window, so that i have an output window for the script telling me to write a number, and an input window that gives the script back my written number and than again getting an output (in the same output window as before) telling me which number i typed in.

Is there a possibility to ececute this main and sending an input not appended, but within the program.