How to communicate between two esp8266

Moderators: grovkillen, TD-er, Stuntteam

Post Reply
Message
Author
User avatar
Sasch600xt
Normal user
Posts: 117
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: 3500
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: 117
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: 117
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: 3500
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: 106
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: 185
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: 117
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: 117
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"

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests