H Hamied Abou Hulaikah Well-Known Member Licensed User Longtime User Apr 23, 2024 #1 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? 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!
DonManfred Expert Licensed User Longtime User Apr 23, 2024 #2 Hamied Abou Hulaikah said: Why this is not working? Click to expand... because mqttclient_MessageArrived is not a resumeable sub. It is an Eventsub. Resumeable subs only have ONE Returnvalue. [B4X] Resumable subs that return values (ResumableSub) Remember that that a call to Sleep or Wait For in a resumable sub causes the code flow to return to the parent. Example: Sub Button1_Click Sum(1, 2) Log("after sum") End Sub Sub Sum(a As Int, b As Int) Sleep(100) 'this will cause the code flow to return to the parent Log(a + b) End Sub... www.b4x.com Upvote 0
Hamied Abou Hulaikah said: Why this is not working? Click to expand... because mqttclient_MessageArrived is not a resumeable sub. It is an Eventsub. Resumeable subs only have ONE Returnvalue. [B4X] Resumable subs that return values (ResumableSub) Remember that that a call to Sleep or Wait For in a resumable sub causes the code flow to return to the parent. Example: Sub Button1_Click Sum(1, 2) Log("after sum") End Sub Sub Sum(a As Int, b As Int) Sleep(100) 'this will cause the code flow to return to the parent Log(a + b) End Sub... www.b4x.com
H Hamied Abou Hulaikah Well-Known Member Licensed User Longtime User Apr 23, 2024 #3 DonManfred said: because mqttclient_MessageArrived is not a resumeable sub. Resumeable subs only have ONE Returnvalue. Click to expand... How can i write inline wait for mqttclient_MessageArrived ? Upvote 0
DonManfred said: because mqttclient_MessageArrived is not a resumeable sub. Resumeable subs only have ONE Returnvalue. Click to expand... How can i write inline wait for mqttclient_MessageArrived ?
teddybear Well-Known Member Licensed User Apr 23, 2024 #4 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
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
H Hamied Abou Hulaikah Well-Known Member Licensed User Longtime User Apr 23, 2024 #5 Hamied Abou Hulaikah said: 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! Click to expand... 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
Hamied Abou Hulaikah said: 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! Click to expand... 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
DonManfred Expert Licensed User Longtime User Apr 23, 2024 #6 Hamied Abou Hulaikah said: I tested it by running other publish code, the wait for inline code fired normally. Click to expand... then use this code when it is working Upvote 0
Hamied Abou Hulaikah said: I tested it by running other publish code, the wait for inline code fired normally. Click to expand... then use this code when it is working
H Hamied Abou Hulaikah Well-Known Member Licensed User Longtime User Apr 23, 2024 #7 DonManfred said: then use this code when it is working Click to expand... I want to write publish and wait in the same code block! but no luck. should be separated in different code block! If anyone has the ability to do it? Upvote 0
DonManfred said: then use this code when it is working Click to expand... I want to write publish and wait in the same code block! but no luck. should be separated in different code block! If anyone has the ability to do it?
Sagenut Expert Licensed User Longtime User Apr 23, 2024 #8 The mqttclient_MessageArrived event does return a value normally? I don't know mqtt, this is why I am asking. Upvote 0
The mqttclient_MessageArrived event does return a value normally? I don't know mqtt, this is why I am asking.
H Hamied Abou Hulaikah Well-Known Member Licensed User Longtime User Apr 23, 2024 #9 Sagenut said: The mqttclient_MessageArrived event does return a value normally? Click to expand... Yes, return topic and message payload. Upvote 0
Sagenut said: The mqttclient_MessageArrived event does return a value normally? Click to expand... Yes, return topic and message payload.
Sagenut Expert Licensed User Longtime User Apr 23, 2024 #10 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
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.
DonManfred Expert Licensed User Longtime User Apr 23, 2024 #11 Hamied Abou Hulaikah said: Yes, return topic and message payload. Click to expand... NO. It does NOT return anything. It is SENDING two values. It is a Eventsub Upvote 0
Hamied Abou Hulaikah said: Yes, return topic and message payload. Click to expand... NO. It does NOT return anything. It is SENDING two values. It is a Eventsub