IoT Cloud + emon energy monitor w/ESP32

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();
}
1 Like

Hi!

When you say 'If I comment this out' I understand you mean when you comment the ArduinoCloud.update() line. Is that right?

What are the values that go to zero? The ones that you are serial printing or the variables currentIoT and energyIoT?

If it is the second case, how do you know that those variables go to zero (as you are not printing them)?

The values I am serial printing go to zero, not the ones associated with the ArduinoCloud.update function.

I did figure out the issue last night. I'm using a Wemos Lolin32 with a built in OLED display. I was originally using pin 2, then tried 4, then a few others and finally when I tried GPIO 39 it worked. So the issue must have been some pin incompatibility when using WiFi or some other function on the board.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.