Library error: was not declared in this scope drive me Nuts(Kinda solved)

Hi, must be not much, but I don’t see IT, can any one help?

#include <Uart_WIFI.h>

Uart_WIFI WIFI=Uart_WIFI(1);

void setup() {
}

void loop() {
 }

I took the good habit to test my library on every step, so no code so far.

This is the .h file:

#ifndef Uart_WIFI_h
#define Uart_WIFI_h

#include <WString.h>

class Uart_WIFI {

public:
  	
	Uart_WIFI(int);
  	Uart_WIFI(int, int, int);
  	
	void Initialisation();
 	void Gestion_de_donnee(String);
	
	bool etat;
	String ssid;
	String mot_de_passe;
	

private:
	
	int _Port_Uart_WIFI;
	int _donnee_temporaire;
	int _donnee_sortante;
	void _Envois_de_donnee(String);
 
};

#endif

And here is the .cpp file:

#include "Uart_WIFI.h"
#include <WString.h>

#if (ARDUINO >= 100)

	#include "Arduino.h"
	
#else
 
	#include "WProgram.h"
	
#endif

extern "C" {

}

String chaine_entrante;
	
Uart_WIFI::Uart_WIFI(int n_port){

	_Port_Uart_WIFI = n_port;
	
}

Uart_WIFI::Uart_WIFI(int n_port, int r, int c){

	_Port_Uart_WIFI = n_port;

}


void Uart_WIFI::Initialisation(){

	switch (_Port_Uart_WIFI) {
    
		case 1:

			Serial.begin(9600);
			break;
		
		case 2:
		
			Serial.begin(9600);
			break;
		
		case 3:
		
			Serial.begin(9600);
			break;
			    
	}
	
}




void Uart_WIFI::_Envois_de_donnee(String Donnee){

	switch (_Port_Uart_WIFI) {
    
		case 1:

			Serial.print(Donnee);
			break;
		
		case 2:
		
			Serial.print(Donnee);
			break;
		
		case 3:
		
			Serial.print(Donnee);
			break;
		
	}

}

void serialEvent1() {
  
	int position;
	
	while (Serial.available()) {

		position++;
		char caractere_entrant = (char)Serial1.read(); 
		chaine_entrante[position] += caractere_entrant;
    
	}
	
	Gestion_de_donnee(chaine_entrante);

}

void serialEvent2() {
  
	int position;
	
	while (Serial.available()) {

		position++;
		char caractere_entrant = (char)Serial2.read(); 
		chaine_entrante[position] += caractere_entrant;
    
	}
	
	Gestion_de_donnee(chaine_entrante);
	
}

void serialEvent3() {
  
	int position;
	
	while (Serial.available()) {
	
		position++;
		char caractere_entrant = (char)Serial3.read(); 
		chaine_entrante += caractere_entrant;
		
	}
	
	Gestion_de_donnee(chaine_entrante);
	
}

	
void Uart_WIFI::Gestion_de_donnee(String donnnee) {
	
}

Not much has been done, Thank God, so it will be easy to find.

But Arduino IDE return:

C:\Documents and Settings\Cath.CHAMBRE\My Documents\Arduino\libraries\Uart_WIFI\Uart_WIFI.cpp: In function 'void serialEvent1()':
C:\Documents and Settings\Cath.CHAMBRE\My Documents\Arduino\libraries\Uart_WIFI\Uart_WIFI.cpp:94: error: 'Gestion_de_donnee' was not declared in this scope
C:\Documents and Settings\Cath.CHAMBRE\My Documents\Arduino\libraries\Uart_WIFI\Uart_WIFI.cpp: In function 'void serialEvent2()':
C:\Documents and Settings\Cath.CHAMBRE\My Documents\Arduino\libraries\Uart_WIFI\Uart_WIFI.cpp:110: error: 'Gestion_de_donnee' was not declared in this scope
C:\Documents and Settings\Cath.CHAMBRE\My Documents\Arduino\libraries\Uart_WIFI\Uart_WIFI.cpp: In function 'void serialEvent3()':
C:\Documents and Settings\Cath.CHAMBRE\My Documents\Arduino\libraries\Uart_WIFI\Uart_WIFI.cpp:126: error: 'Gestion_de_donnee' was not declared in this scope

Got any idea?

In your cpp file you implement the function serialEvent1(), which is global namespace. However, the Gestion_de_donee() function is of namespace Uart_WIFI. You must creat an object of that class to use the function. Or you make the function static and call it with Uart_WIFI::Gestion_de_donnee().

The same for the functions serialEvent2 and 3.

I'm happy to find some one that see the problem right away, but sorry to say it that way, but what you are saying sound Chinese to me ;) I will put your name in the credit.lol

Can you correct my mistake and send it back. lol

So far I only made simple library, and this one seem to be one step further then what I've made so far.

Are you saying that I can't use serialEvent1(), serialEvent2() and serialEvent3() in a library in the same way that I use it in a sketch?

Frédéric_Plante:
Are you saying that I can’t use serialEvent1(), serialEvent2() and serialEvent3() in a library in the same way that I use it in a sketch?

What he’s saying is you better stick

Uart_WIFI:: in front of

serialEvent1() in the function definition.

You might need to include <arduino.h> in your source file since you’re using arduino’s serial events.

You can. The Problem is that you created a class. To access anything that is in the class you must create an object of that class and access the elemets than. Think of it as an hotel. If you just say room no. 1, the compiler does not know to which hotel it has to go in order to access room no. 1.

You can avoid this if you just don't use classes at all. just declare your functions as you would do in a sketch.

If you want to use classes, than you have to access the function through an object:

Uart_WIFI object(1);
object.Gestion_de_donnee(...);

The dot-operator is telling the compiler use the fuction from this class.

Just as a design hint. Do not use an initialize function. Initialize all the things in your constructor. Otherwise a user might forget to call initialize and the code does not run as expected.

Is this line correct? Should it have the "=" in it?

Uart_WIFI WIFI=Uart_WIFI(1);

...R

@mistergreen But than the three serialEvent1/2/3 functions must be included in the header-file as well!

Ah! Thank you guys. I feel lot lighter now. Many people are waiting for this, and getting that kind of problem right from the start was pretty disappointing.

Sketch uses 4,280 bytes (1%) of program storage space. Maximum is 258,048 bytes.
Global variables use 690 bytes (8%) of dynamic memory, leaving 7,502 bytes for local variables. Maximum is 8,192 bytes.

Thank you all very much once more.

I can now fall in the AT command hell part ;)

Robin2: Is this line correct? Should it have the "=" in it?

Uart_WIFI WIFI=Uart_WIFI(1);

...R

This line is correct, otherwise there would had been a compile error. But maybe just writing

Uart_WIFI wifi(1);

would be easier.

I think he calls the operator= there to copy the object from right to left...

Just as a design hint. Do not use an initialize function. Initialize all the things in your constructor. Otherwise a user might forget to call initialize and the code does not run as expected.

The use of constructors for this purpose in an arduino context is not appropriate. There is initialization of the hardware which must be complete before code such as serial.begin will work correctly. You should expect that the constructors will be executed before this init code. This is why so many Arduino libraries have a begin method to do the job that you might use a constructor for in a different environment.