How to communicate between two esp8266

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

How to communicate between two esp8266

#1 Post by Sasch600xt » 26 Mar 2020, 13:38

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
"the flat earth society has members all around the globe"

User avatar
grovkillen
Core team member
Posts: 3603
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: How to communicate between two esp8266

#2 Post by grovkillen » 26 Mar 2020, 15:31

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).
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: How to communicate between two esp8266

#3 Post by Sasch600xt » 26 Mar 2020, 18:00

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
"the flat earth society has members all around the globe"

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: How to communicate between two esp8266

#4 Post by Sasch600xt » 27 Mar 2020, 08:41

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 :)
"the flat earth society has members all around the globe"

User avatar
grovkillen
Core team member
Posts: 3603
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: How to communicate between two esp8266

#5 Post by grovkillen » 27 Mar 2020, 08:56

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.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
iron
Normal user
Posts: 108
Joined: 24 Sep 2016, 08:37
Location: Veria, Greece
Contact:

Re: How to communicate between two esp8266

#6 Post by iron » 27 Mar 2020, 11:12

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
-D

Wiki
Normal user
Posts: 272
Joined: 23 Apr 2018, 17:55

Re: How to communicate between two esp8266

#7 Post by Wiki » 28 Mar 2020, 00:40

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

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: How to communicate between two esp8266

#8 Post by Sasch600xt » 28 Mar 2020, 18:14

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 :)
"the flat earth society has members all around the globe"

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: How to communicate between two esp8266

#9 Post by Sasch600xt » 28 Mar 2020, 18:43

got it !


this was the right syntax:

Code: Select all

on MQTT_INPUT#Dimmer1 do
PCAPWM,0,[MQTT_INPUT#Dimmer1]
"the flat earth society has members all around the globe"

besterquester
Normal user
Posts: 6
Joined: 07 Jun 2020, 11:38

Re: How to communicate between two esp8266

#10 Post by besterquester » 07 Jun 2020, 12:21

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
Last edited by besterquester on 07 Jun 2020, 13:53, edited 1 time in total.

TD-er
Core team member
Posts: 2768
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: How to communicate between two esp8266

#11 Post by TD-er » 07 Jun 2020, 12:50

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,....
???

besterquester
Normal user
Posts: 6
Joined: 07 Jun 2020, 11:38

Re: How to communicate between two esp8266

#12 Post by besterquester » 07 Jun 2020, 13:54

yes of course.
thx!!

AlWire
Normal user
Posts: 2
Joined: 17 Jun 2020, 10:41

Re: How to communicate between two esp8266

#13 Post by AlWire » 17 Jun 2020, 10:53

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.

TD-er
Core team member
Posts: 2768
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: How to communicate between two esp8266

#14 Post by TD-er » 17 Jun 2020, 12:30

Maybe you should use quotes and also call for "save" + reboot that node.

Code: Select all

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

AlWire
Normal user
Posts: 2
Joined: 17 Jun 2020, 10:41

Re: How to communicate between two esp8266

#15 Post by AlWire » 21 Jun 2020, 16:59

Thanks for your help.

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests