johnquoc
I want to send the state data of a relay to topic_sent, but I do not know which block I should add to do it, so please help me surpass this problem bro. 
[203128%2F8460859%2Fmceclip0][203128%2F8460861%2Fmceclip0]
Reply 0 0
thiagoralves
With MQTT you can only send strings. The easiest option is to convert your relay to string and then attach that to the MQTT MESSAGE pin
Reply 0 0
johnquoc
I converted the relay to string. When I subscribed to the topic quoc123 in hivemq, it did not show anything in the part message.
[203128%2F8460952%2Fmceclip0][203128%2F8460953%2Fmceclip0]
Reply 0 0
thiagoralves
You should see either a 1 or a 0 at the message body, unless your MQTT broker requires some specific formatting for the message
Reply 0 0
thiagoralves
Actually, since relay is in series with the SEND pin, it will only send something when relay is 1.
Reply 0 0
johnquoc
I rewrote this ladder, but when I subscribed to the topic led2, hivemp did not indicated anything about the state of my relay.
[203128%2F8462408%2Fmceclip0][203128%2F8462409%2Fmceclip0][203128%2F8462410%2Fmceclip0][203128%2F8462411%2Fmceclip0]
Reply 0 0
guodong
Hello, I have been reading MQTT recently. May I ask what is the function of the delay device TON in your ladder diagram, and why is TON added? I want to understand the principle
Reply 0 0
thiagoralves
The timers are used to generate a square wave that controls when to send a message. If you simply let the SEND input on the MQTT block true all the time the code will try to send a message on every scan cycle, which most likely is not what you want.
Reply 0 0
guodong
Okay, thank you. I roughly understand. Now I'll give it a try,
Reply 0 0
Reply