Post about your Basic project here

Moderator: Mmiscool

User avatar
By joeygbsn
#53188 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
udpbegin 8081
let data = 0
let stat = "OFF"
wprint "Status = "
wprint htmlvar(stat)
wprint "<br>"
button "Toggle Relay", [doit]

timer 500, [read]

if data = 1 then let data = 0 else let data = 1
udpwrite "", 8082, str(data)

let stat = udpread()

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

timer 500,[doit]

let rec = val(udpread())
if rec = 1 then let stat = "ON" else let stat = "OFF"
udpwrite "", 8081, stat
User avatar
By joeman2116
#53196 joeygbsn,

Ran the code.
When I toggle the relay the slave status on the master never changes.
In the debug mode it displays the vars for stat is changing on and off as I press the toggle button.
So code is working with the exception of actually displaying the correct slave status on the master module.