This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

MQTT subscribe
#41
It looks like all the examples run inside the resident script. I would like to be able to send something through a separate function that is not in the resident script.

Do you have an example I can use, or nudge me in a direction?
Reply
#42
First script here: https://kb.logicmachine.net/integration/mqtt-client/
Reply
#43
I am testing the resident script with 0 sleep interval. It works fine, I receive messages and send messages through tagged grp objects. But let's say I have another function running in a script outside of this resident script.

Code:
function sendToMqtt(message)
-- the code to send something over mqtt on the already established connection --
end

-- script using the function
foo = 1
if foo<2 then
sendToMqtt('less than two')
end

How can I accomplish this without opening a new connection?
Reply
#44
Just create a new connection, it's much easier this way.
Reply
#45
Yes, it is easy. But wouldn't this affect speed and performance? Let's consider 200 objects changing value within 5 seconds and I want all that data pushed up outside of the resident script scope?
Reply
#46
Then use a resident script. The script can modified with an additional callback function per object (similar to mqtt_to_object_conv, but in reverse). It will transform the object value the way you needed before publishing it to MQTT.
Reply
#47
(31.01.2024, 13:23)admin Wrote: Then use a resident script. The script can modified with an additional callback function per object (similar to mqtt_to_object_conv, but in reverse). It will transform the object value the way you needed before publishing it to MQTT.

I am sending large amount of data generated from functions. I can not store the data in an object and therefore need to send it directly to the mqtt broker.
Reply
#48
Use a separate connection for publishing then.
Reply
#49
Hi There,
I am currently trying to write a single Value from a JSON Payload to an Object.

I tested JSON Parse to Lua Table by adding the Payload from my MQTT Browser to the Script and decode it. Works just fine. MQTT Payload to Objects works as well.
But my JSON is too large for a String Object. But I struggle to add the MQTT Payload to a Variable.

Does Anyone have any Ideas or experience with this?

Thanks
Reply
#50
Check this: https://forum.logicmachine.net/showthrea...7#pid33207
Reply
#51
How i can set my "Client ID" ?
There is a code like client:id_set(Client ID) ?

BR
Reply
#52
See this: https://kb.logicmachine.net/libraries/mo...an_session

We highly recommend using MQTT client app instead of scripts.
Reply
#53
(08.12.2024, 08:25)admin Wrote: See this: https://kb.logicmachine.net/libraries/mo...an_session

We highly recommend using MQTT client app instead of scripts.

yes but i need to use a different client_id, one for any device with metering data
Reply
#54
Then you need a separate script for each device. Client id is sent once connection is established.
Reply


Forum Jump: