Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modbus-Flex-Connector node service status indication #483

Open
hacesoft opened this issue Jul 30, 2024 · 2 comments
Open

Modbus-Flex-Connector node service status indication #483

hacesoft opened this issue Jul 30, 2024 · 2 comments
Assignees

Comments

@hacesoft
Copy link

hacesoft commented Jul 30, 2024

Which node-red-contrib-modbus version are you using?

5.41

What happened?

Unable to verify current service status. Even if I am disconnected from the TCP communication with the inverter or it is connected or connected, the output from the Modbus-Flex-Connector node is not indicated in any way.

Server

Other/External server

How can this be reproduced?

node-red 4.02 drives me to the NAS synology version in docker, and I connect to CERBO (communication device for victron inverters), although it is on another VLAN, but that is a network solution. It is enough to fill the node function with data and send it to the Modbus-Flex-Connector node, connect debug to the output and turn on the output to the goat and you can see that no message comes when disconnecting, no message during connection either, the only thing that comes is a message after connecting to given sent configuration. If you send your configuration, you need another IP address where there is no HW, so a message will come saying that the device did not connect. I only know the connection based on the need for current and data from the modbus-read node.

What did you expect to happen?

I expected that when disconnecting I would get a message that I am disconnected from the TCP server, or I would receive a message, I am currently trying to connect to the given TCP configuration, or I managed to connect with the given IP address to the given port with this ID, or that to the given IP is not a HW device...

Other Information

No response

@hacesoft hacesoft added the bug label Jul 30, 2024
@hacesoft hacesoft changed the title Modbus-Flex-Connector node indikace stavu služby Modbus-Flex-Connector node service status indication Jul 30, 2024
@biancode biancode added help wanted support community could be done by the community unexpected behaviour and removed bug labels Jul 31, 2024
@grewek
Copy link

grewek commented Aug 29, 2024

I took a look at the issue and i can reproduce it, but right now i am not sure what changes would be necessary
to implement the proposed feature. I will do my best to solve this issue but can't make any promise when it will
actually happen! Time is a little bit short these days!

Best Regards,

Kay

@hacesoft
Copy link
Author

Good day, although it's not a 100% solution, but somehow I got hung up on the absence of the connection status check. Here it works reliably :).
Flow works like this: I have a second injector that goes to the Check SN function, there is data for reading the SN system. If the function succeeds, I have a number other than 0. And thus I am connected. If I have a bad IP address or the device is not connected to modbus, the check connection function checks whether I have a valid time stamp, this is so that I receive messages, if I have 4 consecutive valid time stamps, then I am not connected, otherwise the calculator resets and we connected to the IP address :).

[ { "id": "6f269dbc176339b8", "type": "tab", "label": "Flow 2", "disabled": false, "info": "", "env": [] }, { "id": "38f637084b7cd43f", "type": "modbus-flex-connector", "z": "6f269dbc176339b8", "name": "connection", "maxReconnectsPerMinute": 4, "emptyQueue": false, "showStatusActivities": false, "showErrors": false, "server": "6c801ec0cc108747", "emptyMsgOnFail": false, "configMsgOnChange": false, "x": 550, "y": 320, "wires": [ [ "bd7406b0bf6f2069" ] ] }, { "id": "66960bd8137f9326", "type": "function", "z": "6f269dbc176339b8", "name": "connect", "func": "//*****************************************************************************\n//\n// File Name : N/A\n// Title : N/A\n// Author : http://www.prochazka.zde.cz -> hacesoft 2024\n// Created : 20-07-2024, 17:01\n// Revised : 25-07-2024, 19:42\n// Version : 1.2\n// Target Platform : Node-RED\n//\n// This code is distributed under the GNU Public License\n// Všechny informace jsou zahrnuty pod GPL licenci, pokud není explicitně uveden jiný typ licence.\n// Používání těchto stránek a produktů ke komerčním účelům lze jen se souhlasem autora.\n// Všechna práva vyhrazena (c) 1997 - 2024 hacesoft.\n//\n//*****************************************************************************\n// Debugging flag\nconst debug = false; // Nastavte na true pro zapnutí debug zpráv\n\n//definice globalních funkci\nconst fGetConfigProperty = global.get('getConfigProperty');\nconst fSetConfigProperty = global.get('setConfigProperty');\n\nconst tcpHost = fGetConfigProperty(\"connectorConfig.tcpHost\") || 0; //dotaz na data z globalni strukturu\nconst tcpPort = fGetConfigProperty(\"connectorConfig.tcpPort\") || 0; //dotaz na data z globalni strukturu\nconst unitId = fGetConfigProperty(\"connectorConfig.unitId\") || 0; //dotaz na data z globalni strukturu\n\nnode.debug(\"debug message\");\n\nmsg.payload = {\n 'connectorType': \"TCP\",\n 'tcpHost': tcpHost,\n 'tcpPort': tcpPort,\n 'unitId': unitId,\n 'modbusResponse.status': 0\n};\n\n \n\nreturn msg;\n\n/*\nnode.log(\"Informational message\"); // Logs at info level\nnode.warn(\"Warning message\"); // Logs at warn level\nnode.error(\"Error message\"); // Logs at error level\nnode.debug(\"Debug message\"); // Logs at debug level\nnode.trace(\"Trace message\"); // Logs at trace level\n*/\n", "outputs": 1, "timeout": "", "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 380, "y": 320, "wires": [ [ "38f637084b7cd43f" ] ] }, { "id": "95392e1b35b58aaa", "type": "delay", "z": "6f269dbc176339b8", "name": "500ms", "pauseType": "delay", "timeout": "500", "timeoutUnits": "milliseconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "allowrate": false, "outputs": 1, "x": 230, "y": 320, "wires": [ [ "66960bd8137f9326" ] ] }, { "id": "9e04c9c53ad544a4", "type": "ui_button", "z": "6f269dbc176339b8", "name": "", "group": "ba1c560b4a2f6b32", "order": 4, "width": 5, "height": 1, "passthru": false, "label": "Connect", "tooltip": "", "color": "", "bgcolor": "", "className": "", "icon": "", "payload": "", "payloadType": "str", "topic": "connectButton", "topicType": "msg", "x": 220, "y": 360, "wires": [ [ "66960bd8137f9326" ] ] }, { "id": "fc78c29618584961", "type": "function", "z": "6f269dbc176339b8", "name": "Check Connection", "func": "//*****************************************************************************\n//\n// File Name : N/A\n// Title : N/A\n// Author : http://www.prochazka.zde.cz -> hacesoft 2024\n// Created : 29-07-2024, 17:01\n// Revised : 29-07-2024, 19:42\n// Version : 1.1\n// Target Platform : Node-RED\n//\n// This code is distributed under the GNU Public License\n// Všechny informace jsou zahrnuty pod GPL licenci, pokud není explicitně uveden jiný typ licence.\n// Používání těchto stránek a produktů ke komerčním účelům lze jen se souhlasem autora.\n// Všechna práva vyhrazena (c) 1997 - 2024 hacesoft.\n//\n//*****************************************************************************\n// Debugging flag\nconst debug = false; // Nastavte na true pro zapnutí debug zpráv\nconst nCountTimeStamp = 4; //kolik cyklu se má provest nez bude uznane platne casove razitko.\nlet nStatusIndicator = \"\";\nlet modbusResponse = msg.payload;\n\n// Získání počtu přijatých časových razítek z flow contextu\nlet timestampCounter = flow.get(\"timestampCounter\") || 0;\n\nconst nCode = isTimestamp(modbusResponse);\n\nif (nCode == true) {\n // Pokud je hodnota platným časovým razítkem, zvyšte čítač\n timestampCounter += 1;\n \n // Pokud čítač dosáhne hodnoty nCountTimeStamp, resetuje modbusResponse a čítač\n if (timestampCounter >= nCountTimeStamp) {\n modbusResponse = 0; // Platné časové razítko 10x za sebou\n timestampCounter = nCountTimeStamp; // Resetování čítače\n }\n} else {\n // Pokud nepřijde platné časové razítko, čítač se vynuluje\n timestampCounter = 0;\n}\n\n// Uložení aktuálního stavu čítače do flow contextu\nflow.set(\"timestampCounter\", timestampCounter);\n\nif (modbusResponse != 0){\n nStatusIndicator =\"on\"\n} else {\n nStatusIndicator =\"off\";\n} \nconst indicatorMsg = { indicator: '_tcp_connect', status: nStatusIndicator, topic: 'update-indicator' };\nreturn { payload: indicatorMsg };\n\n\n// Funkce pro zjištění, zda je hodnota časové razítko\nfunction isTimestamp(value) {\n if (typeof value !== 'number' || isNaN(value)) {\n return false;\n }\n\n const now = Date.now();\n const minTimestamp = new Date('1970-01-01').getTime(); // UNIX epoch start\n const maxTimestamp = new Date('2100-01-01').getTime(); // Future limit\n\n // Check if it's a millisecond timestamp\n if (value >= minTimestamp && value <= maxTimestamp) {\n return true;\n }\n\n // Check if it's a second timestamp (divide by 1000)\n if (value * 1000 >= minTimestamp && value * 1000 <= maxTimestamp) {\n return true;\n }\n\n return false;\n}\n", "outputs": 1, "timeout": "", "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 810, "y": 260, "wires": [ [ "b6192d60fb8f64e3" ] ] }, { "id": "bd7406b0bf6f2069", "type": "modbus-response", "z": "6f269dbc176339b8", "name": "", "registerShowMax": 20, "x": 770, "y": 360, "wires": [] }, { "id": "ff7281d91ed2871d", "type": "function", "z": "6f269dbc176339b8", "name": "Check SN", "func": "//*****************************************************************************\n//\n// File Name : N/A\n// Title : N/A\n// Author : http://www.prochazka.zde.cz -> hacesoft 2024\n// Created : 28-09-2024, 16:23\n// Revised : 28-09-2024, 17:43\n// Version : 1.0\n// Target Platform : Node-RED\n//\n// This code is distributed under the GNU Public License\n// Všechny informace jsou zahrnuty pod GPL licenci, pokud není explicitně uveden jiný typ licence.\n// Používání těchto stránek a produktů ke komerčním účelům lze jen se souhlasem autora.\n// Všechna práva vyhrazena (c) 1997 - 2024 hacesoft.\n//\n//*****************************************************************************\n// Debugging flag\nconst debug = false; // Nastavte na true pro zapnutí debug zpráv\n\nmsg.payload = { \n value: msg.payload, \n 'fc': 4, \n 'unitid': 100, \n 'address': 800,\n 'quantity': 1\n}; \nreturn msg;", "outputs": 1, "timeout": "", "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 440, "y": 260, "wires": [ [ "df73fa3bb0946406" ] ] }, { "id": "df73fa3bb0946406", "type": "modbus-flex-getter", "z": "6f269dbc176339b8", "name": "read", "showStatusActivities": false, "showErrors": false, "showWarnings": true, "logIOActivities": false, "server": "6c801ec0cc108747", "useIOFile": false, "ioFile": "", "useIOForPayload": false, "emptyMsgOnFail": false, "keepMsgProperties": false, "delayOnStart": false, "startDelayTime": "", "x": 570, "y": 260, "wires": [ [ "2f0cdcc0435f4deb", "fc78c29618584961" ], [] ] }, { "id": "2f0cdcc0435f4deb", "type": "debug", "z": "6f269dbc176339b8", "name": "debug 54", "active": false, "tosidebar": true, "console": false, "tostatus": true, "complete": "true", "targetType": "full", "statusVal": "payload", "statusType": "auto", "x": 760, "y": 200, "wires": [] }, { "id": "323d658ae80306c4", "type": "inject", "z": "6f269dbc176339b8", "name": "", "props": [ { "p": "payload" } ], "repeat": "1", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 270, "y": 260, "wires": [ [ "ff7281d91ed2871d", "fc78c29618584961" ] ] }, { "id": "b6192d60fb8f64e3", "type": "ui_template", "z": "6f269dbc176339b8", "group": "ba1c560b4a2f6b32", "name": "Indicators", "order": 5, "width": 1, "height": 1, "format": "<div style=\"display: flex; flex-direction: column; gap: 8px; border: 0px solid black; padding-top: 5px; padding-bottom: 5px; background-color: #3c3c3c;\">\n <div style=\"display: flex; align-items: center; justify-content: space-between; margin-left: 13px;\">\n <span></span>\n <div id=\"_tcp_connect-indicator\"\n style=\"width: 20px; height: 20px; border-radius: 50%; background-color: grey; margin-right: 13px;\">\n </div>\n </div>\n</div>\n<script>\n (function(scope) {\n function updateIndicator(indicatorId, turnValue) {\n var indicator = document.getElementById(indicatorId);\n if (turnValue === 'on') {\n indicator.style.backgroundColor = '#32cd32'; // Zelená barva\n } else {\n indicator.style.backgroundColor = 'grey'; // Šedá barva\n }\n }\n\n scope.$watch('msg.payload', function(msg) {\n if (msg && msg.indicator && msg.status) {\n updateIndicator(msg.indicator + '-indicator', msg.status);\n }\n });\n})(scope);\n</script>\n", "storeOutMessages": true, "fwdInMessages": true, "resendOnRefresh": true, "templateScope": "local", "className": "", "x": 1020, "y": 260, "wires": [ [] ] }, { "id": "6c801ec0cc108747", "type": "modbus-client", "name": "linea", "clienttype": "tcp", "bufferCommands": true, "stateLogEnabled": false, "queueLogEnabled": false, "failureLogEnabled": false, "tcpHost": "127.0.0.1", "tcpPort": "502", "tcpType": "DEFAULT", "serialPort": "/dev/ttyUSB", "serialType": "RTU-BUFFERD", "serialBaudrate": "9600", "serialDatabits": "8", "serialStopbits": "1", "serialParity": "none", "serialConnectionDelay": "100", "serialAsciiResponseStartDelimiter": "0x3A", "unit_id": 100, "commandDelay": 1, "clientTimeout": 1000, "reconnectOnTimeout": true, "reconnectTimeout": 2000, "parallelUnitIdsAllowed": false, "showErrors": false, "showWarnings": true, "showLogs": true }, { "id": "ba1c560b4a2f6b32", "type": "ui_group", "name": "TCP", "tab": "421891c215fdf211", "order": 2, "disp": true, "width": "6", "collapse": true, "className": "" }, { "id": "421891c215fdf211", "type": "ui_tab", "name": "Config", "icon": "settings_input_component", "disabled": false, "hidden": false } ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants