【问题标题】:Node Red: Temperature Alarm if measured value is at multiple times different to set value红色节点:如果测量值多次与设定值不同,则温度报警
【发布时间】:2021-06-02 20:17:10
【问题描述】:

我正在使用 Node Red 来监控一组水族箱。我们有 14 个 DS18b20 传感器,每个水族箱一个。如果一个传感器的测量温度与设定值不同,我可以通过电子邮件发送警报。但是,有时,在维护期间,我们会将传感器从水族箱中取出。因此,我想编写一个仅在测量到异常值时才设置警报的函数,例如连续三次(每 15 分钟测量一次值)。我怎么能这样做?
目前,我编写了一个函数,如果任何msg.payload[i].temp(数组中的 14 个测量值)与设定值的差异超过 1.5 °C,则将msg.payload 设置为“警报”。此功能后跟一个开关,然后触发电子邮件。
你对我的问题有什么建议吗?感谢您的帮助!

【问题讨论】:

    标签: javascript monitoring node-red alarm temperature


    【解决方案1】:

    您可以尝试使用global context 来保存连续异常措施的计数器。 例如,在一个名为“评估全局异常度量”的函数节点上

    // Set the variable GlobalAbnormalAlert (the counter) to not get undefined error later
    if(!global.get("GlobalAbnormalAlert")){
        global.set("GlobalAbnormalAlert", 0);
    }
    
    // Check if is anormal  measure, and if it so, add 1 to the counter
    if (msg.payload[i].temp > 1.5 ){
        global.set("GlobalAbnormalAlert", global.get("GlobalAbnormalAlert") + 1);
    }
    else {
        // If not anormal, reset the counter
        global.set("GlobalAbnormalAlert", 0);
    }
    return msg;
    

    然后您可以在 global.GlobalAbnormalAlert 上配置一个开关来触发邮件(或不触发):

    然后,流程看起来像这样:

    初始节点触发度量是你的回忆过程(从那里得到msg.payload[i].temp

    【讨论】:

    • 谢谢!好主意!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多