[résolu] arduino erreur : "error: 'client' was not declared in this scope"

bonjour j’ai recopié le programme ci-dessous d’un site, j’ai réglé les différentes erreurs sauf une seul, je ne sais pas comment la resoudre
Cela me dit " error: ‘client’ was not declared in this scope "

et voici le programme.

#include <Ethernet.h>

#define S1_PIN 0 // input pin for first inductive sensor
#define S2_PIN 5 // input pin for second inductive sensor
#define SAMPLES 10000 // number of samples to take
#define NUM_READINGS 10 // number of readings to average
int val1 = 0;
int val2 = 0;
int reading_cnt = 0; // counter for 1 second samples
float total_rms1 = 0;
float total_rms2 = 0;

byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip = { 192, 168, 0, 177 };
byte gateway = { 192, 168, 0, 1 };
byte subnet = { 255, 255, 255, 0 };
byte server = { 192, 168, 0, 1 }; // router.springfield

void setup() {
Ethernet.begin(mac, ip, gateway, subnet);
analogReference(EXTERNAL);
Serial.begin(9600);

delay(1000);
Serial.println(“Connecting…”);

}

void loop() {

int max_val1 = 0;
int max_val2 = 0;
float rms_val1 = 0;
float rms_val2 = 0;

for (int cnt=0; cnt < SAMPLES; cnt++) { val1 = analogRead(S1_PIN); val2 = analogRead(S2_PIN); rms_val1 = rms_val1 + sq((float)val1); rms_val2 = rms_val2 + sq((float)val2); } rms_val1 = sqrt(rms_val1 / (SAMPLES/2) ); rms_val2 = sqrt(rms_val2 / (SAMPLES/2) ); total_rms1 = total_rms1 + rms_val1; total_rms2 = total_rms2 + rms_val2; reading_cnt++; if (reading_cnt >= NUM_READINGS) {

float average_rms1 = total_rms1 / NUM_READINGS;
float average_rms2 = total_rms2 / NUM_READINGS;

Serial.print("AVG VALUES RMS - “);
Serial.print(average_rms1);
Serial.print(” ");
Serial.println(average_rms2);

if (client.connect()) {
Serial.println(“Sending data”);

client.print(“GET /cgi-bin/relay.pl?value1=”);
client.print(average_rms1);
Serial.print(" ");
Serial.println(average_rms2);

if (client.connect()) {
Serial.println(“Sending data”);

client.print(“GET /cgi-bin/relay.pl?value1=”);
client.print(average_rms1);
client.print("&value2=");
client.print(average_rms2);
client.println(" HTTP/1.1");
client.println();
client.stop();
} else {
Serial.println(“Failed to connect to client”);
}

total_rms1 = 0;
total_rms2 = 0;
reading_cnt = 0;
}

}

}

merci de vouloir m’aider :slight_smile:

Bonne journée.

Bonjour,

Si tu travaille avec l'ide arduino 1.0.x la librairie Ethernet a été un peu modifié :
Client -> EthernetClient
Server -> EthernetServer

j’ai rajouter la ligne

#include <EthernetClient.h>

pour résoudre l’erreur scope, mais ca me la mets toujours :confused:

sketch_mar26a.ino: In function ‘void loop()’:
sketch_mar26a:52: error: ‘client’ was not declared in this scope

Arf t’as pas compris …

#include <SPI.h>
#include <Ethernet.h>

puis dans le code :

EthernetClient client;
// ...

désolé je suis une brelle en C++ xD .
la ligne "EthernetClient client;" se met ou ?

skyline57800:
la ligne "EthernetClient client;" se met ou ?

C'est un exemple de déclaration ...
ctrl+f -> "Client" -> remplacer -> "EthernetClient"

cela me met maintenant " error: expected primary-expression before '.' token"

Donne ton code complet ...

Voici tout mon programme
j'ai tout remis comme avant
Merci de prendre de ton temps pour moi ^^ c'est vraiment symapthique . :slight_smile:

#include <SPI.h>
#include <Ethernet.h>

#define S1_PIN 0 // input pin for first inductive sensor
#define S2_PIN 5 // input pin for second inductive sensor
#define SAMPLES 10000 // number of samples to take
#define NUM_READINGS 10 // number of readings to average
int val1 = 0;
int val2 = 0;
int reading_cnt = 0; // counter for 1 second samples
float total_rms1 = 0;
float total_rms2 = 0;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 177 };
byte gateway[] = { 192, 168, 0, 1 };
byte subnet[] = { 255, 255, 255, 0 };
byte server[] = { 192, 168, 0, 1 }; // router.springfield

void setup() {
Ethernet.begin(mac, ip, gateway, subnet);
analogReference(EXTERNAL);
Serial.begin(9600);

delay(1000);
Serial.println("Connecting...");

}

void loop() {

int max_val1 = 0;
int max_val2 = 0;
float rms_val1 = 0;
float rms_val2 = 0;

for (int cnt=0; cnt < SAMPLES; cnt++) { val1 = analogRead(S1_PIN); val2 = analogRead(S2_PIN); rms_val1 = rms_val1 + sq((float)val1); rms_val2 = rms_val2 + sq((float)val2); } rms_val1 = sqrt(rms_val1 / (SAMPLES/2) ); rms_val2 = sqrt(rms_val2 / (SAMPLES/2) ); total_rms1 = total_rms1 + rms_val1; total_rms2 = total_rms2 + rms_val2; reading_cnt++; if (reading_cnt >= NUM_READINGS) {

float average_rms1 = total_rms1 / NUM_READINGS;
float average_rms2 = total_rms2 / NUM_READINGS;

Serial.print("AVG VALUES RMS - ");
Serial.print(average_rms1);
Serial.print(" ");
Serial.println(average_rms2);

if (client.connect()) {
Serial.println("Sending data");

client.print("GET /cgi-bin/relay.pl?value1=");
client.print(average_rms1);
Serial.print(" ");
Serial.println(average_rms2);

if (client.connect()) {
Serial.println("Sending data");

client.print("GET /cgi-bin/relay.pl?value1=");
client.print(average_rms1);
client.print("&value2=");
client.print(average_rms2);
client.println(" HTTP/1.1");
client.println();
client.stop();
} else {
Serial.println("Failed to connect to client");
}

total_rms1 = 0;
total_rms2 = 0;
reading_cnt = 0;
}

}

}

#include <SPI.h>
#include <Ethernet.h>

#define S1_PIN 0    // input pin for first inductive sensor
#define S2_PIN 5    // input pin for second inductive sensor
#define SAMPLES 10000 // number of samples to take
#define NUM_READINGS 10 // number of readings to average
int val1 = 0;
int val2 = 0;
int reading_cnt = 0; // counter for 1 second samples
float total_rms1 = 0;
float total_rms2 = 0;


byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 
  192, 168, 0, 177 };
byte gateway[] = { 
  192, 168, 0, 1 };
byte subnet[] = { 
  255, 255, 255, 0 };
byte server[] = { 
  192, 168, 0, 1 }; // router.springfield



void setup() {
  Ethernet.begin(mac, ip, gateway, subnet);
  analogReference(EXTERNAL);
  Serial.begin(9600);

  delay(1000);
  Serial.println("Connecting...");

}


void loop() {


  int max_val1 = 0;
  int max_val2 = 0;
  float rms_val1 = 0;
  float rms_val2 = 0;

  for (int cnt=0; cnt < SAMPLES; cnt++) {     
    val1 = analogRead(S1_PIN);     
    val2 = analogRead(S2_PIN);     
    rms_val1 = rms_val1 + sq((float)val1);     
    rms_val2 = rms_val2 + sq((float)val2);   
  }   
  rms_val1 = sqrt(rms_val1 / (SAMPLES/2) );   
  rms_val2 = sqrt(rms_val2 / (SAMPLES/2) );   
  total_rms1 = total_rms1 + rms_val1;   
  total_rms2 = total_rms2 + rms_val2;   
  reading_cnt++;   
  if (reading_cnt >= NUM_READINGS) {

    float average_rms1 = total_rms1 / NUM_READINGS;
    float average_rms2 = total_rms2 / NUM_READINGS;

    Serial.print("AVG VALUES *RMS* - ");
    Serial.print(average_rms1);
    Serial.print("   ");
    Serial.println(average_rms2);

    EthernetClient client; // Déclaration de l'objet EthernetClient
    if (client.connect(server, 80)) { // Connexion au serveur
      Serial.println("Sending data");

      client.print("GET /cgi-bin/relay.pl?value1=");
      client.print(average_rms1);
      Serial.print("   ");
      Serial.println(average_rms2);
      client.println(" HTTP/1.1"); // Avec le HTTP/1.1 en fin de GET ça marchera mieux ;)
      client.println();
      delay(10); // Pas de coupure sauvage de la connexion
      client.stop(); // Fermeture de la connexion

      if (client.connect(server, 80)) {  // Même chose
        Serial.println("Sending data");

        client.print("GET /cgi-bin/relay.pl?value1=");
        client.print(average_rms1);
        client.print("&value2=");
        client.print(average_rms2);
        client.println(" HTTP/1.1");
        client.println();
        delay(10); // Même chose
        client.stop(); // Même chose
      } 
      else {
        Serial.println("Failed to connect to client");
      }

      total_rms1 = 0;
      total_rms2 = 0;
      reading_cnt = 0;
    }

  }

}

Merci beaucoup :smiley: !

J'utilise l'ide 1.0.3 et 1.0.4.

Copié / collé du code de mon post :

Done compiling

Binary sketch size: 12 482 bytes (of a 32 256 byte maximum)

j'ai supprimé mon ancien message j'avais mal copié (autant pour moi) !
Haha !merci encore !