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

What is wrong with my project? (battery not lasting as long as expected)


#21

@wanek yes they look legit and I have the data tables ready for when the OP provides the up time. I did a rough calculation earlier based on a guess of the up time and it was similar to actual results.

@helpfinder setting the IP of your MCU will speed up connection times compared with DHCP. There is also a Blynk library hack for faster connections. If you don’t need humidity readings then DS18B20 is the way to go. Even at 12 bit resolution it’s only 750ms compared with 2000ms for the DHT22. Personally I would go with 9 bit resolution at 94ms for deepSleep.

Every second counts when you compare 80mA on time with 40uA off time.


#22

but if he uses the api, he do not have to use blynk library at all. according to @vshymanskyy, the api is the best option for battery powered blynking.

i can provide code for pushing data periodically to api.

@helpfinder, also consider to upload data only in every 10 minutes for a significantly longer battery life. uploading every 5 minutes is kinda useless, until you do not monitor the temperature of an atomic reactor…


#23

setting the IP of the MCU will still speed things up when using the API.


#24

ok, i didn’t know that!
i thought it is valid only with the library.


#25

It relates to the speed of the WiFi connection.


#26

I really appreciate how many comments is in this discussion trying to help me. Many thnaks

It seems to get connected to wifi takes 3-6 secs (not always the same time) and device is powered around 14 secs in total, then goes to sleep for 300 secs as I wrote.

I tried in the past implemens into this code static IP instead of DHCP so the connection time is faster, but I was not successful. Also that API recommandation … I am not sure if I am so skilled to do it myself. I am more enthustiastic than coder or electrotechnician, unfortunately.

Also I can try to use DS18B20, but then I am not sure about the code to upload to the ESP (maybe I can try to use the code from the link I posted in the first post here, but then it will not communicate with Blynk I guess, and I really wanted to have thisconnected to blynk as it is really handy and easy to use - also share with family members)

btw slightly different question, what do you think about battery life and what would be the best battery type pick to use one such a thermometer outside? Especially in the winter as cold weather will have impact on battery life. Here in the winter is usaualy aprox -5 degrees Celsius

btw2 - here on the forum see this topic and my comment where I used ESP8266-12E and measured 75mA and 2,5mA in the deepsleep - so way more than 40uA and the projests was working for one month on batteries (sure, sifferent batteries - 4xAA, but not sure if the battery type play so significant role here)


#27

I hate it I read about which batteries to use for outdoors and can’t find the exact reference. Normally I bookmark stuff like this. This is a start:

Choices of Primary Batteries

This is from a site called Battery University. You can probably find more than needed information. Best I recall it was Lithium Ion that had the best battery life in cold weather.


#28

this is because of a defaultly implemented delay in blynk lib. with the hack that @Costas talked about, you can reduce this, if you wish to go the library way

this is way to much for a low power application. if all you want to do is to push some data, it should be under 5 seconds!

these tasks are actually no big deal, i can help you with those. if you wish, just post your latest code properly formatted, to see what you’ve got so far.

using ds18 instead of dht has another advantage, that you can hook up lots of sensors to a single digital pin, measuring temp on multiple places. they also tolerate quite well longer cable runs. i do not know the scenario where you want to use these units, but you should consider placing the mcu + battery inside, and just the sensors outside via a wire. than the battery can last longer…

just stick with ORIGINAL panasonic / sanyo / samsung / sony / lg cells, 18650. currently the highest REAL capacity you can get is around 3200-3400mah. anything above that is fake bullshit. forget the chinese 8000mah cells.

in europe you can get at decent prices original 18650 panasonic cells at tme.eu


#29

yeah, battery university is a quality source.
i also use it often.


#30

you mean to set a static ip in the router for the respective mcu?


#31

So possible approximate calculation if you are saying total up time is 14s

14s @ 80mA = 1120mA
300s X 98% (deepSleep actual time) X 0.040ma = 12mA

Total mA 1132 every 308 (14 + 300 - 6) seconds. So average consumption rate is 3.7mA

For a 3400 mAh battery the Digi-Key battery life calculator at https://www.digikey.ca/en/resources/conversion-calculators/conversion-calculator-battery-life gives 643 hours approx 27 days.

If the 14s was as long as 16s due to WiFi connection sometimes being 6s not 3s then it’s approx 24 days.

So it’s broadly similar to your actual result.

Taking a 5s uptime and a real 10 minute sleep (10.2 deepSleep) it would be:

5s @ 80mA = 400mA
600s @ 0.04mA = 2.4mA

Total mA 402.4 every 605s, average consumption rate down to 0.67mA (3552 hours, 148 days).
The huge improvement is primarily down to the much lower up time, down time changes are not too important at the negligible mA involved.

I would probably factor in a further 50% reduction for the 148 days down to 74 days because I know from experience that I never achieve anywhere near calculated rates.


Recommend temp sensor for esp8266 deep sleep
#32

@wanek the IP can be fixed in the router but this is what I do:

// FixedIP_ESP.ino for ESP8266

#include <ESP8266WiFi.h>

IPAddress ip(192, 168, 1, 128);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress DNS(192, 168, 1, 1);

char ssid[]       = "xxxx";
char pwd[]        = "xxxx";

void setup()
{
  Serial.begin(115200);
  Serial.print("\nRebooted at: ");
  long starttime = millis();
  Serial.println(starttime);
  WiFi.config(ip, gateway, subnet, DNS);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pwd);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");  // not required, just used for effect
    delay(1);
  }
  long endtime = millis();
  Serial.print("\nConnection took: ");
  Serial.print(endtime - starttime);
  Serial.println(" ms");  // approx 150ms v 1000ms+ with DHCP
}

void loop(){
  yield();  
}

#33

thanks!


#34

Thanks. :smile: This is one of those things I wish they could pin somewhere as helpful code.


#35

On the subject of non-protected batteries: https://www.youtube.com/watch?v=1rg3ZWxBNUE


#36

Sorry guys to not respond a few days, I had really hard week and no time for ESP

Many thanks again all for you, I like how this topic goes and for all your helpful tips

I would like to have a humidity as well measured, but when I have to decide humidity vs. battery lasting I choiose battery.

So I am going to order sensor from ebay as I am not able to buy it anywhere locally in the store (ppitty is that it will take a few weeks undtil I receive sensor(s))

@Costas - thank you for your calculation, that 74 days sounds promising, my desired life time was about 3 minths and this is close (btw do you have experience with battery CR123A? I see these are used in Fibaro sensors, but also it seems it is only 3V, what is probably low limit for ESP8266-01)

I used the same or very similar code to have static (not DHCP IP address) but it does not work. I could try to do a MAC reservation on the router, I am not sure if the connect time is the same (fast) ans with the code with static IP

@wanek - what do you mean by post code properly formatted? I am using the code as I provided in the 1st post. If there is a way how to optimize the code and make it working with DS18B20 and Blynk then I would appreciate really a lot


#37

i will be busy in next days, but i will take a look at your code and will help implementing ds18.
you anyway have to wait for the sensors, so i guess it is not very urgent.


#38

Hi guys,
so I was able to find a local store where they have DS18 (but what a price, 2,30€ per piece, on ebay I ordered 5 pcs for such a price, and guess what - first I bought I mistakely connected wrong way so there was a little smoke in the room, so I can say I have 1 working DS18 for 4,60€, what a deal, nevermind :smile: )

So I started with some tests. It seems I was able to implement proper code for DS18 (right now I am working on ESP8266-12E dev board because it is more comfortable to play with connections on this board, but I guess all what is applicable on 12E is also on ESP8266-01 which I want to use in my final setup). I have to check power consumption of 12E, but I would say it will be higher than 01 model so not so convinient for funal product (guessing)

Code looks like this:

#define BLYNK_PRINT Serial 
#include <ESP8266WiFi.h> 
#include <BlynkSimpleEsp8266.h> 
#include <OneWire.h> 
#include <DallasTemperature.h> 

#define ONE_WIRE_BUS D2 

OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire); 

char auth[] = "xxxxx"; 
char ssid[] = "xxx"; 
char pass[] = "xxx"; 

void setup() 
{ 
Serial.begin(115200); 
Blynk.begin(auth, ssid, pass); 
sensors.begin(); 

} 

void sendTemps() 
{ 
sensors.requestTemperatures(); 

float temp = sensors.getTempCByIndex(0); 
Serial.println(temp); 
Blynk.virtualWrite(V20, temp); 
ESP.deepSleep(60000000);

} 

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

So now I have connection to Blynk and I can see the temp value in the Blynk app on the cell phone. Also I see that deepsleep is working and after I see value in serial monitor ESP goes for 60 secs to sleep.
I tried to implement static IP into this code, but no success, I have seen several syntaxes, but none worked for me. Not sure where I did the mistake.
Anyway I measured time how long after reboot ESP sends first temp value and it seems the time is the same when ESP obtains IP from DHCP or I have on my router set mac reservation for the ESP - around 6 secs time from reboot to get 1st value in both cases

Also what I found out is not to good connection quality between wifi router and ESP - firstly I thought problem is I am too far from the wifi router, but the results were the same when I put ESP next to router. I am not sure if this is problem or why ESP has such a poor pings (see printscreen attached):

So not sure what could be the next steps. Decrease time ESP is alive by static IP in the code? Other code optimalization? Here we come to the point I am total noob :blush:

Thank you all


#39

Presumably you are doing the pings with deepSleep disabled. They do look bad.

Take a look back at the fixed IP code but then instead of:

Blynk.begin(auth, ssid, pass);

use:

Blynk.config(auth);
Blynk.connect();

I always put sensors.begin() as the first line ofsetup() as you don’t want to wait until the connection to the server is made before enabling the DS18B20.

I would also call sendTemps() as the last line of setup() rather than in loop().


#40

Hi masters,
so I tried to edit the code as smart as I can do (I can not much :slight_smile:) and here is the result I uploaded into ESP (at least I did not get any compilation errors (yay))

#define BLYNK_PRINT Serial 
#include <ESP8266WiFi.h> 
#include <BlynkSimpleEsp8266.h> 
#include <OneWire.h> 
#include <DallasTemperature.h> 

#define ONE_WIRE_BUS D2 

OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire); 

char auth[] = "xxxxx"; 
char ssid[] = "xxx"; 
char pass[] = "xxx";
IPAddress ip(192, 168, 16, 166);
IPAddress gateway(192, 168, 16, 254);
IPAddress subnet(255, 255, 255, 0);
IPAddress DNS(8, 8, 8, 8);

void setup() 
{ 
sensors.begin(); 
Serial.begin(115200);
  Serial.print("\nRebooted at: ");
  long starttime = millis();
  Serial.println(starttime);
  WiFi.config(ip, gateway, subnet, DNS);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");  // not required, just used for effect
    delay(1);}
Blynk.config(auth);
Blynk.connect(); 
sendTemps();

} 

void sendTemps() 
{ 
sensors.requestTemperatures(); 

float temp = sensors.getTempCByIndex(0); 
Serial.println(temp); 
Blynk.virtualWrite(V20, temp);
ESP.deepSleep(30000000); 

} 

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

based on measurements it seems it is still around 6 seconds from time I reboot ESP by button until the first temp value is shown in the serial monitor. Basically the most time is spend (it seems like that) until I get [5001] Connecting to blynk-cloud.com:8442. Time between I see the “blynk picture” and Connecting to blynk-cloud is approximately 4 seconds

is this somehow connected with that statement blynk has some default timer until it connects to wifi, and this can be bypassed? I have seen in another Costas topic something like:
Blynk.connect(3333)


BME280 in Blynk