Android Question MQTT Event not fired

CR95

Active Member
Licensed User
In a B4A program, I have several B4XPages which send and receive MQTT requests to/from an external broker.

For an external reason, this page disappears. When it reappears, the MQTT receive events are not fired.

AT that point, I am sure that the connection is working fine (mqtt.connected = true) and that the broker returns correctly the demands.

WHat could be my issue ?
 

amorosik

Expert
Licensed User
Without code is almost impossible to answer
I have some Android projects that use MQTT to send/receive data from the central system, and they work correctly
Especially after implementing the connect/reconnect method described by Erel
Are you sure the client is "subscribed" to the same path used by the sender of the message?
 
Last edited:
Upvote 0

CR95

Active Member
Licensed User
Thanks, amorosik

I understand that the lack of code is a issue, but my program is very long.

Yes, the android client subscribe at the starting of the program and then continues to use the same path. As I said before, I have a "MQTT spy" running on Windows which guarantees that the broker receives and returns the demands. This is my B4A program which does not receive the return of the broker

From my point of view (with a low knowledge), the issue seems to be linked to the disappearing and reappearing of the B4Xpage
 
Upvote 0

amorosik

Expert
Licensed User
You could set a timer for 1 second
Every time the timer goes on, check the connection with the broker, at least to ensure communication is active
 
Upvote 0

CR95

Active Member
Licensed User
I already followed the connection status with the broker.

And yes, after the disappearing of me page, the connection sometimes fails. But it automatically restarts a moment later (quality of the connect/reconnect method).

COuld it be this connection failure which could explain that the event is not found after ?
 
Upvote 0

CR95

Active Member
Licensed User
My (stupid ?) idea could be that after a connection interrupt, Android considers that the application is "finished" and it is not able to forward the MQTT messages ????
 
Upvote 0

amorosik

Expert
Licensed User
The application and the connection are two separate things
I have no reason to associate the connection with the app
Instead, are you SURE SURE the connection will re-enable itself?
 
Upvote 0

CR95

Active Member
Licensed User
As I told you, I follow the connection status in the Log (several lines contain the status of MQTT connected)
May be the picture hereafter could help you to understand :
- above the red line ((20:03), this is the log of a "normal" MQTT exchange (send amuteoff, receive and ignore my MQTT message, receive MQTT response of server)
- at 20 h 09 -> B4Xpage disappears (may be I was using another application)
- 4 minutes later, connection fails
- at 20 h 59 (50 minuts later which could be explained by the fact that I don't use the phone during this time !)), communication restarts and then B4XPage reappears (MQTT is connected)
- 5 seconds later, B4XPage disappears and reappears (MQTT is connected). Why ?
- after the blue line, a new internal command is processed
- then, a new MQTT command (Cmenu) is sent to the broker
BUT the B4XPage does not receive any return from the broker (even my demand)
which is followed by a timeout

MQTT Log.jpg
 
Upvote 0

amorosik

Expert
Licensed User
It's already hard to get things going by studying the code used
Discussing without seeing what the program does is only a waste of time for both you and me.
 
Upvote 0

amorosik

Expert
Licensed User
- at 20 h 09 -> B4Xpage disappears (may be I was using another application)

I don't think so.
I have an app that communicates via MQTT with Mosquitto physically installed on one pc of my lan
To 'know' if the app is running, l'app sends a command to the broker every 60 seconds, a sort of ping, so to speak.
And I see the ping arrive even if I'm using another app on my Android device (the app that communicates via MQTT in the background)
 
Upvote 0

CR95

Active Member
Licensed User
My configuration is close of yours.
My Android communicates via MQTT to Erel's simple broker (5 lines) installed on a Raspberry via a LAN.
Erels' connectAndReconnect method sends a ping every 5 seconds. The difference is that its ping is "in the space".
Furthermore, I am sure that the PI broker sends a response as the "MQTT spy" running on a separate PC sees this response

On the forum, I found a similar issue :
https://www.b4x.com/android/forum/t...g-when-broker-running-in-rpi-solution.155200/
I don't try to implement his solution as I have a "pw.KeepAlive(True)" instruction at the starting of my Android program.
 
Upvote 0

CR95

Active Member
Licensed User
@amorosik
Thanks for all your efforts
At this point, I am thinking to change the Service part of my application (which starts the ConnectAndReconnect section).
Based on what I read, it seems that the "receiver" system is more appropriate with recent Android.
 
Upvote 0
Top