Client was not declared in this scope

Hello. My arduino is configured as client and working correctly. But when I want to use the fonction client.print outside of the void loop(), I have the message: "Client was not declared in this scope"

void SubProg() { client.print("HELLO"); }

What is the error ? (Newbe ....)


You can either include Client.h or Ethernet.h into your sketch. Depends weather you are using the Ethernet.

Ethernet.h includes Client.h

Variables, structs and class objects declared inside of a function are only seen inside of that function. If the variable, etc, is not declared static then it will get wiped when the function ends. The function has scope. Libraries have scope too. One way around that is to use global variables, etc, that can be 'seen' by all the sketch.

Did you create client inside of loop()? Or is it a libraries conflict?

EthernetClient client = server.available(); was declared inside loop So I can't use it in a subprogram ... I will try an other way... Thank you for your help!!

EthernetClient client = server.available(); was declared inside loop

I see. You have to be in run-time to declare the object, at least that way. I don't know the library so the best I can think is to see how they do it in examples.

Next best, I might declare/create the object as static and use a global pointer to address it but that's clunky.