BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

One value is now missing from Blynk 'project'

I created a very satisfactory Blynk project to receive Temp and Humidity data from an ESP-12F unit, using DHT-22 sensor.

The ‘project’ had a gauge for each of Temp and humidity, plus a history graph for each.

For literally weeks, the device transmitted all values correctly, and they appeared on the project gauge and charts correctly in all aspects.

WITHOUT CHANGING anything, the Temperature value is no longer received by Blynk - it appears neither on gauge or graph.

Humidity remains up to date and correct.

If connected to the Arduino app the serial monitor shows that the device is pulling the data from the sensor correctly for both Temp and humidity.

I have not posted any code as literally nothing has been touched. The project still has the correct pins in use, so nothing has been corrupted there. I’ve forced quit the Blynk app many times, plus ‘stopped’ and ‘restarted’ the project. I’ve changed virtual pin numbers and then set back to right values. Humidity behaves as expected, but temp no response.

Any thoughts as to why this failure has occurred?

What happens if you change the code so that the humidity isn’t written to Blynk, or swap the temperature/humidity sequence around?

How frequently are you taking the readings, is this done by a timer, and do you have any other Blynk.virtualWrites in your code?

Pete.

Super quick reply, thanks Pete.

Interesting, swapping the Blynk.virtualWrite lines for Temp and Humidity has indeed ‘bumped’ temp back into life via Blynk. At least for the last 5 mins.

So, good call, but why? Nothing was touched.

To answer your Q re frequency: the readings are read and transmitted once per minute. The ESP-12 deepSleeps in between (have been evaluating for battery application).

The Blynk app is set to ‘push’ for each value.

Okay, the whole deep sleep thing needs you to take a totally different approach, and to break all the Blynk rules about a clean void loop and the use of timers.

I’m guessing that previously your process was borderline, and then (for some unidentified reason) this no longer worked. This could be to do with your ISP, power supply or router, or because the ESP was feeling uncooperative :grinning:

It’s important to allow the write to the Blynk server to complete before the device goes back to sleep, and I always like to put a Blynk.run in there before the deep sleep command.

@christophebl and I did quite a bit of work on a project of his which involved deep sleep and he’s now take that much further.
Here’s a link to his project, which may be of some assistance in the deep sleep coding:

One issue that this project identified is that using Blynk.begin with deep sleep isn’t a good idea. If a connection tonWiFi or the Blynk server can’t be established for any reason then the device will keep trying until the battery goes flat. Much better to use Blynk.config and Blynk.connect.

It’s also better if you allocate a reserved IP address for your ESP in your router, and preferably use a (the same) static IP in your code rather than rely on a DHCP allocates IP, as it makes the re/connection time much quicker. You won’t notice this when testing and using a short sleep time, as your router will remember the MAC address of your ESP in its routing table. Once you increase the sleep time the routing table will have nbeen purged, and a slower DHCP address negotiation process will have to be done, which will bump-up your wake times and you won’t be able to figure-out why you aren’t getting a pro-rata battery life with longer sleep times.

Pete.

OK, understand the issue regarding ensuring that nothing ‘falls asleep’ before the job is fully done.

I will look at the project above and trial mods to test the reliability. Tricky as it took two weeks to fail…!

FWIW, this is my loop code. I know that some suggest adding various delays pre and post to ‘help’ with the deepSleep working ‘properly’, but I never understood the real basis for them.

The sendSensor fn has the two Blynk.virtualWrite lines for T and H.

void loop()
{
  Blynk.run(); // Initiates Blynk
  timer.run(); // Initiates the timer
  sendSensor(); // Pulls data from DHT sensor
  // The following serial code allows you to ensure that you are getting valid readings which can be checked when connected via USB
  Serial.print("Humidity: ");
  Serial.print(String(h).c_str());
  Serial.println(" %");
  Serial.print("Temperature: ");
  Serial.print(String(t).c_str());
  Serial.println(" C"); 
  // REMEMBER to set any 'offline alerts' in Blynk Projects to EXCEED the read time delay  
  ESP.deepSleep(60e6); // DEEP SLEEP for 60 seconds 
}
1 Like

You can find that the before the deep sleep “kicks-in” the void loop starts executing again, which seems to cancel the deep sleep command. The way to stop this is to add a delay after the deep sleep command so that nothing else has chance to execute before the sleep process begins.

I would forget about the timer, which presumably calla a routine which does the virtualWrites of temp and humidity and move these into the void loop, in with the serial print commands. I’d then add a Blynk.run after the last Blynk.virtualWrite command.
This would normally be totally the wrong thing to do, as it would lead to flooding the server if the void loop actually looped, but in this case it doesn’t - it executes once then sleeps.

Pete.

Wilco, I’ll give that a go Pete. Thanks for your guidance - bit new to this and so was indeed trying to do the ‘right’ thing, but didn’t know enough about foibles of deepSleep.

OK, tried various changes, but not working for me. Still losing the first data stream from Blynk, which is n ow Humidity as I swapped them earlier.

Also, a bug has emerged - on that same faulty data stream I cannot ‘Erase data’ - when I do:

  1. I am left with a few points several hours ago
  2. The ‘live’ display will not scroll to the present time - it will only scroll UP TO the data points of several hours ago that will not erase.

I have to ask - has anything changed server side? Simply because this was 100% reliable for two weeks, and now will not work at all…

Can you post your latest code?

Pete.

//HUMIDITY and TEMPERATURE WIRELESS SENSOR
/**************************************************************
 * VERSION HISTORY
 * Vn2 includes correction for crap sensor used for humidity 
 * Vn3 includes more notes and code tidied, delays added to reduce power consumption
 * Vn4 includes DEEP SLEEP tests
 * Vn5 code rewritten 
 * Vn6 adjustments to ensure deepSleep works as equired and seruial output is clean
 * Vn7 FOR ESP-12F ONLY
 * Vn8 DEBUG for Blynk temp bug
 * Vn9 - rewritten with Blynkwrite in the loop code
 * Vn10 - moved wifi connect to inside loop
 */

// #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
//LIBRARIES
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

// WiFi network authorisation
// You should get Auth Token in the Blynk App, and this will also be emailed to you
char auth[] = "REDACTED"; //Enter the Auth code which was sent by Blink

// WiFi network details 
// NOTE only 2.4GHz is used
// Set password to "" for open networks.
char ssid[] = "REDACTED";  //Enter your WIFI Name
char pass[] = "REDACTED";  //Enter your WIFI Password

// SENSOR DETAILS
// This line defines which pin will get used to accept the DATA from the sensor
#define DHTPIN 0          // Digital pin 0 *****ESP-12F mod

// UNcomment the type of temp and humidity sensor in use
// INFO: DHT11 is readable every ONE second, DHT22 every TWO seconds
// INFO: DHT11 RH +/-5%, range 20-90%, resolution 1%; Temp +/-2degC, range 0-50degC,resolution 1 degC
// INFO: DHT22 RH +/-2%, range 0-100%, resolution 0.1%; Temp +/-0.5degC, range -40 - 80degC, resolution 0.1 degC
//#define DHTTYPE DHT11     // DHT 11
#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

// DEFINE VARIABLES
// variables h, t, and f, for humidity, temperature in celcius and temperature in fahrenheit
float h;
float t;
float f; //not used degF
float c; //CORRECTION for HUMIDITY if DHT11 used
int d;


// FUNCTION to read data from the SENSOR
DHT dht(DHTPIN, DHTTYPE);


// FUNCTION to read data from SENSOR
void sendSensor()
{
  h = dht.readHumidity();
  t = dht.readTemperature(); 
  //f = dht.readTemperature(true) for Fahrenheit
  c = 0; // ASSIGN the correction, POSITIVE if sensor OVER-READS
  d = 2000; //the delay to be used at end of loop to stop anything else happening
  
// Check if any reads failed and exit early (to try again)

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }


}

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
  
}

void loop()
{
  Blynk.run(); // Initiates Blynk
  Blynk.begin(auth, ssid, pass);
  dht.begin();
  // timer.run(); // Initiates the timer - TEMP DISABLED
  sendSensor(); // Pulls data from DHT sensor
  //send the data values to Blynk
  delay(100);
  Blynk.virtualWrite(V6, t);  //V6 is for Temperature NOTE degC is assumed here, change code throughout if you use degF and variable f
  Blynk.virtualWrite(V5, (h-c));  //V5 is for Humidity
  Blynk.run(); // makes sure it has run
  // The following serial code allows you to ensure that you are getting valid readings which can be checked when connected via USB
  Serial.print("Humidity: ");
  Serial.print(String(h).c_str());
  Serial.println(" %");
  Serial.print("Temperature: ");
  Serial.print(String(t).c_str());
  Serial.println(" C"); 
  // REMEMBER to set any 'offline alerts' in Blynk Projects to EXCEED the read time delay  
  ESP.deepSleep(60e6-d); // DEEP SLEEP for 60 seconds less delay
  delay(d);
}

Try adding a 100ms delay between the two Blynk.virtualWrites.

The Blynk run before the Blynk.begin is redundant.

Pete.

Ok, edited accordingly, will report back Pete. thanks.