ArduinoCloud mem use - mkrgsm - seems high

I’d like to use the cloud / dashboard so did some work on available memory. My application requires (hopefully) both SMS and cloud. In doing the calcs I used the freememory util (https://github.com/mpflaga/Arduino-MemoryFree) . What I found is the following, and it seems odd, so looking for some advice.

  1. Using the code snippet - with no calls to the “cloud” but using arduino.cc - mem left is 9047 (27% mem left if you use 32768 for 32k) - 27% free, so setting up the cloud takes 73% of memory.
  2. Adding the calls to arduinoCloud.begin/update mem left is 2651. (takes another 19.5%) so, there is only 8.5% room left to write code in AND this is with no cloud variables, so no wonder applications are running out of memory !

Using the SAME code snippet on IDE (no calls to cloud of course, and had to manually add in the PIN/etc) leaves 29183 mem available (89% free).
Using the “cloud” takes the diffference of 89% free to 8.5% free or, 80% of memory just to START using the cloud.
This severely limits my use of the cloud. Am I doing something wrong here with the snippet?
(note: I’ve removed all my “other” code to do the comparisons so there are lots of “if docloud stuff” there.

thanks for any help

/*
  Sketch generated by the Arduino IoT Cloud Thing "AMB"
  https://create.arduino.cc/cloud/things/2dc4a084-3188-459a-8a3e-b9ffede9c552

  Arduino IoT Cloud Variables description

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


  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.
*/


#define DEBUG    1          // set to '1' for debug prints  
#define DOCLOUD  1         // set to '1' to  send data to cloud in arduinoupdate. set to 0 then can uncomment flash 

#ifdef DEBUG
#define DEBUG_PRINTLN(x)  Serial.println(x)
#define DEBUG_PRINT(x)  Serial.print(x)
#else
#define DEBUG_PRINTLN(x)
#define DEBUG_PRINT(x)
#endif


#include "thingProperties.h"

// Include the GSM library
#include <MKRGSM.h>

//FreeMemory function for debugging  (can remove, and remove all calls in functions/main)

#ifdef __arm__
// should use uinstd.h to define sbrk but Due causes a conflict
extern "C" char* sbrk(int incr);
#else  // __ARM__
extern char *__brkval;
#endif  // __arm__

int freeMemory() {
  char top;
#ifdef __arm__
  return &top - reinterpret_cast<char*>(sbrk(0));
#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
  return &top - __brkval;
#else  // __arm__
  return __brkval ? &top - __brkval : &top - __malloc_heap_start;
#endif  // __arm__
}


// initialize the library instance
GSM gsmAccess;  // (true);      // (true) enables debugger?
GSM_SMS sms;                    // For sending/receiving SMS
GPRS gprs;                      // data over connection
GSMScanner carrier;             // carrier and signal level (avail on SMS command and if lcd)



void setup() {
  
  Serial.begin(9600);

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  if (DOCLOUD) {
    initProperties();
    delay(500);
  }
  
 
  if (DOCLOUD) {
    // Connect to Arduino IoT Cloud
    ArduinoCloud.begin(ArduinoIoTPreferredConnection);

    setDebugMessageLevel(4);
    ArduinoCloud.printDebugInfo();
  }

  bool gsmConnected = connectGSM();
  // connectGSM
  DEBUG_PRINT("GSM initialized and");
  if (gsmConnected) {
    DEBUG_PRINTLN(" connected.");
  }
  else {
    DEBUG_PRINTLN(" FAILED to connect. Please Re-start.");
  }

   if (DOCLOUD) {
    while (ArduinoCloud.connected() != 1) {
      ArduinoCloud.update();
      delay(150);
    }
  }


}

void loop() {
  if (DOCLOUD) {
 
    ArduinoCloud.update();
  }
  

  digitalWrite (LED_BUILTIN, HIGH); //turn the LED on
  delay(200);
  digitalWrite (LED_BUILTIN, LOW);  //turn the LED off
  delay(200);
  Serial.print(freeMemory());
  delay(1000);



}


bool connectGSM() {
  // 02.17 copied from github and modified to fit.
  // https://github.com/arduino-libraries/MKRGSM/issues/66
  // re-call of this will cause arduino mqtt to disconnect.
  gprs.setTimeout(180000);
  gsmAccess.setTimeout(180000);

  boolean connected = false;
  while (!connected) {
    DEBUG_PRINT("connectGSM:Begin GSM Access....");

    if ((gsmAccess.begin() == GSM_READY) &&
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
      connected = true;
      DEBUG_PRINTLN("... Success");
    }
    else {
      DEBUG_PRINTLN("...failed - Not connected");
      delay(1000);
    }
  }
  return connected;
}

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