Like you can see I have a menu, and when a user choose is option I comunicate with i2c devices and others protocols.
I want to know if this is possible in Node Red.
Like you may realize this need to be in real time and fast.
I try to run one of my scripts using pythonshell but it gives me an error.
I will leave some videos that i do, to you have some ideas:
Its possible to run a script like this in Node-Red ?
Thanks
Well,,,you can start/run a python script using the Exec node and it will then show your menu in a window like that. But you have to tell that the script shall run in a window on the display. Otherwise it will be hidden from the display
I do start my python scripts this way, I give you an example how to do:
In the picture below I have 4 different python scripts doing different things. I installed xterm first because it gives me more control of windows size and position on display etc
The syntax for the command is as example below. But your menu is not so good looking, right? Try make your users more happy, in Node-RED you can create a nice dashboard for your menu instead and send user choice as parameter to your python script instead, I think you should try this?
We also have the node-red-node-daemon which is like the exec node but for long running processes - you can feed inputs via stdin and get back stdout and stderr - so you may be able to drive menus that way also (if that isn't just a one off operation).
Hey guys,
I don't use python myself, but I thought you would have advised Marcos to start using the node-red-contrib-python-function. Seems at first sight a very easy to use node, similar to the Javascript function node which we use all over the place... Or does python work completely different?
Bart
It depends what is in the python script. Not everything works in the node. And the python script will run non-visible, no menu for users will be shown!?
If you read the notes it’s saying “only use this in sandbox, not production ready”. And counting the number of issues I’ve seen with it on the forum that I had to assist on, I’ve to agree with that. The pythonshell node is arguably better. The python function nodes start a script with the contents of the function in the background, then attempt to serialise the incoming message contents and send them to the running python process, where it’s unserialised again. While an understandable approach, the python code that handles this isn’t properly set up with error handling to report back to the user what went wrong, and how/why to solve this.
I’m adding here that as a Python expert user I’m able to provide support but only because I’m familiar with core modules and where certain parts of stacktraces are likely caused by. If anything with the code you put in this node or messages you feed it goes wrong, you’re basically on your own unless you know you’re way around in the Python core to debug the underlying script that powers the node.
then I try the solution of @krambriw because it seems very logical but it gives error again ... however i think that the error might be related with the input of exec_node .... i dont know, just see
The window appears, despite of not run the script inside .... I have now another question:
There's any way of, instead open a terminal to run the script, run the script itself in a widget or something fixed in the webpage, like a display ?? .... I don't know
Something is blocking the script to continue, maybe something also related to the missing fonts
how did you run the script manually? Did you click on it to start it or what?
have you tried to run the script manually from the terminal?
you can also try to configure the exec node like this, in spawn mode, to see if there is any change
but I do not know what is inside your script so I cannot debug. If you make a simple version of your script or share it, I can test it myself
I do not think you can embed a terminal display like that into a webpage. Maybe someone else knows a trick but if you want to make a web gui, I think the script needs re-design. The main functionality is most likely what you keep but you need to provide the script to take inputs from users like you have already in menu, "Pick an option", but now instead from buttons or dropdown menu. Then you have to display the result to user in the web page, to do this the script needs to return the result via websocket so the webpage can be updated dynamically.
I could see a solution structure like this:
dashboard menu -> user selection to script -> script execution -> script result -> via websocket -> dashboard presentation of result
If the user needs to interact more in between, like the script needs some more input from user while it is executing, everything becomes more complicated
What is your use case, why you wanna run the script from Node-RED? It seems to be working fine as is. Is it used for testing pcb board that you manufacture and sell to customers?
This is for my final university project, I have some PCB, used in my workplace, and the comunication is mainly I2C or RS232 or SPI.
I used Python to do scripts, user frindly, test the PCB. Each PCB has a different python script and they share some functions, to simplify the work.
And well I just want to know if Node Red can do it.
I cannot run it anyway in my systems, we seem to have so different character sets & language support installed
But anyway, just some questions? I suppose the functionality is working as you wish? So the python code is fine but not looking "too attractive"? Is that the point?
Well if so, Node-RED is not suited to make a "facelift" of an existing character based software. There are development tools for python gui applications if that is what you really want. But it will be quite a lot work too.
Node-RED could be used as I described earlier but then the python script has to be "stripped off" from display & user inputs via screen. You could then have the python script as a "service" doing it's stuff in the background and report the result back. But also for this, pretty lot to do.
Thnks for the enlightenment .... of course the work worth the effort but, this in the future will grow and i will have more scripts, and maybe do a database .... so it cant be to much hard to implement the code in the GUI
Maybe i will turn on PyQT again (in first i try but was hard, for someone who doesnt know to much programing ... just C and Python) or Tkinter
Python and C is very valuable to be skilled in! Thinking about the future, for you now as student, so much is happening in AI, Python is heavily used there with OpenCV for image analyze and C (and also Cython in some cases) for performance. Self driving taxi will be launched here later this year. You have an interesting future!
I have done so much in Python, I think started 2006. With Node-RED again a change, now focus on javascript and html. I could re-use many of my Python working packages as services and I was hoping to stay on this high level. Until I could not stay away from the small device ESP32, I had to dive down into C again, life is a challenge
Thanks a lot ..... I will do some Testing in a script of python receive inputs from Node ... And then I will, maybe and if I have time, modify my scripts to integrate in Node .... Node seems to be very easy to use