Pages: [1]   Go Down
Author Topic: [résolu] arduino erreur : "error: 'client' was not declared in this scope"  (Read 892 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Quote
#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 smiley

Bonne journée.
« Last Edit: March 26, 2013, 09:01:59 am by skyline57800 » Logged

France
Offline Offline
Faraday Member
**
Karma: 55
Posts: 5347
Arduino Hacker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Bonjour,

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

Des news, des tuto et plein de bonne chose sur http://skyduino.wordpress.com !

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

j'ai rajouter la ligne
Quote
#include <EthernetClient.h>
pour résoudre l'erreur scope, mais ca me la mets toujours :/

Quote
sketch_mar26a.ino: In function 'void loop()':
sketch_mar26a:52: error: 'client' was not declared in this scope
Logged

France
Offline Offline
Faraday Member
**
Karma: 55
Posts: 5347
Arduino Hacker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Arf t'as pas compris ...

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

puis dans le code :
Code:
EthernetClient client;
// ...
Logged

Des news, des tuto et plein de bonne chose sur http://skyduino.wordpress.com !

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

France
Offline Offline
Faraday Member
**
Karma: 55
Posts: 5347
Arduino Hacker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

la ligne "EthernetClient client;" se met ou ?
C'est un exemple de déclaration ...
ctrl+f -> "Client" -> remplacer -> "EthernetClient"
Logged

Des news, des tuto et plein de bonne chose sur http://skyduino.wordpress.com !

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

France
Offline Offline
Faraday Member
**
Karma: 55
Posts: 5347
Arduino Hacker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Donne ton code complet ...
Logged

Des news, des tuto et plein de bonne chose sur http://skyduino.wordpress.com !

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Quote
#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;
  }
 
}

}
Logged

France
Offline Offline
Faraday Member
**
Karma: 55
Posts: 5347
Arduino Hacker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#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;
    }

  }

}
Logged

Des news, des tuto et plein de bonne chose sur http://skyduino.wordpress.com !

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Merci beaucoup smiley-grin !
Logged

France
Offline Offline
Faraday Member
**
Karma: 55
Posts: 5347
Arduino Hacker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

J'utilise l'ide 1.0.3 et 1.0.4.

Copié / collé du code de mon post :
Quote
Done compiling

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

Des news, des tuto et plein de bonne chose sur http://skyduino.wordpress.com !

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: