Switching on wifi only when data is sent through the app

Hey hi guys. I am building a project where I am using NodeMCU board. So I want to switch on the wifi on the board only when I send data from the app. I want to do this to reduce battery usage. Is there a way to do this?

Simple answer is NO. You trying to walk over the river without a bridge. When there is no protocol between the app n the hardware, how can the communication be established ? You can use deepsleep to save battery, but during this time you cannot trigger the board from the app, but wait for the board to wakeup n wait for a msg from the app n again go to deepsleep.

If you can tell us the real case scenario, we can think of a walk-around.

You can use light sleep, which turns off the WiFi, but it doesn’t save much power and in most cases deep sleep is far better.
The advantage of light sleep is that you can still do some processing and data collection, but as Blynk doesn’t allow batch uploads of historical data it’s not really a very useful approach.

Take a look at some of the experiments done by “the guy with the Swiss accent” (Andreas Spiess) on YouTube if you want to know more about reducing power consumption in MCUs.


1 Like

So I am actually using this function to turn off the wifi and put the nodemcu into modem sleep mode. Is this the right code?

void wifiDisconnect() { //To disconnect WiFi and then to sleep
  if(WiFi.status() == WL_DISCONNECTED) {
    Serial.println("WiFi is down");
  else {
    Serial.println("WiFi is going down");
    WiFi.mode( WIFI_OFF );

So then what is happening is I used the above function in this function–

void timeCheck() {
  if (currentSec - startSec >= 10000) {

and then called timeCheck() in the void loop() function. So then what is happening is if the conditional is true, the wifi is getting disconnected but it is connecting right away again. Why is that happening?
Thanks for your reply!

@Harsh_Muriki please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code.
Triple backticks look like this:


1 Like

Impossible to say, based on the code snippets you’ve provided.


But like if I wanted to disconnect from the wifi and go into modem sleep mode, the wifiDisconnect function is right?
If not, what is wrong in that?