node-red执行Python

node-red和python的结合使用,直接就是神器,前端和后端就都有了

图片如下
在这里插入图片描述
见代码



[
    {
        "id": "59d5b15.ad8035",
        "type": "template",
        "z": "eeb650e6.286b2",
        "name": "python content",
        "field": "payload",
        "fieldType": "msg",
        "format": "python",
        "syntax": "mustache",
        "template": "import os\na=os.getcwd()\nprint(a)",
        "output": "str",
        "x": 380,
        "y": 140,
        "wires": [
            [
                "674727ec.c18738"
            ]
        ]
    },
    {
        "id": "afcb6ff0.29a97",
        "type": "inject",
        "z": "eeb650e6.286b2",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 200,
        "y": 140,
        "wires": [
            [
                "59d5b15.ad8035"
            ]
        ]
    },
    {
        "id": "5bdf8e81.b3b82",
        "type": "exec",
        "z": "eeb650e6.286b2",
        "command": "python C:\\data\\1\\py001.py",
        "addpay": "payload",
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "",
        "x": 430,
        "y": 300,
        "wires": [
            [
                "ef46f3bb.2b14f"
            ],
            [],
            []
        ]
    },
    {
        "id": "674727ec.c18738",
        "type": "file",
        "z": "eeb650e6.286b2",
        "name": "",
        "filename": "C:\\data\\1\\py001.py",
        "appendNewline": true,
        "createDir": true,
        "overwriteFile": "true",
        "encoding": "none",
        "x": 590,
        "y": 140,
        "wires": [
            [
                "73781b8.e38c0e4"
            ]
        ]
    },
    {
        "id": "73781b8.e38c0e4",
        "type": "delay",
        "z": "eeb650e6.286b2",
        "name": "",
        "pauseType": "delay",
        "timeout": "2",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "outputs": 1,
        "x": 380,
        "y": 240,
        "wires": [
            [
                "5bdf8e81.b3b82"
            ]
        ]
    },
    {
        "id": "ef46f3bb.2b14f",
        "type": "debug",
        "z": "eeb650e6.286b2",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 630,
        "y": 300,
        "wires": []
    },
    {
        "id": "8eb98748.6f58d8",
        "type": "comment",
        "z": "eeb650e6.286b2",
        "name": "输入python代码进行执行",
        "info": "1.写入python文件\n2.构建文件的程序",
        "x": 230,
        "y": 100,
        "wires": []
    }
]
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Node-RED is a flow-based programming tool that allows you to visually create applications by connecting pre-built nodes together. It is often used for IoT projects and automation tasks. While Node-RED itself is written in Node.js, it provides support for executing Python scripts through the use of the "exec" node. To use Python in Node-RED, you can follow these steps: 1. Install Node.js: Node-RED requires Node.js to be installed on your machine. You can download it from the official website and follow the installation instructions. 2. Install Node-RED: Once Node.js is installed, you can install Node-RED globally by running the following command in your terminal: ``` npm install -g node-red ``` 3. Start Node-RED: After installation, you can start Node-RED by running the following command: ``` node-red ``` 4. Install Python dependencies: To execute Python scripts in Node-RED, you need to install the required Python dependencies. You can do this by running the following command in your terminal: ``` pip install pyserial ``` 5. Use the "exec" node: In Node-RED's visual editor, you can drag and drop an "exec" node from the palette onto your flow. Configure the node to run a Python script by specifying the path to the script file. 6. Write Python scripts: Create a Python script that performs the desired functionality. You can use the `sys.stdin` and `sys.stdout` streams to receive input from and send output to Node-RED. Remember to configure any required input/output parameters and handle errors appropriately in your Python script. That's a brief overview of using Python in Node-RED. Let me know if you have any more specific questions or need further assistance!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值