Blynk local server Wan Hardware connect

Hello everyone

I’ve created Blynk local server and its working fine on LAN local ip also Im able to connect it on WAN at blynk app with port 9443. Everything seems perfect till here.

Also esp32 hardware is connected and working fine on LAN with port 8080 But when I try to connect esp32 hardware to wan ip/public ip it doesn’t connect at all. I’ve tried with port 9443, 8080, 80, 443 & 8440 but couldn’t connect.

So my issue is that I need to connect hardware esp32 to wan ip of local server.

#include <WiFi.h>
#include <DHT.h>
#include <BlynkSimpleEsp32.h>
#include "LiquidCrystal.h"
/*------------------ YOUR WIFI AND BLYNK SETTINGS ------------------*/
const char ssid[] = "Zxxxxx";
const char pass[] = "xxxxx";

int connection_loss_count = 0;

char auth[] = "-XXXXXXXXX-x_XXXXXX";

void connection_check(){
  if(Blynk.connected() == true){
    lcd.setCursor(0, 0);
    lcd.print("Blynk Connected!");
    connection_loss_count = 0;
  }
  else if(Blynk.connected() == false){
    connection_loss_count = connection_loss_count + 1;
     lcd.setCursor(0, 0);lcd.print("Blynk Not Connected");
    lcd.print(connection_loss_count);
    Blynk.connect();
  
  if(connection_loss_count >= 6 && Blynk.connected() == false){
    lcd.setCursor(0, 0);lcd.print("Connection Timeout Reset");
    delay(4000);
    //digitalWrite(3, LOW);
    lcd.setCursor(0, 0);lcd.print("This never happens!");
  }
}
}

void setup()
{
  delay(2000);
  
  timer.setInterval(1000L, connection_check);


  Blynk.begin(auth, ssid, pass, IPAddress(39,33,XXX,XX), 8080);//NOT WORKING

 // Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,7), 8080); // works fine
  
}

void loop()
{
  Blynk.run();
  timer.run();
}

You need to treat your Local Server as if it was a Cloud server… just based in your premises.

If you are running the device outside of your network, then you first need to connect to the internet through another AP via WiFi.begin(), then setup Blynk.config() to connect to your WAN IP. And you also need to have port forwarding setup in your router to redirect the incoming WAN port request to the internal LAN IP of your server.

  WiFi.begin(ssid, pass);
  Blynk.config(auth, server, port);
  Blynk.connect();

Blynk begin() should also work… just not as elegantly and the sketch stays blocked until connected.

The key is how are you getting the device online?

Infact Ive tried this as well. But it doesn’t make any difference in my case.

/*  const char* mqtt_server = "192.168.1.7";// "39.33.xx.xx";
  
  WiFi.begin(ssid, pass);
  
  Blynk.config(auth, mqtt_server, 8080);
  
Blynk.connect();
*/

It’s live on a compact desktop pc with windows server installed which is on and connected to internet all the time.

I meant are you using two separate, independent ISP sources to get on-line, one for the Server and one for the ESP32… or the same ISP connection? If the same one then you do NOT use the WAN IP, rather the LAN IP of the Server.

Have you done the port forwarding for ports 9443 and 8080 in your router?

Pete.

Yes, Port forwarding is on.

As I said I’m able to connect to server using Blynk app on WAN IP and its working just fine.

Now trying to do the same from esp32 hardware board.

Very true, I’m using two separate ISPs for this.

I already knew this as During testing I discovered this and was trying on different ISPs. Everything works fine on LAN IP(Blynk app, hardware) but on WAN IP Blynk app is connecting as intended but hardware can’t connect.

App and devices are different processes and use different ports.

No reason it shouldn’t work in ESP32 any differently then ESP8266. Assuming Blynk (Legacy) as your code seems to imply.

None of the hardware gets connected on WAN IP, I mentioned ESP32 specifically as I’m testing on that.

Hardware gets connected on LAN IP with Port 8080 and works fine. For WAN IP I’ve tried 9443, 8080, 80, 443 & 8440 so far. (port forwarding is done on port 9443 port in router)

So you want to share details of what you’ve forwarded, and how?

Pete.

You’ve highlighted the correct issue I think. I tried to check ports which are open on my router with online tool and it tells only 9443 port is open and not 8080. However I’ve added same rule for 8080 as for 9443.

See attached image please

These port scanning tools often don’t give accurate results.

One of your ISPs could be blocking the 8080 traffic. You could try changing the port in your server.propterties file and restarting.

Pete.

Sure, Now I’ve forwarded two ports 9443 and 8440 and tool is showing them open.

Should I change http.port or hardware.mqtt.port in server.properties to 8440?

The entry you need to change is:

 http.port=8080

Don’t do this through the admin portal though. edit the server.proprties file directly and change that line, then save the file and restart he server.

Test it internally first, then externally.

If you don’t have a server.properties file then you’ll need to create one…

Pete.

Got it worked. I setup a custom server.properties file, attached it with server and changed the http.port to 8440 required in my case and it worked perfectly fine for LAN and WAN ips.

Thanks a lot for the help.

1 Like

Excellent!

Pete.