Hello,
Whenever I include the ArduinoCloud.update function in my main loop, the values I'm reading in the serial monitor for current and energy go to zero and do no move when I activate a device. If I comment this out, I'm able to read the values just fine. I cannot find where the possible issue may be. My ultimate goal is to just show current and energy on the IoT app using Arduino cloud. Any help would be greatly appreciated! I'm using a Wemos LOLIN32 board.
// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/da4c8fae-e083-41c6-83ba-90341cb927e9
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float currentIoT;
float energyIoT;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include "EmonLib.h" // Include Emon Library
EnergyMonitor emon1; // Create an instance
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
emon1.current(2, 5.3); // Current: input pin, calibration.
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
//setDebugMessageLevel(2);
//ArduinoCloud.printDebugInfo();
}
void loop() {
double Irms = emon1.calcIrms(1480); // Calculate Irms only
Serial.print(Irms*230.0); // Apparent power
Serial.print(" ");
Serial.println(Irms); // Irms
currentIoT = Irms;
energyIoT = Irms * 230.0;
ArduinoCloud.update();
}