Chat freely about anything...

User avatar
By Atlantis
#33531 I know it is a basic question, but I am still learning ESP8266 and I am not sure of one thing.
Until now, I was using 8bit AVR microcontrolers. On that platform, you have to declare data as "PROGMEM" if you want it to be stored on flash memory only.

For example:

Code: Select allconst uint8_t some_data[5] PROGMEM = {3, 6, 12, 24, 48};


Then you have to use pgm_read_byte(*uint8_t) to read it.

If you decide to define and use it regular way, it will be copied to the RAM anyway. So if we are talking about complicated structures and/or long arrays, project will run out of memory.

I know it is not a problem on modern 32bit platforms. For example on PIC32 it is sufficient to define data as "const" and it will be stored in and read from flash directly, without wasting any RAM space.

I want to know how it is done in ESP8266. "Const" data structure is stored only in flash by default, or do I need to do something else to preserve RAM?
User avatar
By picstart
#33544 I have a PIC background ( two decades ). First PIC's are harvard architecture so data is never commingled with code.The PIC has specific RISK instructions to fetch data from program flash. The esp8266 appears to commingle code and data both moving into RAM for execution speed. This makes much sense for time critical WiFi code. To get data into the equivalent of PROGMEM on a PIC const is all that is needed. For ESP8266 the PROGMEM keyword is needed const alone will not place the data into flash. The ESP8266 flash is fast enough for most applications but is almost an order of magnitude slower than RAM. For large data arrays ( Ex a font) RAM isn't often big enough. I believe the ESP8266 PCB has a 32 bit flash..... the arduino pgm_read_byte(*uint8_t) fetches a byte at a time but it seems fast enough ( it probably buffers the physical 4 byte read to speed sequential access).
User avatar
By GengusKahn
#33545 Hi there, have you tried using the SPIFFS SPI Flash File System......

http://arduino.esp8266.com/versions/1.6.5-1160-gef26c5f/doc/reference.html#file-system-object-spiffs

Code: Select all#include <ESP8266WiFi.h>
#include "FS.h"
// above needs included........
// Below are some snippets.....
  if (!SPIFFS.begin()) {
    Serial.println("SPIFFS init failed");
  }
 
    if (!SPIFFS.format()) {
      Serial.println("format failed");
    }
    Dir root = SPIFFS.openDir("/");
    int count = 0;
    while (root.next()) {
      ++count;
    }
    if (count > 0) {
      Serial.println("some files left after format");// Remember to setup Serial.....
    }

int lst=0;

        File dataFile1 = SPIFFS.open("/humidlog.CSV", "w");
             dataFile1.print("22");
             dataFile1.println(" Celsius ");
             dataFile1.close();
dataFile1 = SPIFFS.open("/humidlog.CSV", "r+");
  if (dataFile1) {
  for (lst=0;lst<2048;lst++){     
      dataFile1.print("2nd Cavity Humidity = ");
      dataFile1.print("55");
      dataFile1.print("   2nd  Cavity  Temp  = ");
      dataFile1.print("16");
      dataFile1.print(" Celsius ");
      dataFile1.print("   Bedroom Humidity = ");
      dataFile1.print("41");
      dataFile1.print("  Bedroom Temperature = ");
      dataFile1.print("22");
      dataFile1.println(" Celsius ");
  }
      dataFile1.close();
      Serial.println("Closing humidlog.CSV");

    delay(500);
      }
    else {
      Serial.println("error opening humidlog.CSV");
    }


Load the Webpage from SPIFFS....
7 - 2KB files for the Gauge + lastpres - BMP180 Pressure reading + Footer again 2KB.....
See the Output....

http://bbc.in/1PkBPYE

Code: Select all                        client.println("HTTP/1.1 200 OK");     
                        client.println("Content-Type: text/html");
                        client.println("Connection: close");
                        client.println();
      // send web page
      for (int i = 0; i < 7; ++i) {
      String name = "/presure";
      name += i;
      name += ".htm";

      File webFile = SPIFFS.open(name, "r");
      if (!webFile) {
        lcd.clear();       
        lcd.print("ror open webpage");
        while(1);
        }
             while(webFile.available()) {
             client.print(webFile.readString()); // send web page to client
             }
        }
                           client.print(lastpres);       
                      File webFile = SPIFFS.open("/presureF.htm", "r");        // open web page file
                        if (webFile) {
                           while(webFile.available()) {
                           client.print(webFile.readString()); // send web page to client
                            }
                        }