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();
}
//************************************************************************************//