Post about your Basic project here

Moderator: Mmiscool

User avatar
By Edi
#59252 Thank you, Mmiscool!

I was looking for the keyword "Interrupt" in the doku, never thought to look for "Branch" ...
But I suppose, you meant UdpBranch, not SerialBranch, right? ;)

Btw.: The new Terminal is really helpfull! Thank you so much, for your increddible work!
User avatar
By Mmiscool
#59257 I will say that there might be a problem with the let commnd.

You will probably be better off just not using the let command at all.

X = 5

Not

Let x =5
User avatar
By Miloit
#62711
joeygbsn wrote:Here is some simple udp code to toggle a relay. Both of the esps set up udp servers. The master sends the slave a 0 or a 1 to toggle the pin state, and the slave sends the status of the pin back to the master.
You can toggle the pin by connecting to the master website and clicking the button. You would have to add some handshaking or something if you want to add more slaves. This works very reliably though for me so far with very little lag on v3 a39.

master code:
Code: Select allmemclear
wifiapsta
udpbegin 8081
let data = 0
let stat = "OFF"
wprint "Status = "
wprint htmlvar(stat)
wprint "<br>"
button "Toggle Relay", [doit]

timer 500, [read]

[doit]
if data = 1 then let data = 0 else let data = 1
udpwrite "192.168.0.109", 8082, str(data)
wait


[read]
let stat = udpread()
wait


slave code:
Code: Select allmemclear
udpbegin 8082
let stat = "OFF"

timer 500,[doit]
wait

[doit]
let rec = val(udpread())
io(po,2,rec)
if rec = 1 then let stat = "ON" else let stat = "OFF"
udpwrite "192.168.0.102", 8081, stat
wait


I can't operate the button via Internet. I have set up port forwarding on the router and I access remotely the page, but nothing happens when I click. In local network all works. why ?
User avatar
By Mmiscool
#62768 you have to port forward 2 ports.
The http port and the web sockets port.