Hi all. I need some assistance or at least someone to give me a link to point me in the right direction or something like that. I need two ESP8266's to be able to communicate with each other over the internet while being on different networks. Nothing super complicated, just a single on or off command. All the tutorials I have found on the internet have been with one being a server and one being a client on their own network. Both networks have static IP's and I can port forward if necessary.
It is no problem that the ESP8266'are in different networks. Important is that there is network connectivity between them over, say, port 80. You will have to define port forwarding to allow incoming traffic from the internet on your chosen port to arrive at the ESP8266 devices.
Both ESP8266's run in STA (wireless client) mode. You run a Web server on both. If A wants to talk to B, A uses an HTTP GET to talk to the web server on B to either deposit or retrieve data.
There are other ways of doing this. The cleanest is if you have access to a web server on the internet (say a hosted service). ESP8266 A can deposit a command or data via the Web server to the Web server's back end database. ESP8266 B can periodically check if there is data there through a predefined web page and act on it. This does not need any port forwarding.
I don't mind port forwarding and I like the idea of that option more. How would I run a web server on them and use HTTP GET? I've used these for doing things with Amazon Alexa and that's about it so I don't know a lot about this stuff.
Heaps of example sketches and other explanation on how to set up an ESP8266 web server here.
You have to set up port forwarding on both sides, and you have to ensure that you have a fixed IP address on both sides. If you have a dynamic IP address you can work around that problem by either having an external server (as mentioned in #1) or by setting up a dynDNS account, or something similar.