Android Question MQTT B4A

fernando.oliboni

Active Member
Licensed User
Longtime User
Hi,

Hello, I used ESP32 to publish a topic to an MQTT broker. I would like to use B4A to subscribe to the publication. Could anyone give an example? Thank you
 
What MQTT broker? Do you have your own server?, Do you want to use ready-made solutions ... Use a search engine, type ESP8266...
 
Upvote 0
This library is compatible with B4A

 
Upvote 0
[QUOTE = "kisoft, postagem: 775883, membro: 97798"]
Qual corretor MQTT? Você tem seu próprio servidor ?, Quer usar soluções prontas ... Use um mecanismo de busca, digite ESP8266 ...
[/CITAR]


I searched the forum and found iMQTT, but I couldn't use it completely because I don't know how to use the MQTT_MessageArrived function.
 
Upvote 0
This library is compatible with B4A


I found jMQTT but I couldn't use it completely because I don't know how to use the MQTT_MessageArrived function.
 
Upvote 0
B4X:
Sub Process_Globals
    Public client As MqttClient
End Sub

Sub ConnectMQTT
    Log("Connecting")
    client.Initialize("client", "tcp://your_server:your_port", "your_topic")
'    client.Connect  ***If you don't need user and password, then uncomment this line and comment the 3 next ones
    Dim options As MqttConnectOptions
    options.Initialize("your_user", "your_password")
    client.Connect2(options)
End Sub

Private Sub client_MessageArrived (Topic As String, Payload() As Byte)
    Dim obj As Object = serializator.ConvertBytesToObject(Payload)
    Dim msg As String = obj
    Log("Topic: " & Topic  & " Mensaje: " & msg)
End Sub
 
Upvote 0

Similar Threads

Back
Top