Hi, this is probably a simple fix but is frustrating the hell out of me, I’m not a pro at this by any means. All I was after is a simple code that I can use two CT clamps to compare wattage (with out a voltage sensor so I’ll multiply by 240v). I have suscessfully used the arduino sketch from emonlib.h and adapted for 2x ct clamps. The serial monitor gives me the values fine on esp32 now trying to go mobile with blynk app, every you tube videos says it’s easy but I’m struggling, especially how to implement virtual pins with real pins and how they don’t correlate.
Please find my code and error message any help would be greatly appreciated
/*************************************************************
You’ll need:
- Blynk IoT app (download from App Store or Google Play)
- ESP32 board
- Decide how to connect to Blynk
(USB, Ethernet, Wi-Fi, Bluetooth, ...)
There is a bunch of great example sketches included to show you how to get
started. Think of them as LEGO bricks and combine them as you wish.
For example, take the Ethernet Shield sketch and combine it with the
Servo example, or choose a USB sketch and add a code from SendData
example.
*************************************************************/
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID "TMPLQPQz8rzC"
#define BLYNK_DEVICE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "ROm1XzZNz8BMEEFeWQN4LA0JD2FRJ6g8"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial\
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "EmonLib.h" // Include Emon Library
#define EnergyMonitor emon1.current; // Create an 1st instance
#define EnergyMonitor emon2.current; // Create an 2nd instance
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "HUAWEI P30";
char pass[] = "7a7312850689";
BlynkTimer timer;
void myTimerEvent() {
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V7, emon1.current);
Blynk.virtualWrite(V6, emon2.current);
}
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
emon1.current(32, 111.1); // Current: input pin, calibration.58.6
emon2.current(33, 111.1); // Current: input pin, calibration.58.6
timer.setInterval(1000L, sendSensor);
}
void loop()
{
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
double Irms1 = emon1.calcIrms(2280); // Calculate Irms only
double Irms2 = emon2.calcIrms(2280); // Calculate Irms only
Serial.println(Irms1*240.0);
Serial.println(Irms2*240.0);
Blynk.run();
timer.run();
}
Error message
C:\Users\MuscatP\OneDrive - DOTCS\Documents\Arduino\libraries\Solar_Diverter_Simple\Solar Diverter Simple_Blynk\Solar Diverter Simple_Blynk.ino: In function 'void myTimerEvent()':
C:\Users\MuscatP\OneDrive - DOTCS\Documents\Arduino\libraries\Solar_Diverter_Simple\Solar Diverter Simple_Blynk\Solar Diverter Simple_Blynk.ino:51:26: error: 'emon1' was not declared in this scope
Blynk.virtualWrite(V7, emon1.current);
^~~~~
C:\Users\MuscatP\OneDrive - DOTCS\Documents\Arduino\libraries\Solar_Diverter_Simple\Solar Diverter Simple_Blynk\Solar Diverter Simple_Blynk.ino:52:26: error: 'emon2' was not declared in this scope
Blynk.virtualWrite(V6, emon2.current);
^~~~~
C:\Users\MuscatP\OneDrive - DOTCS\Documents\Arduino\libraries\Solar_Diverter_Simple\Solar Diverter Simple_Blynk\Solar Diverter Simple_Blynk.ino: In function 'void setup()':
C:\Users\MuscatP\OneDrive - DOTCS\Documents\Arduino\libraries\Solar_Diverter_Simple\Solar Diverter Simple_Blynk\Solar Diverter Simple_Blynk.ino:66:2: error: 'emon1' was not declared in this scope
emon1.current(32, 111.1); // Current: input pin, calibration.58.6
^~~~~
C:\Users\MuscatP\OneDrive - DOTCS\Documents\Arduino\libraries\Solar_Diverter_Simple\Solar Diverter Simple_Blynk\Solar Diverter Simple_Blynk.ino:67:2: error: 'emon2' was not declared in this scope
emon2.current(33, 111.1); // Current: input pin, calibration.58.6
^~~~~
C:\Users\MuscatP\OneDrive - DOTCS\Documents\Arduino\libraries\Solar_Diverter_Simple\Solar Diverter Simple_Blynk\Solar Diverter Simple_Blynk.ino:69:26: error: 'sendSensor' was not declared in this scope
timer.setInterval(1000L, sendSensor);
^~~~~~~~~~
C:\Users\MuscatP\OneDrive - DOTCS\Documents\Arduino\libraries\Solar_Diverter_Simple\Solar Diverter Simple_Blynk\Solar Diverter Simple_Blynk.ino: In function 'void loop()':
C:\Users\MuscatP\OneDrive - DOTCS\Documents\Arduino\libraries\Solar_Diverter_Simple\Solar Diverter Simple_Blynk\Solar Diverter Simple_Blynk.ino:79:18: error: 'emon1' was not declared in this scope
double Irms1 = emon1.calcIrms(2280); // Calculate Irms only
^~~~~
C:\Users\MuscatP\OneDrive - DOTCS\Documents\Arduino\libraries\Solar_Diverter_Simple\Solar Diverter Simple_Blynk\Solar Diverter Simple_Blynk.ino:80:18: error: 'emon2' was not declared in this scope
double Irms2 = emon2.calcIrms(2280); // Calculate Irms only
^~~~~
Multiple libraries were found for "WiFi.h"
Used: C:\Users\MuscatP\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\libraries\WiFi
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
exit status 1
Compilation error: 'emon1' was not declared in this scope