# How to enter query/funtion to secure Modbus read with CronePlus

**URL:** <https://discourse.nodered.org/t/how-to-enter-query-funtion-to-secure-modbus-read-with-croneplus/76686>\
**Category:** General\
**Tags:** modbus\
**Created:** [18 March 2023 11:35 UTC](https://discourse.nodered.org/t/how-to-enter-query-funtion-to-secure-modbus-read-with-croneplus/76686 "2023-03-18T11:35:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GuE](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@GuE](https://discourse.nodered.org/u/GuE)\
**Post date:** [18 March 2023 11:35 UTC](https://discourse.nodered.org/t/how-to-enter-query-funtion-to-secure-modbus-read-with-croneplus/76686/1 "2023-03-18T11:35:54Z")

</div>

Hello.  
Using several flows to read data from Modbus device -\> data are stored in influxdb.  
Using CronePlus or inject node to trigger the read with a modbus-getter node. Read durations are different -\> some 15s / every 15min / 1 time per 24h

Issue:  
Getting problems when i would like to collect the data 1x / 24h or every 15min - looks like the device is in sleep or not ready.

Therefore I would like to implement a function/query to secure the data are read and stored in influxdb.  
How could I integrate a function or something else to check?

Please - need some help for a smart way.  
Thx.

Following flow as an example.

 ![Read-Tiefenbohrung](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/c/4c2c245e9bdf7863dd01a28b91eecb56c4283798.png)

```auto
[
    {
        "id": "c454cc2a06e55e7e",
        "type": "tab",
        "label": "Flow 5",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "5f544df279f3bdc4",
        "type": "modbus-getter",
        "z": "c454cc2a06e55e7e",
        "name": "Tiefenbohrung_EIN_AUS",
        "showStatusActivities": false,
        "showErrors": false,
        "logIOActivities": false,
        "unitid": "1",
        "dataType": "HoldingRegister",
        "adr": "529",
        "quantity": "4",
        "server": "82be51f24ff6f9e9",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": true,
        "keepMsgProperties": false,
        "x": 610,
        "y": 240,
        "wires": [
            [
                "2861e297a45dbdcd"
            ],
            []
        ]
    },
    {
        "id": "2861e297a45dbdcd",
        "type": "buffer-parser",
        "z": "c454cc2a06e55e7e",
        "name": "",
        "data": "responseBuffer.buffer",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "floatle",
                "name": "Tiefenbohrung_Ein",
                "offset": 0,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "floatle",
                "name": "Tiefenbohrung_Aus",
                "offset": 4,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "swap16",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "value",
        "resultTypeType": "output",
        "multipleResult": true,
        "fanOutMultipleResult": true,
        "setTopic": true,
        "outputs": 2,
        "x": 870,
        "y": 240,
        "wires": [
            [
                "ffc01717643e7f2c",
                "fadf47f850783c4a"
            ],
            [
                "05605fca6b978349",
                "fadf47f850783c4a"
            ]
        ]
    },
    {
        "id": "ffc01717643e7f2c",
        "type": "debug",
        "z": "c454cc2a06e55e7e",
        "name": "Tiefenbohrung_EIN",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1110,
        "y": 240,
        "wires": []
    },
    {
        "id": "05605fca6b978349",
        "type": "debug",
        "z": "c454cc2a06e55e7e",
        "name": "Tiefenbohrung_AUS",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1120,
        "y": 280,
        "wires": []
    },
    {
        "id": "fadf47f850783c4a",
        "type": "join",
        "z": "c454cc2a06e55e7e",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "2",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "num",
        "reduceFixup": "",
        "x": 1090,
        "y": 200,
        "wires": [
            [
                "da5112150a27b07c"
            ]
        ]
    },
    {
        "id": "50f6d9dfd3f57599",
        "type": "influxdb out",
        "z": "c454cc2a06e55e7e",
        "influxdb": "52608438d6b07280",
        "name": "InfluxDB_Write",
        "measurement": "Tiefenbohrung_EIN_AUS",
        "precision": "ms",
        "retentionPolicy": "",
        "database": "test",
        "precisionV18FluxV20": "s",
        "retentionPolicyV18Flux": "",
        "org": "GuE_InfluxDB",
        "bucket": "WP_Database",
        "x": 1520,
        "y": 200,
        "wires": []
    },
    {
        "id": "1aadfcc9ef44e517",
        "type": "cronplus",
        "z": "c454cc2a06e55e7e",
        "name": "Cron-Plus-Trigger",
        "outputField": "payload",
        "timeZone": "",
        "persistDynamic": false,
        "commandResponseMsgOutput": "output1",
        "outputs": 1,
        "options": [
            {
                "name": "TriggerKeinBetriebTrue",
                "topic": "TriggerKeinBetriebTrue",
                "payloadType": "bool",
                "payload": "true",
                "expressionType": "cron",
                "expression": "*/15 * * * *",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            }
        ],
        "x": 230,
        "y": 240,
        "wires": [
            [
                "5f544df279f3bdc4"
            ]
        ]
    },
    {
        "id": "da5112150a27b07c",
        "type": "switch",
        "z": "c454cc2a06e55e7e",
        "name": "KeinBetrieb_TRUE",
        "property": "BetriebszustandArray.KeinBetrieb",
        "propertyType": "global",
        "rules": [
            {
                "t": "true"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 1310,
        "y": 200,
        "wires": [
            [
                "50f6d9dfd3f57599"
            ]
        ]
    },
    {
        "id": "82be51f24ff6f9e9",
        "type": "modbus-client",
        "name": "RS232_MOXA_NP5110",
        "clienttype": "serial",
        "bufferCommands": false,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "failureLogEnabled": true,
        "tcpHost": "192.168.100.18",
        "tcpPort": "950",
        "tcpType": "TCP-RTU-BUFFERED",
        "serialPort": "/dev/ttyr00",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "serialAsciiResponseStartDelimiter": "0x3A",
        "unit_id": "1",
        "commandDelay": "50",
        "clientTimeout": "1000",
        "reconnectOnTimeout": true,
        "reconnectTimeout": "2000",
        "parallelUnitIdsAllowed": false
    },
    {
        "id": "52608438d6b07280",
        "type": "influxdb",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "database",
        "name": "WP_Database",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "2.0",
        "url": "http://localhost:8086",
        "rejectUnauthorized": true
    }
]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [19 March 2023 18:11 UTC](https://discourse.nodered.org/t/how-to-enter-query-funtion-to-secure-modbus-read-with-croneplus/76686/2 "2023-03-19T18:11:16Z")

</div>

> [@GuE](#):
>
> Getting problems when i would like to collect the data 1x / 24h or every 15min - looks like the device is in sleep or not ready.

I noticed in the Modbus node that you shared that you have " **Empty msg on Modbus fail**" enabled.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b68e873b41537eb8ac16435265a075196d5e72cf.png)

Maybe it would be better to uncheck this option so if the device goes to sleep and Modbus fails you will not get a msg .. that would also cause buffer parser to fail and also send unneeded values to influxdb

Also .. do you need that Join node after Buffer parser ? you could set the parser node's Output as Key/value

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 May 2023 18:11 UTC](https://discourse.nodered.org/t/how-to-enter-query-funtion-to-secure-modbus-read-with-croneplus/76686/3 "2023-05-18T18:11:38Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
