Answer the question
In order to leave comments, you need to log in
How to establish a connection between a server on the Internet and a server on the router's WiFi local network?
Hello.
I am making an IoT system and I have a couple of questions about IP and routing.
What's available
* NodeMCU microcontroller with ESP8266 WiFi module (C, C++) as WebServer
* Mobile 2G internet flash included in WiFi router
* NodeJS server on domain
* Forntend on domain
Sequence of actions
* NodeMCU connects to WiFi router and rises on its address, for example 192.168.0.100:80
* NodeJS server should knock POST requests to NodeMCU.
* NodeMCU accepts requests from the NodeJS server and can also POST to the NodeJS server.
* Frontend knocks on NodeJS server, server checks, processes and knocks on NodeMCU.
What is the problem
Everything seems to be simple, but the problem is in the IP. What address will the NodeJS server knock on if the NodeMCU is up on the local network?
When frontend, NodeJS and NodeMCU are on the same local network of the router, everything works, but how to transfer it to the Internet?
Answer the question
In order to leave comments, you need to log in
The issue was resolved using the MQTT protocol. The principle of operation is very similar to WebSocket.
The NodeMCU connects to the NodeJS server (mqtt broker hosted by mosca) and exchanges packets. In this case, the NodeJS server does not need to know the IP of the NodeMCU.
you need a white ip, or contact via dns (no-ip services). Assign white ip either immediately to a piece of iron, or NAT from white ip to gray ip piece of iron in the local network.
My option is to run a server on the web with an external IP. And knock only through it.
Option two - I chose it for my tasks - all clients first break into their own VPN on the Internet, and already communicate within the VPN network. In this case, the client can have any Internet, everything will be a bundle.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question