Android Question MQTT forget some information at mobile sleep, any help?

Adamdam

Active Member
Licensed User
Longtime User
Dear all
Greetings,
I created an app, based on MQTT between some mobiles, to transfer data between them. The Apps accept all data good when all mobiles waked-up if one goes to save power mode it accept some data and lost residual (most of all data sent) .
Any help to prevent that ? and make slept mobile accept and store data in array until it waked-up ?
Best regards
 

Adamdam

Active Member
Licensed User
Longtime User
Thanks Peter for your reply.
I'll try it.
by the way I need to wakeup the mobile when receive any MQTT message, how ?
i.e.
need to add wakeup function at this function code :
Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)

what is the function make this wakeup ?

on the other way, I try also to store all arrived message in an array, that may MQTT have a limited buffer, that after sleep the mobile receive some bytes and stop (that appear after wakeup)

best regards
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Make sure to use B4XPages.
2. Your solution will not work as good as push notifications. Once the device sleeps, the network connection will disconnect.
You will need to prevent the device from sleeping with partial lock and a foreground service. Example here: Background location tracking
It will not be reliable.
 
Upvote 0

Adamdam

Active Member
Licensed User
Longtime User
Many thanks Mr. Erel
I bought Huawei tablet to test; it is not receiving the notifications. and found many users gave solutions for this problem but fail until now.
So, I go with other solution (i.e. MQTT instead of notification).
I'll try again with Huawei may I find right solution for working the notification.
also, I'll try your suggestion (Partial Lock).
Really, many thanks
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Besides what Erel already told you, consider the progressive numbering of sent messages.
Each client will record its last received message. When started up (after reboot, pause, other) it checks with the server and eventually claims all the messages it missed so far. You can accomplish this via a "service" channel other than the regular "data" channel where new messages are sent by the server.
 
Upvote 0

MbedAndroid

Active Member
Licensed User
Longtime User
it's already an old post, but I had the same thing. Mqtt_message receive stopped after about 4 minutes. Solution was to send a "ping" . Once every 1 or 2 minutes is fine. The connection then continues to work.
 
Upvote 0
Top