Hi everyone,
I’m coming back to you regarding my beehive connected project. One month ago I found a solution to use my ESP8266 in modem sleep, coming back to finalize all because I received all electronic components now my program is not working any more.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "*********************";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*****";
char pass[] = "*****";
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
#include <DHT.h>
#include <HX711.h>
// Capteur de poids setting
const int SCALE_DOUT_PIN = D5;
const int SCALE_SCK_PIN = D6;
HX711 scale(SCALE_DOUT_PIN, SCALE_SCK_PIN);
float weight;
// Capteur température DHT11
#define DHT1PIN D3 // what pin we're connected to
#define DHT1TYPE DHT11 // DHT 11
float t1;
float h1;
// Capteur température DHT22
#define DHT2PIN D7 // what pin we're connected to
#define DHT2TYPE DHT22 // DHT 22
float t2;
float h2;
// Initialize DHT sensor for normal 16mhz Arduino
DHT dht1(DHT1PIN, DHT1TYPE);
DHT dht2(DHT2PIN, DHT2TYPE);
BlynkTimer timer;
// Voltage batterie
float volt=0;
float volt1=0.00;
void batterie()
{
pinMode(A0, INPUT);
volt = analogRead(A0);
volt1=volt/233,8;
//Serial.println(volt1);
Blynk.virtualWrite(V3, volt1);
}
/* void getDht1Data(void){
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h1 = dht1.readHumidity();
// Read temperature as Celsius
float t1 = dht1.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h1) || isnan(t1)){
Serial.println("Défault DHT11");
return;
}
Blynk.virtualWrite(V6, t1); //virtual pin V6 DHT11
Blynk.virtualWrite(V5, h1); // virtual pin V5 DHT11
}
*/
void getDht2Data(void){
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h2 = dht2.readHumidity();
// Read temperature as Celsius
float t2 = dht2.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h2) || isnan(t2)){
Serial.println("Défault DHT22");
return;
}
//Serial.println(t2);
//Serial.println(h2);
Blynk.virtualWrite(V7, t2); //virtual pin V7 DHT22
Blynk.virtualWrite(V8, h2); // virtual pin V8 DHT22
}
void sendWeight()
{
String weight = String(scale.get_units(1), 2);
//Serial.println(weight);
Blynk.virtualWrite(V4, weight);
}
/*void sendSensor()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V6, t1); //virtual pin V6 DHT11
Blynk.virtualWrite(V5, h1); // virtual pin V5 DHT11
Blynk.virtualWrite(V7, t2); //virtual pin V7 DHT22
Blynk.virtualWrite(V8, h2); // virtual pin V8 DHT22
//Blynk.virtualWrite(V4, weight); // virtual pin V12
}
*/
void setup(){
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
scale.set_scale( -6000 / 0.3095 );
scale.tare();
//dht1.begin(); // initialize dht11
dht2.begin(); // initialize dht22
// timer.setInterval(4000L, getDht1Data);
timer.setInterval(4000L, getDht2Data);
pinMode(A0, INPUT);
timer.setInterval(1000L, batterie);
timer.setInterval(120000L, SleepFunction); //wifi activé pendant 120s
timer.setInterval(1000L, sendWeight);
}
void SleepFunction() {
{
Serial.println("will be disconnected soon");
delay(2000);
wifi_set_sleep_type(LIGHT_SLEEP_T);
WiFi.disconnect();
WiFi.forceSleepBegin();
Serial.println("wifi disconnected");
// timer.setTimeout(20000L, WakeUpFunction); //Pas de wifi pendant 100s
delay(80000);
Serial.println("after delay");
wifi_set_sleep_type(NONE_SLEEP_T);
WiFi.forceSleepWake();
Blynk.begin(auth, ssid, pass);
delay(2000);
Serial.println("connected");
}
}
void loop(){
Blynk.run();
timer.run();
}
Aftert 120s I got this error:
[20188] Connected to WiFi
[20188] IP: 192.168.1.25
[20188]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.5.0 on NodeMCU
[20194] Connecting to blynk-cloud.com:8442
[20323] Ready (ping: 41ms).
very soon disconnect
Soft WDT reset
ctx: cont
sp: 3ffffd60 end: 3fffffd0 offset: 01b0
>>>stack>>>
3fffff10: 00000000 000002f6 00000000 3ffffea3
3fffff20: 00000000 0000018d 0000018d 4010020c
3fffff30: 3fffff50 3fffff50 00000004 402240a0
3fffff40: 0fffffff 00000008 3ffe95a0 40100518
3fffff50: 3ffe9368 3ffe9370 000002f6 00000000
3fffff60: 0001260d 00000600 3ffef2fc 402237e0
3fffff70: 0fffffff 40203b1e 00000000 40203b09
3fffff80: 3fffdad0 3ffef2fc 3ffef468 402038d1
3fffff90: 3fffdad0 3ffef068 3ffef068 40204c5c
3fffffa0: 3fffdad0 00000000 3ffef538 40203935
3fffffb0: 3fffdad0 00000000 3ffef538 402055ac
3fffffc0: feefeffe feefeffe 3ffe8624 40100739
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(1,7)
ets Jan 8 2013,rst cause:4, boot mode:(1,7)
wdt reset
I just want to disconnect the ESP8266 wifi during a while and turn on few second. I spent the week trying to figure out why it does not work anymore … thanks for your help 