[RESOLU] Enregistrer data sur carte SD puis Envoie vers COSM

Le voici merci encore pour ton aide

// /////////////////////////////// 1. Entête déclarative /////////////////////// 
// A ce niveau sont déclarées les librairies incluses, les constantes, les variables, les objets utiles...

// --- Déclaration des constantes ---

// --- Inclusion des librairies ---
#include <SD.h>
#include <SPI.h>         
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Time.h>
#include <avr/pgmspace.h>
// --- Déclaration des constantes utiles ---
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield

// cosm
#define APIKEY         "xxxxxxxxxxxxxxx" // replace your Cosm api key here
#define FEEDID         56809 // replace your feed ID
#define USERAGENT      "Vera" // user agent is the project name
//

byte mac[] = {  
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

unsigned int localPort = 8888;      // local port to listen for UDP packets

IPAddress timeServer(192, 43, 244, 18); // time.nist.gov NTP server

const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message

byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets 

// A UDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
// cosm
// initialize the library instance:
EthernetClient client;
char server[] = "api.cosm.com";   // name address for cosm API

unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
boolean lastConnected = false;                 // state of the connection last time through the main loop
const unsigned long postingInterval = 10*1000; //delay between updates to cosm.com
//

time_t prevDisplay = 0; // when the digital clock was displayed
const  int timeZoneOffset = +1; // GMT zone;
// --- Déclaration des constantes des broches E/S numériques ---

const int brocheSDCardSelect=4;

// --- Déclaration des constantes des broches analogiques ---


// --- Déclaration des variables globales ---

volatile long comptageImpulsion=0; // variable accessible dans la routine interruption externe 0
int test; // Variable utilisée pour tester valeur renvoyée par fonctions SD Card

// --- Déclaration des objets utiles pour les fonctionnalités utilisées ---
File file; // objet file 
File root; // objet root pour le répertoire racine

// ////////////////////////// 2. FONCTION SETUP = Code d'initialisation ////////////////////////// 
// La fonction setup() est exécutée en premier et 1 seule fois, au démarrage du programme

void setup()   { // debut de la fonction setup()

  // --- ici instructions à exécuter 1 seule fois au démarrage du programme --- 

  // ------- Initialisation fonctionnalités utilisées -------  

  Serial.begin(115200); // initialise connexion série à 115200 bauds
  // IMPORTANT : régler le terminal côté PC avec la même valeur de transmission 

  //---- initialise l'utilisation de la carte mémoire SD en mode SPI  
  pinMode(10, OUTPUT); // met la broche 10 (SS) en sortie (nécessaire avec module ethernet)
  digitalWrite(10, HIGH); // mais désactive le  circuit intégré W5100 du module ethernet!

  //----- initialisation de la carte SD ----- 
  Serial.println( (__FlashStringHelper *)PSTR("Initialisation de la SD card..."));

  pinMode(10, OUTPUT); // laisser la broche SS en sortie - obligatoire avec librairie SD

  test=SD.begin(brocheSDCardSelect); // initialisation de la carte SD avec broche 4 en tant que CS - renvoie true/false

  if (test!=true) { // si initialisation n'est pas réussie
    Serial.println( (__FlashStringHelper *)PSTR("Echec initialisation!")); // message port Série
  }
  else { // si nitialisation réussie
    Serial.println( (__FlashStringHelper *)PSTR("Initialisation reussie !")); // message port Série

    //----- affiche le contenu du répertoire 

    root = SD.open("/"); // ouvre la SD Card à la racine

    Serial.println( (__FlashStringHelper *)PSTR("Repertoire racine ouvert !"));
  }

  attachInterrupt(0, gestionINT0, RISING); // attache l'interruption externe n°0 à la fonction gestionINT0()
  // mode déclenchement possibles = LOW, CHANGE, RISING, FALLING


    // start Ethernet and UDP
  if (Ethernet.begin(mac) == 0) {
    Serial.println( (__FlashStringHelper *)PSTR("Failed to configure Ethernet using DHCP"));
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  Udp.begin(localPort);
  setSyncProvider(getNtpTime);
  while(timeStatus()== timeNotSet)   
    ; // wait until the time is set by the sync provider
  //---- crée fichier en écriture --- 
  file = SD.open("data.txt", FILE_WRITE); // ouvre le fichier en écriture
  // NB : le fichier est créé si il n'existe pas !

  //---- test si fichier dispo en écriture 
  if (!file) { // si fichier pas dispo 

    Serial.println( (__FlashStringHelper *)PSTR("Erreur ouverture fichier !"));

  } // fin if

  else { // si le fichier existe et est ouvert 

    Serial.println( (__FlashStringHelper *)PSTR("Fichier pret pour ecriture !"));

    //----- Ecriture dans le fichier au format CSV ----- 

    // premiere ligne du fichier CSV - entete avec liste des champs
    // showStringfileln(PSTR("Nbreimpulsion;Millis;Heure;Minute;Seconde;Jour;Mois;Annee"));
    file.println( (__FlashStringHelper *)PSTR("Nbreimpulsion;Millis;Heure;Minute;Seconde;Jour;Mois;Annee") );

    file.close(); // ferme le fichier
    Serial.println( (__FlashStringHelper *)PSTR("Fin enregistrement !"));  
    Serial.println( (__FlashStringHelper *)PSTR("Fermeture fichier !"));
  }  
  // ------- Broches en sorties numériques -------  

  // ------- Broches en entrées numériques -------  

  // ------- Activation si besoin du rappel au + (pullup) des broches en entrées numériques -------  

  // ------- Initialisation des variables utilisées -------  

} // fin de la fonction setup()
// ********************************************************************************

////////////////////////////////// 3. FONCTION LOOP = Boucle sans fin = coeur du programme //////////////////
// la fonction loop() s'exécute sans fin en boucle aussi longtemps que l'Arduino est sous tension

void loop(){ // debut de la fonction loop()





  //---- crée fichier en écriture --- 
  file = SD.open("data.txt", FILE_WRITE); // ouvre le fichier en écriture
  // NB : le fichier est créé si il n'existe pas !

  //---- test si fichier dispo en écriture 
  if (!file) { // si fichier pas dispo 

    Serial.println( (__FlashStringHelper *)PSTR("Erreur ouverture fichier !"));

  } // fin if

  else { // si le fichier existe et est ouvert 

    Serial.println( (__FlashStringHelper *)PSTR("Fichier pret pour ecriture !"));

    //----- Ecriture dans le fichier au format CSV ----- 

    Serial.println( (__FlashStringHelper *)PSTR("Enregistrement en cours :"));

    // valeur deuxieme champ
    file.print(comptageImpulsion);
    file.print(';'); 
    // valeur quatrieme champ
    file.print(millis()), file.print(';');

    // le dernier champ doit se terminer par un saut de ligne +++
    if( now() != prevDisplay) //update the display only if the time has changed
    {
      prevDisplay = now();
      digitalClockDisplay();  
    }  
    file.close(); // ferme le fichier
    Serial.println( (__FlashStringHelper *)PSTR("Fin enregistrement !"));  
    Serial.println( (__FlashStringHelper *)PSTR("Fermeture fichier !")); 

    // cosm
    // read the analog sensor:
    int sensorReading = comptageImpulsion ;   

    // if there's incoming data from the net connection.
    // send it out the serial port.  This is for debugging
    // purposes only:
    if (client.available()) {
      char c = client.read();
      Serial.print(c);
    }
    // if there's no net connection, but there was one last time
    // through the loop, then stop the client:
    if (!client.connected() && lastConnected) {
      Serial.println();
      Serial.println( (__FlashStringHelper *)PSTR("disconnecting."));
      client.stop();
    }
    // if you're not connected, and ten seconds have passed since
    // your last connection, then connect again and send data:
    if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
      sendData(sensorReading);
    }
    // store the state of the connection for next time through
    // the loop:
    lastConnected = client.connected();


    //

    delay(120000);

  } // fin else

} // fin de la fonction loop() - le programme recommence au début de la fonction loop sans fin
// ********************************************************************************