-->
Page 1 of 2

No MSG Branch defined again !

PostPosted: Thu Mar 01, 2018 4:25 am
by Scugnizzo
Hi all !
Maybe I found a bug on Msgbranch command.
this is my code :

Code: Select allmsgbranch [azione]
Button "Esci",[uscita]
wait

[azione]
esito = "NOK"
action=msgget("act")

if action == "TEM" then
   temperature=DHT.TEMP()
   humidity= DHT.HUM()
   sendts("W5RQDTRSNKD113J6","3",str(temperature) & "&field4=" & str(humidity))
   esito=temperature&"x"&humidity
end if

if action == "ON1" then
   tmr1=0
ora1="0"
minuti1="0"
io(po,D5,1)
Do
   sendts("W5RQDTRSNKD113J6","1","1")
   delay 5000
   action= readts("5L3ICJTZZH1PYZL6","415417","1")
loop until action == "1"
action = "ON1"
esito="OK"
end if

if action == "ON2" then
   tmr2=0
   ora2="0"
   minuti2="0"
   io(po,D6,1)
   Do
      sendts("W5RQDTRSNKD113J6","2","1")
      delay 5000
      action= readts("5L3ICJTZZH1PYZL6","415417","2")
   loop until action == "1"
   action = "ON2"
   esito="OK"
end if

if action == "OF1" then
   tmr1=0
   ora1="0"
   minuti1="0"
   io(po,D5,0)
   Do
      sendts("W5RQDTRSNKD113J6","1","0")
      delay 5000
      action= readts("5L3ICJTZZH1PYZL6","415417","1")
   loop until action == "0"
   action = "OF1"   
   esito="OK"
end if

if action == "OF2" then
   tmr2=0
   ora2="0"
   minuti2="0"
   io(po,D6,0)
   Do
      sendts("W5RQDTRSNKD113J6","2","0")
      delay 5000
      action= readts("5L3ICJTZZH1PYZL6","415417","2")
   loop until action == "0"
   action = "OF2"   
   esito="OK"
end if

if len(action)=5 then
   rele=left(action,1)
   if rele=="1" then
      minuti1=right(action,2)
      ora1=mid(action,2,2)
      tmr1=1
      io(po,D5,1)
   else
      minuti2=right(action,2)
      ora2=mid(action,2,2)
      tmr2=1
      io(po,D6,1)
   end if
   esito=right(action,4)
   Do
      sendts("W5RQDTRSNKD113J6",rele,esito)
      delay 5000
      action = readts("5L3ICJTZZH1PYZL6","415417",rele)
   loop until action == esito
   esito="OK"
   Timer 55000, [controra]
end if

msgreturn esito
wait

[uscita]
Timer 0
end


Msgreturn works fine ONLY if the ACTION variable is equal to TEM (first IF.. THEN block) or if the ACTION variable doesn't match NONE of the IF..THEN blocks (NOK is returned).
For all other IF.. THEN blocks Msgreturn give "No MSG Branch defined" message, even if the related block is correctly performed.
Maybe the "DELAY" or "DO.. END LOOP" commands affects negatively Msgreturn ?

Thank you.

Re: No MSG Branch defined again !

PostPosted: Fri Mar 02, 2018 4:39 pm
by Oldbod
Personally for testing this module I would replace the action=readts..... with action= "value im testing for", and see what impact that has.

Will the value returned by readts always be a string one character in length? if not, I'm not sure if test
value == "1" will be true if value == "11" for instance. I would normally check or adjust string length somewhere before testing, and maybe print the ascii value of the first char in the string for testing.

Just a thought.
BTW - Timer 55000, [controra] <<<< is this label defined? quick ctrlf couldnt find it....

Re: No MSG Branch defined again !

PostPosted: Thu Nov 22, 2018 10:05 am
by Scugnizzo
After a lot of code maybe I have found the problem.
When you insert a DELAY instruction into the MSGBRANCH routine it cause the error.

msgbranch [mybranch]
print "set the branch"
wait

[mybranch]
myColorVar = msgget("color")
print myColorVar
delay 10 ' JUST ADD THIS LINE
let myReturnMsg = "You Entered " & myColorVar
msgreturn myReturnMsg
wait

Anyone have experienced this ?

Re: No MSG Branch defined again !

PostPosted: Thu Nov 22, 2018 6:57 pm
by Alberto_2
Yes I do confirm that using delay within msgbranch routine will create issues. Very likely the delay instruction close the socket, so the comunication ends.

I ended up calling twice in order to avoid to use the delay.

Alberto