Core should keep running or be able to start even w/o Cloud access

I presume this code is in loop()?

Can you simply call Spark.connect() only once and output the result of Spark.connected() to serial? :smile:

Iā€™m just thinking if Wifi.on() and Spark.Connect() got called repeatedly somehow since i cannot see your entire code and where this are being executed

No, it is in a separate function and only called once.
I will try your suggestion to print the output to Serial.

I removed the do while loop and added this code:

	Serial.print("Before Spark.connect(): ");
Serial.println(Spark.connected());
Spark.connect(); // Connect to the Spark Cloud
delay(1000);
Serial.print("After Spark.connect(): ");
Serial.println(Spark.connected());

The result at the Serial output is:

Before Spark.connect(): 0

So no Serial output after the Spark.connect(). Still the same kind of RGB flashing (red SOS?).

1 Like

Hmm, the red SOS is the firmware panic code telling you something crashed (ran out of memory, fault, etc)ā€¦

Iā€™m going to guess itā€™s running out of ram, since the cloud handshake is fairly memory intensive. Are you allocating large arrays or lots of objects?

@Dave If I look at the outcome of the compiler the memory usage seems to be within the limits:

Invoking: ARM GNU Print Size
arm-none-eabi-size --format=berkeley core-firmware.elf
text data bss dec hex filename
91548 3020 12980 107548 1a41c core-firmware.elf

Is there another way to check the memory usage of the firmware?

@nika8991, I just tested the above code in setup() with the LED part commented. It worked fine on my side. What else apart from this code are you trying to run ?

@satishgn, there is more code, it is a statemachine that does a number of steps. In the last step it gets the time from an NTP server and sends a status email.

Before I used the #include ā€œspark_disable_wlan.hā€ and ā€œspark_disable_cloud.hā€ the firmware ran successfully but with the start up delay of 4+ seconds. Then I included both include files and first tried to access the WiFi, that went okay (the firmware was able to get the time, send the email and the start up was roughly 1 sec.). After that I added the connection to the Cloud and got the red SOS after successful WiFi access. As @Dave already mentioned it might be a memory problem, but I like to know how to check that.

Thanks,
Henk

nika8991, if the linker output you included is correct, then the total statically allocated RAM is 3020+12980 = 16,000 or 0x3E80 which is under the 0x4000 (or so) limit. So to exceed available RAM, your program must be dynamically allocating extra RAM above and beyond the statically allocated RAM. I can review your code privately if you donā€™t wish to share it if that helps. :smile:

1 Like

You could try running this and seeing if your memory pushes up against the 20k limit.

Also, you might not see it get past like 15k used, 5k free because the background tasks are dynamically allocating and freeing RAM when your application is not running.

1 Like

Hmm. Battery Powered Portable Router; should do the trick. Before Long I will power my carā€™s electronics with my Smart Core.

@peekay123, it might be the dynamically allocated RAM that causes the problem. I do have a linked list with logging information that will be send in the mail to show all the steps that has been taken.

Thanks for the offer to review my ā€˜codeā€™ really appriciated, I will PM it to you.

1 Like

@BDub, I have added to code to the application and commented out the Leds and the delays, see below.

WiFi.on(); // Startup WiFi connection
Serial.print("After WiFi.on(), freeMemory()=");
Serial.println(freeMemory());
do {
	//yellowLed->on();
	wifiStatus = WiFi.status();
	//delay(500);
	//yellowLed->off();
	//delay(500);
}
while (wifiStatus != WIFI_ON); // Repeat until WiFi is connected

/* Begin problem
 * Here the part that causing the problem !!!!
 *
 */
    Spark.connect(); // Connect to the Spark Cloud
    Serial.print("After Spark.connect(),freeMemory()=");
    Serial.println(freeMemory());
	do {
		//yellowLed->on();
		cloudStatus = Spark.connected();
//		delay(500);
//		yellowLed->off();
//		delay(500);
	}
	while (cloudStatus == false); // Repeat until Spark Cloud is connected
    Serial.print("After Spark.connected() loop, freeMemory()=");
    Serial.println(freeMemory());
/*
 * End problem
 */

The result is:

After WiFi.on(), freeMemory()=17460
After Spark.connect(),freeMemory()=17460

It seems that the code doesnā€™t pass the while (cloudStatus == false); statement.
With these changes I donā€™t see the red SOS anymore but the RGB led keeps breathing green, I assume indicating connection to the WiFi.

Thanks,
Henk

Yep, you're correct.

Can you program Tinker on this Core and have it connect to the Cloud ok? Perhaps your credentials are wrong?

BDub, youā€™re right on the credentials. One thing to remember is that the wifi related buffers are pre-allocated during the core firmware startup so you wonā€™t see any memory changes with wifi.on and spark.connect. I think any memory problems my be related to the rest of his code and dynamic allocation. :smile:

1 Like

Actually, I was thinking Wifi credentialsā€¦ but that wouldnā€™t make sense as heā€™s seeing Breathing Green which indicates heā€™s connected to Wifi.

So it probably IS a dynamic memory allocation issue, most likely the AES handshake stuff with the Cloud.

Still a good question: Does Tinker work?

Seeing as a couple of months have now passed: just wondering if thereā€™s any solution now to remove the reliance on cloud?

Iā€™d like my Core to function on a WAN that has no internet connection.

Thank you.

@bufferout, though this is not yet documented (mostly because this will change), you can start your core without wifi or cloud by including one or both of these lines in your application:

#include "spark_disable_wlan.h"     //Turn off both wifi and cloud
#include "spark_disable_cloud.h"   //Turn off cloud only

Then in your code, you can turn wifi on and off using WiFi.on() and WiFi.off() while you can do the same with the cloud connection using Spark.connect() and Spark.disconnect(). :smile:

2 Likes