B4J Question MQTT first test

giggetto71

Active Member
Licensed User
Longtime User
guys,
I am using jMQTT library and JMQTTBroker libraries for a small test: local networ, raspberry PI and my pc.
the broker runs on the raspberry pi @ 192.168.1.5 where the broker is initialized and on client publishes a random number every 5 seconds on the topic "RandomNumbers"
On the PC side I have a B4J app that connects to the raspberry PI MQTT connections and correctly receives the random numbers published by the raspberry PI on the topic "RandomNumbers".
in the same b4J app I am trying to publish a start/stop command to the raspberry PI to stop or start publishing the random numbers.
for some reasons that I can't understand it seems that while the messages from the raspberry PI flow nicely to the B4J app, the other way oround does not work..

In B4J app start
....
B4X:
Dim clientId As String = Rnd(0, 999999999) & DateTime.Now
mqtt.Initialize("mqtt", "tcp://192.168.1.5:51041", clientId)
Dim mo As MqttConnectOptions
mo.Initialize(user, password)
mqtt.Connect2(mo)
mqtt.Subscribe("RandomNumber", 0)
....

then in
B4X:
Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)
    Dim obj As Object = serializator.ConvertBytesToObject(Payload)
    Dim ii As Int = obj
    Label1.Text = Topic & ":" & ii
end sub

then I have 1 button where I publish on the topic "command" to the raspberry PI the payload "stop"
B4X:
Sub Button1_MouseClicked (EventData As MouseEvent)
   mqtt.Publish2("command", serializator.ConvertObjectToBytes("stop"),1,True)
end sub

On the Raspberry PI side, I have the broker initialized and the code which publishes a new random number every 5 seconds. unfortunately the event

B4X:
sub mqttclient_MessageArrived
does not fire when I publish the message from the B4J app.


Any hint to try to understand what is wrong?
thanks!
 
Last edited:
Top