Re: New UDP commands example
Posted: Wed Apr 06, 2016 1:56 pm
Thanks cicciocb.
And I'm gobsmacked it was done in the 22 mins between your two posts.
And I'm gobsmacked it was done in the 22 mins between your two posts.
-->
Open Community Forum for ESP8266, Come share Arduino and IoT (Internet of Things)
https://www.esp8266.com/
'let local_name = "default" ' Default node name must be changed to something unique (currently not case sensitive)
let local_name = "MP3lounge" ' Unique node name
let system = "All" ' Allows different system groups of nodes to be addressed separately if required
udpbegin 5001
udpbranch [udpmsg]
wait
end
[udpmsg]
msg = udpread()
print "UDP msg received: " & msg ' For test purposes only
if left(upper(msg), len(name)) == upper(name) then goto [local_commands] ' handle specifically local "name" commands
if instr(upper(msg), upper(name)) > 0 then goto [group_commands] ' handle partial-name group commands
if left(upper(msg), 3) == upper(system) then goto [global_commands] ' handle this global "system"s node commands
print "msg not recognised by " & name ' For test purposes only
udpreply name & " ERROR: unrecognised msg: " & msg
return
[global_commands]
' (Sent prefixed by system, eg: "All ")
if instr(upper(msg), upper("?")) then goto [declare]
if instr(upper(msg), upper("Report")) then goto [report] 'change [branch] to report back something else
if instr(upper(msg), upper("Blink")) then goto [blink] 'for physically spotting the "system" nodes
if instr(upper(msg), upper("FlashIP")) then goto [flashIP] 'for physically identifying node IP addresses
if instr(upper(msg), upper("Reset")) then goto [reset] 'to reboot the complete "system"
udpreply name & " ERROR: no recognised global command in msg: " & msg
returm
[group_commands]
' (Sent to partial names, eg: "PIR ?" would be recognised by PIR1 and PIR2 and PIR3 etc)
print "Checking Group commands" 'For test purposes only
if instr(upper(msg), upper("GroupTest")) then print "Group test"
' if only interested in specific Group commands (partial local name) then uncomment return
' else drop through to also action local_commands
'return
[local_commands]
' (Sent to a specific unique node name)
print "Checking Local commands" 'For test purposes only
' Unique commands for this local node
' Subsequent print statements are test only, they should actually branch to appropriate subroutines, eg: goto [play]
if instr(msg,"PLAY") <> 0 then print "Play"
if instr(msg,"PAUSE") <> 0 then print "Pause"
if instr(msg,"NEXT") <> 0 then print "Next"
if instr(msg,"PREVIOUS") <> 0 then print "Previous"
if instr(msg,"VUP") <> 0 then print "Volume Up"
if instr(msg,"VDOWN") <> 0 then print "Volume Down"
' Common commands for all system nodes
if instr(upper(msg), upper("Report")) then goto [report]
if instr(upper(msg), upper("Blink")) then goto [blink]
if instr(upper(msg)A, upper("FlashIP")) then goto [flashIP]
if instr(upper(msg), upper("Reset")) then goto [reset]
udpreply name & " ERROR: no recognised local command in msg: " & msg
return
[declare]
udpreply name
return
[report]
udpreply name ' change name to whatever info needs to be sent back
return
[blink]
print "cause GPIO01 led to blink"
return
[flashIP]
print "cause GPIO01 led to flash the significant last IP address byte"
return
[reset]
print "cause node to reset"
return
[button]
' Broadcast system nodes to declare themselves (Who's there)
print "GPIO00 button pressed"
return