Android Question MQTT inline wait for code

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
Why this is not working?
B4X: Copy
' code ....
Wait For mqttclient_MessageArrived(Topic As String, Payload() As Byte)  
' rest of code ....
I can't go to rest of code after publishing and should receiving msg!
 
Why this is not working?
because mqttclient_MessageArrived is not a resumeable sub. It is an Eventsub.
Resumeable subs only have ONE Returnvalue.

 
Upvote 0
As DonManfred said, mqttclient_MessageArrived is an eventsub, you need not to wait for it, when message arrived, it will been called. the example has been explained very clear
 
Upvote 0
Why this is not working?
B4X: Copy
' code ....
Wait For mqttclient_MessageArrived(Topic As String, Payload() As Byte) 
' rest of code ....
I can't go to rest of code after publishing and should receiving msg!
Oh sorry, After analysing the situation, the inline wait for code is working fine, why my code not worked? because wait for line will be waiting for any publish occurred.
Where is my mistake? I was want to put publish and wait for in same code block.
I tested it by running other publish code, the wait for inline code fired normally.

Thanks
 
Upvote 0
The mqttclient_MessageArrived event does return a value normally?
I don't know mqtt, this is why I am asking.
 
Upvote 0
Checking the forum I found this
B4X: Copy
Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)
 
End Sub
so the sub receive 2 parameters but return nothing.
Maybe try
B4X: Copy
' code ....
Wait For mqttcomplete(Topic As String, Payload() As Byte) 
' rest of code ....
B4X: Copy
Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)

CallSub3(Me, "mqttcomplete", Topic, Payload)

End Sub
Untested code, wrote from mobile.
 
Upvote 0

Similar Threads

Replies
5
Views
4K
Replies
16
Views
26K
Replies
36
Views
137K
Replies
67
Views
139K
  • Article Article
Android Tutorial Inline Java Code
Replies
75
Views
113K
Back
Top