Post topics, source code that relate to the Arduino Platform

User avatar
By treii28
#65689 I'm working on a project and my code was starting to get unmanageable in a single structured INO so I started refactoring some of the task-specific code out into class definitions. I would like to set up one such class to handle a WebServer for changing configuration parameters. The first thing I ran into was that I need to do my 'handleClient' somewhere in my main program loop so I made a method that triggers it within the class. But now I have a problem compiling the class in that the set-up code isn't working right when I'm trying to point the server config to run a class method.

relevant code from my my class header file CfgServer.h:

Code: Select all#ifndef _CFGSERVER_h
#define _CFGSERVER_h

#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
#include <EEPROM.h>

class CfgServer
{
  public:
    CfgServer();
    void handleNotFound();
    void handleAPClient();
    void setupServer();


  protected:
    ESP8266WebServer APWebServer;
    IPAddress myIP;
};

#endif


relevant code from the cpp file CfgServer.cpp:

Code: Select all#include "CfgServer.h"

#define DBG_OUTPUT_PORT Serial

CfgServer::CfgServer() {
  hasData = false;
  APWebServer = ESP8266WebServer(80);
}

void CfgServer::handleNotFound() {
    /*
     * this chunk has a means of finding page content indexed by the specified
     * server path from an array of flash/progmem data. If the index is not
     * found, it gives a 404
     */
}

void CfgServer::handleAPClient()
{
  APWebServer.handleClient();
}

void CfgServer::setupServer() {
    /* the following is producing an error */
    APWebServer.onNotFound(handleNotFound);
    APWebServer.begin();
    DBG_OUTPUT_PORT.println("HTTP server started");
}


My cut/paste is not currently working from my vnc window to the machine running the Arduino ID, but the error I am getting back is 'no matching function call to 'ESP8266WebServer::onNotFound()'

I'm assuming this is because it's pointing at the internal class method and I'm doing it wrong. Is there a way to get this to work? Or am I going about it the wrong way?
User avatar
By Wouter
#69264
philbowles wrote:
Wouter wrote:That was my first approach, but then I couldn't access any variables in the class, which is a problem as they contain the data that I want to send out...


...make the variables static!


Which causes problems reading them from other classes and so... It's all way too interwoven for that kind of trickery!