is it possible to change a GPIO on an other ESP-device ?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Stef2s
Normal user
Posts: 10
Joined: 25 Mar 2024, 20:01

is it possible to change a GPIO on an other ESP-device ?

#1 Post by Stef2s » 01 Apr 2024, 11:57

hello,
I want to change an IO-pin on an other ESP device. The devices are coupled by P2P.
I feel it should be possible, but I can't find the answer.
In more general, how to "address" another ESP in the network ?
cheers, Stef

User avatar
Ath
Normal user
Posts: 3531
Joined: 10 Jun 2018, 12:06
Location: NL

Re: is it possible to change a GPIO on an other ESP-device ?

#2 Post by Ath » 01 Apr 2024, 12:30

There are at least 2 ways of doing that, either via the P2P network, or by http command, and when using an MQTT server, you can even use MQTT for that (somewhat depending on the MQTT server and ESPEasy-Controller used)

1) Via P2P there is the SendTo command, where you can send a command to another P2P unit (you're already having unique Unit number, right?). I'll explain about how to use a command, below.

2) Via http you can use the "http://<ip-address-of-the-remote-esp>/control?cmd=<command-with-arguments>" format.

About the command:
To avoid needing knowledge of what exact GPIO (or TaskName/TaskIndex to enable/disable/run something) on the remote device, you should better not use direct commands, but use Rules as an intermediate, so instead of sending "GPIO,12,1", you could send "event,switch=1" to turn on the Relay on a Sonoff switch.
In rules you would add:

Code: Select all

On Switch Do
  If %eventvalue1|-1%>-1 // Don't respond if no argument given...
    If %eventvalue1%=1
      GPIO,12,1 // Relay On
      LongPulse_MS,13,0,500,500,3 // Slow-Flash the green led on the Sonoff 3x to indicate (remote) action
    Else
      GPIO,12,0 // Relay Off
    Endif
  Endif
Endon
This way you could use the same commands for all kind of ESPEasy devices, and not have to change GPIO pins on several other devices, if the hardware might be replaced, or is rather differently wired.
Another advantage is that you can do some argument checking, like I did in the example, and you can execute multiple commands with a single trigger (also in the example).

To get some inspiration on Rules, there is quite some documentation on that, including examples: https://espeasy.readthedocs.io/en/lates ... Rules.html
/Ton (PayPal.me)

Stef2s
Normal user
Posts: 10
Joined: 25 Mar 2024, 20:01

Re: is it possible to change a GPIO on an other ESP-device ?

#3 Post by Stef2s » 01 Apr 2024, 13:00

Ath thanks for the extended answer, Sndto worsk like a charm.

Post Reply

Who is online

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