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

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

1 Like

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

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.

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

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().

1 Like

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)

I think I was having a blonde moment when I wrote that because Blynk indicates the 10s I was looking for doesn’t include a X3 multiplier in the libraires.

There is though a library hack for faster connections. I’ll see if I can find it but the text of the thread referred to “5 seconds” from memory.

Here you go Blynk takes 3-4 seconds to connect to server

Hmmm … so what I did right now is I found where this values is. I found:
c:\Users\admin\Documents\Arduino\libraries\blynk-library-master\src\Blynk\BlynkProtocol.h
and I changed 5000UL to 10000UL, now the mentioned code part looks like:

#ifdef BLYNK_USE_DIRECT_CONNECT
        if (!tconn)
            conn.connect();
#else
        if (tconn && (t - lastLogin > BLYNK_TIMEOUT_MS)) {
            BLYNK_LOG1(BLYNK_F("Login timeout"));
            conn.disconnect();
            state = CONNECTING;
            return false;
        } else if (!tconn && (t - lastLogin > 10000UL)) {
            conn.disconnect();
            if (!conn.connect()) {
                lastLogin = t;
                return false;
            }

after this change I updatet the ESP code again to the dev board but still it seems connection time is the same. Around 6 secs from reboot and most waiting time is between “blynk picture” and [5001] connecting …
Does this hack works also when connecting to the Blynk cloud? Because in the refered topic I have seen a lot about home blynk server (what is not my case)

OMG, now I see I have one additional zero probably here. I am going to test with 1000 instead of 10000UL

\ OK, I am on 3 seconds now :heart_eyes::heart_eyes:

1 Like

I spotted it straight away. Blynk server is cloud unless the term “local” is mentioned.

Much better but still seems high.
Paste Serial Monitor.

you mean to paste what I see int he Serial monitor?

I cannot copy/paste, so just attaching printscreen

OK so the 3 seconds you referred to includes reading the temperature sensor. Not too bad. You should be able to cut another 500ms by dropping the 1000L library hack to 500L. From memory you can’t go much below this.

You should also upgrade to the latest Blynk version, 0.4.8, and then do the hack again.

Yes, I referenced 3 seconds to total time from reboot to 1st reading. Sounds great to me.
not sure if there is chance to save a few miliseconds by removing something from the code, but anyway there is a huge improvement (but we will see what will be the real battery lasting :slight_smile: )
I will try with 500UL as well.
So another task for me is to prepare small board with this sensor and try to solder tiny wire to ESP8266-01 to allow deepsleep - that will be again challenging :slight_smile:

Btw will be the connection faster in case I build my own Blynk server on Raspberry home? Maybe in the future I can imagine I will build also this setup with own Blynk. So no data outside the LAN (I am not sure if in case of home Blynk server I am paying for widgets or not)

It will be a little faster with a local server but it doesn’t make a huge difference.

You allocate the Energy yourself on a local server.

many thanks all there participating, especiall Costas.
I will keed you updated what progress I did and how long I was able to power the project on the one battery charge

hello!

i’m glad you’ve figured out the ds18 hookup. i know i’ve promised to help you with this stuff, but this week i was quite busy with lots of work to do.

your code seems much better than the old one.
maybe you could make bit faster by setting a lower resolution for the ds18. also, you could try the api method. and in final version for max speed of course remove all serial prints.

i will send you some code tomorrow for api, to test.

Hi gents,
just short status update.
These are measured voltage values on my 18650 battery

17.10 - 4,11V
28.10 - 4,08V
5.11 - 4,07V

2 Likes