Beehive project issue

If you’re looking for a cheap source for load cells, check out the local charity shops, car boot sales, flea markets etc for old Wii Fit balance boards. If the balance board is roughly the right size then you could even retain the plastic structure, and remove the existing circuit board and replace with your HX711 and MCU of choice.
Old bathroom scales also contain load cells, but may not be rated high enough for your needs.

I have a little project on the back burner where I intend to use an old Wii Fit to weigh my propane gas bottles to tell me when they’re getting low. Maybe if I could tear myself away from the forum I might actually get the project off the ground.

Pete.

3 Likes

Also check out for a similar project by Nathan Siedle, ex SparkFun CEO. He had it posted somewhere, most likely on their blog. You might learn something.

2 Likes

Here:

Pete.

1 Like

many thanks for the link Pete

This is wonderful that so many people have joined together to help one person get the project working I used to keep bees many years ago but we never had this tec then good luck with the project sounds good Bob - in the UK

1 Like

Hi Everybody,

I’m coming back to you because I still have another issue. I was looking for code samples to use the function modem sleep on my ESP to reduce my current consumption. By using the function WiFi.forceSleepBegin it working find but when I used it with Blynk nothing work correctly. I couldn’t find good example to automatically turn on and off the ESP wifi and send the data with blynk to my mobile.

One topic seems to me good but there is not more details: [SOLVED] Solar Powered Weather Station ESP8266 + Blynk

Many thanks for your help

Can you post your latest code?

Pete.

My code with sleep mode but is on the void loop… I do not know how to automaticlly add in the void setup

#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;

float t;
float h;

#define DHTPIN D3     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11


// Initialize the OLED display using Wire library
SSD1306  display(0x3c, D2, D1);
// SH1106 display(0x3c, D3, D5);
// Display Settings


// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

void displayTempHumid(){
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  t = dht.readTemperature();
  h = dht.readHumidity();
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)){
    display.clear(); // clearing the display
    display.drawString(5,0, "failed read from DHT");
    return;
  }
  display.clear();
  String weight = String(scale.get_units(1), 2);
  display.drawString(0, 0, "ruche connectée"); 
  display.drawString(0, 16, "Humidité: " + String(h) + "%\t"); 
  display.drawString(0, 32, "Temp: " + String(t) + "C"); 
  display.drawString(0, 48, "Poids: " + String(weight) + "KG"); 
  display.display();
}
void sendWeight()
{
  
  String weight = String(scale.get_units(1), 2);
  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, t); //virtual pin V6 DHT11
  Blynk.virtualWrite(V5, h); // virtual pin V5 DHT11
  //Blynk.virtualWrite(6, temp2); //virtual pin V7 DHT22
  //Blynk.virtualWrite(5, hum2); // virtual pin V8 DHT22
  //Blynk.virtualWrite(V4, weight); // virtual pin V12
}

void setup(){
  // Initialising the UI will init the display too.
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  display.init();
  display.flipScreenVertically();
  display.setFont(ArialMT_Plain_16);
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  scale.set_scale( -6000 / 0.3095 );
  scale.tare();
  dht.begin(); // initialize dht
  timer.setInterval(5000L, sendSensor);
  timer.setInterval(5000L, displayTempHumid);
  timer.setInterval(1000L, sendWeight);
 }
 
void loop(){
  Blynk.run();
  timer.run();
  delay(40000);
  Serial.println("déconnecté");
  WiFi.disconnect();
 WiFi.forceSleepBegin();
  delay(20000);
  WiFi.forceSleepWake();
  
}

Well, your code certainly wont work with those delays in the void loop - Blynk doesn’t like that because they block the execution of the code until the delay has completed.

I’m no expert on the use of timers, and haven’t used Wi-Fi force sleep/wake before. However, I would suspect that the solution is to have a timer that calls a “wakeup” routine every 40 seconds, which then updates the Blynk server and puts the Wi-Fi back to sleep once its executed.

However, I suspect that your OLED display consumes more power than the ESP’s Wi-Fi routines.

Pete.

1 Like

@christophebl
salut Christophe :wink:

il faut que tu vires ton code de void loop, sinon blynk ne peut pas fonctionner.
tu dois juste avoir :

void loop(){
  Blynk.run();
  timer.run();
}

@christophebl

pour le sleep mode tu dois faire un timer lambda
donc on a toutes les 40 secondes sleep, et 20 secondes plus tard wake up, puis 20 secondes plus tard sleep etc …
si c’est ce que tu recherches

void setup(){
timer.setInterval(40000L, SleepFunction);
.
.
}

void SleepFunction() {
 {
    Serial.println("déconnecté");
    WiFi.disconnect();
    WiFi.forceSleepBegin();
    timer.setTimeout(20000L, WakeUpFunction);
      }
}
void WakeUpFunction() {    
     Serial.println("connecté");
     WiFi.forceSleepWake();
  }
2 Likes

Merci beaucoup Alexis. Je vais essayer ça! :slight_smile:

2 Likes

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 :yum:

First of all, I think you need to re-visit the logic of these timers.
You’re trying to send the weight readings to Blynk every second, but then trying to put the Wi-Fi to sleep every 120 seconds.
It’s almost as though you’re thinking that these numbers represent the duration rather than the frequency of the event?

I think you probably only w at one f7nction that’s called every 120 seconds. When it’s called it does the following:

  • Take a humidity reading

  • Take a temperature reading

  • Take a battery reading

  • Turn on Wi-Fi

  • Upload the readings to Blynk

  • Turn off Wi-Fi

The delays in your current SleepFunction won’t be needed then. It’s probably these delays that are causing your WDT resets.

Pete.

Many thanks for your answer Pete,

ok I understand what you explained to me regarding the timer. I also try this code with the same result:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

extern "C" {
  #include "user_interface.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[] = "Livebox-667E";
char pass[] = "***********";


#include <Arduino.h>

BlynkTimer timer;

 void setup() 
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(120000L, SleepFunction); 

}

void SleepFunction() {
 {
    Serial.println("very soon disconnect");
    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();
    
}

The 120 are just used for test, after I want to send my data every 2 hours. But just for testing the stability of my program I used 120s

@christophebl may I ask why you are not using deepSleep() ?

The code you posted won’t compile because it calls a function called WakeUpFunction which doesnt exist.

But your SleepFunction still contains delays, and is structured in the opposite way to what I suggested.

I’ve modified your earlier code to work the way I think it should. It compiles okay, but I’ve not tested it…

#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 getBatterie()
{
   pinMode(A0, INPUT);
   volt = analogRead(A0);
   volt1=volt/233,8;
   Serial.print("Voltage = ");  
   Serial.println(volt1);
}
  
void getDht2Data()
{
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  h2 = dht2.readHumidity();
  // Read temperature as Celsius
  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.print("Temperature = ");    
  Serial.println(t2);
  Serial.print("Humidity = ");        
  Serial.println(h2);
} 
  
void getWeight()
{
  String weight = String(scale.get_units(1), 2);
  Serial.print("Weight = ");  
  Serial.println(weight);
}


void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  scale.set_scale( -6000 / 0.3095 );
  scale.tare();
  dht2.begin(); // initialize dht22
  pinMode(A0, INPUT);
  timer.setInterval(120000L, Wakeup_and_do_something); //wifi activé pendant 120s
}
 
void Wakeup_and_do_something()
{
  // Take readings of Battery Voltage, Temperature, Humidity and Weight...
  getBatterie();  
  getDht2Data();
  getWeight();    

  // Turn on the Wi-Fi and connect to Blynk...
  Serial.println("Turning Wi-Fi on...");
  wifi_set_sleep_type(NONE_SLEEP_T);
  WiFi.forceSleepWake();
  Blynk.begin(auth, ssid, pass);
  delay(2000); // Not sure if this is needed, or desireable - PeteKnight
  Serial.println("Connected to Blynk");

  //Update Blynk with the latest readings...
  Blynk.virtualWrite(V3, volt1);
  Blynk.virtualWrite(V7, t2); //virtual pin V7 DHT22
  Blynk.virtualWrite(V8, h2); // virtual pin V8 DHT22
  Blynk.virtualWrite(V4, weight);   

  // Disconnect Blynk then turn off the Wi-Fi...
  Blynk.disconnect();
  Serial.println("Blynk disconnected");
  wifi_set_sleep_type(LIGHT_SLEEP_T);
  WiFi.disconnect();
  WiFi.forceSleepBegin();
  Serial.println("Wi-Fi disconnected");
  Serial.println();  
}

void loop(){
  Blynk.run();
  timer.run();  
}

Pete.

I think the original plan was to have a display that could be activated at any point to show the current readings. Although this could be done whilst using Deep Sleep, it would be a bit more complex.

I think Deep Sleep might actually be worth revisiting now, as @christophebl’s understanding of the way that Blynk works has improved, and the requirements have been revised somewhat.

Pete.

1 Like

If I’m using the deepSleep mode I lost my data of the weight. When the ESP start the 0 weight is set like a calibration and after I can get the weight. If I’m using the deepsleep after it my weight will back to 0 even if I have some weight on it. I dont know if it’s clear for you :grinning:

I don’t see anywhere in your current code that you’re saving a previous weight reading.
I would be possible to save the starting weight, or even the last weight reading, in SPIFFS and re-load this at every reboot (which would occur when the ESP wakes up from deep sleep.

Can you explain more about what you wnat your final solution to look like? Have you abandoned the OLED display, and what do you want the weight functionality to do exactly?

Pete.