I've got a library that connects to a server as a client to send a command. It is currently working on the ESP with the ESP8266WiFi.h library being used in the sketch and my library.
The .begin method in my library has a WiFiClient object reference as argument like this:
void begin(WiFiClient &clientref, IPAddress serverIP)
From that point onward the methods in the class will send the commands to that IP using that client object.
Now, if I wanted to use the code with the Ethernet shield on an Arduino it wouldn't work. It'd only take a bit of work but the client class would have to be redefined to suit that Ethernet library (e.i. EthernetClient).
I've seen libraries (e.g.ArduinoJson) that are able to "print" the command to both types of clients and even to a serial out. I've been reading for a while and there seems to be a Stream.h that could be involved, but I'm new to classes and I definitely don't know the inner workings of these libraries, so I'm
a bit a lot lost!
So the questions:
1-Is it possible to do it (at least for the ESP and Ehternet shield)?
2-If it is, how could I do it? Is there a more "generic" client class I could use?
Please let me know if I'm not clear enough or if some code would make it clearer and I'll post it.