节点红色的Schedex节点

时间:2018-11-26 17:59:36

标签: javascript 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;

非常感谢您的帮助

1 个答案:

答案 0 :(得分:0)

第一个示例中return之前的最后一行通过用字符串msg.payload取代对象,从而消除了您对"'## Programmatic Control"对象所做的所有更改。