Android Question mqtt disconnect event not firing when broker running in RPi [SOLUTION]

giggetto71

Active Member
Licensed User
Longtime User
I AM NOT EXPECTING ANY SUPPORT FROM ANYWHERESOFTWARE PEOPLE OR FROM EREL GIVEN THE CURRENT TRAGIC SITUATION IN ISRAEL.

Hi,
strange case..for the 2 scenarios described below, in case 1 I get both connected and disconnected events on client app side.

in case 2, I only get the connected event but NOT the disconnected. only difference is that the broker is running in Rpi. Actually there is a small difference. in case one to fire the disconnection on client side, I stop the B4j broker app, while in case 2 I reboot the Rpi. Can it be the reason?

case 1: mqtt broker running in a B4J pc non ui application as:

B4X:
broker.Initialize("", 51041)
broker.SetUserAndPassword(user,pw)
broker.Start
broker.DebugLog = False

mqtt client running on a B4J UI app:

B4X:
 '''''''''''''''
 Dim clientId As String = Rnd(0, 999999999) & DateTime.Now 'create a unique id
 mqtt.Initialize("mqtt", "tcp://192.168.1.11:51041", clientId)
 Dim mo As MqttConnectOptions
 mo.Initialize(user, password)  
 mqtt.Connect2(mo)
 
 ''''''''''
Sub mqtt_Connected (Success As Boolean)
    Log("Connected event:" & Success)
    If Success = False Then
        Log(LastException)          
    Else
        Log("client Connected")
        mqtt.subscribe("#",0)      
    End If
End Sub

Private Sub mqtt_Disconnected
    Log("Disconnected")
End Sub


Case 2: same as case 1 only that the Broker is running in a Rpi as B4j non ui application. same code for broker. client side, same client, same code.
 

teddybear

Well-Known Member
Licensed User
You can try to kill the broker process rather than reboot on the Rpi , to see if the disconnected event fire
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
yes, @teddybear killing the process does fire the event but rebooting the Rpi does not.
Any idea how to capture that event in that case ? I am pretty sure it's something on client side because MQTTBox client app does detect it as "disconnected" during the reboot..
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
yes..keepalive is the key..too bad it is not implemented as a native parameter and you need to use a javaobject. but that's ok.


B4X:
jo.RunMethod("setKeepAliveInterval", Array(10)) '20 seconds
 mqtt.Connect2(mo)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…