MSSQL and MySQL timestamp issue

Dear friends,

Hello, its been a while that I'm checking my database and I noticed that the stored data in each table has a common issue! The problem is, in flows, data is colllecing from Modbus read every 2 second and storing in MSSQL but when I go through the database I am wondering why the records are not consequtively stored! Even I tried to use HeidiSQL to check if the problem come up from MSSQL but the problem still exist!
For better understanding I am sharing some images regarding this issue . .

  1. records in mysql :

  2. records in mssql :

I would appreciate it if you help me to fix this problem.

What populates the timestamp field in your flow? (e.g. what does your insert query look like?)

Can you share a screenshot of the flow and annotate it with some notes on the basic outline/sequence?

Hi, Thanks for your quick reply,
Actually, in the flows that I used Mysql database, every 5 second current timesamp will be recorded

TimeStamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP

These images are related to Mysql database:

and these are related to MSSQL:

Can you share these 2 flows please (select nodes, CTRL+E)

Mysql :

[
    {
        "id": "c0526f884ea7c8b8",
        "type": "debug",
        "z": "ed7fcd60c48f9d97",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 710,
        "y": 220,
        "wires": []
    },
    {
        "id": "2cce2c1ecd29f57f",
        "type": "debug",
        "z": "ed7fcd60c48f9d97",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 530,
        "y": 340,
        "wires": []
    },
    {
        "id": "d8bade50b049d460",
        "type": "modbus-read",
        "z": "ed7fcd60c48f9d97",
        "name": "BMU14",
        "topic": "",
        "showStatusActivities": false,
        "logIOActivities": false,
        "showErrors": false,
        "unitid": "1",
        "dataType": "HoldingRegister",
        "adr": "8608",
        "quantity": "32",
        "rate": "5",
        "rateUnit": "s",
        "delayOnStart": false,
        "startDelayTime": "",
        "server": "d631304d.f42a4",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "x": 310,
        "y": 280,
        "wires": [
            [
                "6a921d3ca29f06ed"
            ],
            [
                "2cce2c1ecd29f57f",
                "90b1be8fb3d9d553"
            ]
        ]
    },
    {
        "id": "962dda3b55da3ea7",
        "type": "debug",
        "z": "ed7fcd60c48f9d97",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 890,
        "y": 260,
        "wires": []
    },
    {
        "id": "fae7eb1b08c1c38f",
        "type": "debug",
        "z": "ed7fcd60c48f9d97",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 690,
        "y": 300,
        "wires": []
    },
    {
        "id": "90b1be8fb3d9d553",
        "type": "buffer-parser",
        "z": "ed7fcd60c48f9d97",
        "name": "",
        "data": "payload.data",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "int16be",
                "name": "Array[32] of 16bits",
                "offset": 0,
                "length": 32,
                "offsetbit": 2,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "",
        "resultType": "value",
        "resultTypeType": "output",
        "multipleResult": true,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 530,
        "y": 300,
        "wires": [
            [
                "fae7eb1b08c1c38f"
            ]
        ]
    },
    {
        "id": "6a921d3ca29f06ed",
        "type": "function",
        "z": "ed7fcd60c48f9d97",
        "name": "Data scaling",
        "func": "\n/************************* Definition *****************************/\n/******************************************************************/\nvar buffer =[];\nvar msg0 = {payload: msg.payload[0]/1000};\nvar msg1 = {payload: msg.payload[1]/1000};\nvar msg2 = {payload: msg.payload[2]/1000};\nvar msg3 = {payload: msg.payload[3]/1000};\nvar msg4 = {payload: msg.payload[4]/1000};\nvar msg5 = {payload: msg.payload[5]/1000};\nvar msg6 = {payload: msg.payload[6]/1000};\nvar msg7 = {payload: msg.payload[7]/1000};\nvar msg8 = {payload: msg.payload[8]/1000};\nvar msg9 = {payload: msg.payload[9]/1000};\nvar msg10 = {payload: msg.payload[10]/1000};\nvar msg11 = {payload: msg.payload[11]/1000};\nvar msg12 = {payload: msg.payload[12]/1000};\nvar msg13 = {payload: msg.payload[13]/1000};\nvar msg14 = {payload: msg.payload[14]/1000};\nvar msg15 = {payload: msg.payload[15]/1000};\n// var msg16 = {payload: msg.payload[16]};\n// var msg17 = {payload: msg.payload[17]};\n// var msg18 = {payload: msg.payload[18]};\n// var msg19 = {payload: msg.payload[19]};\n// var msg20 = {payload: msg.payload[20]};\n// var msg21 = {payload: msg.payload[21]};\n// var msg22 = {payload: msg.payload[22]};\n// var msg23 = {payload: msg.payload[23]};\nvar msg24 = {payload: msg.payload[24]};\nvar msg25 = {payload: msg.payload[25]};\nvar msg26 = {payload: msg.payload[26]};\nvar msg27 = {payload: msg.payload[27]};\nvar msg28 = {payload: msg.payload[28]};\nvar msg29 = {payload: msg.payload[29]};\nvar msg30 = {payload: msg.payload[30]};\nvar msg31 = {payload: msg.payload[31]};\n\n\n\n\n\n\n\nbuffer = [[msg0,msg1,msg2,msg3,msg4,msg5,\nmsg6,msg7,msg8,msg9,msg10,msg11,msg12,msg13,msg14,msg15\n//,msg16,msg17,msg18,msg19,msg20,msg21,msg22,msg23\n,msg24,msg25\n,msg26,msg27,msg28,msg29,msg30,msg31]];\n\n// msg.topic = 'INSERT INTO BMU1 VALUES (Cell_V1, Cell_V2, Cell_V3, Cell_V4,Cell_V5,Cell_V6,Cell_V7,Cell_V8,Cell_V9,Cell_V10,Cell_V11,Cell_V12,Cell_V13,Cell_V14,Cell_V15,Cell_V16,Cell_T1,Cell_T2,Cell_T3,Cell_T4,Cell_T5,Cell_T6,Cell_T7,Cell_T8)'\n\n\nreturn buffer;\n\n\n// for (var i = 0; i < 32; i++) {\n//     if (i == 16 ){\n//         break;\n//     }\n//     msg.payload[i] = msg.payload[i]/1000;\n    \n// }\n// return msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 530,
        "y": 260,
        "wires": [
            [
                "c0526f884ea7c8b8",
                "a7068786db4ec205"
            ]
        ]
    },
    {
        "id": "9a3c15b685d5af06",
        "type": "comment",
        "z": "ed7fcd60c48f9d97",
        "name": "Module 14 into MySQL",
        "info": "",
        "x": 340,
        "y": 240,
        "wires": []
    },
    {
        "id": "a7068786db4ec205",
        "type": "join",
        "z": "ed7fcd60c48f9d97",
        "name": "",
        "mode": "custom",
        "build": "array",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "24",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 690,
        "y": 260,
        "wires": [
            [
                "962dda3b55da3ea7",
                "2de6e5420447d890"
            ]
        ]
    },
    {
        "id": "5369d7978de7ecb1",
        "type": "mysql",
        "z": "ed7fcd60c48f9d97",
        "mydb": "2d238b17bf867932",
        "name": "",
        "x": 1080,
        "y": 220,
        "wires": [
            []
        ]
    },
    {
        "id": "2de6e5420447d890",
        "type": "function",
        "z": "ed7fcd60c48f9d97",
        "name": "Data scaling",
        "func": "\n/************************* Definition *****************************/\n/******************************************************************/\n\n\n\nmsg.topic = 'INSERT INTO BMU1(Cell_V1, Cell_V2, Cell_V3, Cell_V4,Cell_V5,Cell_V6,Cell_V7,Cell_V8,Cell_V9,Cell_V10,Cell_V11,Cell_V12,Cell_V13,Cell_V14,Cell_V15,Cell_V16,Cell_T1,Cell_T2,Cell_T3,Cell_T4,Cell_T5,Cell_T6,Cell_T7,Cell_T8) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);';\n\n\n// msg.topic = 'INSERT INTO BMU1(Cell_V1, Cell_V2, Cell_V3, Cell_V4,Cell_V5,,Cell_V6,\\\n//                               Cell_V7,Cell_V8,Cell_V9,Cell_V10,Cell_V11,Cell_V12,\\\n//                               Cell_V13,Cell_V14,Cell_V15,Cell_T1,Cell_T2,Cell_T3,\\\n//                               Cell_T4,Cell_T5,Cell_T6,Cell_T7,Cell_T8) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);';\n\nreturn msg\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 910,
        "y": 220,
        "wires": [
            [
                "373b7e6773d11fc7",
                "5369d7978de7ecb1"
            ]
        ]
    },
    {
        "id": "373b7e6773d11fc7",
        "type": "debug",
        "z": "ed7fcd60c48f9d97",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1070,
        "y": 180,
        "wires": []
    },
    {
        "id": "d631304d.f42a4",
        "type": "modbus-client",
        "name": "BMS",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "tcpHost": "192.168.0.21",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "serialAsciiResponseStartDelimiter": "",
        "unit_id": "1",
        "commandDelay": "1",
        "clientTimeout": "1000",
        "reconnectOnTimeout": true,
        "reconnectTimeout": "2000",
        "parallelUnitIdsAllowed": true
    },
    {
        "id": "2d238b17bf867932",
        "type": "MySQLdatabase",
        "name": "",
        "host": "127.0.0.1",
        "port": "3306",
        "db": "max2022",
        "tz": "",
        "charset": "UTF8",
        "credentials": {}
    }
]

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

Thanks for correcting my errors, I am quite beginner in node red.

and also this is for MSSQL flow:

[
    {
        "id": "8581bb2eddc223e0",
        "type": "debug",
        "z": "7499127a37bbb386",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 710,
        "y": 360,
        "wires": []
    },
    {
        "id": "15ad3f2d55f43235",
        "type": "debug",
        "z": "7499127a37bbb386",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 490,
        "y": 460,
        "wires": []
    },
    {
        "id": "784a2cbd114ec957",
        "type": "modbus-read",
        "z": "7499127a37bbb386",
        "name": "BMU1",
        "topic": "",
        "showStatusActivities": false,
        "logIOActivities": false,
        "showErrors": false,
        "unitid": "1",
        "dataType": "HoldingRegister",
        "adr": "8192",
        "quantity": "32",
        "rate": "2",
        "rateUnit": "s",
        "delayOnStart": false,
        "startDelayTime": "",
        "server": "d631304d.f42a4",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "x": 270,
        "y": 420,
        "wires": [
            [
                "25950c90bcc18c12"
            ],
            [
                "15ad3f2d55f43235",
                "17a27f265c597d87"
            ]
        ]
    },
    {
        "id": "f0e1f0a1c7ce0ea0",
        "type": "MSSQL",
        "z": "7499127a37bbb386",
        "mssqlCN": "491533d6adb397ad",
        "name": "",
        "outField": "payload",
        "returnType": "1",
        "throwErrors": 1,
        "query": "INSERT INTO BMU1 \r\n    (TimeStamp, Cell_V1, Cell_V2, Cell_V3, Cell_V4,Cell_V5,\r\n    Cell_V6, Cell_V7, Cell_V8, Cell_V9, Cell_V10, Cell_V11,\r\n    Cell_V12, Cell_V13, Cell_V14, Cell_V15, Cell_V16,Cell_T1,\r\n    Cell_T2, Cell_T3, Cell_T4, Cell_T5, Cell_T6, Cell_T7, Cell_T8) \r\nVALUES\r\n    (@ts, @v1, @v2, @v3,@v4,@v5,@v6,@v7,@v8,@v9,@v10,@v11,@v12,@v13\r\n    ,@v14,@v15,@v16,@t1,@t2,@t3,@t4,@t5,@t6,@t7,@t8)\r\n",
        "modeOpt": "queryMode",
        "modeOptType": "query",
        "queryOpt": "payload",
        "queryOptType": "editor",
        "paramsOpt": "",
        "paramsOptType": "editor",
        "rows": "rows",
        "rowsType": "msg",
        "params": [
            {
                "output": false,
                "name": "ts",
                "type": "DateTime",
                "valueType": "datetime",
                "value": "0",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v1",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[0]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v2",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[1]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v3",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[2]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v4",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[3]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v5",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[4]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v6",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[5]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v7",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[6]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v8",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[7]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v9",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[8]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v10",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[9]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v11",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[10]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v12",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[11]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v13",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[12]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v14",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[13]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v15",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[14]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v16",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[15]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t1",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[24]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t2",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[25]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t3",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[26]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t4",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[27]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t5",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[28]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t6",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[29]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t7",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[30]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t8",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[31]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            }
        ],
        "x": 720,
        "y": 440,
        "wires": [
            [
                "fe1e48b0765f1132"
            ]
        ]
    },
    {
        "id": "fe1e48b0765f1132",
        "type": "debug",
        "z": "7499127a37bbb386",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 910,
        "y": 440,
        "wires": []
    },
    {
        "id": "cbe8b20156a7b261",
        "type": "debug",
        "z": "7499127a37bbb386",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "Node 2",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 710,
        "y": 500,
        "wires": []
    },
    {
        "id": "17a27f265c597d87",
        "type": "buffer-parser",
        "z": "7499127a37bbb386",
        "name": "",
        "data": "payload.data",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "int16be",
                "name": "Array[32] of 16bits",
                "offset": 0,
                "length": 32,
                "offsetbit": 2,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "",
        "resultType": "value",
        "resultTypeType": "output",
        "multipleResult": true,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 490,
        "y": 420,
        "wires": [
            [
                "cbe8b20156a7b261"
            ]
        ]
    },
    {
        "id": "25950c90bcc18c12",
        "type": "function",
        "z": "7499127a37bbb386",
        "name": "Data scaling",
        "func": "//msg.topic = \"Varible 1\";\n//msg.payload = msg.payload[0];\n//return msg;\n\nfor (var i = 0; i < 32; i++) {\n    if (i == 16 ){\n        break;\n    }\n    msg.payload[i] = msg.payload[i]/1000;\n    \n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 490,
        "y": 380,
        "wires": [
            [
                "8581bb2eddc223e0",
                "f0e1f0a1c7ce0ea0",
                "774e16f0ca869b43"
            ]
        ]
    },
    {
        "id": "774e16f0ca869b43",
        "type": "function",
        "z": "7499127a37bbb386",
        "name": "Set global variable",
        "func": "\nglobal.set(\"Module_1\",msg.payload);\n\n\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 730,
        "y": 400,
        "wires": [
            [
                "1148af20c92f4dc1"
            ]
        ]
    },
    {
        "id": "1148af20c92f4dc1",
        "type": "debug",
        "z": "7499127a37bbb386",
        "name": "Show function output",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 940,
        "y": 400,
        "wires": []
    },
    {
        "id": "daf86ff46323c853",
        "type": "comment",
        "z": "7499127a37bbb386",
        "name": "Module 1",
        "info": "",
        "x": 300,
        "y": 380,
        "wires": []
    },
    {
        "id": "d631304d.f42a4",
        "type": "modbus-client",
        "name": "BMS",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "tcpHost": "192.168.0.21",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "serialAsciiResponseStartDelimiter": "",
        "unit_id": "1",
        "commandDelay": "1",
        "clientTimeout": "1000",
        "reconnectOnTimeout": true,
        "reconnectTimeout": "2000",
        "parallelUnitIdsAllowed": true
    },
    {
        "id": "491533d6adb397ad",
        "type": "MSSQL-CN",
        "name": "",
        "server": "localhost",
        "port": "",
        "encyption": false,
        "trustServerCertificate": false,
        "database": "MAXBESS_1",
        "useUTC": false,
        "connectTimeout": "",
        "requestTimeout": "",
        "cancelTimeout": "",
        "pool": "",
        "parseJSON": false,
        "enableArithAbort": true
    }
]

I see in function "Set global variable" you have global.set("Module_1",msg.payload);

Do you modify Module_1 anywhere in your flows (on any flow tab, anywhere)

Yes, There are 14 flows like this with different Modbus addresses(Module_1, .......,Module_14)
And in another tab all these nodes will be called for monitoring in a dashborad:

in the function you can see:

BMU_Num = global.get("num");


Module_1 = global.get("Module_1");
Module_2 = global.get("Module_2");
Module_3 = global.get("Module_3");
Module_4 = global.get("Module_4");
Module_5 = global.get("Module_5");
Module_6 = global.get("Module_6");
Module_7 = global.get("Module_7");
Module_8 = global.get("Module_8");
Module_9 = global.get("Module_9");
Module_10 = global.get("Module_10");
Module_11 = global.get("Module_11");
Module_12 = global.get("Module_12");
Module_13 = global.get("Module_13");
Module_14 = global.get("Module_14");

//return [{payload:Module_1}]



switch(BMU_Num) {
    
    case "1":
        //msg.payload = "1";
        return [{payload:Module_1}]
        
    case "2":
        //msg.payload = "2";
        return [{payload:Module_2}]
        
    case "3":
        //msg.payload = "3";
        return [{payload:Module_3}]
        
    case "4":
        
        return [{payload:Module_4}]
    
    case "5":
        
        return [{payload:Module_5}]
    
    case "6":
        
        return [{payload:Module_6}]
    
    case "7":
        
        return [{payload:Module_7}]
    
    case "8":
        
        return [{payload:Module_8}]
    
    case "9":
        
        return [{payload:Module_9}]
    
    case "10":
        
        return [{payload:Module_10}]
    
    case "11":
        
        return [{payload:Module_11}]
        
    case "12":
        
        return [{payload:Module_12}]
    
    case "13":
        
        return [{payload:Module_13}]
    
    case "14":
        
        return [{payload:Module_14}]
    
}

I have modified your MSSQL to do the following...

  1. add timestamp to the msg so that it is intrinsically linked to the data (point in time timestamp)
  2. I have ensured the data array is cloned before setting into global context (to avoid possible "by reference" modifications before being written to database)

Try this flow to see if there is any improvement...

[
    {
        "id": "15ad3f2d55f43235",
        "type": "debug",
        "z": "cd9631e07a7cb243",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 430,
        "y": 820,
        "wires": []
    },
    {
        "id": "784a2cbd114ec957",
        "type": "modbus-read",
        "z": "cd9631e07a7cb243",
        "name": "BMU1",
        "topic": "",
        "showStatusActivities": false,
        "logIOActivities": false,
        "showErrors": false,
        "unitid": "1",
        "dataType": "HoldingRegister",
        "adr": "8192",
        "quantity": "32",
        "rate": "2",
        "rateUnit": "s",
        "delayOnStart": false,
        "startDelayTime": "",
        "server": "d631304d.f42a4",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "x": 210,
        "y": 780,
        "wires": [
            [
                "25950c90bcc18c12"
            ],
            [
                "15ad3f2d55f43235"
            ]
        ]
    },
    {
        "id": "f0e1f0a1c7ce0ea0",
        "type": "MSSQL",
        "z": "cd9631e07a7cb243",
        "mssqlCN": "491533d6adb397ad",
        "name": "",
        "outField": "payload",
        "returnType": "1",
        "throwErrors": 1,
        "query": "INSERT INTO BMU1 \r\n    (TimeStamp, Cell_V1, Cell_V2, Cell_V3, Cell_V4,Cell_V5,\r\n    Cell_V6, Cell_V7, Cell_V8, Cell_V9, Cell_V10, Cell_V11,\r\n    Cell_V12, Cell_V13, Cell_V14, Cell_V15, Cell_V16,Cell_T1,\r\n    Cell_T2, Cell_T3, Cell_T4, Cell_T5, Cell_T6, Cell_T7, Cell_T8) \r\nVALUES\r\n    (@ts, @v1, @v2, @v3,@v4,@v5,@v6,@v7,@v8,@v9,@v10,@v11,@v12,@v13\r\n    ,@v14,@v15,@v16,@t1,@t2,@t3,@t4,@t5,@t6,@t7,@t8)\r\n",
        "modeOpt": "queryMode",
        "modeOptType": "query",
        "queryOpt": "payload",
        "queryOptType": "editor",
        "paramsOpt": "",
        "paramsOptType": "editor",
        "rows": "rows",
        "rowsType": "msg",
        "params": [
            {
                "output": false,
                "name": "ts",
                "type": "DateTime",
                "valueType": "msg",
                "value": "timestamp",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v1",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[0]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v2",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[1]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v3",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[2]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v4",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[3]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v5",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[4]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v6",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[5]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v7",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[6]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v8",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[7]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v9",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[8]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v10",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[9]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v11",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[10]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v12",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[11]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v13",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[12]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v14",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[13]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v15",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[14]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v16",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[15]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t1",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[24]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t2",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[25]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t3",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[26]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t4",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[27]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t5",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[28]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t6",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[29]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t7",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[30]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t8",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[31]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            }
        ],
        "x": 640,
        "y": 800,
        "wires": [
            [
                "fe1e48b0765f1132"
            ]
        ]
    },
    {
        "id": "fe1e48b0765f1132",
        "type": "debug",
        "z": "cd9631e07a7cb243",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 830,
        "y": 800,
        "wires": []
    },
    {
        "id": "25950c90bcc18c12",
        "type": "function",
        "z": "cd9631e07a7cb243",
        "name": "Data scaling",
        "func": "//msg.topic = \"Varible 1\";\n//msg.payload = msg.payload[0];\n//return msg;\n\nfor (var i = 0; i < 32; i++) {\n    if (i == 16 ){\n        break;\n    }\n    msg.payload[i] = msg.payload[i]/1000;\n    \n}\nmsg.timestamp = new Date()\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 430,
        "y": 740,
        "wires": [
            [
                "774e16f0ca869b43"
            ]
        ]
    },
    {
        "id": "774e16f0ca869b43",
        "type": "function",
        "z": "cd9631e07a7cb243",
        "name": "Set global variable",
        "func": "const payload = RED.util.cloneMessage(msg.payload);\nglobal.set(\"Module_1\", payload);\n\n\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 630,
        "y": 740,
        "wires": [
            [
                "1148af20c92f4dc1",
                "f0e1f0a1c7ce0ea0"
            ]
        ]
    },
    {
        "id": "1148af20c92f4dc1",
        "type": "debug",
        "z": "cd9631e07a7cb243",
        "name": "Show function output",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 860,
        "y": 740,
        "wires": []
    },
    {
        "id": "daf86ff46323c853",
        "type": "comment",
        "z": "cd9631e07a7cb243",
        "name": "Module 1",
        "info": "",
        "x": 240,
        "y": 740,
        "wires": []
    },
    {
        "id": "d631304d.f42a4",
        "type": "modbus-client",
        "name": "BMS",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "tcpHost": "192.168.0.21",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "unit_id": "1",
        "commandDelay": "1",
        "clientTimeout": "1000",
        "reconnectOnTimeout": true,
        "reconnectTimeout": "2000",
        "parallelUnitIdsAllowed": true
    },
    {
        "id": "491533d6adb397ad",
        "type": "MSSQL-CN",
        "name": "",
        "server": "localhost",
        "port": "",
        "encyption": false,
        "trustServerCertificate": false,
        "database": "MAXBESS_1",
        "useUTC": false,
        "connectTimeout": "",
        "requestTimeout": "",
        "cancelTimeout": "",
        "pool": "",
        "parseJSON": false,
        "enableArithAbort": true
    }
]

Thanks Steve, I applied the modification and let the system work for half an hour but it seems the problem still exist!

My anticipation is to see records 173 and 218 consecutively! Its strange . . .

Is this the SQL Server data?

Are you inputting data from multiple places to the same table?

Yes this is from SQL server, These are the data related to a specific Module and there is no interference wih another Modbus read!

can you share the MSSQL nodes (same nodes as last time) so I can see if you implemented the changes correctly?

Dear Steve thank you for following my problem, here is the modified flow related to only one node!

[
    {
        "id": "8581bb2eddc223e0",
        "type": "debug",
        "z": "7499127a37bbb386",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 710,
        "y": 360,
        "wires": []
    },
    {
        "id": "15ad3f2d55f43235",
        "type": "debug",
        "z": "7499127a37bbb386",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 490,
        "y": 460,
        "wires": []
    },
    {
        "id": "784a2cbd114ec957",
        "type": "modbus-read",
        "z": "7499127a37bbb386",
        "name": "BMU1",
        "topic": "",
        "showStatusActivities": false,
        "logIOActivities": false,
        "showErrors": false,
        "unitid": "1",
        "dataType": "HoldingRegister",
        "adr": "8192",
        "quantity": "32",
        "rate": "2",
        "rateUnit": "s",
        "delayOnStart": false,
        "startDelayTime": "",
        "server": "d631304d.f42a4",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "x": 270,
        "y": 420,
        "wires": [
            [
                "25950c90bcc18c12"
            ],
            [
                "15ad3f2d55f43235"
            ]
        ]
    },
    {
        "id": "f0e1f0a1c7ce0ea0",
        "type": "MSSQL",
        "z": "7499127a37bbb386",
        "mssqlCN": "491533d6adb397ad",
        "name": "",
        "outField": "payload",
        "returnType": "1",
        "throwErrors": 1,
        "query": "INSERT INTO BMU1 \r\n    (TimeStamp, Cell_V1, Cell_V2, Cell_V3, Cell_V4,Cell_V5,\r\n    Cell_V6, Cell_V7, Cell_V8, Cell_V9, Cell_V10, Cell_V11,\r\n    Cell_V12, Cell_V13, Cell_V14, Cell_V15, Cell_V16,Cell_T1,\r\n    Cell_T2, Cell_T3, Cell_T4, Cell_T5, Cell_T6, Cell_T7, Cell_T8) \r\nVALUES\r\n    (@ts, @v1, @v2, @v3,@v4,@v5,@v6,@v7,@v8,@v9,@v10,@v11,@v12,@v13\r\n    ,@v14,@v15,@v16,@t1,@t2,@t3,@t4,@t5,@t6,@t7,@t8)\r\n",
        "modeOpt": "queryMode",
        "modeOptType": "query",
        "queryOpt": "payload",
        "queryOptType": "editor",
        "paramsOpt": "",
        "paramsOptType": "editor",
        "rows": "rows",
        "rowsType": "msg",
        "params": [
            {
                "output": false,
                "name": "ts",
                "type": "DateTime",
                "valueType": "msg",
                "value": "timestamp",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v1",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[0]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v2",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[1]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v3",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[2]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v4",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[3]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v5",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[4]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v6",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[5]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v7",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[6]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v8",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[7]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v9",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[8]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v10",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[9]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v11",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[10]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v12",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[11]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v13",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[12]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v14",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[13]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v15",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[14]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "v16",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[15]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t1",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[24]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t2",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[25]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t3",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[26]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t4",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[27]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t5",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[28]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t6",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[29]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t7",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[30]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "t8",
                "type": "Float",
                "valueType": "msg",
                "value": "payload[31]",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            }
        ],
        "x": 720,
        "y": 440,
        "wires": [
            [
                "fe1e48b0765f1132"
            ]
        ]
    },
    {
        "id": "fe1e48b0765f1132",
        "type": "debug",
        "z": "7499127a37bbb386",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 910,
        "y": 440,
        "wires": []
    },
    {
        "id": "17a27f265c597d87",
        "type": "buffer-parser",
        "z": "7499127a37bbb386",
        "name": "",
        "data": "payload.data",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "int16be",
                "name": "Array[32] of 16bits",
                "offset": 0,
                "length": 32,
                "offsetbit": 2,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "",
        "resultType": "value",
        "resultTypeType": "output",
        "multipleResult": true,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 490,
        "y": 420,
        "wires": [
            [
                "fe69f2fac37870be"
            ]
        ]
    },
    {
        "id": "25950c90bcc18c12",
        "type": "function",
        "z": "7499127a37bbb386",
        "name": "Data scaling",
        "func": "//msg.topic = \"Varible 1\";\n//msg.payload = msg.payload[0];\n//return msg;\n\nfor (var i = 0; i < 32; i++) {\n    if (i == 16 ){\n        break;\n    }\n    msg.payload[i] = msg.payload[i]/1000;\n    \n}\nmsg.timestamp = new Date()\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 490,
        "y": 380,
        "wires": [
            [
                "8581bb2eddc223e0",
                "774e16f0ca869b43",
                "f0e1f0a1c7ce0ea0"
            ]
        ]
    },
    {
        "id": "774e16f0ca869b43",
        "type": "function",
        "z": "7499127a37bbb386",
        "name": "Set global variable",
        "func": "const payload = RED.util.cloneMessage(msg.payload);\n\nglobal.set(\"Module_1\",msg.payload);\n\n\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 730,
        "y": 400,
        "wires": [
            [
                "1148af20c92f4dc1"
            ]
        ]
    },
    {
        "id": "1148af20c92f4dc1",
        "type": "debug",
        "z": "7499127a37bbb386",
        "name": "Show function output",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 940,
        "y": 400,
        "wires": []
    },
    {
        "id": "daf86ff46323c853",
        "type": "comment",
        "z": "7499127a37bbb386",
        "name": "Module 1(Timesatmp modified !)",
        "info": "",
        "x": 370,
        "y": 340,
        "wires": []
    },
    {
        "id": "fe69f2fac37870be",
        "type": "debug",
        "z": "7499127a37bbb386",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 710,
        "y": 500,
        "wires": []
    },
    {
        "id": "d631304d.f42a4",
        "type": "modbus-client",
        "name": "BMS",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "tcpHost": "192.168.0.21",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "serialAsciiResponseStartDelimiter": "",
        "unit_id": "1",
        "commandDelay": "1",
        "clientTimeout": "1000",
        "reconnectOnTimeout": true,
        "reconnectTimeout": "2000",
        "parallelUnitIdsAllowed": true
    },
    {
        "id": "491533d6adb397ad",
        "type": "MSSQL-CN",
        "name": "",
        "server": "localhost",
        "port": "",
        "encyption": false,
        "trustServerCertificate": false,
        "database": "MAXBESS_1",
        "useUTC": false,
        "connectTimeout": "",
        "requestTimeout": "",
        "cancelTimeout": "",
        "pool": "",
        "parseJSON": false,
        "enableArithAbort": true
    }
]

ok, so you made a mistake in the function node. It should be storing the cloned payload NOT msg.payload.

Also, look at that screenshot ↑ I added a logging node (node-red-contrig-flogger) - I suggest you insert a logging node (like above) and capture everything to file for later comparison - to see if the issue is related to data being sent to SQL - OR - something to do with SQL / Table Locks etc.

sql_logger.txt (417.5 KB)

Dear Steve,
I just checked the output of flogger and I guess before entering to next node(MSSQL) everything is fine as you can see in text file that I share with you! I don't know if I left any parameter in
MSSQL-PLUS or something else. I should confess that I have no idea where is my mistake :thinking:

Does the data in the table differ in order or count to the log file?

Does your table have an auto index field?


The final solution is to use a queue pattern where instead of inserting to DB, you push the data into a STACK then ...

  1. If there is data in the STACK, build an INSERT query and send that to database
  2. If you get a SUCCESS from the database, SHIFT that data out of the STACK
  3. Else If you get a FAILURE from the database, do NOT SHIFT the data
    1. log failure to console/log file
  4. Go to step 1

Another solution would be - log data value changes ONLY (instead of "every 2 seconds" - as you are recording LOTS of useless data :person_shrugging:)

Happy hunting


EDIT:

I forgot to say, as you seem to be sampling timeseries data, influxdb would probably be much better fit than MySQL / MSSQL