-->
Page 1 of 2

udpbranch [udp.received] not working why ?

PostPosted: Tue Mar 14, 2017 3:16 am
by Miloit
I created this code that transmits to a Pc with server listening udp port 7001 , the status of the relays and is operating correctly. But when server request 'status' of relays the udpbranch [udp.received] not working properly. Enclose code and screen
Code: Select allmemclear
cls
localip = ip()
localudp = 7001
ipser = "192.168.1.55"
ipport = 7001
'
'************ CHECK IF AP MODE
if localip = "192.168.4.1" then
gosub [wifiinit]
else
'
'************ LOAD NODE DATA
gosub [loadnodedata]
endif
'
a = 1
b = 1
r1 = 16
r2 = 3
pwm = 2
ciclo = 1
dimmer = 1024
io(po,r1,1)
io(po,r2,1)
io(pwo,pwm,1024)
'
interrupt 14,[inta]
interrupt 12,[intb]
interrupt 13,[intc]
interrupt 5,[intd]
'
udpbranch [udp.received]
'
wprint "<H2>"
wprint "**** ESP  NODE ****"
wprint "</H2>"
wprint "Node Name "
textbox namenode
wprint " Tipo nodo "
dropdown typenode , "RL,HT,IO"
wprint "<br><br>"
wprint "IP Address "
textbox localip
wprint "  UDP Port "
textbox localudp
wprint "<br><br>"
wprint "Subnet Mask "
textbox subnet
wprint " Gateway "
textbox gate
wprint "<br><br>"
'
wprint "WiFi Name "
textbox namewifi
wprint " WiFi Password "
passwordbox passwifi
wprint "<br><br>"
button "Save", [salva]
'
wprint "<br><br>"
wprint "Out A (On/Off) "
button "On", [Aon]
button "Off", [Aoff]
wprint "<br><br>"
wprint "Out B (On/Off) "
button "On", [Bon]
button "Off", [Boff]
wprint "<br><br>"
wprint "Out A and B (Cilic) "
button "On", [ciclic]
wprint "<br><br>"
wprint "Dimmer C "
button "Step", [dimm]
wprint "<br><br>"
textbox a
textbox b
textbox dimmer
wait
'
[Aon]
io(po,r1,0)
a = 0
gosub [status]
wait
'
[Aoff]
io(po,r1,1)
a = 1
gosub [status]
wait
'
[Bon]
io(po,r2,0)
b = 0
gosub [status]
wait
'
[Boff]
io(po,r2,1)
b = 1
gosub [status]
wait
'
[ciclic]
if ciclo = 0 then
io(po,r1,1)
a = 1
io(po,r2,1)
b = 1
ciclo = 1
gosub [status]
wait
end if
'
if ciclo = 1 then
io(po,r1,0)
a = 0
io(po,r2,1)
b = 1
ciclo = 2
gosub [status]
wait
end if
'
if ciclo = 2 then
io(po,r1,1)
a = 1
io(po,r2,0)
b = 0
ciclo = 3
gosub [status]
wait
end if
'
if ciclo = 3 then
io(po,r1,0)
a = 0
io(po,r2,0)
b = 0
ciclo = 0
gosub [status]
wait
end if
wait
'
[dimm]
dimmer = dimmer - 256
if dimmer <0 then
dimmer = 1024
io(pwo,pwm,dimmer)
else
io(pwo,pwm,dimmer)
endif
gosub [status]
wait

'
[inta]
if io(laststat,14)= 1 then wait
if a=0 then
io(po,r1,1)
a = 1
else
io(po,r1,0)
a = 0
endif
gosub [status]
wait
'
[intb]
if io(laststat,12)= 1 then wait
if b=0 then
io(po,r2,1)
b = 1
else
io(po,r2,0)
b = 0
endif
gosub [status]
wait
'
[intc]
if io(laststat,13)= 1 then wait
if ciclo = 0 then
io(po,r1,1)
a = 1
io(po,r2,1)
b = 1
ciclo = 1
gosub [status]
wait
end if
'
if ciclo = 1 then
io(po,r1,0)
a = 0
io(po,r2,1)
b = 1
ciclo = 2
gosub [status]
wait
end if
'
if ciclo = 2 then
io(po,r1,1)
a = 1
io(po,r2,0)
b = 0
ciclo = 3
gosub [status]
wait
end if
'
if ciclo = 3 then
io(po,r1,0)
a = 0
io(po,r2,0)
b = 0
ciclo = 0
gosub [status]
wait
end if
wait
'
[intd]
if io(laststat,5)= 1 then wait
dimmer = dimmer - 256
if dimmer <0 then
dimmer = 1024
io(pwo,pwm,dimmer)
else
io(pwo,pwm,dimmer)
endif
gosub [status]
wait
'
[wifiinit]
cls
wprint "<H2>"
wprint "**** ESP  NODE ****"
wprint "</H2>"
wprint "Node Name "
textbox namenode
wprint " Tipo nodo "
dropdown typenode , "RL,HT,IO"
wprint "<br><br>"
wprint "IP Address "
textbox localip
wprint "  UDP Port "
textbox localudp
wprint "<br><br>"
wprint "Subnet Mask "
textbox subnet
wprint " Gateway "
textbox gate
wprint "<br><br>"
wprint "WiFi Name "
textbox namewifi
wprint " WiFi Password "
passwordbox passwifi
wprint "<br><br>"
button "Save", [salva]
wait
'
[salva]
write(WIFIname,namewifi)
write(WIFIpass,passwifi)
write(nodename,namenode)
write(nodetype,typenode)
write(ipaddress,localip)
write(udpport,localudp)
write(subnetmask,subnet)
write(gateway,gate)
goto [rebooting]
wait
'
[rebooting]
cls
wprint "REBOOTING..."
wait
'
[loadnodedata]
namewifi = read(WIFIname)
passwifi = read(WIFIpass)
namenode = read(nodename)
typenode = read(nodetype)
'localudp = read(udpport)
subnet = read(subnetmask)
gate = read(gateway)
udpbegin 7001
return
'
[udp.received]
let rec = udpread()
let rem = udpremote()
if rec = "status" then
print "Message received " & rec & " from " & rem
udpreply typenode & "-" & namenode & "-A=" & a & " B=" & b & " D=" & dimmer
end if
return
'
[status]
'print "A " & a & " B " & b & " D " & dimmer
print ipser
print ipport
udpwrite ipser,ipport, typenode & "-" & namenode & "-A=" & a & " B=" & b & " D=" & dimmer
return
'
[Exit]
end 




Re: udpbranch [udp.received] not working why ?

PostPosted: Tue Mar 14, 2017 3:19 am
by Miloit
Mask.jpg

Re: udpbranch [udp.received] not working why ?

PostPosted: Tue Mar 14, 2017 5:12 pm
by bugs
I am not sure from your post what is not happening.
I would add an extra debug part in the [udp.received] code so you can see if anything arrives there. At the moment you only see if exactly "status" arrives. Perhaps the server is sending e.g. "Status" instead?

Code: Select all[udp.received]
let rec = udpread()
let rem = udpremote()
if rec = "status" then
  print "Message received " & rec & " from " & rem
  udpreply typenode & "-" & namenode & "-A=" & a & " B=" & b & " D=" & dimmer
else
  print "Different message received " & rec & " from " & rem
end if
return

Re: udpbranch [udp.received] not working why ?

PostPosted: Tue Mar 14, 2017 11:47 pm
by Mmiscool
Need a double = sign for if tjens with strings

If bla == "test" then .....