Close

Log 2

A project log for SMS Garage Alert system using an Ultrasonic sensor

ESP8266 SMS Garage Alert system using a RCW-0001 Micro Ultrasonic Sensor and a Webhook (IFTTT.com and IFTTT android app)

paul-gPaul G. 11/11/2019 at 19:100 Comments

Currently I'm trying to reduce the power consumption of my project setup by turning the WiFi module off, when it's not needed, thus during the time period were the watchdog isn't active. I'm testing my new code at the moment.

The following functions are essential for achieving my goal:

// function for turning the WiFi module off
void stopWiFiAndSleep() {
  WiFi.disconnect();
  delay(1000);
  WiFi.mode(WIFI_OFF);
  WiFi.forceSleepBegin();
  delay(1);
  Serial.println("WiFi module disabled...");
}

Why delay(1000)? If you want to know why, click on the link. :) I had the same problem and the suggestion of ardyesp fixed it.

// function for wake up and starting WiFi connection
void startWiFiAndWake() {
  WiFi.forceSleepWake();
  delay(1);
  // Bring up the WiFi connection
  WiFi.mode(WIFI_STA);
  WiFi.begin(WLAN_SECRET_SSID, WLAN_SECRET_PASS);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.print("WiFi Connected, IP address: ");
  Serial.println(WiFi.localIP());
}

Till next time!

Discussions