B4J Question MQTT multiple subscribes

madru

Active Member
Licensed User
Longtime User
Good afternoon,

can sombody show me how to use the MQTT client with several (20) subscriptions ?

I tried to put the lib into a separated module but then no event is firing....
tried to Dim the lib as as array (Private mqtt(19) AsMqttClient)
but that always gives you dived by zero....

I have really no idea :(




THX
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
for every server you may need a mqttClient

i believe that this option is okey.
What error raises?

B4X:
Private mqtt(19) As MqttClient

for i = 0 to mqtt.length - 1
mq(i).initialize("mq","server")
next

private Sub mq_Connected (Success As Boolean)
dim mq as mqttClient = sender
log(mq.clientId)
end sub
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
Hi Erel,

I tried this (what is properly wrong)
mqttclass:
B4X:
Sub Class_Globals
    Private fx As JFX
    Private mqtt_test As MqttClient
End Sub


Public Sub Initialize(uri As String, id As String)

    mqtt_test.Initialize("mqtt", uri, id)

End Sub

public Sub connect

    mqtt_test.Connect

EndSub


Sub mqtt_Connected (Success As Boolean)

    'Dim client AsMqttClient = Sender
    'Log(client.clientId)

    If Success = False Then
        Log(LastException)
    Else
        LogError("Connected")
    End If

End Sub

Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)

    Log(BytesToString(Payload, 0, Payload.Length, "utf8"))

End Sub

Main:
B4X:
Dim mqtt_test As mqttclass
mqtt_test.Initialize("tcp://192.168.237.239:1883", ClientID)
mqtt_test.connect

using this I cannot even see that a connection to the broker was opened :'(

can you point me into the right direction?
 
Last edited:
Upvote 0

madru

Active Member
Licensed User
Longtime User
little update, we can close this.....

all issues are related to a half-open connection between firewall and router. The network people in the office explained that a component got out of sync with the other (whatever that means)

THX for all the help :)
 
Upvote 0
Top