General area when it fits no where else

Moderator: Mmiscool

User avatar
By Electroguard
#48165 All I can offer are my own observations and what steps I would take if in your place.
I've spent days trying to get MsgBranch working how I needed it to on Alpha 24, but in the end I have had to give up.
I could see in [VARS] that msgs were being sent and received ok, but [mybranch] was never actually being invoked properly by the msgs, because I could put anything I wanted in there which was never actioned, ie: 'end' never ended the program.
No point logging it as a bug because version 2 is history anyway, so it's a matter of being patient for the guys to release version 3 then see if that works properly.

In the meantime you might want to reformat and reflash your ESP, because I have had several occassions where an error has caused partial flash ram corruption such that things appeared to be working correctly except that branches and variables were being tangled up with each other and going to the wrong destination or returning the wrong value.
In your case - and I am only guessing and surmising - I'm wondering if your 'a' variable might be the equivalent of an 8 bit 'C' signed integer in which case it's possible that your 1 per sec 'a' count might have rolled over past it's max value after a few hours which could have caused corruption. Preventing subsequent rollovers would not undo any existing corruption, nor would a reflash, so you would need to do a reformat to clear it.

Your script is not sending any info back to the browser, so there is no effective way of knowing what is happening under the skin.

That situation is quite easy to correct, and could offer you an alternative means of remote control to the msgbranch, if you used udp network commands to send control info and receive feedback from the esp using cicciocb's udp_debugger utility.

I am in the process of doing a tutorial which covers exactly this sort of scenario, but in the meantime add these initialisation lines to the beginning of your script...
let udpport = "5001"
udpbegin udpport
udpbranch [UDPMAIN]

then add a...

[UDPMAIN]
let msg = udpread()
if msg is this that or the other then go do whatever you need to do
wait

... subroutine which effectively does the same as your existing msgbranch subroutine.
You then just need to send your appropriate instructions/variables from the udp debugger utility instead of the msg? browser strings.

You can add...
udpwrite "192.168.4.255", udpport, "Return msg info=" & returnmsg
... anywhere in your script to send back whatever info you wish to the udp debugger utility.

Obviously if you are not in AP mode you will need to replace the first 3 bytes with whatever your subnet address is, but the last byte should always be 255 (broadcast address) instead of the actual nodes address.
User avatar
By Mmiscool
#48168 I would be interested in your problem with the msg branch stuff.

Note that to receive a msg and execute the msgbranch branch you must use the proper url on the device.

example:
http://192.168.1.101/msg?color=blue

The response should be in plain text. No extra html.

Have you tried the msgbranch example on the site.
http://www.esp8266basic.com/msg-url-usage.html
User avatar
By Electroguard
#48179 Hi Mike, I'm not sure if I can adequately explain what I was trying to do, but I'll try.

If you click the Config button, then select Toggle from the centre dropbox, then click Home button, you will see the big home page Toggle button that I want, but also the similarly affected Help and Config buttons which is not what I want.

The intention was to select the required mode of operation from within Config and save it as the default 'Home' page mode, so the unit would then always start up in that big button default mode, but it would still need to have smaller buttons available for Config and Help options.
Unfortunately I don't know how to make ESP_Basic button CSS styles only applicable to just the main Toggle button, therefore all other ESP_Basic buttons are similarly affected, which is not what I am after.
I tried to get around this by only using the ESP_Basic button for the main big Toggle button, and using [Config] and [Help] text links instead of buttons, but that means making those links msgbranch to the appropriate ESP_Basic subroutines, which was where I was having the msgbranch problem.
The [HELP] and [CONFIG] branches are obviously working ok as can be proved by clicking their ESP_Basic 'buttons'. But if you try to access them via the [Help] and [Config] text links using msgbranching, it returns an error saying 'No MSG Branch Defined', and apparently doesn't make it to the defined msgbranch [mybranch] which contains an 'end' instruction for test and debug purposes which never gets actioned. But if you then check [VARS] it shows that the links are actually returning the correct msg?'s, it's just that the msg's never cause a msgbranch to [mybranch].

I should mention that I did discover how to have different style html buttons (as opposed to ESP_Basic buttons) which would have let me get the appropriate button sizes and styles that I am wanting, but unfortunately I don't know how to make a html 'Config' button branch onclick to an appropriate ESP_Basic [CONFIG] subroutine, so that doesn't help me either.

I should also add that this was planned to be part of the continued Driving Lessons tutorial which I am working on.

Code: Select all'SonOff example
memclear
let ledpin = 13
let ledlogic = 1  ' Default led pin off state
let relaypin = 12
let relaylogic = 0  ' Default relay pin off state
io(po,ledpin,ledlogic)
io(po,relaypin,relaylogic)
let localbutton = 0  ' Uses onboard GOIO00 flashing button by default, change to suit.
interrupt localbutton [PRESSED]  ' Interrupt pin requires a pull-up resistor to work.
let mode = "default"
gosub [READVARS]
if name == "" then let name = "Electroguard"
if description == "" then let description = "Switched Mains Relay - version 1"
let esp_basic = " - Developed on Alpha 24"
let udpport = "5001"
udpbegin udpport
udpbranch [UDPMAIN]
msgbranch [mybranch]
[HOME]
cls
print " "
button "Help" [HELP]
wprint " "
button "Config" [CONFIG]
wprint  " "
wprint |<a href="http://192.168.4.1/msg?action=help">[ HELP ]</a>|
wprint  " "
wprint |<a href="http://192.168.4.1/msg?action=config">[ CONFIG ]</a>|
wprint  " "
wprint |<a href="../msg?action=config">[ CONFIG2 ]</a>|
wprint  " "
wprint |<a href="../edit">[ EDIT ]</a>|
wprint  " "
wprint " "
wprint name & " " & description & esp_basic
print " "
if mode == "Toggle" then goto [USERTOGGLE]
if mode == "OnOff" then goto [USERONOFF]
if mode == "Heater" then goto [USERHEATER]
if mode == "Cooler" then goto [USERCOOLER]
if mode == "Humidity" then goto [USERHUMIDITY]
if mode == "TimedOn" then goto [USERTIMEDON]
if mode == "TimedOff" then goto [USERTIMEDOFF]
wprint "<BR><BR><BR>"
if io(laststat,relaypin) == relaylogic then wprint "Relay is OFF" else wprint "Relay is ON"
wprint "<BR><BR><BR>"
button "On" [RELAYON]
button "toggle" [TOGGLE]
button "Off" [RELAYOFF]
wprint "<BR><BR><BR>"
wait

[mybranch]
let MyReturnMsg = "Not a valid msg received"
end ' this is never reached
msgget "action" cmd
udpwrite "192.168.4.255", udpport, "Command=" & cmd
print comd
let myReturnMsg = "Action=" & cmd
if cmd == "help" then gosub [HELP]
if cmd == "config" then gosub [CONFIG]
msgreturn MyReturnMsg
wait

'[USERTOGGLE]
wprint "<BR><BR><BR><BR><BR><BR>"
if io(laststat,relaypin) = 0 then button "ON" [TOGGLE] else button "OFF" [TOGGLE]
wait

[USERTOGGLE]
wprint "<BR><BR><BR><BR><BR><BR>"
wprint |<!DOCTYPE html>|
wprint |<html>|
wprint |<head>|
wprint |<style>|
wprint | .bigbutton, input[type="button"], input[type="submit"] { |
wprint |  display: inline-block;|
wprint |  padding: 15px 25px;|
wprint |  font-size: 24px;|
wprint |  cursor: pointer;|
wprint |  text-align: center;|
wprint |  color: #fff;|
if io(laststat,relaypin)=0 then
 wprint |background-color: #4CAF50; /* Green */|
else
 wprint |background-color: #f44336; /* Red */|
endif
wprint |  border: 2px solid black;|
wprint |  border-radius: 15px;|
'wprint |  box-shadow: 0 9px #999;|
wprint |}|
wprint | .box, input[type="button"], input[type="submit"] { |
wprint |}|
wprint |</style>|
wprint |</head>|
wprint |<body>|
wprint |<div style="font-size: 32px; text-align: center;">|
if io(laststat,relaypin) = 0 then button "ON" [TOGGLE] else button "OFF" [TOGGLE]
wprint |</div>|
wprint |</body>|
wprint |</html>|
wait

[HELP]
cls
print " "
button "X" [HOME]
wprint "   "
wprint name & " " & description & esp_basic
print " "
wprint "<BR>"
wprint "<BR><BR>"
wprint "Offers On, Off and Toggle switching of relay"
wprint "<BR><BR>"
wprint "Also offers local hardware button toggle of relay."
wprint "<BR><BR>"
wprint "Configuration options allow changing of title Name and Description."
wprint "<BR><BR>"
wprint "Home button changes are temporary, Save button changes are permanent to non-volatile flash memory."
wprint "<BR><BR>"
wprint "This script is configured for a Sonoff module, but should be adaptable for any alternative "
wprint "switched relay modules."
wprint "<BR><BR>"
wprint "Sonoff pins - button=0, led=12, relay=13. "
wprint "<BR>"
wprint "Sonoff relay is active high, so relaylogic=0 (OFF default=0)."
wprint "<BR>"
wprint "Ledlogic=1 (active low),"
wprint "<BR>"
wprint "<BR><BR>"
wprint |<div style="text-align: center;color: #fff; font-size: 32px;">|
button "Home" [HOME]
wprint |</div>|
wait

[CONFIG]
cls
print " "
button "X" [HOME]
wprint " "
wprint name & " " & description & esp_basic
print " "
wprint "<BR><BR>"
html "Name:  "
textbox name
wprint " "
html "Description:  "
textbox description
html "<BR><BR>"
wprint "Select default 'Home' page"
dropdown "default, On/Off,Toggle,Timed On Cycle,Timed Off Cycle,Heater Thermostat,Cooler Thermostat, Humidity Stat" mode
wprint "<BR><BR><BR>"
button "Home" [HOME] ' don't save edits
wprint " "
button "Save" [SAVE] ' save details to persistent memory
wprint " "
wprint "HOME loses changes at power-off, SAVE holds changes in non-volatile flash memory. "
wprint "<BR><BR>"
wait

[READVARS]
read Name name  ' "Name" = flash memory var name, "name" = ESP_Basic var name
read Description description
return

[SAVE]
write Name name
write Description description
goto [HOME]

[PRESSED]
if io(laststat,localbutton) = 0 then goto [TOGGLE] ' (toggles only on button press instead of on button release)
goto [HOME]

[TOGGLE]
if io(laststat,relaypin) = 0 then io(po,relaypin,1) else io(po,relaypin,0)
if io(laststat,ledpin) = 0 then io(po,ledpin,1) else io(po,ledpin,0)
goto [HOME]

[RELAYON]
if relaylogic == 0 then io(po,relaypin,1) else io(po,relaypin,0)
if ledlogic == 0 then io(po,ledpin,1) else io(po,ledpin,0)
goto [HOME]

[RELAYOFF]
if relaylogic == 0 then io(po,relaypin,0) else io(po,relaypin,1)
if ledlogic == 0 then io(po,ledpin,0) else io(po,ledpin,1)
goto [HOME]
User avatar
By Mmiscool
#48180 if you use the wprint command you can embed css code in your page.

The HTMLID() function will give you the html id tag for the last gui item you created. You can then use this id to aply css to a specific item.

No need to get to crazy with things. Just the out of the box commands.