IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Arduino Discussion :

De l'IDE Arduino à VS Code


Sujet :

Arduino

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Cryogenie
    Inscrit en
    Septembre 2022
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Cryogenie

    Informations forums :
    Inscription : Septembre 2022
    Messages : 7
    Points : 6
    Points
    6
    Par défaut De l'IDE Arduino à VS Code
    Bonjour à tous,

    Ca fais quelques semaines que j'ai mis les doigts dans le monde du code. Pour des projets perso "classique"
    J'ai commencé en utilisant l'IDE Arduino ( car achat d'un Arduino Uno ) simple et efficace comme IDE,
    j'ai un projet sur serveur où je dois utiliser VSCode ( pour la gestion des pages html, j'aurai d'ailleurs des questions la dessus ... plus tard dans un autre topic. )

    J'abandonne l'IDE d'Arduino pour me focaliser entierement à VSCode ( qui comme vous le savez, est plus complexe mais bien plus puissant. ) en utilisant la platforme " PlatformIO "

    Bref voici mon petit soucis. Simple.
    J'ai 2 erreurs dans mon code sur VSCode ( que je n'avais pas sur l'IDE Arduino ) je pense que cela doit venir d'un "placement" de ligne.
    Pouvez vous me faire cette correction et m'expliquer le pourquoi, que je puisse comprendre d'où cela vient.

    Projet : Timelaps de plante en serre : Le code a pour but :
    - prendre une photo tout les X temps
    - enregistrement sur carte SD
    - incrémentation des numéros photos pour éviter que celle presente sur la SD soit écraser lors d'un nouvelle prise de photo apèrs un Reset de la carte.
    - Réglages des photos (qualité)
    - Forçage de la LED Flash éteinte.

    Matériel : ESP32 Cam Al Thinker

    Bien sur si vous voyez des améliorations, des corrections ou autre, je suis bien sur preneur.

    Merci à vous pour votre aide.

    Voici le code sur VSCode avec les erreurs
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    
    #include <Arduino.h>
    #include "esp_camera.h"
    #include "FS.h"                // SD Card ESP32
    #include "SD_MMC.h"            // SD Card ESP32
    #include "soc/soc.h"           // Disable brownout problems
    #include "soc/rtc_cntl_reg.h"  // Disable brownout problems
    #include "driver/rtc_io.h"
    #include "SPI.h"
    
    #define MINUTES_BETWEEN_PHOTOS 1
    
    // Pin definition for CAMERA_MODEL_AI_THINKER
    // Change pin definition if you're using another ESP32 with camera module
    #define PWDN_GPIO_NUM     32
    #define RESET_GPIO_NUM    -1
    #define XCLK_GPIO_NUM      0
    #define SIOD_GPIO_NUM     26
    #define SIOC_GPIO_NUM     27
    #define Y9_GPIO_NUM       35
    #define Y8_GPIO_NUM       34
    #define Y7_GPIO_NUM       39
    #define Y6_GPIO_NUM       36
    #define Y5_GPIO_NUM       21
    #define Y4_GPIO_NUM       19
    #define Y3_GPIO_NUM       18
    #define Y2_GPIO_NUM        5
    #define VSYNC_GPIO_NUM    25
    #define HREF_GPIO_NUM     23
    #define PCLK_GPIO_NUM     22
    #define BUILTIN_LED 4
    
    // Keep track of number of pictures
    unsigned int pictureNumber = 0;
    
    //Stores the camera configuration parameters
    camera_config_t config;
    
    void setup() {
    
      WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
     
      Serial.begin(115200);
      
      //Initialize the camera  
      Serial.print("Initializing the camera module...");
      configInitCamera();
      Serial.println("Ok!");
     
      // Initialize the SD card
        if (!SD_MMC.begin("/sdcard", true)){
            Serial.println("Failed to mount SD card");
            return;
        }
    
        // Specify that LED pin
        pinMode(BUILTIN_LED, OUTPUT);
        digitalWrite(BUILTIN_LED, LOW);
    
        // Check for an SD card
        uint8_t cardType = SD_MMC.cardType();
        if (cardType == CARD_NONE){
            Serial.println("No SD card attached");
            return;
        }
    }
    
    void loop() {
    
      //Path where new picture will be saved in SD Card
      String path = "/picture" + String(pictureNumber) +".jpg";  
      Serial.printf("Picture file name: %s\n", path.c_str());
    
      //Take and Save Photo
      takeSavePhoto(path);
      pictureNumber++;
      delay(10000); 
      
    }
    
    void configInitCamera(){
      config.ledc_channel = LEDC_CHANNEL_0;
      config.ledc_timer = LEDC_TIMER_0;
      config.pin_d0 = Y2_GPIO_NUM;
      config.pin_d1 = Y3_GPIO_NUM;
      config.pin_d2 = Y4_GPIO_NUM;
      config.pin_d3 = Y5_GPIO_NUM;
      config.pin_d4 = Y6_GPIO_NUM;
      config.pin_d5 = Y7_GPIO_NUM;
      config.pin_d6 = Y8_GPIO_NUM;
      config.pin_d7 = Y9_GPIO_NUM;
      config.pin_xclk = XCLK_GPIO_NUM;
      config.pin_pclk = PCLK_GPIO_NUM;
      config.pin_vsync = VSYNC_GPIO_NUM;
      config.pin_href = HREF_GPIO_NUM;
      config.pin_sscb_sda = SIOD_GPIO_NUM;
      config.pin_sscb_scl = SIOC_GPIO_NUM;
      config.pin_pwdn = PWDN_GPIO_NUM;
      config.pin_reset = RESET_GPIO_NUM;
      config.xclk_freq_hz = 20000000;
      config.pixel_format = PIXFORMAT_JPEG; //YUV422,GRAYSCALE,RGB565,JPEG
    
      // Select lower framesize if the camera doesn't support PSRAM
      if(psramFound()){
        config.frame_size = FRAMESIZE_SXGA; // FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA
        config.jpeg_quality = 4; //10-63 lower number means higher quality
        config.fb_count = 2;
      } else {
        config.frame_size = FRAMESIZE_SVGA;
        config.jpeg_quality = 12;
        config.fb_count = 1;
      }
      
      // Initialize the Camera
      esp_err_t err = esp_camera_init(&config);
      if (err != ESP_OK) {
        Serial.printf("Camera init failed with error 0x%x", err);
        return;
      }
    
      sensor_t * s = esp_camera_sensor_get();
      s->set_brightness(s, 0);     // -2 to 2
      s->set_contrast(s, 0);       // -2 to 2
      s->set_saturation(s, 0);     // -2 to 2
      s->set_special_effect(s, 0); // 0 to 6 (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, 4 - Green Tint, 5 - Blue Tint, 6 - Sepia)
      s->set_whitebal(s, 1);       // 0 = disable , 1 = enable
      s->set_awb_gain(s, 1);       // 0 = disable , 1 = enable
      s->set_wb_mode(s, 0);        // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home)
      s->set_exposure_ctrl(s, 1);  // 0 = disable , 1 = enable
      s->set_aec2(s, 0);           // 0 = disable , 1 = enable
      s->set_ae_level(s, 0);       // -2 to 2
      s->set_aec_value(s, 300);    // 0 to 1200
      s->set_gain_ctrl(s, 1);      // 0 = disable , 1 = enable
      s->set_agc_gain(s, 0);       // 0 to 30
      s->set_gainceiling(s, (gainceiling_t)0);  // 0 to 6
      s->set_bpc(s, 0);            // 0 = disable , 1 = enable
      s->set_wpc(s, 1);            // 0 = disable , 1 = enable
      s->set_raw_gma(s, 1);        // 0 = disable , 1 = enable
      s->set_lenc(s, 1);           // 0 = disable , 1 = enable
      s->set_hmirror(s, 0);        // 0 = disable , 1 = enable
      s->set_vflip(s, 0);          // 0 = disable , 1 = enable
      s->set_dcw(s, 1);            // 0 = disable , 1 = enable
      s->set_colorbar(s, 0);       // 0 = disable , 1 = enable
    }
    
    void initMicroSDCard(){
      // Start Micro SD card
      Serial.println("Starting SD Card");
      if(!SD_MMC.begin()){
        Serial.println("SD Card Mount Failed");
        return;
      }
      uint8_t cardType = SD_MMC.cardType();
      if(cardType == CARD_NONE){
        Serial.println("No SD Card attached");
        return;
      }
    }
    
    void takeSavePhoto(String path){
      // Take Picture with Camera
      camera_fb_t  * fb = esp_camera_fb_get();
    
      
      if(!fb) {
        Serial.println("Camera capture failed");
        return;
      }
    
      // Save picture to microSD card
      fs::FS &fs = SD_MMC; 
      File file = fs.open(path.c_str(), FILE_WRITE);
      if(!file){
        Serial.println("Failed to open file in writing mode");
      } 
      else {
        file.write(fb->buf, fb->len); // payload (image), payload length
        Serial.printf("Saved file to path: %s\n", path.c_str());
      }
      file.close();
      
      //return the frame buffer back to the driver for reuse
      esp_camera_fb_return(fb); 
    
      // Delay until the next photo
    
      delay(MINUTES_BETWEEN_PHOTOS * 1 * 1000);
      
    }

  2. #2
    Modérateur
    Avatar de al1_24
    Homme Profil pro
    Retraité
    Inscrit en
    Mai 2002
    Messages
    9 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Retraité
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2002
    Messages : 9 080
    Points : 30 783
    Points
    30 783
    Par défaut
    Bonjour,

    Dommage que tu n'aies pas donné aussi les messages d'erreur que te retourne le compilateur. Cela aurait limité l'étendue des recherches d'anomalie.

    Je ne suis pas rentré dans le détail de ton programme mais j'ai relevé une anomalie qui pourrait être la source de tes problèmes :
    Lorsque tu ne développes pas dans l'IDE Arduino, il devient nécessaire de respecter la norme syntaxique du langage C (a fortiori C++) et de déclarer les fonctions avant de les utiliser.
    Donc, soit tu ramènes tes fonctions setup et loop à la fin du programme, soit tu ajoutes avant celles-ci les forward declaration des fonctions qui sont implémentées plus loin.
    Modérateur Langage SQL
    Règles du forum Langage SQL à lire par tous, N'hésitez pas à consulter les cours SQL
    N'oubliez pas le bouton et pensez aux balises
    [code]
    Si une réponse vous a aidé à résoudre votre problème, n'oubliez pas de voter pour elle en cliquant sur
    Aide-toi et le forum t'aidera : Un problème exposé sans mentionner les tentatives de résolution infructueuses peut laisser supposer que le posteur attend qu'on fasse son travail à sa place... et ne donne pas envie d'y répondre.

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Cryogenie
    Inscrit en
    Septembre 2022
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Cryogenie

    Informations forums :
    Inscription : Septembre 2022
    Messages : 7
    Points : 6
    Points
    6
    Par défaut
    Meric à toi pour ton coup de main,
    J'ai repris mon code car je voulais y ajouté des choses en plus du timelapse :
    - DHT 22
    - connexion au serveur firebase
    - Envoie données sur firebase

    Mais je suis confronté renouveau à une erreur, connu, mais je n'y arrive pas ...
    Mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
     
     
    #include <Arduino.h>
    //#include <Adafruit_Sensor.h>
    #include <WiFi.h>
    #include <Firebase_ESP_Client.h>
    #include "DHT.h" 
    #include <Wire.h>
    #include "time.h"
    #include "esp_camera.h"
    #include "FS.h"                // Micro SD ESP32
    #include "SD_MMC.h"            // Micro SD ESP32
    #include "soc/soc.h"           // Désactiver les problèmes de baisse de tension
    #include "soc/rtc_cntl_reg.h"  // Désactiver les problèmes de baisse de tension
    #include "driver/rtc_io.h"
    #include "SPI.h"               // Gestion LED 4
    #include <Preferences.h>
     
    // Provide the token generation process info.
    #include "addons/TokenHelper.h"
    // Provide the RTDB payload printing info and other helper functions.
    #include "addons/RTDBHelper.h"
     
    // Définition Pin DHT22
    #define DHTPIN 2
    #define DHTTYPE DHT22
     
    // Déclaration DHT22
    DHT dht(DHTPIN, DHTTYPE);
     
    // Insert your network credentials
    #define WIFI_SSID "*****************"
    #define WIFI_PASSWORD "*****************"
     
    // Insert Firebase project API Key
    #define API_KEY "*****************"
     
    // Insert Authorized Email and Corresponding Password
    #define USER_EMAIL "*****************"
    #define USER_PASSWORD "*****************"
     
    // Insert RTDB URLefine the RTDB URL
    #define DATABASE_URL "*****************"
     
    // Pin definition for CAMERA_MODEL_AI_THINKER
    #define PWDN_GPIO_NUM     32
    #define RESET_GPIO_NUM    -1
    #define XCLK_GPIO_NUM      0
    #define SIOD_GPIO_NUM     26
    #define SIOC_GPIO_NUM     27
    #define Y9_GPIO_NUM       35
    #define Y8_GPIO_NUM       34
    #define Y7_GPIO_NUM       39
    #define Y6_GPIO_NUM       36
    #define Y5_GPIO_NUM       21
    #define Y4_GPIO_NUM       19
    #define Y3_GPIO_NUM       18
    #define Y2_GPIO_NUM        5
    #define VSYNC_GPIO_NUM    25
    #define HREF_GPIO_NUM     23
    #define PCLK_GPIO_NUM     22
    #define BUILTIN_LED 4
     
    //prototypes
    void configInitCamera();
    void initMicroSDCard();
    void takeSavePhoto(String path);
     
    // Define Firebase objects
    FirebaseData fbdo;
    FirebaseAuth auth;
    FirebaseConfig config;
     
    // Variable to save USER UID
    String uid;
     
    // Database main path (to be updated in setup with the user UID)
    String databasePath;
    // Database child nodes
    String tempPath = "/temperature";
    String humPath = "/humidity";
    String timePath = "/timestamp";
     
    // Parent Node (to be updated in every loop)
    String parentPath;
     
    int timestamp;
    FirebaseJson json;
     
    const char* ntpServer = "pool.ntp.org";
     
    float temperature;
    float humidity;
     
    // Timer variables (send new readings every 10 minutes)
    unsigned long sendDataPrevMillis = 0;
    unsigned long timerDelay = 600000;
     
    // Initialize WiFi
    void initWiFi() {
      WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
      Serial.print("Connecting to WiFi ..");
      while (WiFi.status() != WL_CONNECTED) {
        Serial.print('.');
        delay(1000);
      }
      Serial.println(WiFi.localIP());
      Serial.println();
    }
     
    // Function that gets current epoch time
    unsigned long getTime() {
      time_t now;
      struct tm timeinfo;
      if (!getLocalTime(&timeinfo)) {
        //Serial.println("Failed to obtain time");
        return(0);
      }
      time(&now);
      return now;
    }
     
    // Stocke les paramètres de configuration de la caméra
    camera_config_t config1;
    Preferences photos;
    int lastNumber;
     
    // Gestion du temps
    unsigned long SECONDES = 1000L;
    unsigned long  MINUTES = SECONDES * 60;
    unsigned long  HEURES = MINUTES * 60;
    // Définitions de la pause entre les prises de vue
    unsigned long  DELAY_BETWEEN_PHOTOS = 0 * HEURES + 0 * MINUTES + 1 * SECONDES;
     
    // Garde une trace du nombre de photos
    unsigned int pictureNumber = 0;
     
    void setup(){
      Serial.begin(115200); 
    //  Serial.println(F("DHTxx test!")); 
     
      // Initialise le DHT22 & Wifi & Time
      dht.begin();
      initWiFi();
      configTime(0, 0, ntpServer);
     
      // Assign the api key (required)
      config.api_key = API_KEY;
     
      // Assign the user sign in credentials
      auth.user.email = USER_EMAIL;
      auth.user.password = USER_PASSWORD;
     
      // Assign the RTDB URL (required)
      config.database_url = DATABASE_URL;
     
      Firebase.reconnectWiFi(true);
      fbdo.setResponseSize(4096);
     
      // Assign the callback function for the long running token generation task */
      config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
     
      // Assign the maximum retry of token generation
      config.max_token_generation_retry = 5;
     
      // Initialize the library with the Firebase authen and config
      Firebase.begin(&config, &auth);
     
      // Getting the user UID might take a few seconds
      Serial.println("Getting User UID");
      while ((auth.token.uid) == "") {
        Serial.print('.');
        delay(1000);
      }
      // Print user UID
      uid = auth.token.uid.c_str();
      Serial.print("User UID: ");
      Serial.println(uid);
     
      // Update database path
      databasePath = "/UsersData/" + uid + "/readings";
     
      // Désactive le détecteur de baisse de tension
      WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
     
      // Initialise la caméra
      Serial.print("Initialisation du module caméra...");
      configInitCamera();
      Serial.println("Ok!");
     
      // Initialise l'EEPROM
      photos.begin("numeros", false);
      lastNumber = photos.getInt("counter", 0) + 1;
     
      // Initialise la carte Micro SD
      if (!SD_MMC.begin("/sdcard", true)) {
        Serial.println("Impossible de monter la carte Micro SD");
        return;
      }
     
      // Specifie la pin de la LED 4
      pinMode(BUILTIN_LED, OUTPUT);
      digitalWrite(BUILTIN_LED, LOW);
     
      // Recherche une carte Micro SD
      uint8_t cardType = SD_MMC.cardType();
      if (cardType == CARD_NONE) {
        Serial.println("Aucune carte Micro SD détecté");
        return;
      }
    }
     
    void loop(){
     
      // Temps entre chaques mesures
      delay(60000);
     
      // La lecture de la température ou de l'humidité prend environ 250 millisecondes !
      // Les lectures du capteur peuvent également être "anciennes" jusqu'à 2 secondes (c'est un capteur très lent)
      float h = dht.readHumidity();
      float t = dht.readTemperature();
     
      // Vérifiez si des lectures ont échoué et quittez plus tôt (pour réessayer).
      if (isnan(h) || isnan(t)) {
        Serial.println(F("Failed to read from DHT sensor!"));
        return;
      }
     
      // Send new readings to database
      if (Firebase.ready() && (millis() - sendDataPrevMillis > timerDelay || sendDataPrevMillis == 0)){
        sendDataPrevMillis = millis();
     
        //Get current timestamp
        timestamp = getTime();
        Serial.print ("time: ");
        Serial.println (timestamp);
     
        parentPath= databasePath + "/" + String(timestamp);
     
        json.set(tempPath.c_str(), String(dht.readTemperature()));
        json.set(humPath.c_str(), String(dht.readHumidity()));
        json.set(timePath, String(timestamp));
        Serial.printf("Set json... %s\n", Firebase.RTDB.setJSON(&fbdo, parentPath.c_str(), &json) ? "ok" : fbdo.errorReason().c_str());
      }
     
      // Ecriture dans le moniteur
      Serial.print("Humidite: ");
      Serial.print(h);
      Serial.println (" %\t");
      Serial.print("Temperature: ");
      Serial.print(t);
      Serial.println (" *C ");
     
    // Chemin où la nouvelle image sera enregistrée sur la carte SD
    String path = "/picture" + String(lastNumber + pictureNumber) + ".jpg";
      Serial.printf("Nom du fichier image: %s\n", path.c_str());
      // Prend et enregistre une photo
    takeSavePhoto(path);
      photos.putInt("counter", lastNumber + pictureNumber);
      pictureNumber++;
      delay(10000);
     
    }
    Les messages d'erreurs :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
     
    Building in release mode
    Linking .pio/build/esp32cam/firmware.elf
    /Users/vincent/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32cam/src/main.cpp.o:(.literal._Z5setupv+0x94): undefined reference to `configInitCamera()'
    /Users/vincent/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32cam/src/main.cpp.o:(.literal._Z4loopv+0x5c): undefined reference to `takeSavePhoto(String)'
    /Users/vincent/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32cam/src/main.cpp.o: in function `setup()':
    /Users/vincent/Documents/PlatformIO/Projects/TEST/src/main.cpp:194: undefined reference to `configInitCamera()'
    /Users/vincent/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32cam/src/main.cpp.o: in function `loop()':
    /Users/vincent/Documents/PlatformIO/Projects/TEST/src/main.cpp:264: undefined reference to `takeSavePhoto(String)'
    collect2: error: ld returned 1 exit status
    *** [.pio/build/esp32cam/firmware.elf] Error 1

  4. #4
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 711
    Points : 5 390
    Points
    5 390
    Par défaut
    où est le code de takeSavePhoto()???

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Cryogenie
    Inscrit en
    Septembre 2022
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Cryogenie

    Informations forums :
    Inscription : Septembre 2022
    Messages : 7
    Points : 6
    Points
    6
    Par défaut
    Autant pour moi, j'ai oublié un bout de code effectivement :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
     
     
    // #define WIFI_SSID "Bbox-6B1631DF"
    // #define WIFI_PASSWORD "SziX29Nv67sKn5N93D"
    // #define WIFI_SSID "DACMPCE172 0434"
    // #define WIFI_PASSWORD "5x168#G3"
    // #define WIFI_SSID "iPhone de Vincent"
    // #define WIFI_PASSWORD "s0ggxjzrbd16r"
     
    // #include <Adafruit_Sensor.h>
    #include "WiFi.h"
    #include "Firebase_ESP_Client.h"
    #include "Wire.h"
    #include "time.h"
    #include "DHT.h"
    #include "esp_camera.h"
    #include "FS.h"                // Micro SD ESP32
    #include "SD_MMC.h"            // Micro SD ESP32
    #include "soc/soc.h"           // Désactiver les problèmes de baisse de tension
    #include "soc/rtc_cntl_reg.h"  // Désactiver les problèmes de baisse de tension
    #include "driver/rtc_io.h"
    #include "SPI.h"               // Gestion LED 4
    #include "Preferences.h"
     
    // Pin definition for CAMERA_MODEL_AI_THINKER
    #define PWDN_GPIO_NUM     32
    #define RESET_GPIO_NUM    -1
    #define XCLK_GPIO_NUM      0
    #define SIOD_GPIO_NUM     26
    #define SIOC_GPIO_NUM     27
    #define Y9_GPIO_NUM       35
    #define Y8_GPIO_NUM       34
    #define Y7_GPIO_NUM       39
    #define Y6_GPIO_NUM       36
    #define Y5_GPIO_NUM       21
    #define Y4_GPIO_NUM       19
    #define Y3_GPIO_NUM       18
    #define Y2_GPIO_NUM        5
    #define VSYNC_GPIO_NUM    25
    #define HREF_GPIO_NUM     23
    #define PCLK_GPIO_NUM     22
    #define BUILTIN_LED 4
     
    //prototypes
    void configInitCamera();
    void initMicroSDCard();
    void takeSavePhoto(String path);
     
    // Stocke les paramètres de configuration de la caméra
    camera_config_t config1;
    Preferences photos;
    int lastNumber;
     
    // Gestion du temps
    unsigned long SECONDES = 1000L;
    unsigned long  MINUTES = SECONDES * 60;
    unsigned long  HEURES = MINUTES * 60;
    // Définitions de la pause entre les prises de vue
    unsigned long  DELAY_BETWEEN_PHOTOS = 0 * HEURES + 0 * MINUTES + 1 * SECONDES;
     
    // Garde une trace du nombre de photos
    unsigned int pictureNumber = 0;
     
    // Provide the token generation process info.
    #include "addons/TokenHelper.h"
    // Provide the RTDB payload printing info and other helper functions.
    #include "addons/RTDBHelper.h"
     
    // Définition Pin DHT22
    #define DHTPIN 27
    #define DHTTYPE DHT22
     
    // Déclaration DHT22
    DHT dht(DHTPIN, DHTTYPE);
     
    // Insert your network credentials
    #define WIFI_SSID "Bbox-6B1631DF"
    #define WIFI_PASSWORD "SziX29Nv67sKn5N93D"
     
    // Insert Firebase project API Key
    #define API_KEY "AIzaSyBtHFS-vIFZDIJHWIEOWdEXVZnSuO_i1rg"
     
    // Insert Authorized Email and Corresponding Password
    #define USER_EMAIL "programmation187@hotmail.com"
    #define USER_PASSWORD "qUzruf-figbod-7tahhe"
     
    // Insert RTDB URLefine the RTDB URL
    #define DATABASE_URL "https://climat-box-v01-default-rtdb.europe-west1.firebasedatabase.app/"
     
    // Define Firebase objects
    FirebaseData fbdo;
    FirebaseAuth auth;
    FirebaseConfig config;
     
    // Variable to save USER UID
    String uid;
     
    // Database main path (to be updated in setup with the user UID)
    String databasePath;
    // Database child nodes
    String tempPath = "/temperature";
    String humPath = "/humidity";
    String timePath = "/timestamp";
     
    // Parent Node (to be updated in every loop)
    String parentPath;
     
    int timestamp;
    FirebaseJson json;
     
    const char* ntpServer = "pool.ntp.org";
     
    float temperature;
    float humidity;
     
    // Timer variables (send new readings every 10 minutes)
    unsigned long sendDataPrevMillis = 0;
    unsigned long timerDelay = 600000;
     
    // Initialize WiFi
    void initWiFi() {
      WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
      Serial.print("Connecting to WiFi ..");
      while (WiFi.status() != WL_CONNECTED) {
        Serial.print('.');
        delay(1000);
      }
      Serial.println(WiFi.localIP());
      Serial.println();
    }
     
    // Function that gets current epoch time
    unsigned long getTime() {
      time_t now;
      struct tm timeinfo;
      if (!getLocalTime(&timeinfo)) {
        //Serial.println("Failed to obtain time");
        return(0);
      }
      time(&now);
      return now;
    }
     
    void setup(){
     
        // Désactive le détecteur de baisse de tension
      WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
     
      Serial.begin(115200); 
    //  Serial.println(F("DHTxx test!")); 
     
      // Initialise le DHT22 & Wifi & Time
      dht.begin();
      initWiFi();
      configTime(0, 0, ntpServer);
     
      // Assign the api key (required)
      config.api_key = API_KEY;
     
      // Assign the user sign in credentials
      auth.user.email = USER_EMAIL;
      auth.user.password = USER_PASSWORD;
     
      // Assign the RTDB URL (required)
      config.database_url = DATABASE_URL;
     
      Firebase.reconnectWiFi(true);
      fbdo.setResponseSize(4096);
     
      // Assign the callback function for the long running token generation task */
      config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
     
      // Assign the maximum retry of token generation
      config.max_token_generation_retry = 5;
     
      // Initialize the library with the Firebase authen and config
      Firebase.begin(&config, &auth);
     
      // Getting the user UID might take a few seconds
      Serial.println("Getting User UID");
      while ((auth.token.uid) == "") {
        Serial.print('.');
        delay(1000);
      }
      // Print user UID
      uid = auth.token.uid.c_str();
      Serial.print("User UID: ");
      Serial.println(uid);
     
      // Update database path
      databasePath = "/UsersData/" + uid + "/readings";
     
      // Initialise la caméra
      Serial.print("Initialisation du module caméra...");
      configInitCamera();
      Serial.println("Ok!");
     
      // Initialise l'EEPROM
      photos.begin("numeros", false);
      lastNumber = photos.getInt("counter", 0) + 1;
     
      // Initialise la carte Micro SD
      if (!SD_MMC.begin("/sdcard", true)) {
        Serial.println("Impossible de monter la carte Micro SD");
        return;
      }
     
      // Specifie la pin de la LED 4
      pinMode(BUILTIN_LED, OUTPUT);
      digitalWrite(BUILTIN_LED, LOW);
     
      // Recherche une carte Micro SD
      uint8_t cardType = SD_MMC.cardType();
      if (cardType == CARD_NONE) {
        Serial.println("Aucune carte Micro SD détecté");
        return;
      }
     
    }
     
    void loop(){
     
      // Chemin où la nouvelle image sera enregistrée sur la carte SD
      String path = "/picture" + String(lastNumber + pictureNumber) + ".jpg";
      Serial.printf("Nom du fichier image: %s\n", path.c_str());
     
      // Prend et enregistre une photo
      takeSavePhoto(path);
      photos.putInt("counter", lastNumber + pictureNumber);
      pictureNumber++;
      delay(10000);
     
      // Temps entre chaques mesures
      delay(60000);
     
      // La lecture de la température ou de l'humidité prend environ 250 millisecondes !
      // Les lectures du capteur peuvent également être "anciennes" jusqu'à 2 secondes (c'est un capteur très lent)
      float h = dht.readHumidity();
      float t = dht.readTemperature();
     
      // Vérifiez si des lectures ont échoué et quittez plus tôt (pour réessayer).
      if (isnan(h) || isnan(t)) {
        Serial.println(F("Failed to read from DHT sensor!"));
        return;
      }
     
      // Send new readings to database
      if (Firebase.ready() && (millis() - sendDataPrevMillis > timerDelay || sendDataPrevMillis == 0)){
        sendDataPrevMillis = millis();
     
        //Get current timestamp
        timestamp = getTime();
        Serial.print ("time: ");
        Serial.println (timestamp);
     
        parentPath= databasePath + "/" + String(timestamp);
     
        json.set(tempPath.c_str(), String(dht.readTemperature()));
        json.set(humPath.c_str(), String(dht.readHumidity()));
        json.set(timePath, String(timestamp));
        Serial.printf("Set json... %s\n", Firebase.RTDB.setJSON(&fbdo, parentPath.c_str(), &json) ? "ok" : fbdo.errorReason().c_str());
      }
     
      // Ecriture dans le moniteur
      Serial.print("Humidite: ");
      Serial.print(h);
      Serial.println (" %\t");
      Serial.print("Temperature: ");
      Serial.print(t);
      Serial.println (" *C ");
     
    }
     
    // Configure l'ESP CAM 32
    void configInitCamera() {
      config.ledc_channel = LEDC_CHANNEL_0;
      config.ledc_timer = LEDC_TIMER_0;
      config.pin_d0 = Y2_GPIO_NUM;
      config.pin_d1 = Y3_GPIO_NUM;
      config.pin_d2 = Y4_GPIO_NUM;
      config.pin_d3 = Y5_GPIO_NUM;
      config.pin_d4 = Y6_GPIO_NUM;
      config.pin_d5 = Y7_GPIO_NUM;
      config.pin_d6 = Y8_GPIO_NUM;
      config.pin_d7 = Y9_GPIO_NUM;
      config.pin_xclk = XCLK_GPIO_NUM;
      config.pin_pclk = PCLK_GPIO_NUM;
      config.pin_vsync = VSYNC_GPIO_NUM;
      config.pin_href = HREF_GPIO_NUM;
      config.pin_sscb_sda = SIOD_GPIO_NUM;
      config.pin_sscb_scl = SIOC_GPIO_NUM;
      config.pin_pwdn = PWDN_GPIO_NUM;
      config.pin_reset = RESET_GPIO_NUM;
      config.xclk_freq_hz = 20000000;
      config.pixel_format = PIXFORMAT_JPEG; //YUV422,GRAYSCALE,RGB565,JPEG
     
      // Sélectionnez une taille d'image inférieure si la caméra ne prend pas en charge la PSRAM
      if (psramFound()) {
        config.frame_size = FRAMESIZE_UXGA; // FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA
        config.jpeg_quality = 7;            // entre 10 - 63 un nombre inférieur signifie une qualité supérieure
        config.fb_count = 2;
      } else {
        config.frame_size = FRAMESIZE_SVGA;
        config.jpeg_quality = 12;
        config.fb_count = 1;
      }
     
      // Initialiser la caméra
      esp_err_t err = esp_camera_init(&config);
      if (err != ESP_OK) {
        Serial.printf("L'initialisation de la camera a échoué avec une erreur 0x%x", err);
        return;
      }
     
     
    }
     
    void initMicroSDCard() {
     
      // Démarre la carte Micro SD
      Serial.println("Starting SD Card");
      if (!SD_MMC.begin()) {
        Serial.println("SD Card Mount Failed");
        return;
      }
      uint8_t cardType = SD_MMC.cardType();
      if (cardType == CARD_NONE) {
        Serial.println("Aucune carte Micro SD détecté");
        return;
      }
    }
     
    void takeSavePhoto(String path) {
     
      // Prendre une photo avec l'appareil photo
      camera_fb_t  * fb = esp_camera_fb_get();
     
      if (!fb) {
        Serial.println("La capture de photo a échoué");
        return;
      }
     
      // Enregistre l'image sur la carte Micro SD
      fs::FS &fs = SD_MMC;
      File file = fs.open(path.c_str(), FILE_WRITE);
      if (!file) {
        Serial.println("Impossible d'ouvrir le fichier en mode écriture");
      }
      else {
        file.write(fb->buf, fb->len);   // payload (image), payload length
        Serial.printf("Fichier enregistré dans le chemin: %s\n", path.c_str());
      }
      file.close();
     
      // Return the frame buffer back to the driver for reuse
      esp_camera_fb_return(fb);
     
      // Gestion du temps
      delay(DELAY_BETWEEN_PHOTOS);
     
    }
    Je n'ai pas à ma dispotion l'erreur du programme, mais elle est situé sur la config de la caméra :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
     
     
    // Configure l'ESP CAM 32
    void configInitCamera() {
      config.ledc_channel = LEDC_CHANNEL_0;
      config.ledc_timer = LEDC_TIMER_0;
      config.pin_d0 = Y2_GPIO_NUM;
      config.pin_d1 = Y3_GPIO_NUM;
      config.pin_d2 = Y4_GPIO_NUM;
      config.pin_d3 = Y5_GPIO_NUM;
      config.pin_d4 = Y6_GPIO_NUM;
      config.pin_d5 = Y7_GPIO_NUM;
      config.pin_d6 = Y8_GPIO_NUM;
      config.pin_d7 = Y9_GPIO_NUM;
      config.pin_xclk = XCLK_GPIO_NUM;
      config.pin_pclk = PCLK_GPIO_NUM;
      config.pin_vsync = VSYNC_GPIO_NUM;
      config.pin_href = HREF_GPIO_NUM;
      config.pin_sscb_sda = SIOD_GPIO_NUM;
      config.pin_sscb_scl = SIOC_GPIO_NUM;
      config.pin_pwdn = PWDN_GPIO_NUM;
      config.pin_reset = RESET_GPIO_NUM;
      config.xclk_freq_hz = 20000000;
      config.pixel_format = PIXFORMAT_JPEG; //YUV422,GRAYSCALE,RGB565,JPEG
     
      // Sélectionnez une taille d'image inférieure si la caméra ne prend pas en charge la PSRAM
      if (psramFound()) {
        config.frame_size = FRAMESIZE_UXGA; // FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA
        config.jpeg_quality = 7;            // entre 10 - 63 un nombre inférieur signifie une qualité supérieure
        config.fb_count = 2;
      } else {
        config.frame_size = FRAMESIZE_SVGA;
        config.jpeg_quality = 12;
        config.fb_count = 1;
      }
     
      // Initialiser la caméra
      esp_err_t err = esp_camera_init(&config);
      if (err != ESP_OK) {
        Serial.printf("L'initialisation de la camera a échoué avec une erreur 0x%x", err);
        return;
      }
    Merci à vous, mes début sur VSCode sont un peu laborieux

  6. #6
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 711
    Points : 5 390
    Points
    5 390
    Par défaut
    postez l'erreur quand vous pourrez, ça nous en dira plus

  7. #7
    Futur Membre du Club
    Homme Profil pro
    Cryogenie
    Inscrit en
    Septembre 2022
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Cryogenie

    Informations forums :
    Inscription : Septembre 2022
    Messages : 7
    Points : 6
    Points
    6
    Par défaut
    Alors j'ai touché un peu le code en déplaçant la partie erroné ( notifié dans le post precedent )
    Je me retrouve avec cette erreur :

    Le nouveau message d'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    src/main.cpp: In function 'void loop()':
    src/main.cpp:233:25: error: a function-definition is not allowed here before '{' token
     void configInitCamera() {
    Le nouveau code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    // Identifiant Wifi
    // #define WIFI_SSID "Bbox-6B1631DF"
    // #define WIFI_PASSWORD "SziX29Nv67sKn5N93D"
    // #define WIFI_SSID "DACMPCE172 0434"
    // #define WIFI_PASSWORD "5x168#G3"
    // #define WIFI_SSID "iPhone de Vincent"
    // #define WIFI_PASSWORD "s0ggxjzrbd16r"
     
    // #include <Adafruit_Sensor.h>
    #include "WiFi.h"
    #include "Firebase_ESP_Client.h"
    #include "Wire.h"
    #include "time.h"
    #include "DHT.h"
    #include "esp_camera.h"
    #include "FS.h"                // Micro SD ESP32
    #include "SD_MMC.h"            // Micro SD ESP32
    #include "soc/soc.h"           // Désactiver les problèmes de baisse de tension
    #include "soc/rtc_cntl_reg.h"  // Désactiver les problèmes de baisse de tension
    #include "driver/rtc_io.h"
    #include "SPI.h"               // Gestion LED 4
    #include "Preferences.h"
     
    // Pin definition for CAMERA_MODEL_AI_THINKER
    #define PWDN_GPIO_NUM     32
    #define RESET_GPIO_NUM    -1
    #define XCLK_GPIO_NUM      0
    #define SIOD_GPIO_NUM     26
    #define SIOC_GPIO_NUM     27
    #define Y9_GPIO_NUM       35
    #define Y8_GPIO_NUM       34
    #define Y7_GPIO_NUM       39
    #define Y6_GPIO_NUM       36
    #define Y5_GPIO_NUM       21
    #define Y4_GPIO_NUM       19
    #define Y3_GPIO_NUM       18
    #define Y2_GPIO_NUM        5
    #define VSYNC_GPIO_NUM    25
    #define HREF_GPIO_NUM     23
    #define PCLK_GPIO_NUM     22
    #define BUILTIN_LED 4
     
    //prototypes
    void configInitCamera();
    void initMicroSDCard();
    void takeSavePhoto(String path);
     
    // Stocke les paramètres de configuration de la caméra
    camera_config_t config1;
    Preferences photos;
    int lastNumber;
     
    // Gestion du temps
    unsigned long SECONDES = 1000L;
    unsigned long  MINUTES = SECONDES * 60;
    unsigned long  HEURES = MINUTES * 60;
    // Définitions de la pause entre les prises de vue
    unsigned long  DELAY_BETWEEN_PHOTOS = 0 * HEURES + 0 * MINUTES + 1 * SECONDES;
     
    // Garde une trace du nombre de photos
    unsigned int pictureNumber = 0;
     
    // Provide the token generation process info.
    #include "addons/TokenHelper.h"
    // Provide the RTDB payload printing info and other helper functions.
    #include "addons/RTDBHelper.h"
     
    // Définition Pin DHT22
    #define DHTPIN 27
    #define DHTTYPE DHT22
     
    // Déclaration DHT22
    DHT dht(DHTPIN, DHTTYPE);
     
    // Insert your network credentials
    #define WIFI_SSID "Bbox-6B1631DF"
    #define WIFI_PASSWORD "SziX29Nv67sKn5N93D"
     
    // Insert Firebase project API Key
    #define API_KEY "AIzaSyBtHFS-vIFZDIJHWIEOWdEXVZnSuO_i1rg"
     
    // Insert Authorized Email and Corresponding Password
    #define USER_EMAIL "programmation187@hotmail.com"
    #define USER_PASSWORD "qUzruf-figbod-7tahhe"
     
    // Insert RTDB URLefine the RTDB URL
    #define DATABASE_URL "https://climat-box-v01-default-rtdb.europe-west1.firebasedatabase.app/"
     
    // Define Firebase objects
    FirebaseData fbdo;
    FirebaseAuth auth;
    FirebaseConfig config;
     
    // Variable to save USER UID
    String uid;
     
    // Database main path (to be updated in setup with the user UID)
    String databasePath;
    // Database child nodes
    String tempPath = "/temperature";
    String humPath = "/humidity";
    String timePath = "/timestamp";
     
    // Parent Node (to be updated in every loop)
    String parentPath;
     
    int timestamp;
    FirebaseJson json;
     
    const char* ntpServer = "pool.ntp.org";
     
    float temperature;
    float humidity;
     
    // Timer variables (send new readings every 10 minutes)
    unsigned long sendDataPrevMillis = 0;
    unsigned long timerDelay = 600000;
     
    // Initialize WiFi
    void initWiFi() {
      WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
      Serial.print("Connecting to WiFi ..");
      while (WiFi.status() != WL_CONNECTED) {
        Serial.print('.');
        delay(1000);
      }
      Serial.println(WiFi.localIP());
      Serial.println();
    }
     
    // Function that gets current epoch time
    unsigned long getTime() {
      time_t now;
      struct tm timeinfo;
      if (!getLocalTime(&timeinfo)) {
        //Serial.println("Failed to obtain time");
        return(0);
      }
      time(&now);
      return now;
    }
     
    void setup(){
     
        // Désactive le détecteur de baisse de tension
      WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
     
      Serial.begin(115200); 
    //  Serial.println(F("DHTxx test!")); 
     
      // Initialise le DHT22 & Wifi & Time
      dht.begin();
      initWiFi();
      configTime(0, 0, ntpServer);
     
      // Assign the api key (required)
      config.api_key = API_KEY;
     
      // Assign the user sign in credentials
      auth.user.email = USER_EMAIL;
      auth.user.password = USER_PASSWORD;
     
      // Assign the RTDB URL (required)
      config.database_url = DATABASE_URL;
     
      Firebase.reconnectWiFi(true);
      fbdo.setResponseSize(4096);
     
      // Assign the callback function for the long running token generation task */
      config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
     
      // Assign the maximum retry of token generation
      config.max_token_generation_retry = 5;
     
      // Initialize the library with the Firebase authen and config
      Firebase.begin(&config, &auth);
     
      // Getting the user UID might take a few seconds
      Serial.println("Getting User UID");
      while ((auth.token.uid) == "") {
        Serial.print('.');
        delay(1000);
      }
      // Print user UID
      uid = auth.token.uid.c_str();
      Serial.print("User UID: ");
      Serial.println(uid);
     
      // Update database path
      databasePath = "/UsersData/" + uid + "/readings";
     
      // Initialise la caméra
      Serial.print("Initialisation du module caméra...");
      configInitCamera();
      Serial.println("Ok!");
     
      // Initialise l'EEPROM
      photos.begin("numeros", false);
      lastNumber = photos.getInt("counter", 0) + 1;
     
      // Initialise la carte Micro SD
      if (!SD_MMC.begin("/sdcard", true)) {
        Serial.println("Impossible de monter la carte Micro SD");
        return;
      }
     
      // Specifie la pin de la LED 4
      pinMode(BUILTIN_LED, OUTPUT);
      digitalWrite(BUILTIN_LED, LOW);
     
      // Recherche une carte Micro SD
      uint8_t cardType = SD_MMC.cardType();
      if (cardType == CARD_NONE) {
        Serial.println("Aucune carte Micro SD détecté");
        return;
      }
     
    }
     
    void loop(){
     
      // Chemin où la nouvelle image sera enregistrée sur la carte SD
      String path = "/picture" + String(lastNumber + pictureNumber) + ".jpg";
      Serial.printf("Nom du fichier image: %s\n", path.c_str());
     
      // Prend et enregistre une photo
      takeSavePhoto(path);
      photos.putInt("counter", lastNumber + pictureNumber);
      pictureNumber++;
      delay(10000);
     
    // Configure l'ESP CAM 32
    void configInitCamera() {
      config.ledc_channel = LEDC_CHANNEL_0;
      config.ledc_timer = LEDC_TIMER_0;
      config.pin_d0 = Y2_GPIO_NUM;
      config.pin_d1 = Y3_GPIO_NUM;
      config.pin_d2 = Y4_GPIO_NUM;
      config.pin_d3 = Y5_GPIO_NUM;
      config.pin_d4 = Y6_GPIO_NUM;
      config.pin_d5 = Y7_GPIO_NUM;
      config.pin_d6 = Y8_GPIO_NUM;
      config.pin_d7 = Y9_GPIO_NUM;
      config.pin_xclk = XCLK_GPIO_NUM;
      config.pin_pclk = PCLK_GPIO_NUM;
      config.pin_vsync = VSYNC_GPIO_NUM;
      config.pin_href = HREF_GPIO_NUM;
      config.pin_sscb_sda = SIOD_GPIO_NUM;
      config.pin_sscb_scl = SIOC_GPIO_NUM;
      config.pin_pwdn = PWDN_GPIO_NUM;
      config.pin_reset = RESET_GPIO_NUM;
      config.xclk_freq_hz = 20000000;
      config.pixel_format = PIXFORMAT_JPEG; //YUV422,GRAYSCALE,RGB565,JPEG
     
      // Sélectionnez une taille d'image inférieure si la caméra ne prend pas en charge la PSRAM
      if (psramFound()) {
        config.frame_size = FRAMESIZE_UXGA; // FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA
        config.jpeg_quality = 7;            // entre 10 - 63 un nombre inférieur signifie une qualité supérieure
        config.fb_count = 2;
      } else {
        config.frame_size = FRAMESIZE_SVGA;
        config.jpeg_quality = 12;
        config.fb_count = 1;
      }
     
      // Initialiser la caméra
      esp_err_t err = esp_camera_init(&config);
      if (err != ESP_OK) {
        Serial.printf("L'initialisation de la camera a échoué avec une erreur 0x%x", err);
        return;
      }
     
    }
     
      // Temps entre chaques mesures
      delay(60000);
     
      // La lecture de la température ou de l'humidité prend environ 250 millisecondes !
      // Les lectures du capteur peuvent également être "anciennes" jusqu'à 2 secondes (c'est un capteur très lent)
      float h = dht.readHumidity();
      float t = dht.readTemperature();
     
      // Vérifiez si des lectures ont échoué et quittez plus tôt (pour réessayer).
      if (isnan(h) || isnan(t)) {
        Serial.println(F("Failed to read from DHT sensor!"));
        return;
      }
     
      // Send new readings to database
      if (Firebase.ready() && (millis() - sendDataPrevMillis > timerDelay || sendDataPrevMillis == 0)){
        sendDataPrevMillis = millis();
     
        //Get current timestamp
        timestamp = getTime();
        Serial.print ("time: ");
        Serial.println (timestamp);
     
        parentPath= databasePath + "/" + String(timestamp);
     
        json.set(tempPath.c_str(), String(dht.readTemperature()));
        json.set(humPath.c_str(), String(dht.readHumidity()));
        json.set(timePath, String(timestamp));
        Serial.printf("Set json... %s\n", Firebase.RTDB.setJSON(&fbdo, parentPath.c_str(), &json) ? "ok" : fbdo.errorReason().c_str());
      }
     
      // Ecriture dans le moniteur
      Serial.print("Humidite: ");
      Serial.print(h);
      Serial.println (" %\t");
      Serial.print("Temperature: ");
      Serial.print(t);
      Serial.println (" *C ");
     
    }
     
    void initMicroSDCard() {
     
      // Démarre la carte Micro SD
      Serial.println("Starting SD Card");
      if (!SD_MMC.begin()) {
        Serial.println("SD Card Mount Failed");
        return;
      }
      uint8_t cardType = SD_MMC.cardType();
      if (cardType == CARD_NONE) {
        Serial.println("Aucune carte Micro SD détecté");
        return;
      }
    }
     
    void takeSavePhoto(String path) {
     
      // Prendre une photo avec l'appareil photo
      camera_fb_t  * fb = esp_camera_fb_get();
     
      if (!fb) {
        Serial.println("La capture de photo a échoué");
        return;
      }
     
      // Enregistre l'image sur la carte Micro SD
      fs::FS &fs = SD_MMC;
      File file = fs.open(path.c_str(), FILE_WRITE);
      if (!file) {
        Serial.println("Impossible d'ouvrir le fichier en mode écriture");
      }
      else {
        file.write(fb->buf, fb->len);   // payload (image), payload length
        Serial.printf("Fichier enregistré dans le chemin: %s\n", path.c_str());
      }
      file.close();
     
      // Return the frame buffer back to the driver for reuse
      esp_camera_fb_return(fb);
     
      // Gestion du temps
      delay(DELAY_BETWEEN_PHOTOS);
     
    }
    Je pense que cette erreur en cache d'autre ...

  8. #8
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 711
    Points : 5 390
    Points
    5 390
    Par défaut
    ben c'est clair non ? (ce serait encore plus clair si vous indentez le code)

    vous avez

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     void loop(){
      ...
       // Configure l'ESP CAM 32
       void configInitCamera() {
          ...
        }
      ...
    }
    ==> la définition de la fonction configInitCamera() est coincée dans la définition de la fonction loop()... On ne peut pas faire cela en C++ il faut la sortir de là

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    // Configure l'ESP CAM 32
    void configInitCamera() {
      ...
    }
     
    void loop(){
      ...
    }

  9. #9
    Futur Membre du Club
    Homme Profil pro
    Cryogenie
    Inscrit en
    Septembre 2022
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Cryogenie

    Informations forums :
    Inscription : Septembre 2022
    Messages : 7
    Points : 6
    Points
    6
    Par défaut
    ben c'est clair non ? (ce serait encore plus clair si vous indentez le code)
    Pas totalement quand on débute depuis peu dans ce monde, surtout en apprennant sur IDE Arduino pour passer ensuite sur VSCode & PlatformIO
    En plus de celui ci il y avait d'autres coquilles, mais c'est bon c'est réglé !!

    Merci pour le coup de pouce

  10. #10
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 711
    Points : 5 390
    Points
    5 390
    Par défaut
    Citation Envoyé par vinz187 Voir le message
    surtout en apprennant sur IDE Arduino pour passer ensuite sur VSCode & PlatformIO
    Bof bof… ça n’a rien à voir avec les IDEs. C’est juste pas correct de faire comme cela en C++…

    Mais faut bien apprendre

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Débutant] De l'IDE Arduino à VS Code
    Par vinz187 dans le forum Visual Studio
    Réponses: 0
    Dernier message: 27/09/2022, 13h21
  2. Dialogue client / serveur ESP8266 avec IDE ARDUINO
    Par F6AAP dans le forum Arduino
    Réponses: 2
    Dernier message: 30/08/2018, 08h50
  3. Formaliser une idée en pseudo-code
    Par Kawamx dans le forum Algorithmes et structures de données
    Réponses: 5
    Dernier message: 17/01/2017, 10h55
  4. Réponses: 1
    Dernier message: 30/10/2016, 11h25

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo