cannot call member function 'String TWebPage::SendHTML(float, String, float)' wi

Bonjour,

J’essais de mettre Webserver dans une class. Mais j’ai l’erreur suivante:
cannot call member function ‘String TWebPage::SendHTML(float, String, float)’ without object. Quand je veux appeler la fonction server->send(200, “text/html”, SendHTML(6,“6”,6)); J’ai simplifier pour envoyer 666 a la fonction et tout mis en static/public pour les tests.

Main
TWebPage Webpage;

void setup()
{

   Webpage.server.on("/", Webpage.handle_OnConnect());
   Webpage.server.onNotFound(Webpage.handle_NotFound());
   Webpage.server.begin();
   Serial.println("HTTP server started");

}

void loop( )
{

    Webpage.server.handleClient();
}

CPP

#include "Arduino.h"
#include "WebPage.h"

TWebPage::TWebPage()
{
  WebServer server(80);   
}

void TWebPage::handle_OnConnect() {
[b]   server.send(200, "text/html", SendHTML(6,"6",6)); [/b]
}

void TWebPage::handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}


String TWebPage::SendHTML(float Temperature,String NiveauBaril,float Temperature2){
  String ptr = "<!DOCTYPE html> <html>\n";
  ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  ptr +="<link rel=\"stylesheet\" href=\"https://use.fontawesome.com/releases/v5.7.2/css/all.css\" integrity=\"sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr\" crossorigin=\"anonymous\">\n";
  //ptr +="<title>ESP32 Temperature Monitor</title>\n";
  
  ptr +="<style>html { font-family: Arial; display: inline-block; margin: 0px auto; text-align: center;}\n";
  ptr +="h2 {font-size: 3.0rem;}\n";
  ptr +="p { font-size: 3.0rem; }\n";
  ptr +=".units { font-size: 1.2rem; }\n";
  ptr +=".ds-labels{font-size: 1.5rem; vertical-align:middle; padding-bottom: 15px;}\n";
  ptr +="</style>\n";
  
  
  ptr +="<script>\n";
  ptr +="setInterval(loadDoc,1000);\n";
  ptr +="function loadDoc() {\n";
  ptr +="var xhttp = new XMLHttpRequest();\n";
  ptr +="xhttp.onreadystatechange = function() {\n";
  ptr +="if (this.readyState == 4 && this.status == 200) {\n";
  ptr +="document.body.innerHTML =this.responseText}\n";
  ptr +="};\n";
  ptr +="xhttp.open(\"GET\", \"/\", true);\n";
  ptr +="xhttp.send();\n";
  ptr +="}\n";
  ptr +="</script>\n";
  
  ptr +="</head>\n";
  ptr +="<body>\n";
  ptr +="<div id=\"webpage\">\n";
  ptr +="<h2>Keg</h2>\n";

  ptr +="<h1>Temperature: </h1>";
  
  ptr +="<p>";
  ptr +="<i class=\"fas fa-thermometer-half\" style=\"color:#059e8a;\"></i>\n";
  ptr +=Temperature;
  ptr +="&deg;C</p>";

  ptr +="<p>\n";
  ptr +="<i class=\"fas fa-thermometer-half\" style=\"color:#059e8a;\"></i>\n";
  ptr +=Temperature2;
  ptr +="&deg;C</p>";

       
  ptr +="<h1>Niveau: </h1>";
  ptr +="<p>\n";
  ptr +="<i class=\"fas fa-beer\" style=\"color:#059e8a;\"></i>\n";
  ptr +=NiveauBaril;

  ptr +="</div>\n";
  ptr +="</body>\n";
  ptr +="</html>\n";
  
  return ptr;
}

H

#ifndef WebPage_h
#define WebPage_h

#include <WebServer.h>

class TWebPage
{
   private:
      float fTemperature;
      String sNiveauBaril;
      float fTemperature2;
   public:
      TWebPage();
      static WebServer server;   
      String SendHTML(float Temperature,String NiveauBaril,float Temperature2);
      static void handle_OnConnect();
      static void handle_NotFound();
};
#endif

The “cannot call member function without object” error is a common C++ error that occurs while working with classes and objects. The error is thrown when one tries to access the functions of a class without instantiating it.

Je suppose que tu devrais créer une instance de TWebPage et appeler instance.SendHTML

comme tu ne mets pas tout ton code, on est obligé de deviner ce que tu as oublié.

Voila un lien pour le code entier:
Trop de caractère pour poster, mais je pense que c'est plus facile comme ça.

https://drive.google.com/drive/folders/1LVqY87LpQ2M8nJG56EZ_BZwebGyO_GAD?usp=sharing

Merci