EmonliteESP

Hey i found this nice library in internet. It works normally with my NodeMCU and my ACS712 current sensor. But unfortunatelly when i used it with the Blynk, there’s a “heartbeat error”. I have no idea what make this “heartbeat error” in this case. Any help and suggestion will apreciated, thanks!

emonliteESP library by xoseperez


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <Wire.h>
#include <Adafruit_ADS1015.h> 
#include "EmonLiteESP.h"              

char auth[] = "xxxxxxxx";
char ssid[] = "xxxxxxxx";
char pass[] = "xxxxxxxx";

SimpleTimer timer;
Adafruit_ADS1115 ads;           
EmonLiteESP power;

#define TestLED D4
#define relay D3

//emonliteesp
unsigned int adcBits = 16;      // ADC bit resoltion (normally 10)
double referenceVoltage = 5.0;  // 1.0V for a bare ESP8266 chip
double currentRatio = 18.5;     // 30A 1V for a YHDC SCT-013-030    
unsigned int samples = 1000;    // 1000 samples each time we measure
//----------   


int timer_emonlite;

//***********************************SETUP*********************************************//

void setup()
{
  Serial.begin(9600);
  Wire.begin(D2, D1);
  
  pinMode(TestLED,OUTPUT);
  pinMode(relay,OUTPUT);
  digitalWrite(TestLED,LOW);     // -> pakai led di nodemcu, HIGH=mati ; LOW=hidup
  digitalWrite(relay,LOW);
  
  power.initCurrent(currentCallback, adcBits, referenceVoltage, currentRatio);
  Blynk.begin(auth, ssid, pass);
  
  
  ads.setGain(GAIN_ONE);          // 1x gain   +/- 4.096V  1 bit = 2mV      0.125mV  
  ads.begin();
  
  Blynk.begin(auth, ssid, pass);
  
  timer_emonlite        = timer.setInterval(1000L, emonlite); 
}

//*************************************************************************************//

//**********************************FUNGSI2********************************************//

unsigned int currentCallback() 
{
   return ads.readADC_SingleEnded(1);
}

void emonlite()
{
  double current = power.getCurrent(samples);
  Blynk.virtualWrite(V8, current);
  
  Serial.print("Current now: "); Serial.print(current); Serial.println(" A");
}




//************************************************************************************//

//************************************LOOP********************************************//

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

//************************************************************************************//




Heartbeat error means something is taking up time from Blynk’s library, causing a missing heartbeat… and considering that it is usually 10 seconds, then I suspect your 1000 samples are being done over an even longer time period then that.

Or at least it is taking longer then your 1 second timer, and thus you are running multiple timers, each new one starting before the previous one is finished… build that up and it will also cause issues.

Try reducing the samples to 100 and/or increasing your timer.

i changed it and run it for about 5 minutes, there is no error. BIg thanks Gunner!

Nadua, can you help me with my circuit? I’m trying to use NodeMCU with ACS712 but I’m having difficulties in the circuit.

Please send me an email if it’s possible…
renatofr95@gmail.com

Thanks for a while…