Where did my RAM go, loaded libraries and options

Hi All,

I've completed a few projects with the info found online and the assistance here. But I've now realized there are some basics that I don't know.

"Sketch uses 236,272 bytes (22%) of program storage space. Maximum is 1,044,464 bytes.
Global variables use 32,181 bytes (39%) of dynamic memory, leaving 49,739 bytes for local variables. Maximum is 81,920 bytes."

I've got a basic ESP 8266 v1 (sometimes called R2) board and can connect to Wifi and have it function as a web server.

  1. Is there a way to know what was loaded in that 39% of dynamic memory. Which modules were loaded as default? I noticed that with just a basic blink sketch that my ESP 8266 was broadcasting an SSID

  2. If I include something like <ESP8266Wifi.h> How do I know what are all the options that I can reference from that included module?

Which Arduino do you have?

I've got a basic ESP 8266 v1 (sometimes called R2) board

  1. Is there a way to know what was loaded in that 39% of dynamic memory.

Well, you could look at your code, as well as the code in all the libraries that you use.

Which modules were loaded as default?

Modules?

I noticed that with just a basic blink sketch that my ESP 8266 was broadcasting an SSID

You should look at the cpp file that is created from your ino file. I'm sure that it is doing far more than you think it is.

  1. If I include something like <ESP8266Wifi.h> How do I know what are all the options that I can reference from that included module?

Most people open the header file in a text editor, and have a look. I suppose you could also consult a psychic.

PaulS:
I've got a basic ESP 8266 v1 (sometimes called R2) board

The ESP8266 is a low-cost Wi-Fi chip with full TCP/IP stack and microcontroller capability produced by Shanghai-based Chinese manufacturer, Espressif.

That's not an Arduino.

But it can be programmed using the Arduino IDE.

Indeed, I am using the Arduino IDE to program my ESP8266.

PaulS:
Well, you could look at your code, as well as the code in all the libraries that you use.
Modules?

Even the basic sketch, without any inclusion of libraries says 39% of dyanmic memory. I'm just trying to find out what else is loaded. I've opened the ino file and it's only my sketch in there.

PaulS:
You should look at the cpp file that is created from your ino file. I'm sure that it is doing far more than you think it is.
Most people open the header file in a text editor, and have a look. I suppose you could also consult a psychic.

Can you advise where this cpp file is typically stored because I cannot find it. It's not in the directory that the .ino is.
Is there no diagnostic command in Arduino IDE to advist all the items being loaded/transferred to the device?

Can you advise where this cpp file is typically stored because I cannot find it. It's not in the directory that the .ino is.

Use Files + Preferences, and enable verbose mode for compiling. The IDE will then tell you where it put the resulting cpp file.

  1. This is not a particularly good place to ask ESP8266 questions, even if you're using it's "Arduino IDE support." Theoretically, these forums support official arduino.cc products, with "some support" for direct compatibles and derivatives (ie based on the same basic cpus), at least if they're properly tithing arduino.cc with support dollars. Since most of the support here comes from volunteers and hobbyists, you can frequently get "generic" support as well.
    The ESP modules are an interesting case. They're certainly not "counterfeits" or even clones of Arduinos, so they probably don't raise the same defensiveness that you might see if you asked about problems particular to a Sainsmart Mega. But on the other hand, we might be a bit jealous of those 1MB/80k memory limits on a $2 platform... (And of course the big problem is that not enough of us are actually USING ESP-based boards.)

  2. There's a tool called "nm" that should come with most gcc-based environments that will report in detail of the memory usage of an application, based on the .elf file (once you've found the build directory where the IDE stashes that.) It'll even sort things based on size. For example:

# initialized data (.data segment)
BillW-MacOSX-2<10039> [color=brown]avr-nm -SC --size-sort *.elf | grep -i ' d '[/color]
00800100 0000000a D images
0080010a 00000040 d aliases
# uninitialized data (.bss segment)
BillW-MacOSX-2<10040> [color=brown]avr-nm -SC --size-sort *.elf | grep -i ' b '[/color]
00800370 00000001 B target_pagesize
00800379 00000001 b timer0_fract
0080036e 00000002 B buff
00800375 00000002 B here
00800377 00000002 B pmode
0080036c 00000002 B target_flashptr
00800371 00000002 B target_startaddr
00800373 00000002 B target_type
0080037a 00000004 B timer0_millis
0080037e 00000004 B timer0_overflow_count
00800382 0000009d B Serial
0080016c 00000200 B target_code

The "avr-" prefix would be replaced by whatever the esp prefix is (tensilica?), and you probably need the full path, which is buried in some internal IDE directory.)

PaulS:
Use Files + Preferences, and enable verbose mode for compiling. The IDE will then tell you where it put the resulting cpp file.

Thanks Paul! This is exactly what I was after.

Curious, I only "included" a single ESP8266Wifi.h in my code, but saw this. Any idea where these other cpp

Using previously compiled file: /var/folders/3w/xywn18cd19143x7t_lck84_r0000gn/T/builde6fab12fa64a6c3d68fee4a3623b7d3c.tmp/libraries/ESP8266WiFi/ESP8266WiFi.cpp.o
Using previously compiled file: /var/folders/3w/xywn18cd19143x7t_lck84_r0000gn/T/builde6fab12fa64a6c3d68fee4a3623b7d3c.tmp/libraries/ESP8266WiFi/ESP8266WiFiAP.cpp.o
Using previously compiled file: /var/folders/3w/xywn18cd19143x7t_lck84_r0000gn/T/builde6fab12fa64a6c3d68fee4a3623b7d3c.tmp/libraries/ESP8266WiFi/ESP8266WiFiGeneric.cpp.o
Using previously compiled file: /var/folders/3w/xywn18cd19143x7t_lck84_r0000gn/T/builde6fab12fa64a6c3d68fee4a3623b7d3c.tmp/libraries/ESP8266WiFi/ESP8266WiFiMulti.cpp.o
Using previously compiled file: /var/folders/3w/xywn18cd19143x7t_lck84_r0000gn/T/builde6fab12fa64a6c3d68fee4a3623b7d3c.tmp/libraries/ESP8266WiFi/ESP8266WiFiSTA.cpp.o
Using previously compiled file: /var/folders/3w/xywn18cd19143x7t_lck84_r0000gn/T/builde6fab12fa64a6c3d68fee4a3623b7d3c.tmp/libraries/ESP8266WiFi/ESP8266WiFiScan.cpp.o
Using previously compiled file: /var/folders/3w/xywn18cd19143x7t_lck84_r0000gn/T/builde6fab12fa64a6c3d68fee4a3623b7d3c.tmp/libraries/ESP8266WiFi/WiFiClient.cpp.o
Using previously compiled file: /var/folders/3w/xywn18cd19143x7t_lck84_r0000gn/T/builde6fab12fa64a6c3d68fee4a3623b7d3c.tmp/libraries/ESP8266WiFi/WiFiClientSecure.cpp.o
Using previously compiled file: /var/folders/3w/xywn18cd19143x7t_lck84_r0000gn/T/builde6fab12fa64a6c3d68fee4a3623b7d3c.tmp/libraries/ESP8266WiFi/WiFiServer.cpp.o
Using previously compiled file: /var/folders/3w/xywn18cd19143x7t_lck84_r0000gn/T/builde6fab12fa64a6c3d68fee4a3623b7d3c.tmp/libraries/ESP8266WiFi/WiFiUdp.cpp.o
Using previously compiled file: /var/folders/3w/xywn18cd19143x7t_lck84_r0000gn/T/builde6fab12fa64a6c3d68fee4a3623b7d3c.tmp/core/cont.S.o

Here is my ESP8266 Webserver

#include <ESP8266WiFi.h>

//////////////////////
// WiFi Definitions //
//////////////////////
const char WiFiAPPSK[] = "sparkfun";

/////////////////////
// Pin Definitions //
/////////////////////
const int LED_PIN = 5; // Thing's onboard, green LED
const int ANALOG_PIN = A0; // The only analog pin on the Thing
const int DIGITAL_PIN = 12; // Digital pin to be read

WiFiServer server(80);

void setupWiFi() 
{
 WiFi.mode(WIFI_AP);

 // Do a little work to get a unique-ish name. Append the
 // last two bytes of the MAC (HEX'd) to "Thing-":
 uint8_t mac[WL_MAC_ADDR_LENGTH];
 WiFi.softAPmacAddress(mac);
 String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) +
                String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
 macID.toUpperCase();
 String AP_NameString = "ESP8266 Thing " + macID;

 char AP_NameChar[AP_NameString.length() + 1];
 memset(AP_NameChar, 0, AP_NameString.length() + 1);

 for (int i=0; i<AP_NameString.length(); i++)
   AP_NameChar[i] = AP_NameString.charAt(i);

 WiFi.softAP(AP_NameChar, WiFiAPPSK);
}

void initHardware()
{
 Serial.begin(115200);
 pinMode(DIGITAL_PIN, INPUT_PULLUP);
 pinMode(LED_PIN, OUTPUT);
 digitalWrite(LED_PIN, LOW);
 // Don't need to set ANALOG_PIN as input, 
 // that's all it can be.
}

void setup() 
{
 initHardware();
 setupWiFi();
 server.begin();
}

void loop() 
{
 // Check if a client has connected
 WiFiClient client = server.available();
 if (!client) {
   return;
 }

 // Read the first line of the request
 String req = client.readStringUntil('\r');
 Serial.println(req);
 client.flush();

 // Match the request
 int val = -1; // We'll use 'val' to keep track of both the
               // request type (read/set) and value if set.
 if (req.indexOf("/led/0") != -1)
   val = 0; // Will write LED low
 else if (req.indexOf("/led/1") != -1)
   val = 1; // Will write LED high
 else if (req.indexOf("/read") != -1)
   val = -2; // Will print pin reads
 // Otherwise request will be invalid. We'll say as much in HTML

 // Set GPIO5 according to the request
 if (val >= 0)
   digitalWrite(LED_PIN, val);

 client.flush();

 // Prepare the response. Start with the common header:
 String s = "HTTP/1.1 200 OK\r\n";
 s += "Content-Type: text/html\r\n\r\n";
 s += "<!DOCTYPE HTML>\r\n<html>\r\n";
 // If we're setting the LED, print out a message saying we did
 if (val >= 0)
 {
   s += "LED is now ";
   s += (val)?"on":"off";
 }
 else if (val == -2)
 { // If we're reading pins, print out those values:
   s += "Analog Pin = ";
   s += String(analogRead(ANALOG_PIN));
   s += "
"; // Go to the next line.
   s += "Digital Pin 12 = ";
   s += String(digitalRead(DIGITAL_PIN));
 }
 else
 {
   s += "Invalid Request.
 Try /led/1, /led/0, or /read.";
 }
 s += "</html>\n";

 // Send the response to the client
 client.print(s);
 delay(1);
 Serial.println("Client disonnected");

 // The client will actually be disconnected 
 // when the function returns and 'client' object is detroyed
}

From your output:

... /libraries/ESP8266WiFi/ESP8266WiFiGeneric.cpp ...

Your "libraries" folder sounds like a sensible place to start looking.

What I'm wondering is why loading the ESP8266Wifi.H loads 5-6 other libraries, possibly even stuff I don't need. I was thinking I have a lot of memory to utilize on these boards, but when it's 38% with a basic sketch, I got a bit concerned.

Thanks for the help everyone. Much appreciated.

The nature of memory usage is such that it will probably not grow by as much again if you add a few more lines.

Although written for the AVR processors, see this: Why does it take 1000 bytes to blink one LED?

Much appreciated Nick.