ESP32 stuck on connecting to Wifi

You’ve written your code in the correct style for Blynk - an un-cluttered void loop and a timer to call your functions. However, this isn’t the most efficient way for deep sleep.

There will be a 1 second delay before your sendSensor code is called, which is unnecessary.
Forget the timer and put all of your sendSensor code in the void loop. It will execute immediately and go to sleep attge end of the first cycle through the void loop.

Also, if you haven’t already then you’d be better assigning a static IP address to your ESP, preferably via your router. This way the connection to your router will be quicker.
If you don’t do this, and rely on DHCP instead, the router’s routing table will have flushed in the time between ESP connections and the ESP will have to negotiate a new routing arrangement with your router. This takes time, and slows down the connection process.

You may also find that rather than connecting to Blynk using Blynk.begin or Blynk.config you’d be better-off doing a series of API calls to the Blynk server to upload the data. This approach has been discussed before In an old topic called something like “why doesn’t my battery last very long”.

Oh, just found the topic I was thinking of. It’s this one:

I can’t be bothered to read the whole topic, and the bit about API calls might be in one of the linked topics, but it’s worth you having a read.

Pete.

1 Like