MQTT subscribe - 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: MQTT subscribe (/showthread.php?tid=1759) |
MQTT subscribe - pentadom - 30.11.2018 Hello, I'm trying to subscribe to a MQTT topic ("arqueta/humedad") and asign his value to an object of logic machine. I'm using de test Mosquitto broker and I publish previously a value to the topic "arqueta/humedad". I'm using this code (extracted from here) as a resident script but It seems doesn't works and I don't know what I'm doing wrong... Code: -- Define a function which is called by mqtt_client:handler(), RE: MQTT subscribe - admin - 03.12.2018 Upgrade firmware to 2018 RC1. It has built-in MQTT library support and some other features required for this script. Create resident script with 0 sleep interval. Change broker IP address and mapping tables as needed. mqtt_to_object maps topic to a group address, object_to_mqtt maps group address to atopic. Do full script restart via disable/enable when changing any mapping tables and/or broker address. Code: if not broker then RE: MQTT subscribe - pentadom - 03.12.2018 (03.12.2018, 08:43)admin Wrote: Upgrade firmware to 2018 RC1. It has built-in MQTT library support and some other features required for this script. I'm trying to do this but it doesn't works. I supose that when I send a value to the broker, automatically the script must receive the value? I've just upgrade the firmware. Here's the actual version: Here's my code where I put the mosquitto test broker and the topic "arqueta/humedad" I'm testing. the object 32/1/1 is a "05. 1 byte unsigned integer". As I say, it doesn't works and I don't know what I'm doing wroing. The correct line to broker is without "http://" broker = 'test.mosquitto.org' Now it works the suscribe. RE: MQTT subscribe - Dario - 04.02.2020 Hi! I have problem with object_to_mqtt this topic will change on MQTT when I write new value? Is it necessary event script? Now I don't see change this value on client. RE: MQTT subscribe - admin - 04.02.2020 No event script is needed. Value is published to selected topic when value changes. Have you checked that MQTT client is connected? Does the reverse (mqtt_to_object) work? Does the client have access to the select topic? You can log the publish result like this (line 83): Code: local r, e, c = mclient:publish(topic, tostring(value)) RE: MQTT subscribe - Dario - 04.02.2020 Solved! the problem was client software that I used, MQTT_to_object worked but no the reverse. RE: MQTT subscribe - Tifon - 08.03.2020 Admin thank you for this code!, it works great. But how can i apply a scale factor to one of the "mqtt_to_object"? RE: MQTT subscribe - admin - 09.03.2020 I've updated example post. Edit mqtt_to_object_conv table as needed, custom conversion functions can be added as well. RE: MQTT subscribe - dharma@srujan-infotech.com - 19.02.2021 (09.03.2020, 08:46)admin Wrote: I've updated example post. Edit mqtt_to_object_conv table as needed, custom conversion functions can be added as well. Hi, in my case am using LM as broker and i need to Publish/subscribe single topic Message payloads to different group address? how to achieve below criteria in LM5 ex: for relay-1 is 0/0/1 as group address topic=100 Payload on=C,1,1,\r\n Payload off =C,1,0,\r\n for relay-2 is 0/0/2 as group address topic=100 Payload on=C,2,1,\r\n Payload off=C,2,0,\r\n RE: MQTT subscribe - admin - 19.02.2021 Add custom logic to the MQTT callbacks: Code: mclient.ON_CONNECT = function(res, ...) Using one topic for controlling multiple entities is bad system design. Each relay should have it's own topic for control if possible. RE: MQTT subscribe - dharma@srujan-infotech.com - 20.02.2021 Hi, please elaborate this custom Logic in Mqtt callbacks where we can i find actually am adding this logic in main residence script please find it in attached file(how we have done) am doing it in correct way...? RE: MQTT subscribe - admin - 22.02.2021 Looks correct, add logging for each received message in case it does not work: Code: mclient.ON_MESSAGE = function(mid, topic, payload) RE: MQTT subscribe - dharma@srujan-infotech.com - 22.02.2021 (22.02.2021, 07:24)admin Wrote: Looks correct, add logging for each received message in case it does not work: Hi, Please find attached snap shots of Logs RE: MQTT subscribe - admin - 22.02.2021 Check the latest log entry, it shows what data was published to the topic named "100". Modify the ON_MESSAGE callback function to execute actions based on the received payload: Code: mclient.ON_MESSAGE = function(mid, topic, payload) You can use MQTT explorer (http://mqtt-explorer.com/) to connect to LM and send any data to any topics to test your scripts. RE: MQTT subscribe - myg - 25.02.2021 alternatively you can use my declarative binding for mqtt2knx integration, although it was created for zigbee2mqtt topics https://forum.logicmachine.net/showthread.php?tid=2671 RE: MQTT subscribe - dharma@srujan-infotech.com - 26.02.2021 Hi, in this case the publishing topic=100, and Payload=C,1,1,1,\r\n like this format while subscribing topic=100 and msg Payload=$FD;2;4;0;0;0;0;0;0;@ while watching from LM log we found this. RE: MQTT subscribe - admin - 26.02.2021 Modify the example in my previous post and implement your custom actions based on the received payload value. RE: MQTT subscribe - dharma@srujan-infotech.com - 19.03.2021 (26.02.2021, 11:59)admin Wrote: Modify the example in my previous post and implement your custom actions based on the received payload value. Hi, modification according to the log it is working fine... for Boolean objects but when it comes to light Dimming and Fan regulator the commands are different for each value can you please update that conversation according to the following parameters.. group address to Mqttpublish) fan speed1_very low----->C,5,1,\r\n fanspped-low ------>C,5,2,\r\n fanspeed_medium ------>C,5,3,\r\n fanspeed_High ----->C,5,4,\r\n fan_off ----->C,5,0\r\n mqtt to group addressSubscribe) fan speed1_very low----->C,5,1 fanspped-low ------>C,5,2 fanspeed_medium ------>C,5,3 fanspeed_High ----->C,5,4 fan_off ----->C,5,0 RE: MQTT subscribe - admin - 19.03.2021 You can use 1-byte object with custom values to control values as is (0=off, 4=highest). Then to convert object value to payload use this: Code: payload = 'C,5,' .. value .. '\r\n' To convert payload back to the value use this: Code: value = payload:match('C,%d,(%d)') RE: MQTT subscribe - a455115 - 12.12.2022 Hello, I use the thread to ask: I need to introduce MQTT actuators of damphos in many rooms. How can I scan the broker for devices and automatically create objects with their names? For example, my punishments will have a topic: Danfos /room_001... Danfos /room_200.... How to get the names directly from the broker and create the objects I need - I will need several objects with different types of variables? |