I did some research and know that with an other platform, if I want to connect to 8266 from a device from different wifi, I need to do port forwarding. So I wonder how Blynk can help me with that when no port forwarding needed.
Can you explain what are you trying to achieve exactly ?
As I know, 8266 only supports connecting with devices in the same wifi. If we want it to connect to a different wifi, we need to do port forwarding. But with Blynk, we dont need to forward ports. I dont know why.
If you want to send data packets from one device directly to another device on a different network then you you need to know the pubic IP address of the device where you are sending the data, and specify the port that the data is being sent to.
When that data packet arrives at the router at the receiving end, the router needs to know which internal IP address to route it to. This is where Port Forwarding comes in, it’s your way of telling the router "If you get a data packet on port xxx then send it to IP address xxx.
Blynk doesn’t work like that. It uses a cloud based server as a relay point, and auth tokens as a way to both verify authenticity and manage data routing.
The Blynk app talks to the Blynk server, regardless of whether it’s connected via your local WiFi or via a mobile data service when you’re on the other side of the world.
Your device (ESP8266, Arduino etc) also talks directly to the Blynk server and establishes and always on connection, so there is a direct communications route to the Blynk server - a sort of data tunnel that the device and the server use to constantly do handshake operations and pass data backwards and forwards. This data tunnel is initiated by the device to the server, and because its an outbound request from the device that sets-up that tunnel, no Port Forwarding is needed at your end.
Pete.
Thank you. But there is some codes for 8266:
char auth = BLYNK_AUTH_TOKEN;
char ssid = “YourNetworkName”;
char pass = “YourPassword”;
void setup()
{
Serial.begin(9600);
…
Blynk.begin(auth, ssid, pass);
Blynk.run();
}
I realized that ssid and pass is not for ESP8266. It belongs to my wifi connection. So it means Blynk server will connect to ESP8266 through my WiFi connection? Does it need a port?
No, it means that your ESP8266 will connect to the Blynk server through your WiFi connection. It’s the ESP8266 that initiates the connection, not the Blynk server.
It uses a port (443 or 80 depending on whether you are using SSL or not) but you don’t need to make any port forwarding changes to your router to allow this to happen. In fact, attempting to make port forwarding changes to your router will almost certainly result in you breaking things as far as Blynk is concerned.
Pete.
I have a function BLYNK_WRITE(V1) in my code. So it means when V1 is triggered, the value will be sent to Blynk server, Blynk server will send it to ESP8266, doesn’t it?
As you said, I think ssid and pass are only used for the case we want to send signal from 8266 to Blynk app. But my project only needs to control hardwares though Blynk app.
SSID and WiFi Password are use to initiate a connection to the Blynk server via WiFi. This connection needs to be open all of the time - permanently. Otherwise there can be no communication between the Blynk server and the device.
When the value of V1 changes via the app, web dashboard or API the BLYNK_WRITE(V1) callback function will be triggered, yes.
You can also force it to be triggered by using Blynk.syncVirtual(V1). This ui normally used within the BLYNJK_CONNECTED() callback function, to retrieve the latest values from the Blynk server when the device starts-up.
It would probably be better if you explained more about your project, and posted your sketch, rather than asking random unconnected questions.
Pete.