Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By forlotto
#48621 Now I know mymsgbranch has been changed up a bit I do not know what has been changed.

It would be nice to know a few things.

The limitations on the amount of & data to append it used to be no more than two & appended data per line I believe it was.

Also the syntax and any changes. Using commas instead of spaces or other issues one might run into on 3.0 vs 2.0!

Would be nice to see a more complex example that would address all questions about limitations and syntax to see if their have been any major changes as I am looking to possibly update one of my devices from 2.x to 3.x branch here and change from buttons to using a branch to handle functionality. I love the fact that wifi station and AP no longer are by default in a dual mode this should eliminate conflicts.

The device I want to update on 2.x is doing rather poorly while I believe it may be related to the power supply it may be a conflict with AP/Station being enabled. This device is my latest device to my smart home venture an arctic king AC unit ... These AC units are super quiet well built and feature something called auto restart. Why this is important is we can cut the power to the unit and once power is restored the AC unit will turn back on and start cooling at the previous settings it was cooling at so in the case of a power outage the AC resumes cooling when power is restored!

Why this is important is that we can use this to our advantage no need to decode IR or hack apart the AC and you can setup to turn on and start cooling remotely with a simple relay! And the other nice thing is these AC units are available at your local walmart. Doing this setup will pay for itself over time in the amount of electricity you save by not letting your window unit cool all day long. A rather simple proposition if you ask me if it is 90 degrees outside and you want to have your home cooled after a long day of work at a hot shop you can simply pull out your phone and turn your AC on during your lunch break which should give you ample time to cool your home to a comfortable level.

So a reason for the need of the example.
User avatar
By Mmiscool
#48623 There have been minimal changes to the way the msgbranch command works.

A function is now used to retrieve the desired msg argument. There has never been a limit on the number of arguments. Only how long the string can be in total with out crashing the esp.

See example below. For 3.0

Code: Select allmsgbranch [mybranch]
print "set the branch"
wait

[mybranch]
myColorVar = msgget("color")
print myColorVar
let myReturnMsg = "You Entered " & myColorVar
msgreturn myReturnMsg
wait
User avatar
By forlotto
#48630 I recall there was actually a limit to the amount of variables per line at one time I think you may a fixed this in version 1.x because this was an issue I discussed so my fault for forgetting but I believe it was 3 & symbols per line or something along that line but yes you are correct likely 2.x did not have that limitation I really don't know as my power strip is still sitting happy at 1.x.

I wish there were a way to dump everything on that particular nodemcu and clone it on to another to be honest as it is set in DIO mode and everything functions perfectly with very little overhead and is quick and responsive for DIO mode.

Anyhow back to the original reason for the post:

So lets take this code for example the start of my power strip code:
Code: Select all    msgbranch [mybranch]
    print "SEVER STATUS 200 OK"
debugoff
Wait
    [mybranch]
    MyReturnMsg = "Not a valid msg received"
    msgget "pin" pinNo
    msgget "stat" pinStatus
    msgget "action" pinAction
    if pinAction == "po" then gosub [po.pin]
    if pinAction == "s" then gosub [read.it]
    print "DOne with retrn code"
    msgreturn MyReturnMsg
    wait

    [po.pin]
po pinNo pinStatus
if pinNo == "D1" then D2S = pinStatus
if pinNo == "D2" then D2S = pinStatus
if pinNo == "D3" then D3S = pinStatus
if pinNo == "D4" then D4S = pinStatus
if pinNo == "D5" then D5S = pinStatus
if pinNo == "D6" then D6S = pinStatus
if pinNo == "D7" then D7S = pinStatus
if pinNo == "D8" then D8S = pinStatus

MyReturnMsg = ""
'io(po,pinNO,pinStatus)
if pinStatus = 1 then MyReturnMsg = MyReturnMsg & "Outlet was turned ON successfully" else MyReturnMsg = MyReturnMsg & "Outlet was turned OFF successfully"
return

[read.it]
MyReturnMsg = ""
if D1S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_1 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_1 is ON</p>"
if D2S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_2 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_2 is ON</p>"
if D3S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_3 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_3 is ON</p>"
if D4S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_4 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_4 is ON</p>"
if D5S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_5 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_5 is ON</p>"
if D6S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_6 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_6 is ON</p>"
if D7S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_7 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_7 is ON</p>"
if D8S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_8 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_8 is ON</p>"
   
return
 

- See more at: viewtopic.php?f=43&t=6851&p=35223#sthash.ZonFwwv9.dpuf

I noticed you changed this for example:

you added in debugoff ?

You also added the comment 'io(po,pinNO,pinStatus)

I assume you edited according to v3 syntax?

It really looks like there is no difference to code other than this.

I guess I am missing what was changed you claim the change is A function is now used to retrieve the desired msg argument.

So to make sure I am not missing anything would this edit be correct:

Code: Select all    msgbranch [mybranch]
    print "SEVER STATUS 200 OK"
debugoff '''??? Don't remember this is it to turn debug off in version 3.0?
Wait
    [mybranch]
    MyReturnMsg = "Not a valid msg received"
    msgget "pin" pinNo 'CHANGE TO - - -  pinNo = msgget("pin")
    msgget "stat" pinStatus 'CHANGE TO - - - pinStatus = msgget("stat")
    msgget "action" pinAction 'CHANGE TO - - - pinAction = msgget("action")
    if pinAction == "po" then gosub [po.pin] 'DO I NEED A COMMA HERE? between gosub
    if pinAction == "s" then gosub [read.it] 'DO I NEED A COMMA HERE? between gosub
    print "DOne with retrn code"
    msgreturn MyReturnMsg
    wait

    [po.pin]
po pinNo pinStatus 'CHANGE TO - - - io(po,pinNo,pinStatus)
if pinNo == "D1" then D2S = pinStatus
if pinNo == "D2" then D2S = pinStatus
if pinNo == "D3" then D3S = pinStatus
if pinNo == "D4" then D4S = pinStatus
if pinNo == "D5" then D5S = pinStatus
if pinNo == "D6" then D6S = pinStatus
if pinNo == "D7" then D7S = pinStatus
if pinNo == "D8" then D8S = pinStatus

MyReturnMsg = ""
'io(po,pinNO,pinStatus) ???? What is the purpose of the comment at this location?
if pinStatus = 1 then MyReturnMsg = MyReturnMsg & "Outlet was turned ON successfully" else MyReturnMsg = MyReturnMsg & "Outlet was turned OFF successfully"
return

[read.it]
MyReturnMsg = ""
if D1S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_1 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_1 is ON</p>"
if D2S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_2 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_2 is ON</p>"
if D3S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_3 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_3 is ON</p>"
if D4S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_4 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_4 is ON</p>"
if D5S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_5 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_5 is ON</p>"
if D6S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_6 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_6 is ON</p>"
if D7S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_7 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_7 is ON</p>"
if D8S = 1 then MyReturnMsg = MyReturnMsg & "<p>OUTLET_8 is OFF</p>" else MyReturnMsg = MyReturnMsg & "<p>OUTLET_8 is ON</p>"
   
return
 



From what I can see there is very little change... But in order to make the changes one must know what the needed changes are to make things operational and example is a great way to learn we learn from them every day.