Linking Multiple LM's - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Linking Multiple LM's (/showthread.php?tid=2628) |
Linking Multiple LM's - sjfp - 05.05.2020 I need to Link 5 LM (GSM) machine's back to a central LM Lite, (This a demo system to prove concept to a client) Was looking how I can send various Object values between then all, sending alerts back to the Central and the Central LM sending required control cammands like operating relays etc. Thinking to use as a temporary quick fix for proof of concept Remote Services, but I would like to establish a more scalable and secure solution going forward, as there could be a significant amount of remote LM's on sites (100+) So at the present all LM will sit on a OPEN VPN Network, so using Remote Service is OK for now. Been reading on the forum about MQTT and Broker based solutions, which appears to be the way forward. Just seeing if there is any information or examples of how to get ALL LM's communicating between remote site and the central LM as above. Any suggestions or advise would be useful. RE: Linking Multiple LM's - Daniel - 06.05.2020 The web services would work but MQTT might be better option for such bigger installation. For your demo you can install MQTT broker app, in attachment You need RC2 fw but if you use VPN then you already have it. As for clients you can use this script https://forum.logicmachine.net/showthread.php?tid=1759&pid=10926#pid10926 On the client with broker in use ip 172.0.0.1 For installation for 100LMs it would be recommended to install MQTT broker on your VPN server. Hard to say how many clients broker on LM can handle. BR RE: Linking Multiple LM's - sjfp - 06.05.2020 thank you Daniel. will have a read RE: Linking Multiple LM's - sjfp - 11.05.2020 Daniel, thank you for the example. Have tested the solutions (thank you) and works well. Just what I was looking for. Now tested, I am going to move the broker onto a cloud, done and works great. but now need to secure connection to the broker. How can I implement a user name a password for each client to use. Stopping unauthorized use of broker, RE: Linking Multiple LM's - Daniel - 11.05.2020 If you use it inside the VPN then it is already secured. Only devices which are able to connect to VPN will be able to access broker. Do you want to do it outside of VPN? RE: Linking Multiple LM's - sjfp - 11.05.2020 Yes please. The VPN is on one clients site, but another project isn't, so securing the MQTT is important as well. Plus how can add info on which LM is connected. On the broker I can see active clients (only a number like 4 client), but cant see which ones. Is there a way to find out, and also no if the client disappears ?? Sorry if this is an issue. RE: Linking Multiple LM's - Daniel - 11.05.2020 For connection with encryption use this example. Enable MQTT broker with encryption and add a user and password in the Broker app You may need to reboot LM with broker after changing settings. Code: if not broker then RE: Linking Multiple LM's - sjfp - 11.05.2020 Daniel, just tried the provided code, change IP address and port number (1883) but wont connect to the broker. Tried the connection with a app on android phone with the same credentials, and connect with no issue. So I think there may be an issue in the code provided. Sorry :-( RE: Linking Multiple LM's - Daniel - 11.05.2020 You have to use port 8883 I tested it and works. Make sure you Enable MQTT broker with encryption, add user and password then reboot LM. RE: Linking Multiple LM's - admin - 11.05.2020 If you don't use encryption you need to remove the line that calls tls_insecure_set RE: Linking Multiple LM's - sjfp - 11.05.2020 Thank you both. Tried the tls_insecure_set and worked fine. Will have a go at yours Daniel later today. Thank you both for your help. RE: Linking Multiple LM's - sjfp - 13.05.2020 Having an issue sending 10.3 byte time / day . object data between LM's Is there a conversation that needs to be preformed ? RE: Linking Multiple LM's - Daniel - 13.05.2020 The script you use is sending data in string format. This dpt is a table and will not work. Use date/time in numeric format. RE: Linking Multiple LM's - Daniel - 13.05.2020 Use this script then data will be send in json format so even dpt date and time can be sent. You can also set qos and retain Code: if not broker then RE: Linking Multiple LM's - Erwin van der Zwart - 16.05.2020 Hi Daniel, I see in your last sample that you have added the field "qos" (quality of service), i have a couple of questions about that: For the qos, when i set it to 1 how do we handle the PUBACK packet? If we set it to 2 how do we handle the PUBREC, PUBREL and PUBCOMP packages? Is this handled in the lib already and the re-sending of a topic value is automatically handled and we don't have to take care of this in the client script? Another question is: Can we simply set a extra field 'lwt' in the object to mqtt table to set the last will and testament message? BR, Erwin RE: Linking Multiple LM's - Daniel - 16.05.2020 Hi Erwin QOS is handled automatically in lib. You can set 'Last will' like this client:will_set(topic, message, qos = 0, retain = false) So in example script it will looks like that. mclient:will_set('in/topic2', 'disconnected', 0, true) Add this after line mclient:login_set(username, password or '') RE: Linking Multiple LM's - Erwin van der Zwart - 16.05.2020 Hi Daniel, Thanks! Works perfect, now that we have a MQTT client in Ecostruxure Building Operation 3.2 (still BETA) i have a nice testing broker and it opens up a lot of options for integration. BR, Erwin RE: Linking Multiple LM's - Erwin van der Zwart - 19.05.2020 Hi Daniel, It's possible to send a null value (retained) to a topic to clear the retained value, but is there also a command to clear retained values from a topic including all subtopics or even all topics? Otherwise it's quite a pita to clear retained values if needed (for example during testing). BR, Erwin RE: Linking Multiple LM's - admin - 19.05.2020 From MQTT standard: A PUBLISH Packet with a RETAIN flag set to 1 and a payload containing zero bytes will be processed as normal by the Server and sent to Clients with a subscription matching the topic name. Additionally any existing retained message with the same topic name MUST be removed and any future subscribers for the topic will not receive a retained message. “As normal” means that the RETAIN flag is not set in the message received by existing Clients. A zero byte retained message MUST NOT be stored as a retained message on the Server. RE: Linking Multiple LM's - jmir - 13.08.2021 Hi, I've been testing this code using one LM as broker+publisher and a second one as publisher. I realized that when rebooting the LM that is not the broker, it can't reconnect until I disable and enable the script... This is the log: * arg: 1 * string: mqtt disconnect * arg: 2 * bool: false * arg: 3 * number: 14 * arg: 4 * string: unexpected disconnect * arg: 5 * nil I've added the line "broker = nil" here and now it's working, but i'm not sure that it is the best way to solve it... Code: mclient.ON_DISCONNECT = function(...) Is it correct? Thanks! |