MKR1010 bogs down when cloud connected?

I have a MKR1010 on the latest FW. I have sketch that reads a switch and some humidity sensors. It displays status on the RGB led, a sequence of smooth flashes of different colours. I sorted it all out without any cloud connectivity, then added that part last. For whatever reason, the sketch runs its main loop about 100k times per second without the cloud and only around 25Hz when the cloud connection is operating. How is it slowing down by a factor of 10000.
I dumbed my sketch down to something that is a glorified version of Blink and the same thing happens. No idea what is going on.

Well first error I can see in your code is.... where's the code anyway? :wink:

And please add it as code, not plain text.

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/b107f3ce-d665-4979-b309-4ff7cc42cea7 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  int blue;
  int green;
  int red;

  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 <WiFiNINA.h>
#include <utility/wifi_drv.h>

unsigned long CurrentTime = 0;                          // CurrentTime
unsigned long LampUpdateTimer = 0;                      // Sets lamp delays

//
// Timing checks
//
unsigned long LoopSpeedTime = 0;                // Timer to check processing speed
unsigned long LoopCounter = 0;                  // Process cycles
unsigned long LoopSpeedTestDuration = 10000;    // How long test takes


void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(115200);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

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

  Serial.println(F("SetUp Running"));
  Serial.println();
  red = 128;
  green = 128;
  blue = 128;
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);

  WiFiDrv::pinMode(25, OUTPUT); //define red pin
  WiFiDrv::pinMode(26, OUTPUT); //define green pin
  WiFiDrv::pinMode(27, OUTPUT); //define blue pin
  
}

void loop() {
  ArduinoCloud.update();
  CurrentTime = millis();

  // Loop speed test
  LoopCounter += 1;                                                  // Increment counter each pass
  //if ( (CurrentTime - LoopSpeedTime) > LoopSpeedTestDuration) {
  if ( (CurrentTime - LoopSpeedTime) > 10000) {
    LoopSpeedTime = CurrentTime;
    Serial.println();
    Serial.print("Total loops counted: ");
    Serial.println(LoopCounter);
    //LoopCounter = LoopCounter / (LoopSpeedTestDuration/1000);        // Divide by integer seconds
    LoopCounter = LoopCounter / (10);        // Divide by integer seconds
    
    Serial.print("Arduino processing loops are at: ");
    Serial.print(LoopCounter);
    Serial.println(" Hz");
    Serial.println();
    LoopCounter = 0;                                                 // Reset counter
  }

  if ( (CurrentTime - LampUpdateTimer) > 500) {
    LampUpdateTimer = CurrentTime;
    WiFiDrv::analogWrite(25, red);
    WiFiDrv::analogWrite(26, green);
    WiFiDrv::analogWrite(27, blue);
    
  }
  
  
}


/*
  Since Red is READ_WRITE variable, onRedChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onRedChange()  {
  // Add your code here to act upon Red change
}

/*
  Since Green is READ_WRITE variable, onGreenChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onGreenChange()  {
  // Add your code here to act upon Green change
}

/*
  Since Blue is READ_WRITE variable, onBlueChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onBlueChange()  {
  // Add your code here to act upon Blue change
}

Sorry, never thought to add the code. I was thinking it must be a hardware thing. Anyway, the code is listed above. The other tabs are the auto generated ones.

A couple of suggestions what could be the problem.

  • Some interaction between the cloud code and Serial
  • The debug code
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();

I can try turning off Serial as an experiment. I will try raising the debug level see if anything pops up.