Hi all,
my question is not too Blynk related, but the project uses Blynk and this is the best community i know for esp tinkering
So, i have this simple pulse counter that is reading the led pulses from my house energy meter and giving me a power reading and a total energy value.
It’s working on a battery and what i had was a 10000mAh power bank and an ESP-based board with usb input, which does the job though with a lot of conversion inefficiency.
The combination lasts me about 5 days.
I’m trying to use MODEM_SLEEP, but it seems ineffective and, with a 40% conversion inefficiency and assuming 10000mAh is accurate for the battery, the esp is requesting on average a little less than 40mA.
I’ve tried to implement light sleep and failed, but i couldn’t actually find any definitive answer on whether micros()
actually works when using light sleep, or how i can ensure steady wake-ups on pulses and light sleeping in between.
Can anyone suggest a way to save more power than the following code does?
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
// Blynk Token
char auth[] = "----";
// WiFi credentials.
char ssid[] = "----";
char pass[] = "----";
BlynkTimer timer;
uint32_t t;
uint32_t t_prev;
uint32_t count;
uint32_t count_yesterday;
float power;
bool reset_armed = false;
void setup()
{
WiFi.hostname("Contatore");
WiFi.mode(WIFI_STA);
WiFi.setSleepMode(WIFI_MODEM_SLEEP, 0);
WiFi.begin(ssid, pass);
ArduinoOTA.setHostname("Contatore");
ArduinoOTA.begin();
Blynk.config(auth, "claudiospinella.homepc.it", 8442);
t = micros();
t_prev = t;
pinMode(14, INPUT);
attachInterrupt(digitalPinToInterrupt(14), handleInterrupt, FALLING);
timer.setInterval(5000, timed);
}
void loop()
{
Blynk.run();
timer.run();
delay(250);
}
void handleInterrupt() {
t = micros();
if ((t - t_prev) > 20000) {
count++;
power = 3 * power / 4 + (360000000.0 / (t - t_prev) - power) / 4;
t_prev = t;
}
}
void timed() {
Blynk.virtualWrite(V1, ((double) count) / 10000);
Blynk.virtualWrite(V2, power);
ArduinoOTA.handle();
}
BLYNK_CONNECTED() {
Blynk.syncAll();
}
//Recover total energy from server
BLYNK_WRITE(V1) {
count = (int) 10000 * param.asDouble();
}
//Arm the reset button
BLYNK_WRITE(V3) {
reset_armed = param.asInt() > 0;
}
//Reset total consumption if armed
BLYNK_WRITE(V4) {
if (param.asInt() > 0 && reset_armed) {
count = 0;
}
}
//Trigger daily energy recap
BLYNK_WRITE(V5) {
if (param.asInt() > 0) {
Blynk.virtualWrite(V6, ((double)(count - count_yesterday)) / 10000);
Blynk.virtualWrite(V7, count);
Blynk.virtualWrite(V5, 0);
}
}
//Recover total as per the last daily recap
BLYNK_WRITE(V7) {
count_yesterday = (unsigned int) param.asLong();
}
Maybe useful detail: the pulse counter is giving me a LOW pulse of roughly 5-10ms duration.