Android Question Another MQTT Client crash

techknight

Well-Known Member
Licensed User
Longtime User
I have a new issue thats causing a crash "sometimes".

I get a Client is not Connected crash, AFTER it raises Success = true. Thats very strange. Thoughts?

Crashlog:
Code: Copy
commengine_mqtt_connected (java line: 298)
Client is not connected (32104)
    at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:31)
    at org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:143)
    at org.eclipse.paho.client.mqttv3.MqttAsyncClient.subscribe(MqttAsyncClient.java:721)
    at org.eclipse.paho.client.mqttv3.MqttAsyncClient.subscribe(MqttAsyncClient.java:681)
    at anywheresoftware.b4j.objects.MqttAsyncClientWrapper.Subscribe(MqttAsyncClientWrapper.java:91)
    at md.vscbsoccerxl.commengine._mqtt_connected(commengine.java:298)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.BA$2.run(BA.java:387)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6823)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1557)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
java.lang.RuntimeException: Client is not connected (32104)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:250)
    at anywheresoftware.b4a.BA$2.run(BA.java:387)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6823)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1557)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Caused by: Client is not connected (32104)
    at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:31)
    at org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:143)
    at org.eclipse.paho.client.mqttv3.MqttAsyncClient.subscribe(MqttAsyncClient.java:721)
    at org.eclipse.paho.client.mqttv3.MqttAsyncClient.subscribe(MqttAsyncClient.java:681)
    at anywheresoftware.b4j.objects.MqttAsyncClientWrapper.Subscribe(MqttAsyncClientWrapper.java:91)
    at md.vscbsoccerxl.commengine._mqtt_connected(commengine.java:298)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    ... 8 more

Java line:
Code: Copy
public static String  _mqtt_connected(boolean _success) throws Exception{
//BA.debugLineNum = 138;BA.debugLine="Sub mqtt_Connected (Success As Boolean)";
//BA.debugLineNum = 139;BA.debugLine="ProgressDialogHide";
anywheresoftware.b4a.keywords.Common.ProgressDialogHide();
//BA.debugLineNum = 140;BA.debugLine="connecting = False";
_vvv6 = anywheresoftware.b4a.keywords.Common.False;
//BA.debugLineNum = 141;BA.debugLine="If Success = False Then";
if (_success==anywheresoftware.b4a.keywords.Common.False) {
//BA.debugLineNum = 142;BA.debugLine="CallSub(Main, \"CancelProgressDialog\")";
anywheresoftware.b4a.keywords.Common.CallSubNew(processBA,(Object)(mostCurrent._vvvvvvvvvvvvv0.getObject()),"CancelProgressDialog");
//BA.debugLineNum = 143;BA.debugLine="CallSub3(Main, \"SendMessageBox\", \"Could not conn";
anywheresoftware.b4a.keywords.Common.CallSubNew3(processBA,(Object)(mostCurrent._vvvvvvvvvvvvv0.getObject()),"SendMessageBox",(Object)("Could not connect to scoreboard. Please try again."),(Object)("Connection Error"));
//BA.debugLineNum = 144;BA.debugLine="Log(LastException)";
anywheresoftware.b4a.keywords.Common.LogImpl("09175046",BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),0);
}else {
//BA.debugLineNum = 146;BA.debugLine="CallSub3(Main, \"SendProgressDialog\", \"Standing b";
anywheresoftware.b4a.keywords.Common.CallSubNew3(processBA,(Object)(mostCurrent._vvvvvvvvvvvvv0.getObject()),"SendProgressDialog",(Object)("Standing by for scoreboard. Please Wait."),(Object)(anywheresoftware.b4a.keywords.Common.False));
//BA.debugLineNum = 147;BA.debugLine="TimeoutTimer.Enabled = True";
_vvv0.setEnabled(anywheresoftware.b4a.keywords.Common.True);
//BA.debugLineNum = 148;BA.debugLine="mqtt.Subscribe(\"SendToScoreKeeperRemote\", 0) 'Su";
_vvv1.Subscribe("SendToScoreKeeperRemote",(int) (0));    <---CRASH
//BA.debugLineNum = 149;BA.debugLine="mqtt.Subscribe(\"ping\", 1) 'Subscribe to the hear";
_vvv1.Subscribe("ping",(int) (1));
//BA.debugLineNum = 150;BA.debugLine="mqtt.Subscribe(\"Connected\", 1) 'Subscribe to the";
_vvv1.Subscribe("Connected",(int) (1));
//BA.debugLineNum = 152;BA.debugLine="SendCommandToScoreboard(\"Connect\", \"Connected\")";
_sendcommandtoscoreboard("Connect",(Object)("Connected"));
};
//BA.debugLineNum = 154;BA.debugLine="End Sub";
return "";
}

And the actual B4A Sub:
Code: Copy
Sub mqtt_Connected (Success As Boolean)
    ProgressDialogHide
    connecting = False
    If Success = False Then
        CallSub(Main, "CancelProgressDialog")
        CallSub3(Main, "SendMessageBox", "Could not connect to scoreboard. Please try again.", "Connection Error")
        Log(LastException)
    Else
        CallSub3(Main, "SendProgressDialog", "Standing by for scoreboard. Please Wait.", False)
        TimeoutTimer.Enabled = True
        mqtt.Subscribe("SendToScoreKeeperRemote", 0) 'Subscribe to basic scoreboard data commands.
        mqtt.Subscribe("ping", 1) 'Subscribe to the heartbeat/ping channel which is created by the master controller.
        mqtt.Subscribe("Connected", 1) 'Subscribe to the connection event/return channel.
'        StateChanged
        SendCommandToScoreboard("Connect", "Connected") ' Tell the scoreboard to power-on, and we are connected.
    End If
End Sub

Strange issue as to why it wouldn't be connected after it had raised the connection success = true.
 
Weird how that happens sometimes. BTW the MQTT broker is running in another android app on another android device. Just for context. Maybe there is a bug with that?

After several tries it will eventually work.

Anyways, I can try the catch block and see what happens.
 
Upvote 0
Back
Top