Go Down

Topic: Can't call Client.connect() inside class (Read 471 times) previous topic - next topic


Jun 12, 2018, 10:07 pm Last Edit: Jun 12, 2018, 10:08 pm by Jonathanese
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:

Code: [Select]
class CESEthernet : public CESCommSlot

void taskHandler();
bool isReady();
bool isOnNetwork();
bool sendPayload(String payload);

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:
Code: [Select]
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))
DebugMessage(DM_INFO, F("Connected To ") + itsNetConfig.IPAddr + ":" + String(itsNetConfig.rPort));
itsState = ETH_DHCP;
DebugMessage(DM_ERROR, F("Connection Failed"));



Well yeah. I generally don't post something onto a forum unless I'm having trouble finding relevant information on google.


No technical questions via PM. They will be ignored. Post your questions in the forum so that all may learn.


OK so in the process, I found the issue.

I replaced "itsClient.connect(itsNetConfig.IPAddr.toCharArray" with a string literal. In this case, "Google.com".

guess I'll just have to figure out how to pass the desired website as a char array using some other method.


what you googled "C++ call static member" or somthing like that! I don't think you did. By the way if you look at my initial reply I gave you the answer.

In other words I told you

A. how to find the answer and

B. What the answer was ::


Go Up