首页 > 解决方案 > node-red 表节点

问题描述

我有一个函数,它从仪表板文本输入中获取输入作为时间选择,它计算小时和分钟,它设置其他变量并将 msg 对象返回到 Schedex 节点,但是当流是时它没有设置时间或其他变量执行。我多次修改文档并按照我的最佳理解进行操作,但它仍然没有配置我的 Schedex 节点。Schedex 文档中提到了将配置发送到 Schedex 节点的两种方式,第一种方式是设置 msg.palyload.variable 或将所有配置作为一个字符串发送到 mgs.payload 我将在下面发布两个版本的功能代码。如果您想阅读 Schedex 的文档,可以在下面找到https://www.npmjs.com/package/node-red-contrib-schedex

    msgTemp = msg.payload;
    time = msgTemp / 1000;
    // calculates hour from seconds input
    h = Math.floor(time / 3600); 
    // calculates minutes from remainder 
    m = Math.floor(time % 3600 / 60); 
    // ontime formatted for Schedex standards
    ontime = ('0' + h).slice(-2) + ":" + ('0' + m).slice(-2);
    //setting ontime
    msg.payload.ontime = ontime;
    //setting onpayload
    msg.payload.onpayload = "1";
    //enabling schedule for every time of the week
    msg.payload.mon = true;
    msg.payload.tue = true;
    msg.payload.wed = true;
    msg.payload.thu = true;
    msg.payload.fri = true;
    msg.payload.sat = true;
    msg.payload.sun = true;
    //the documentations mentions that to set the variables from the ui 
    //it has to be in programmatic control, I have put this in the 
    //payload and it's not working.
    //i think my issue is with the line below but i can't figure it out
    msg.payload = "'## Programmatic Control";
    return msg;

这是另一个版本,其中所有配置都作为一个字符串存储在 msg.payload 上

    msgTemp = msg.payload;
    time = msgTemp / 1000;
    // calculates hour from seconds input
    h = Math.floor(time / 3600); 
    // calculates minutes from remainder 
    m = Math.floor(time % 3600 / 60); 
    ontime = "onetime " + ('0' + h).slice(-2) + ":" + ('0' + m).slice(-2) 
    + " ";
    onpayload = "onpayload 1 ";
    mon = "mon true ";
    tue = "tue true ";
    wed = "wed true ";
    thu = "thu true ";
    fri = "fri true ";
    sat = "sat true ";
    sun = "sun true ";
    msg.payload = ontime + onpayload + mon + tue + wed + thu + fri + sat 
    + sun;
    return msg;

非常感谢您的帮助

标签: javascriptnode-red

解决方案


第一个示例前面的最后一行通过用字符串替换该对象return来消除您对对象所做的所有更改msg.payload"'## Programmatic Control"


推荐阅读