I have a ESP8266 D1 mini connected with a hc-sr4 for distance measurement to send periodicaly to my domoticz api.
In continues with usb connected all is OK but i want use a battery (cr2032) and then use the deep sleep mode for e.g 60 minutes.
When i try to use the deep sleep, my ESP8266 goes well in deep sleep, but when he must wake, he print juste 4 characters and that is all.
I don't understand.
Hardware connection seems ok because i got the measure updated in my domoticz.
Pin D0 and RST connected together
Anyone can help me please ??
Thanks
Here is the "com output" log :
--------------------------------------------
4U⸮⸮⸮⸮start
Setup start bis
Attente connexion Wifi
.
Connected to WiFi-2.4-7C5F
IP address: 192.168.1.250
Domoticz connecting to 192.168.1.254
Requesting URL: /json.htm?type=command¶m=udevice&idx=49&nvalue=0&svalue=8.18
closing connection
: ESP8266 goes to Deep Sleep for 30000000
⸮HpY4
Here is the code:
-------------------------
/*
* Distance measurement with HC-SR04 ultrasonic sensor and Wemos D1 Mini, a web-based server
* by author Irwan
* published on www.likecircuit.com
* version 1.0
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WebServer.h>
const char* ssid = "WiFi-2.4-7C5F";
const char* password = "xxx my password";
IPAddress ip(192, 168, 1, xxx);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
// defines pins numbers trigger and echo
const int trigPin = 2; //Trig - D4 - Physical_pin=17 / NodeMCU=4 / Arduino=
const int echoPin = 0; //Echo - D3 - Physical_pin=18 / NodeMCU=3 / Arduino=0
const int TimeSleepS = 30; // Nombre de secondes mode veille Deep Sleep
// defines variables
long duration;
float distance;
float Mdistance;
// Domoticz variables
const char* host = "192.168.1.xxx";
const int port = 8081;
HTTPClient http;
void setup(void){
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
// Connect D0 to RST to wake up
pinMode(D0, WAKEUP_PULLUP);
Serial.begin(9600);
Serial.setTimeout(2000);
// Wait for serial to initialize.
while(!Serial) { }
Serial.println("Setup start");
Serial.println("Setup start bis");
WiFi.config(ip,gateway,subnet);
WiFi.begin(ssid, password);
Serial.println("Attente connexion Wifi");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
distanceData();
String url = "/json.htm?type=command¶m=udevice&idx=49&nvalue=0&svalue=";
url += String(distance);
sendToDomoticz(url);
delay(500);
Serial.print(" : ESP8266 goes to Deep Sleep for ");
Serial.println(TimeSleepS * 1000000);
ESP.deepSleep(TimeSleepS * 1000000);
delay(2000);
}
void loop(void){
}
void distanceData(){
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= (duration*0.034)/2;
}
void sendToDomoticz(String url){
Serial.print("Domoticz connecting to ");
Serial.println(host);
Serial.print("Requesting URL: ");
Serial.println(url);
http.begin(host,port,url);
int httpCode = http.GET();
if (httpCode) {
if (httpCode == 200) {
String payload = http.getString();
Serial.println("Domoticz response ");
Serial.println(payload);
}
}
Serial.println("closing connection");
http.end();
}