Android Question MQTT inline wait for code

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
Why this is not working?
B4X:
' 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!
 

DonManfred

Expert
Licensed User
Longtime User
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

teddybear

Well-Known Member
Licensed User
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

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
Why this is not working?
B4X:
' 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

Sagenut

Expert
Licensed User
Longtime User
The mqttclient_MessageArrived event does return a value normally?
I don't know mqtt, this is why I am asking.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Checking the forum I found this
B4X:
Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)
 
End Sub
so the sub receive 2 parameters but return nothing.
Maybe try
B4X:
' code ....
Wait For mqttcomplete(Topic As String, Payload() As Byte) 
' rest of code ....
B4X:
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

Top