Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write to msg objects from python code #36

Open
corndog2000 opened this issue Oct 22, 2024 · 1 comment
Open

Write to msg objects from python code #36

corndog2000 opened this issue Oct 22, 2024 · 1 comment

Comments

@corndog2000
Copy link

I know that the msg object can be read from the python code. But, I cannot find information whether writing to msg[] objects updates that object in the node-red flow.

@404background
Copy link
Owner

Thank you @corndog2000 for your comments on the issue!

In the node, Python is executed and its output is passed to msg.payload.
This node is not implemented to pass to any property other than msg.payload.
Writing to the msg[] object does not update that object in the node-red flow.

The following is implemented in node/venv.js.

msg.payload = stdoutData
send(msg)

For more information on sending messages, see the following page.
https://nodered.org/docs/creating-nodes/node-js#sending-messages

For now, it is possible to output data in JSON format as follows.
image
image

However, it is passed to msg.payload.
image

Here is the flow.

[{"id":"b192eeb5e97d7214","type":"venv","z":"d6fad9e77ecc8414","venvconfig":"4657b6fbdbaf6f7e","name":"","code":"import json\n\ndef create_json_response():\n    data = {\n        \"payload\": msg['timestamp'],\n        \"message\": \"hello\",\n        \"number\": 100,\n    }\n    return json.dumps(data)\n\n\njson_response = create_json_response()\nprint(json_response)\n","continuous":false,"x":690,"y":2720,"wires":[["82484c9b086e3bf5","bf06d2df025c1dfa"]]},{"id":"945ebeb20fb9b18a","type":"inject","z":"d6fad9e77ecc8414","name":"","props":[{"p":"payload"},{"p":"timestamp","v":"","vt":"date"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"message\":\"hello\",\"number\":100}","payloadType":"json","x":550,"y":2720,"wires":[["b192eeb5e97d7214"]]},{"id":"82484c9b086e3bf5","type":"debug","z":"d6fad9e77ecc8414","name":"debug 183","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":2720,"wires":[]},{"id":"bf06d2df025c1dfa","type":"json","z":"d6fad9e77ecc8414","name":"","property":"payload","action":"obj","pretty":false,"x":590,"y":2800,"wires":[["b93d26177e6fb93b"]]},{"id":"b93d26177e6fb93b","type":"debug","z":"d6fad9e77ecc8414","name":"debug 184","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":2800,"wires":[]},{"id":"4657b6fbdbaf6f7e","type":"venv-config","venvname":"pyenv","version":"default"}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants