I'm trying to create a class that acts as a wrapper for managing various types of internet connections (Ethernet, WiFi, Cellular).
I got Cellular working, which was the hardest by far. But getting Ethernet is proving difficult as well. (The default Ethernet library uses blocking code which is horrible for my application)
Whenever I try to call connect(ip,port) inside my class, I get a compile-time error that says "invalid use of non-static member function".
I'd imagine it has to do with trying pass in data that can be deleted or otherwise non-static into a function that requires it to stick around. As much coding as I do in C++, I don't actually run into this issue terribly often, so I'm prepared for face-palms.
For reference, here is the class:
class CESEthernet : public CESCommSlot
{
public:
CESEthernet();
~CESEthernet();
void taskHandler();
bool isReady();
bool isOnNetwork();
bool sendPayload(String payload);
private:
EthState itsState;
EthernetClient itsClient;
void a_PowerUp();
void a_DHCP();
void a_Connect();
void a_Maintain();
void i_Disconnect();
void i_Poweroff();
StopWatch GP_Timer = StopWatch(false);
uint8_t GP_Counter;
byte mac[6];
};
And here is the method:
void CESEthernet::a_Connect()
{
if (GP_Timer.start(itsNetConfig.RemoteTimeout)) //Initializes to RemoteTimeout when the timer initially starts
{
DebugMessage(DM_INFO, F("Web Connect"));
}
if (GP_Timer.passed(itsNetConfig.RemoteTimeout))
{
if (itsClient.connect(itsNetConfig.IPAddr.toCharArray, itsNetConfig.rPort))
{
//Success
DebugMessage(DM_INFO, F("Connected To ") + itsNetConfig.IPAddr + ":" + String(itsNetConfig.rPort));
itsState = ETH_DHCP;
GP_Timer.stop();
}
else
{
//Failure
DebugMessage(DM_ERROR, F("Connection Failed"));
GP_Timer.reset();
}
}
}