Page 1 of 1

How to communicate between two esp8266

Posted: 26 Mar 2020, 13:38
by Sasch600xt
Hello World (represents my coding skills :)),

I use a bunch of ESPs with MQTT OpenHAB Controller to my IPSymcon Housautomating System.
All works great !

Now i have special needs:

I have one ESP with 2 Buttons connected to an MCP23017
and another ESP with 2 relais connected also to an MCP23017

i would love to push button1 on ESP1 and send it to ESP2 to toggle relais1 (one button push = relais on, next button push = relais off)
same for button2.

Both ESPs are in the same Wifi.

So do i need to set an second cotroller for this need or is there a simple solution ?

Thank you so much for your help an i hope you are all OK in these days
Sascha

Re: How to communicate between two esp8266

Posted: 26 Mar 2020, 15:31
by grovkillen
Since you already have the MQTT broker up and running, why not use it? You can send commands over MQTT. I'd use event calls to the recipient side (relay unit).

Re: How to communicate between two esp8266

Posted: 26 Mar 2020, 18:00
by Sasch600xt
Thank you for your help :)

so far i did try a lot but could not get it to work.
i was reading the "rules tutorial" aswell.


Ist it all possible only by using rules ? (MQTT Controller is set)

I did try this:

ESP1 with buttons:

Code: Select all

on System#Boot do
monitor,mcp,1
endon


on mcp#1=1 do
Publish,"LichtgrHalleVorne","1"
endon
ESP2 with relay:

Code: Select all

on LichtgrHalleVorne=1 do
mcpgpio,1,0
endon
So probably i do a lot wrong here ?

Thanks for help!
Sascha

Re: How to communicate between two esp8266

Posted: 27 Mar 2020, 08:41
by Sasch600xt
ok, i got it to work :)

i used an MQTT generic input in "devices"

and the rule looks like:

Code: Select all

on MQTT_INPUT#LichtgrHalleVorne=1 do
if [plugin#mcpgpio#pinstate#1]=1
mcpgpio,1,0
else
mcpgpio,1,1
endon
so this provides the toggle feature i was looking for.

YAY :)

Re: How to communicate between two esp8266

Posted: 27 Mar 2020, 08:56
by grovkillen
Yes that is probably the most generic way. It's also possible to post to the cmd topic of that particular unit. But using MQTT import you can have any number of units listen to any topic.

Re: How to communicate between two esp8266

Posted: 27 Mar 2020, 11:12
by iron
Unless you do not want to involve MQTT and enable the ESPEasy P2P Networking. You will have 2 units 1 and 2

Unit 2 :

Code: Select all

on System#Boot do
monitor,mcp,1
endon

on mcp#1=1 do
sendTo,1,LichtgrHalleVorne,1
endon

Unit 1:

Code: Select all

on LichtgrHalleVorne=1 do
mcpgpio,1,0
endon
here:
https://www.letscontrolit.com/wiki/inde ... nd_Publish

-D

Re: How to communicate between two esp8266

Posted: 28 Mar 2020, 00:40
by Wiki
I do have tp correct a little bit. Beside the fact that the syntax is wrong for current mega release (I don't know which release iron runs), I don't know exactly since when, but in the current version of ESPEasy Mega you may not use SendTo not like this:
iron wrote: 27 Mar 2020, 11:12

Code: Select all

sendTo,1,LichtgrHalleVorne,1
But instead you have to use

Code: Select all

  SendTo 1,'event,LichtgrHalleVorne=1'
to get the desired result

refer to: https://github.com/letscontrolit/ESPEasy/issues/2724

Re: How to communicate between two esp8266

Posted: 28 Mar 2020, 18:14
by Sasch600xt
ok, thanks a lot for all the answeres :)

no i try something simular which is not working at the moment.
i use an PCA9685 to have some PWM outputs.
i changed the range in plugins from 0 - 4096 to 0 -100 which is enough for my needs.
now i have an MQTT_INPUT plugin where the topic is "Dimmer" and the value i called "Dimmer1"
i am not sure about the sytax now ?

this is not working:

Code: Select all

on MQTT_INPUT#Dimmer1 do
PCAPWM,0,[plugin#MQTT_INPUT#Dimmer#Dimmer1]
at least

Code: Select all

on MQTT_INPUT#Dimmer1 do
seems to be ok as trigger but my PWM signal goes down to "0" always.

so somehow i can not send the value "Dimmer1" which is from 0 - 100

Thank you for your help :)

Re: How to communicate between two esp8266

Posted: 28 Mar 2020, 18:43
by Sasch600xt
got it !


this was the right syntax:

Code: Select all

on MQTT_INPUT#Dimmer1 do
PCAPWM,0,[MQTT_INPUT#Dimmer1]

Re: How to communicate between two esp8266

Posted: 07 Jun 2020, 12:21
by besterquester
Hi,
There is another possibility to communicate between two esp devices.

You can use the rule command
sendto

Example: you have 2 espdevices dev1 (unit:1) and dev2 (unit:2). They can also have the same name , but the Unit Number must be different -> unit=1 and unit=2. The UDP communication is done through the unit numbers
Add a controller ESPEasy P2P Networking on both devices

in rules on dev1:

Code: Select all

on Button#State do
        sendto 2, "event,Button1=1"
endon
senfto command to the unit number

in rules on dev2:

Code: Select all

on Button1 do
      // do something on dev2 when button1 was pressed on dev1
     //  use this to retrieve the event value from the dev1 -> %eventvalue%
endon
Hope that helped

regards Chris

Re: How to communicate between two esp8266

Posted: 07 Jun 2020, 12:50
by TD-er
besterquester wrote: 07 Jun 2020, 12:21 [...]
in rules on dev1:

Code: Select all

on Button#State do
        sendto 1, "event,Button1=1"
endon
[...]
I guess you meant

Code: Select all

sendto 2,....
???

Re: How to communicate between two esp8266

Posted: 07 Jun 2020, 13:54
by besterquester
yes of course.
thx!!

Re: How to communicate between two esp8266

Posted: 17 Jun 2020, 10:53
by AlWire
Hello,

I'd like to change the IP of an existing device with node 14. It is listet at the device with node 16.
Normally the code "SendTo 14, IP XXX.XXX.X.XXX" should work? Although i get an "Ok" as response, the IP has not been changed.

Has anybody an idea or could give some advice?

Thanks in Advance.

Re: How to communicate between two esp8266

Posted: 17 Jun 2020, 12:30
by TD-er
Maybe you should use quotes and also call for "save" + reboot that node.

Code: Select all

SendTo 14,"IP XXX.XXX.X.XXX"

Re: How to communicate between two esp8266

Posted: 21 Jun 2020, 16:59
by AlWire
Thanks for your help.