-->
Page 1 of 1

Please HELP

PostPosted: Sun Jan 22, 2017 12:04 pm
by ssylca
Hi,

I am having some trouble with this project:
http://www.esp8266.com/viewtopic.php?f=40&t=7267&p=37026#p37026
I like to detect a switch closure from one ESP and turn ON a LED on another ESP located elsewhere in the house, the above project is perfect for this, but doesn't seem to work.
Thanks,
S.

Re: Please HELP

PostPosted: Sun Jan 22, 2017 12:42 pm
by danbicks
Hi,

The best approach would be the following. The ESP that indicates an led for switch press run as a TCP server listening on a given port, the sender simply connects to the remote ESP on the port the server is listening too and responds to the client request information.

If you have a dig through this site there is lots of information that will put you on the correct path.

Good luck

Dans

Re: Please HELP

PostPosted: Sun Jan 22, 2017 2:59 pm
by Electroguard
Esp_Basic only supports UDP, so here's a pair of simple UDP send and receive scripts to point you in the right direction - but please keep in mind I've just quickly thrown this together for you without opportunity to test what I've written, so you'll probably need to do some debugging....

Code: Select all'Sender node
udpport = 5001     
localIP = ip()     
pos = instrrev(localIP,".")
netIP = left(localIP,pos)
switch1pin = 0  'Uses gpio00 by default (needs pullup resistor).
interrupt switch1pin, [CHANGED]
wait
[CHANGED]
if io(laststat,switch1pin) = 0 then udpwrite netIP & "255", udpport, "SWITCH1 OFF" else udpwrite netIP & "255", udpport, "SWITCH1 ON"
return


Code: Select all'Receiver node
udpport = 5001     
udpbegin udpport
udpbranch [UDPMSG]
ledpin = 1 'uses gpio01 blue led by default (will mess up serial)
wait
[UDPMSG]
payload = udpread()
if instr(payload,"SWITCH1 ON") > 0 then io(po,ledpin,1)
if instr(payload,"SWITCH1 OFF") > 0 then io(po,ledpin,0)
return