mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 00:55:52 +03:00
[GH-ISSUE #143] How to safely go to deep sleep #111
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#111
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @dinonovak on GitHub (Mar 29, 2016).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/143
HI,
I am using WifiManager class to configure Wifi.
Also I am running server on the same node.
When trying to go to deep sleep something is not right as node keeps fully resetting itself.
This is what i am using before going to deep sleep:
wifi_station_disconnect();
wifi_set_opmode(NULL_MODE); //set wifi mode to null mode.
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); //set force sleep type, clsoe rf&cpu
wifi_fpm_open(); //enable force sleep fucntion
Serial.println("GOING FOR DEEP SLEEP");
ESP.deepSleep(SLEEP_TIME, WAKE_RF_DEFAULT);
delay(1000);
Full code sniplet:
`#include <PietteTech_DHT.h>
include <Arduino.h>
include <Time.h>
include <TimeLib.h>
include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
//needed for library
include <DNSServer.h>
include <ESP8266WebServer.h>
include <ESP8266HTTPClient.h>
include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
include <EEPROM.h>
// Include API-Headers
extern "C" {
include "ets_sys.h"
include "os_type.h"
include "osapi.h"
include "mem.h"
include "user_interface.h"
include "cont.h"
}
//ADC_MODE(ADC_VCC); //vcc read-mode
// RTC-MEM Adresses
define RTC_BASE 100
// state definietions
define STATE_COLDSTART 0
define STATE_SLEEP_WAKE 1
define SLEEP_TIME 2_60_1000000 // sleep intervalls in us
define SLEEP_AFTER_MIN 2 // go to sleep after minutes
// global variables
byte buf[2];
byte state; // state variable
uint32_t sleepCount;
// User variables
String ClientIP;
float temperature = 0.0;
float humidity = 0.0;
long lastInterval = 0;
int port = 80;
define SERIAL_DEBUG
ESP8266WebServer server(80);
//DHT22 config
define DHTPIN 5 // what pin DHT is connected to
define DHTTYPE DHT22 // DHT 11
//declaration
void dht_wrapper(); // must be declared before the lib initialization
// Lib instantiate
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);
// globals
bool bDHTstarted; // flag to indicate we started acquisition
// This wrapper is in charge of calling
// must be defined like this for the lib work
void dht_wrapper() {
DHT.isrCallback();
}
void handle_root() {
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void send_data() {
String yourdata;
int acquireresult;
acquireresult = DHT.acquireAndWait(2000);
if ( acquireresult == 0 ) {
} else {
Serial.println("Failed to read from DHT sensor!");
}
}
void setup() {
// put your setup code here, to run once:
ifdef SERIAL_DEBUG
endif
}
void loop() {
if (state == STATE_COLDSTART)
{
// put your main code here, to run repeatedly:
}
@tzapu commented on GitHub (Mar 30, 2016):
hi, for normal deep sleep, these are not needed:
just use
ESP.deepSleep(...)