Bonjour à tous,
après quelques heures de travail, j'arrive à une première étape: tous les fichiers nécessaires.
Je ne sais, cependant, comment appeler les fonctions d'une classe intégrée. Pouvez-vous m'aider?
Ma classe doit lire un fichier via connexion FTP. Pour cela, évidemment, il faut une connexion Wifi active (Wifi, car c'est avec ESP-10 que je veux faire fonctionner initialement).
Alors, comment créer et interpeler l'objet Wifi dans ma classe ?
Mes pages de codes sont ici: https://github.com/Patriboom/FTP_lireFichier
Mais voici ce qui est pertinent
#include "FTP_lireFichier.h"
FTP_lireFichier::FTP_lireFichier(LIREFTP& lireFTP, char* ftpSrv, char* ftpUsr, char* ftpPsw, char* ftpFile) {
this->_lireFTP = &lireFTP;
this->_ftpSev = ftpSrv;
this->_ftpUsr = ftpUsr;
this->_ftpPsw = ftpPsw;
this->_ftpFile = ftpFile;
}
FTP_lireFichier::FTP_lireFichier(LIREFTP& lireFTP, char* ftpSrv, char* ftpUsr, char* ftpPsw, char* ftpFile, char* ftpRep) {
this->_lireFTP = &lireFTP;
this->_ftpSev = ftpSrv;
this->_ftpUsr = ftpUsr;
this->_ftpPsw = ftpPsw;
this->_ftpFile = ftpFile;
this->_ftpRep = ftpRep;
}
FTP_lireFichier::FTP_lireFichier(LIREFTP& lireFTP, char* ftpSrv, char* ftpUsr, char* ftpPsw, char* ftpFile, char* ftpRep, int ftpFreq) {
this->_lireFTP = &lireFTP;
this->_ftpSev = ftpSrv;
this->_ftpUsr = ftpUsr;
this->_ftpPsw = ftpPsw;
this->_ftpFile = ftpFile;
this->_ftpRep = ftpRep;
this->_ftpFreq = ftpFreq;
}
FTP_lireFichier::FTP_lireFichier(LIREFTP& lireFTP, char* ftpSrv, char* ftpUsr, char* ftpPsw, char* ftpFile, char* ftpRep, int ftpFreq, ftpPort) {
this->_lireFTP = &lireFTP;
this->_ftpSev = ftpSrv;
this->_ftpUsr = ftpUsr;
this->_ftpPsw = ftpPsw;
this->_ftpFile = ftpFile;
this->_ftpRep = ftpRep;
this->_ftpFreq = ftpFreq;
this->_ftpPort = ftpPort;
}
void FTP_lireFichier::begin() {
this->begin(this->_ftpSrv, this->_ftpUsr, this->_ftpPsw, this->_ftpFile);
}
void FTP_lireFichier::begin(char* ftpRep) {
this->_ftpRep = ftpRep;
}
void FTP_lireFichier::begin(char* ftpRep, int ftpFreq) {
this->_ftpRep = ftpRep;
this->_ftpFreq = ftpFreq;
}
void FTP_lireFichier::begin(char* ftpRep, int ftpFreq, int ftpPort) {
this->_ftpRep = ftpRep;
this->_ftpFreq = ftpFreq;
this->_ftpPort = ftpPort;
}
bool FTP_lireFichier::forceUpdate() {
#ifdef DEBUG_FTP_lireFichier
Serial.println("Forcing update of your FTP`s file into the RAM");
#endif
if(!this->Status) { return false; }
this->getText;
this->_lastUpdate = millis();
return true;
}
bool FTP_lireFichier::update() {
if ((millis() - this->_lastUpdate >= this->_updateInterval) || this->_lastUpdate == 0) { // Update after _updateInterval or Update if there was no update yet (if lastUpdate == 0)
return this->forceUpdate();
} else {
return false; // return false if update does not occur
}
return true;
}
char FTP_lireFichier::getText() {
if(!this->Status) {
if (FTP_lire->Connexin()) {
this->Wifi.OpenConnection();
this->Wifi.InitFile(COMMAND_XFER_TYPE_ASCII);
this->Wifi.DownloadString(this->_ftpFile, this->contenuLU);
this->Wifi.CloseConnection();
Serial.print ("Voici la valeur lue : ");
Serial.println(this->contenuLU);
this->fileSize = Wifi.Size();
} else {
return "";
}
}
return this->_contenuLU;
}
bool Connexion() {
int combien = 0;
this->WiFi.begin(this->_ssid, this->_pswd);
while (this->WiFi.status() != WL_CONNECTED && ++combien <= 40) {
delay(500);
Serial.print(".");
}
if (combien > 40) {
Serial.println(" échouée");
return false;
} else {
Serial.println( " réussie! ");
if (this->_ftpRep != "") { this->wifi.ChangeWorkDir(_ftpRep); }
return true;
}
}
bool FTP_lireFichier::isTimeSet() const {
return (this->_lastUpdate != 0); // returns true if the time has been set, else false
}
unsigned long FTP_lireFichier::getTime() const {
return this->WiFi.GetLastModifiedTime();
}
int FTP_lireFichier::getTime() {
return this->fileTime;
}
int FTP_lireFichier::getSize() {
return this->fileSize;
}
void FTP_lireFichier::end() {
this->_udp->stop();
this->_udpSetup = false;
}
void FTP_lireFichier::setFrequ(unsigned int ftpFreq) {
this->_ftpFreq = ftpFreq;
}
void FTP_lireFichier::setServerName(const char* ServerName) {
this->_ftpSrv = ServerName;
}
void FTP_lireFichier::setServerUser(const char* ServerUser) {
this->_ftpUsr = ServerName;
}
void FTP_lireFichier::setServerPswd(const char* ServerPassword) {
this->_ftpPsw = ServerPassword;
}
void FTP_lireFichier::setDirectory(const char* ServerDir) {
this->_ftpRep = ServerDir;
}
void FTP_lireFichier::setFileName(const char* FileName) {
this->_ftpFile = FileName;
}
void FTP_lireFichier::setFrequency(const int ServFreq) {
this->_ftpFreq = this->setFrequ(ServFreq);
}
void FTP_lireFichier::setPort(const int ServPort) {
this->_ftpPort = ServPort;
}
#pragma once
#include <FTPClient_Generic.h>
#define DEBUG_FTP_lireFichier false
#define FTP_FREQUENCE 55000
#define FTP_DEFAULT_PORT 22
class FTP_lireFichier {
private:
LIREFTP* dclient;
bool _udpSetup = true;
const char* _ftpSrv = "ftp.server.org"; // Default time server
const char* _ftpUsr;
const char* _ftpPsw;
const char* _ftpRep = "";
const char* _ftpFile = "contenu.txt";
unsigned int _ftpPort = FTP_DEFAULT_PORT;
long _timeOffset = 0;
unsigned long _ftpFreq = FTP_FREQUENCE; // In ms
unsigned long _lastUpdate = 0; // In ms
char* _contenuLU = "";
void contenuLU();
int fileSize = 0;
char* fileTime = "";
public:
FTP_lireftp(LIREFTP& dclient, ftpSrv, ftpUsr, ftpPsw, ftpFile);
FTP_lireftp(LIREFTP& dclient, ftpSrv, ftpUsr, ftpPsw, ftpFile, const char* ftpRep);
FTP_lireftp(LIREFTP& dclient, ftpSrv, ftpUsr, ftpPsw, ftpFile, const char* ftpRep, int ftpFreq);
FTP_lireftp(LIREFTP& dclient, ftpSrv, ftpUsr, ftpPsw, ftpFile, const char* ftpRep, const int ftpFreq, const int ftpPort);
/**
* Set time server name
*
* @param poolServerName
*/
void setftpSrv(const char* ftpSrv);
/**
* Set random local port
*/
void ftpPort(unsigned int ftpPort);
/**
* Starts the underlying UDP client with the default local port
*/
void begin();
void begin(unsigned char* ftpRep);
void begin(unsigned char* ftpRep, unsigned int ftpFreq;
void begin(unsigned char* ftpRep, unsigned int ftpFreq, unsigned int ftpPort);
/**
* This should be called in the main loop of your application. By default an update from the NTP Server is only
* made every 60 seconds. This can be configured in the FTP_lireFichier constructor.
*
* @return true on success, false on failure
*/
bool update();
/**
* This will force the update from the NTP Server.
*
* @return true on success, false on failure
*/
bool forceUpdate();
/**
* Définition des commandes accessibles à l'usager
*/
void setFrequ(unsigned int ftpFreq);
void setFrequency(unsigned int ftpFreq);
void setServerName(unsigned char* ServerName);
void setServerUser(unsigned char* ServerUser);
void setServerPswd(unsigned char* ServerPassword);
void setDirectory(unsigned char* ServerDir);
void setFileName(unsigned char* FileName);
void setPort(unsigned int ServPort);
/**
* Définition des valeurs retournées par l'objet
*/
unsigned char* getText() const;
unsigned long getTime() const;
unsigned int getSize() const;
//Vérifions ici si la connexion Wifi est bien active
bool getStatus() const;
/**
* Demande de déconnexion Wifi
*/
void end();
};
Merci à l'avance.