ESP32 loses blynk.cloud connection when phone wifi hotspot router switches from home wifi connection to mobile data

Want to be able to control my mobile ESP32S2 away from stationary wifi, and I succeeded to make my device switch automagically between home router and Galaxy S10e phone (Android v12) wifi hotspot, using Arduino IDE Blynk library v1.0.1 example ESP32_WiFi + Blynk_WM wifi manager, however I still always lose blynk.cloud connection whenever phone+device leave home wifi range, even though device connected to phone and phone has strong mobile data internet connection.

Anyone run into this problem have it figured out?

Thanks


#define BLYNK_PRINT Serial

/* Fill-in your Template ID (only if using Blynk.Cloud) */
//#define BLYNK_TEMPLATE_ID   "YourTemplateID"
#define BLYNK_TEMPLATE_ID "TMPL********"
#define BLYNK_DEVICE_NAME "B*****"
#define BLYNK_AUTH_TOKEN "X**********p"

#define USE_LITTLEFS          false
#define USE_SPIFFS            false
#define TIMEOUT_RECONNECT_WIFI                    10000L
#define RESET_IF_CONFIG_TIMEOUT                   true
#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET    5
#define USE_SSL               false  
#define USE_DYNAMIC_PARAMETERS                    false

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32_WM.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
//char auth[] = "X***************p";

// Your WiFi credentials.
// Set password to "" for open networks.
//char ssid[] = "R****";
//char pass[] = "2********";

BLYNK_WRITE(V1)
{
  int pinValue = param.asInt();
  digitalWrite(8, pinValue);
}

void setup()
{
  // Debug console
  pinMode(8, OUTPUT);
  Serial.begin(9600);

  Blynk.begin();
}

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


I’m not really familiar with the 3rd party library that you’re using, but your example seems to be missing some #include references.

If the library outputs meaningful information to the serial monitor without the inclusion of #define BLYNK_PRINT Serial then I’d try connecting the device to a laptop so that you can see what debug messages you get whne the connection is lost.

Otherwise, try adding #define BLYNK_PRINT Serial somewhere at the top of your sketch, but after this line

Pete.

Greetings Mr. Pete!
Thank you kindly for your assistance. As suggested I did remove #define BLYNK_PRINT Serial, resulting in absent serial monitor output, and then I replaced it after #define BLYNK_AUTH_TOKEN "X********** to regain serial monitor output. I noticed no difference in output information when #define BLYNK_PRINT Serial is moved from sketch line #1 to after #define BLYNK_AUTH_TOKEN “X********p”.

On review I suppose third party Blynk_WM wifi manager not relevant to my problem, so I’ve removed it and my home router from my code for simplicity. So now simply using unadulterated Blynk v1.0.1 library examples, same blynk.cloud connection problem persists. I’ve trialed both examples ESP32_WiFi, and ESP32_WiFi_SSL. Per serial monitor, either example always succeeds to connect to my phone wifi hotspot, but the next step the blynk.cloud connection success or failure depends whether phone internet connection via home wifi router or mobile network, respectively. By toggling my phone’s home router wifi connection (which does not affect/toggle the hotspot connection) I get the following serial monitor outputs from either example:

com22_1

com22_2

//#define BLYNK_TEMPLATE_ID   "YourTemplateID"
#define BLYNK_TEMPLATE_ID "T************"
#define BLYNK_DEVICE_NAME "B****"
#define BLYNK_AUTH_TOKEN "X********************p"
#define BLYNK_PRINT Serial
//#define USE_LITTLEFS          false
//#define USE_SPIFFS            false
//#define TIMEOUT_RECONNECT_WIFI                    10000L
//#define RESET_IF_CONFIG_TIMEOUT                   true
//#define CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET    5
//#define USE_SSL               false  
//#define USE_DYNAMIC_PARAMETERS                    false

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "X******************p";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "DanerS10e";
char pass[] = "f*******0";

BLYNK_WRITE(V1)
{
  int pinValue = param.asInt();
  digitalWrite(8, pinValue);
}

void setup()
{
  // Debug console
  pinMode(8, OUTPUT);
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
}

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

It sounds like either your hotspot software or your mobile ISP are blocking the Blynk traffic.

Pete.

After some extensive troubleshooting speaking w Tmobile ISP tech experts, and experimenting with my other home IoT devices, they my mobile ISP have concluded that neither they nor my mobile account settings are blocking any traffic between esp32 and Blynk app.

As part of the troubleshooting process it was suggested to me to duplicate my use case scenario with other IoT products, of which I have a house full. So I deactivated my home router’s 2.4Ghz WiFi connection, but left the 5Ghz connection intact, which 5Ghz my phone can use but IoT devices cannot. Then I renamed my phone hotspot with home router same credentials, resulting in all my home IoT devices connecting to my phone hotspot no problems. Then I toggled the phone internet connection between home wifi router and mobile network, and observed which devices/apps worked and which did not:

Blynk IoT app to esp32s2 connection doesn’t work unless phone to home router internet connection
Blynk legacy app to Particle Photon same problem
Smart LIfe app/smart light switches same problem
Kasa app/smart outlet same problem
Emporia app/home energy monitoring devices same problem

Feit Electric app/ security cameras work regardless of hotspot internet connection type, no problem
besteye app/ security cameras no problem
Arlo app/ doorbell camera no problem
Amazon Kindle no problem
Apple Ipad no problem

In conclusion some devices have this problem and some don’t, so doesn’t appear to be the fault of my ISP provider. It seems the devices having a problem might all be esp32 devices. Unfortunately I don’t really know what to try from here, and still don’t understand why I shouldn’t be able to use my esp32 with Blynk app in this way… Can somebody help me?

Thanks!

Just to be clear, the Blynk app doesn’t connect to the ESP32-S2, the app connects to the Blynk server.
The ESP32-S2 device also connects to the Blynk server - in this case via the hotspot on the phone, which just happens to also be running the Blynk app.

The question, which doesn’t seem to be answered by what you’ve posted, is can you establish if the Blynk app on the phone is remaining connected to the Blynk server when the phone disconnects from the home WiFi?
Is it simply the ESP32-S2 device that is losing the server connection when the phone running the hotspot and not connected to your home WiFi ?

Is your mobile device capable of running a 5GHz WiFi hotspot, or is it 2.4GHz only? The iPhone 13 defaults to 5GHz hotspot, which isn’t compatible with ESP devices.

Pete.

1 Like

My phone a Galaxy S10e is capable of either 2.4 or 5Ghz hotspot connections, and I have it set to 2.4Ghz hotspot mode since always.

i’m not sure I understand but i’ll try to answer. If the esp32 is connected to home router, then it always connects no problem to blynk.cloud, and I can control from phone Blynk app whether phone is using mobile data or home router. So I can say at least when esp32 connected to home router, that phone does remain connected to blynk server when disconnects from home wifi. If the esp32 is connected to phone hotspot then it succeeds to connect to blynk.cloud only while phone is connected to internet via home router, and blynk.cloud connection is lost once phone internet switches to mobile data, though 2.4Ghz hotspot connection is maintained. Within the app I see this change as pictured below:


Also I can continue to use the Blynk app to change my user settings, profile, etc. while the esp32 is listed as offline. So looks to me that only the esp32 device is losing server connection and not the phone. But why it loses connection?

My money is still on the mobile ISP blocking the Blynk protocol…

Pete.

Update:
Since Blynk IoT appears to have been updated recently (yesterday?), now I can finally control my ESP32-S2 connected to smartphone Wifi hotspot, and with phone using cellular network. This is great for my application whose hardware ESP32 is mobile not stationary nor always in home Wifi router range, but which generally is in close proximity to the smartphone. Thanks Blynk team for making this very useful update!