-->
Page 1 of 4

ESP to ESP communication

PostPosted: Wed Dec 23, 2015 7:28 pm
by Mmiscool
For this example I used to node mcu boards.

The button that is connected to the gpio 0 is used to control the on board led on the other unit.

There is a bit of a delay between holding down the button and the light turning on or off.


The controller code
You must change the ip address of the receiving unit for your environment.
Code: Select alltimer 5000 [check]
wait

[check]
serialprintln io(pi,0)
if io(pi,0) = 1 then io(po,d4,0)
if io(pi,0) = 0 then io(po,d4,1) 
if io(pi,0) = 1 then wget("172.16.0.112/msg?stat=0")
if io(pi,0) = 0 then wget("172.16.0.112/msg?stat=1")
wait


Receiver unit code:
Code: Select allmemclear
msgbranch [doit]
wait

[doit]
msgget stat s
io(po,d4,s)
msgreturn s
wait

Re: ESP to ESP communication

PostPosted: Wed Dec 23, 2015 9:18 pm
by forlotto
excellent could do some interesting stuff with this ;)

Re: ESP to ESP communication

PostPosted: Thu Dec 24, 2015 10:13 am
by heckler
That's awesome Mike,
Thanks for sharing the example
These examples REALLY help ALOT as it shows how to use various parts of the ESPBASIC and how to apply the syntax correctly.

could this also be done??

Code: Select all[check]
serialprintln io(pi,0)
if io(pi,0) = 1 then
io(po,d4,0)
wget("172.16.0.112/msg?stat=0")
else
io(po,d4,1) 
wget("172.16.0.112/msg?stat=1")
wait


Probably not as there does not seem to be any sort of "endif" parameter??

Question: How many things can be executed based on an "IF" test?
Only one???

or can we somehow do more than one thing before hitting the "else" part of the test?

thanks for all your work and code examples.

Merry Christmas!
dwight

Re: ESP to ESP communication

PostPosted: Thu Dec 24, 2015 11:08 am
by Mmiscool
There was actually a bug in the if then command that prevented else from working if the then statement consisted of a single command. I just upload a build that fixes it. I will update the demo to reflect this fix.

Merry Christmas all.