I’m trying to to build the bidirectional energy meter per Solardunio blog page using NodeMCU, 16 channel Analog Multiplexer and split core current sensor HSTS016L. I was able to get the reading show up on the Blynk app but all the data stop update after few seconds for minutes (random time). I have tried to power cycle, replace and reprogram the NodeMCU but problems still exist.
Does anyone know what stop the Blynk to receive the data? (all my other Blynk project still dipslay the live data fine, running on local Blynk server)
Below is the code from Solarduino:
/* 0.2- Blynk RTC */
BlynkTimer blynkTimer;
long interval = 5000; // Duration for uploading values to Blynk server in milli seconds (upload every 5 seconds)
int DCVoltageWait = 1; /* Switching variable for DC Voltage */
int DCCurrentWait = 1; /* Switching variable for DC Current */
int DCPowerWait = 1; /* Switching variable for DC Power */
int DCEnergyWait = 1; /* Switching variable for DC Energy */
int ACVoltageWait = 1; /* Switching variable for AC Voltage */
int ACCurrentWait = 1; /* Switching variable for AC Current*/
int ACPowerWait = 1; /* Switching variable for AC Power */
int ACEnergyWait = 1; /* Switching variable for AC Energy */
int ACFrequencyWait = 1; /* Switching variable for frequency */
int multiplexerWait = 1; /* Switching variable for 16 channel multiplexer */
/* 0.3- 16-Channel Multiplexer */
#define S0 D0 /* Assign Multiplexer pin S0 connect to pin D0 of NodeMCU */
#define S1 D1 /* Assign Multiplexer pin S1 connect to pin D1 of NodeMCU */
#define S2 D2 /* Assign Multiplexer pin S2 connect to pin D2 of NodeMCU */
#define S3 D3 /* Assign Multiplexer pin S3 connect to pin D3 of NodeMCU */
#define SIG A0 /* Assign SIG pin as Analog output for all 16 channels of Multiplexer to pin A0 of NodeMCU */
float DC_Voltage; /* Assign the variable as analog output value from Channel C0 */
float DC_Current; /* Assign the variable as analog output value from Channel C1 */
float AC_Voltage; /* Assign the variable as analog output value from Channel C2 */
float AC_Current; /* Assign the variable as analog output value from Channel C3 */
unsigned long channelLastSample = 0; /* Time variable for multiplexer */
/* 0.4 - Initial Offset Function */
float initialAnalogOffset = 4; //4 // Analog Value displayed when sensor provides 0V output - use potentiometer to calibrate multiplexer
float voltageAtAnalogMax = 3.153; //3.16 - 3.289 // Voltage Value measured when sensor provides analog value of 1024 (max) - use potentiometer and multimeter
float analogOffset = ((1024 - initialAnalogOffset) / 1024)*(voltageAtAnalogMax / 3.3) ; /* Variable for offset*/
int initialOffsetWait = 1; /* Switching variable for initial offset */
unsigned long initialOffsetLastSample = 0; /* Time variable for initial offset */
/* 1- DC Voltage Measurement */
float voltageSampleReadDC = 0; /* to read the analog sensor of a sample*/
float voltageSampleSumDC = 0; /* accumulation of sample readings */
float voltageSampleCountDC = 0; /* to count number of sample. */
float voltageMeanDC ; /* to calculate the average value from all samples*/
float finalVoltageDC =0; /* shows the final voltage reading*/
float supplyVoltageDC = 3.3; /* maximum measuring voltage of micro-controller , default 5V for UNO, 3.3V for NodeMCU*/
float R1 = 20000; //19890 // Input resistance value for R1 (in ohm) based on Voltage Divider Method (Based on the wiring diagram)
float R2 = 1000; //987 // Input resistance value for R2 (in ohm) based on Voltage Divider Method (Based on the wiring diagram)
unsigned long DCVoltageLastSample = 0; /* Time variable for DC Voltage */
/* 2- DC Current Measurement */
float mVperAmpValueDC = 3.123; // For example, a 20A Hall-Effect Current Transformer rated at 20A, 2.5V +/- 0.625V, mVperAmp will be 625 mV / 20A = 31.25mV/A
float supplyVoltageCDC = 3300; //3300 -3289 // maximum measuring voltage of micro-controller , default 5000mV for UNO, 3300mV for NodeMCU*/
float currentSampleReadDC = 0; /* to read the analog sensor of a sample*/
float currentSampleSumDC = 0; /* accumulation of sample readings */
float currentSampleCountDC = 0; /* to count number of sample. */
float currentMeanDC ; /* to calculate the average value from all samples*/
float finalCurrentDC ; /* the final current reading without adding offset value*/
float DC_Current_Calibrate=0; /* variable for DC Current Offset */
unsigned long DCCurrentLastSample = 0; /* Time variable for DC Current */
/* 3- DC Power Calculation */
float finalPowerDC; /* Variable for DC Power Value */
/* 4- DC Energy Calculation */
float finalEnergyDC; /* Variable for instantaneous energy unit */
float netEnergyDC = 0; /* Variable for accumulated net energy */
float importEnergyDC = 0; /* Variable for accumulated import energy */
float exportEnergyDC = 0; /* Variable for accumulated export energy*/
/* 5- AC Voltage Measurement */
float R3 = 200; // Input resistance value for R3 (in ohm) based on Voltage Divider Method (Based on the wiring diagram)
float R4 = 330; // Input resistance value for R4 (in ohm) based on Voltage Divider Method (Based on the wiring diagram)
float voltageSampleReadAC = 0; /* to read the analog sensor of a sample including voltageOffset1 */
float voltageSampleSumAC = 0; /* accumulation of sample readings */
float voltageSampleCountAC = 0; /* to count number of sample. */
float voltageMeanAC ; /* to calculate the average value from all samples, in analog values*/
float RMSVoltageMeanAC ; /* square roof of voltageMean without offset value, in analog value*/
float adjustRMSVoltageMeanAC; /* RMS including voltageOffset2 */
float FinalRMSVoltageAC; /* final voltage value with offset value*/
float voltageOffset1AC =0.00 ; /* variable for 1st offset value*/
float voltageOffset2AC = 0.00; /* variable for 2nd offset value*/
float VACResistor; /* Multiplication or reduction based on voltage divider method*/
float waveformMagnification = 1.5; // Vac waveform reduction factor to prevent waveform distortion near to limit. 2 means waveform reduced by 50%.
unsigned long ACVoltageLastSample = 0; /* Time variable for AC Voltage */
/* 6- AC Current Measurement */
float mVperAmpValueAC = 31.25; // For example, a 50A Hall-Effect Current Transformer rated at 50A, 2.5V +/- 0.625V, mVperAmp will be 625 mV / 50A = 12.5 mV/A
float supplyVoltageAC = 3300; /* maximum measuring voltage of micro-controller , default 5000mV for UNO, 3300mV for NodeMCU*/
float currentSampleReadAC = 0; /* to read the analog sensor of a sample including current Offset value*/
float currentSampleSumAC = 0; /* accumulation of sample readings */
float currentSampleCountAC = 0; /* to count number of sample. */
float currentMeanAC ; /* to calculate the average value from all samples, in analog values*/
float RMSCurrentMeanAC ; /* square roof of currentMean, in analog values */
float FinalRMSCurrentAC ; /* the final RMS current reading*/
float AC_Current_Calibrate=0; /* variable for AC Current Offset */
unsigned long ACCurrentLastSample = 0; /* Time variable for AC Current */
/* 7- AC Power Calculation */
float voltageAC ; /* Variable for instantaneous AC Voltage Value */
float currentAC1 ; /* Variable for part of instantaneous AC Current Value */
float currentAC2 ; /* Variable for part of instantaneous AC Current Value */
float currentAC3 ; /* Variable for part of instantaneous AC Current Value */
float powerSampleReadAC=0; /* Variable for analog sample of AC Power */
float powerSampleSumAC = 0; /* accumulation of sample readings */
float powerSampleCountAC = 0; /* to count number of sample. */
float realPowerAC; /* final Real Power Value*/
float apparentPowerAC; /* Apparent Power Value*/
float powerFactorAC; /* Power Factor Value*/
unsigned long ACPowerLastSample = 0; /* Time variable for AC Power */
/* 8- AC Energy Calculation */
float finalEnergyAC; /* Variable for instantaneous energy unit */
float netEnergyAC = 0; /* Variable for accumulated net energy */
float importEnergyAC = 0; /* Variable for accumulated import energy */
float exportEnergyAC = 0; /* Variable for accumulated export energy */
/* 9- AC Frequency Calculation */
float frequencySampleReadAC; /* Variable for voltage analog waveform*/
float frequencyAC; /* Frequency Value */
float cycleNumber = 0; /* Variable to count cycle of waveform*/
int ACFrequencyState = 0; /* Switching state based on waveform*/
unsigned long startMillisAC = 0; /* Time variable for starting time*/
unsigned long currentMillisAC = 0; /* Time variable for every waveform*/
unsigned long ACFrequencyLastSample = 0; /* Time variable for Frequency calculation*/