Problème mémoire ESP32

Bonjour,
Je ne peut plus compiler mon programme sur l'arduino IDE.
J'ai un message d'erreur qui me dit que mon programme est trop gros.
J'ai un programme Bluetooth qui prend 77 % et un programme WIFI qui prend 57 %
Et j'aimerais fusionner les deux .
Savez vous comment je peux faire et si c'est possible sur mon ESP-32
J'ai un ESP-32_Wrover

Vous remerciant

vérifiez quelle partie de la mémoire est allouée au code dans les pref de la carte et prenez Huge APP par exemple

1 Like

J'ai ça

Mon esp32 :
ESP32-DEVKITC-VE Espressif Systems | RF/IF et RFID | DigiKey
Si je comprend bien je dois me mettre en 8 mb c'est bien ça ?

Vous avez le choix par défaut, donc uniquement 1.2 Megas dispo pour le code.
Si vous passez en "Huge APP" vous aurez 3 Megas dispos pour le code, ça devrait aller

D'accord merci je vais essayer ,
Vous avez regardé ma carte ? c'est une wrover donc 8mb de flash .
C'est pas mieux de prendre 8 m flash ? au lieu de huge ?

votre souci est sur la RAM ou la mémoire flash?

Ram

ah OK... alors c'est pas aussi simple... la RAM ne va pas apparaître par magie et utiliser la PSRAM nécessite du code particulier. il y a quelques tutos dispos, en voici un

https://learn.upesy.com/fr/programmation/psram.html

1 Like

grillé par @J-M-L pour la PSRAM !!

si le souci (principal) est sur la RAM et que la carte comporte bien un module un WROVER il faut s'assurer que le choix de carte est fait en conséquence de manière à exploiter la RAM additionnelle prédente dans ce module, PSRAM

Pour la mémoire Flash, sa taille ne dit pas comment on effectue la patition entre zones divesres , dont celle du code

par ailleurs l'ESP32 n'est pas réputé pour pouvoir faire fonctionner simultanément WiFI et BT, son unique
radio à 2,4Gz ne semble pas pouvoir assurer simultanément les deux connections

Avec la première solution , j'arrive à envoyer mon programme.
Mon Bluetooth fonctionne parfaitement, c'est coté WIFI comme tu dis, j'arrive à voir mes valeurs sur le site mais c'est long très long.
Il y aurait un autre moyen ? pour accélérer ceci ?

arrêter temporairement le Bluetooth pour que la radio puisse se consacrer à 100% au WiFi
Il ya une ressource unique (radio 2,4GHz) il et il faut arbitrer !

Mon site affiche la valeur d'un capteur de température en temps réelle, il doit donc s'actualiser tout le temps ?
car pour actualiser je fais f5 :slight_smile:
Il n'y a pas une solution pour faire fonctionner les deux ?

Pas à ma connaissance s'il s'agit du maintien simultané de connections BT et WiFi
Chacune nécessite l'envoi à intervalle de temps rapprochés de signaux de bas niveau (transparents pour le codeur)

Une radio unique ne peut maintenir simultanément les 'signaux de service' BT et WiFI avec les timings nécessaires

Pourtant la mon programme fonctionne,
Juste la partie WIFI qui est plus longue

C'est dommage ça . Les cartes arduinos auront le même problème ?

  1. le WiFi est-il plus réactif en coupant le BT ?
  2. BT classique ou BLE ?

Si oui la lenteur pourrait être liée au fait que l'ESP32 fait de son mieux et fait le WiFi... quand il peut....

oui sans le BT le WIFi est instantané .
J'utilise BT classique avec la libraire BluetoothSerial.h

le BT ESP32 est-il maître ?

Si oui, il me semble que ça occupe davantage l'ESP32 et laisse moins de temps machine disponible au WiFi

La bonne nouvelle est qu'un certaine cohabitaion est possible , ça n'a pas toujours été le cas.
les librairies ont peut être évolué dans ce sens

D'accord .
Je suis débutant ^^ comment je sais si BT est maître ?

publies ton code (en utilsaint la mise en forme et le balisage indiqué dans les Règles) ou, s'il est top long pour le forum mest le en fichiet joint

Voila :slight_smile:

//DS1307
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"};

//SI1145
#include <Wire.h>
#include "Adafruit_SI1145.h"
Adafruit_SI1145 uv = Adafruit_SI1145();

//SGP30
#include "Adafruit_SGP30.h"
Adafruit_SGP30 sgp;
uint32_t getAbsoluteHumidity(float temperature, float humidity) {
    // approximation formula from Sensirion SGP30 Driver Integration chapter 3.15
    const float absoluteHumidity = 216.7f * ((humidity / 100.0f) * 6.112f * exp((17.62f * temperature) / (243.12f + temperature)) / (273.15f + temperature)); // [g/m^3]
    const uint32_t absoluteHumidityScaled = static_cast<uint32_t>(1000.0f * absoluteHumidity); // [mg/m^3]
    return absoluteHumidityScaled;
}
//BME280
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
unsigned long delayTime;

//bluetooth
#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;

//WIFI
#include <WiFi.h>
const char* ssid = "";
const char* password = "";
WiFiServer server(80);

String header;
// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0; 
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;



void setup() {
//DS1307
   Serial.begin(57600);
   
if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
 
//Si1145
 Serial.println("Adafruit SI1145 test");
  if (! uv.begin()) {
    Serial.println("Didn't find Si1145");
    while (1);
  }
  Serial.println("OK!");


//SGP30
  while (!Serial) { delay(10); } // Wait for serial console to open!

  Serial.println("SGP30 test");

  if (! sgp.begin()){
    Serial.println("Sensor not found :(");
    while (1);
  }
  Serial.print("Found SGP30 serial #");
  Serial.print(sgp.serialnumber[0], HEX);
  Serial.print(sgp.serialnumber[1], HEX);
  Serial.println(sgp.serialnumber[2], HEX);

  // If you have a baseline measurement from before you can assign it to start, to 'self-calibrate'
  //sgp.setIAQBaseline(0x8E68, 0x8F41);  // Will vary for each sensor!


  //BME280
   while(!Serial);    // time to get serial running
    Serial.println(F("BME280 test"));
    unsigned status;
    status = bme.begin();  
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        while (1) delay(10);
    }
    
    Serial.println("-- Default Test --");
    Serial.println();

  //bluetooth
  SerialBT.begin("Control'R"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");

  //WIFI
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  // Print local IP address and start web server
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  server.begin();
}

int counter = 0;



void loop() {
//DS1307
    DateTime now = rtc.now();
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    

//Si1145
  Serial.println("===================");
  Serial.print("Lumière Visible : "); Serial.println(uv.readVisible());
  float UVindex = uv.readUV();
  // the index is multiplied by 100 so to get the
  // integer index, divide by 100!
  UVindex /= 100.0;  
  Serial.print("Rayon UV : ");  Serial.println(UVindex);
  Serial.println();
 


//SGP30

  float temperature = bme.readTemperature(); // [°C]
  float humidity = bme.readHumidity(); // [%RH]
  sgp.setHumidity(getAbsoluteHumidity(temperature, humidity));
  if (! sgp.IAQmeasure()) {
    Serial.println("Measurement failed");
    return;
  }
  Serial.print("Taux VOC : "); Serial.print(sgp.TVOC); Serial.println(" ppb\t");
  Serial.print("Taux CO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm");

  if (! sgp.IAQmeasureRaw()) {
    Serial.println("Raw Measurement failed");
    return;
  }
  Serial.print("Taux Brut H2 "); Serial.print(sgp.rawH2); Serial.println(" \t");
  Serial.print("Taux Brut Ethanol "); Serial.print(sgp.rawEthanol); Serial.println("");
  Serial.println();
  counter++;
  if (counter == 30) {
    counter = 0;

    uint16_t TVOC_base, eCO2_base;
    if (! sgp.getIAQBaseline(&eCO2_base, &TVOC_base)) {
      Serial.println("Failed to get baseline readings");
      return;
    }
    Serial.print("****Baseline values: eCO2: 0x"); Serial.print(eCO2_base, HEX);
    Serial.print(" & TVOC: 0x"); Serial.println(TVOC_base, HEX);
  }
//BME280
 printValues();
 delay(10000);





//bluetooth
 if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
    Serial.write(SerialBT.read());
  }
  delay(20);
  
//date
    SerialBT.print(now.year(), DEC);
    SerialBT.print('/');
    SerialBT.print(now.month(), DEC);
    SerialBT.print('/');
    SerialBT.print(now.day(), DEC);
    SerialBT.print(" (");
    SerialBT.print(daysOfTheWeek[now.dayOfTheWeek()]);
    SerialBT.print(") ");
    SerialBT.print(now.hour(), DEC);
    SerialBT.print(':');
    SerialBT.print(now.minute(), DEC);
    SerialBT.print(':');
    SerialBT.print(now.second(), DEC);
    SerialBT.println();
//lumière
    SerialBT.println("===================");
    SerialBT.print("Lumière Visible : "); 
    SerialBT.println(uv.readVisible());
    SerialBT.print("Rayon UV : ");  
    SerialBT.println(UVindex);
//gaz
    SerialBT.print("Taux VOC : "); SerialBT.print(sgp.TVOC); SerialBT.println(" ppb");
    SerialBT.print("Taux CO2 "); SerialBT.print(sgp.eCO2); SerialBT.println(" ppm");
  
//Météo
    SerialBT.print("Température = ");
    SerialBT.print(bme.readTemperature());
    SerialBT.println(" °C");

    SerialBT.print("Pression = ");

    SerialBT.print(bme.readPressure() / 100.0F);
    SerialBT.println(" hPa");


    SerialBT.print("Humidité = ");
    SerialBT.print(bme.readHumidity());
    SerialBT.println(" %");
    SerialBT.println("===================");
    SerialBT.println();
//WIFI
 WiFiClient client = server.available();   // Listen for incoming clients
 if (client) {                             // If a new client connects,
    currentTime = millis();
    previousTime = currentTime;
    Serial.println("New Client.");          // print a message out in the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected() && currentTime - previousTime <= timeoutTime) {  // loop while the client's connected
      currentTime = millis();
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        header += c;
        if (c == '\n') {                    // if the byte is a newline character
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();
            
            // Display the HTML web page
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            // CSS to style the table 
            client.println("<style>body { text-align: center; font-family: \"Trebuchet MS\", Arial;}");
            client.println("table { border-collapse: collapse; width:35%; margin-left:auto; margin-right:auto; }");
            client.println("th { padding: 12px; background-color: #0043af; color: white; }");
            client.println("tr { border: 1px solid #ddd; padding: 12px; }");
            client.println("tr:hover { background-color: #bcbcbc; }");
            client.println("td { border: none; padding: 12px; }");
            client.println(".sensor { color:white; font-weight: bold; background-color: #bcbcbc; padding: 1px; }");
            
            // Web Page Heading
            client.println("</style></head><body><h1>Control'R</h1>");
     client.print(now.year(), DEC);
     client.print('/');
     client.print(now.month(), DEC);
     client.print('/');
     client.print(now.day(), DEC);
     client.print(" (");
     client.print(daysOfTheWeek[now.dayOfTheWeek()]);
     client.print(") ");
     client.print(now.hour(), DEC);
     client.print(':');
     client.print(now.minute(), DEC);
     client.print(':');
     client.print(now.second(), DEC);
     client.println();
            client.println("<table><tr><th>MESURE</th><th>VALEUR</th></tr>");
            client.println("<tr><td>Temp. Celsius</td><td><span class=\"sensor\">");
            client.println(bme.readTemperature());
            client.println(" *C</span></td></tr>");  
            client.println("<tr><td>Temp. Fahrenheit</td><td><span class=\"sensor\">");
            client.println(1.8 * bme.readTemperature() + 32);
            client.println(" *F</span></td></tr>");       
            client.println("<tr><td>Pression</td><td><span class=\"sensor\">");
            client.println(bme.readPressure() / 100.0F);
            client.println(" hPa</span></td></tr>");
            client.println("<tr><td>Approx. Altitude</td><td><span class=\"sensor\">");
            client.println(bme.readAltitude(SEALEVELPRESSURE_HPA));
            client.println(" m</span></td></tr>"); 
            client.println("<tr><td>Humidite</td><td><span class=\"sensor\">");
            client.println(bme.readHumidity());
            client.println(" %</span></td></tr>"); 
            client.println("<tr><td>Lumiere</td><td><span class=\"sensor\">");
            client.println(uv.readVisible());
            client.println(" </span></td></tr>"); 
            client.println("<tr><td>IR</td><td><span class=\"sensor\">");
            client.println(uv.readIR());
            client.println(" </span></td></tr>"); 
            client.println("<tr><td>UV</td><td><span class=\"sensor\">");
            client.println(UVindex);
            client.println(" </span></td></tr>"); 
            client.println("<tr><td>CO2</td><td><span class=\"sensor\">");
            client.println(sgp.eCO2);
            client.println(" ppm</span></td></tr>"); 
            client.println("<tr><td>VOC</td><td><span class=\"sensor\">");
            client.println(sgp.TVOC);
            client.println(" ppb</span></td></tr>"); 
            client.println("<tr><td>H2</td><td><span class=\"sensor\">");
            client.println(sgp.rawH2);
            client.println(" </span></td></tr>"); 
            client.println("<tr><td>Ethanol</td><td><span class=\"sensor\">");
            client.println(sgp.rawEthanol);
            client.println(" </span></td></tr>"); 
            client.println("</body></html>");
            
            // The HTTP response ends with another blank line
            client.println();
            // Break out of the while loop
            break;
          } else { // if you got a newline, then clear currentLine
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
      }
    }
    // Clear the header variable
    header = "";
    // Close the connection
    client.stop();
    Serial.println("Client disconnected.");
    Serial.println("");
  } 
}

void printValues() {
    Serial.print("Température = ");
    Serial.print(bme.readTemperature());
    Serial.println(" °C");

    Serial.print("Pression = ");

    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");


    Serial.print("Humidité = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");
  Serial.println("===================");
  Serial.println();


  
}