arduino's official wifi libraries

Hello,

Recently I almost finished an arduino library to interface with GoPro action cameras (turn on/off, take pictures,ecc), it is here: GoProControl
It is compatible only with esp8266 and esp32 boards, since without arduino I wouldn't ever be able to make it I would like to add support also for the official arduino boards with wifi (if i am not wrong the mkr series).
In ESP8266 and 32 there is a general wifi library and a specific one for HTTP request (which is infact called HTTPClient). Is it the same in the official arduino? Could someone say me how are called the wifi arduino libraries?

This is the precompile part of my library to choose the right library to include. Is there a compile flag to choose all the official arduino with wifi?

#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <HTTPClient.h>
#endif

The original official Arduino WiFi library:

was for the Arduino WiFi Shield, which was retired long ago. That shield can be used with any Arduino board. The API of the ESP8266 and ESP32 libraries is based on the WiFi library.

The next official Arduino WiFi library was the "Arduino Uno WiFi Dev Ed Library", for the original Uno WiFi:

That was an arduino.org product which was not kept by arduino.cc after the two companies merged back together. You can get an idea of how things went with this board from the fact that the library is called the "developer edition", years after the board was released and retired.

The next official Arduino WiFi library was WiFi101, for the MKR 1000 and the Arduino WiFi 101 Shield:

The current hotness in Arduino WiFi libraries is WiFi Nina, used for the MKR 1010, MKR Vidor 4000, and Arduino Uno WiFi Rev2:

So how do you keep up with all these libraries? The answer is that you don't need to. All these libraries use a standardized interfaces of the Arduino core library's Client, Print, and Stream classes. What you do is write your library so that the user creates the Client object in their sketch and then passes it to the library. To the library code, it doesn't matter what the source of the Client object is. This means your library will work with any network communication library that is correctly written (example: GitHub - bportaluri/WiFiEsp: Arduino WiFi library for ESP8266 modules).

my list of networking libraries:

arduino
Ethernet library - shields and modules with Wiznet 5100, 5200 and 5500 chips
WiFi101 - WiFi101 shield and MKR 1000
WiFiNINA - MKR 1010, MKR 4000, Uno WiFi 2, ESP32 as SPI network adapter with WiFiNINA firmware
WiFi - Arduino WiFi Shield
community
UIPEthernet - shields and modules with ENC28j60 chip
WiFiLink - esp8266 as network adapter with WiFiLink firmware (SPI or Serial)
WiFiSpi - esp8266 as SPI network adapter with WiFiSpiESP firmware
WiFiEsp library for esp8266 with AT firmware

all have the Arduino networking API defined with classes Server, Client, UDP

mmmm okk the situation about wifi library looks like more complex then what i thought!

pert:
So how do you keep up with all these libraries? The answer is that you don't need to. All these libraries use a standardized interfaces of the Arduino core library's Client, Print, and Stream classes. What you do is write your library so that the user creates the Client object in their sketch and then passes it to the library. To the library code, it doesn't matter what the source of the Client object is.

This would be the best/simplest approach for me (as writer of the library) but i would like to give a dumb-proof library and manage all the includes and boards with a few #ifdef. It shouldn't be too much headache since there are only two library (WiFi101 and WiFi Nina) and a few flag for the boards

No library for the HTTPClient on arduino? :frowning: it is nice to don't format all the request

anyway it is the first time i have a look at the arduino.org libraries and i find them quite funny extern CiaoClass Ciao;

Juraj:
my list of networking libraries:

arduino
Ethernet library - shields and modules with Wiznet 5100, 5200 and 5500 chips
WiFi101 - WiFi101 shield and MKR 1000
WiFiNINA - MKR 1010, MKR 4000, Uno WiFi 2, ESP32 as SPI network adapter with WiFiNINA firmware
WiFi - Arduino WiFi Shield
community
UIPEthernet - shields and modules with ENC28j60 chip
WiFiLink - esp8266 as network adapter with WiFiLink firmware (SPI or Serial)
WiFiSpi - esp8266 as SPI network adapter with WiFiSpiESP firmware
WiFiEsp library for esp8266 with AT firmware

all have the Arduino networking API defined with classes Server, Client, UDP

great summary, i will save it!

why is Ciao funny? It is for Yun originally. The Uno WiFi version was sad, not funny.

the libraries are all same. with "#define NetClient WiFiXyClient" or with C++ templates you can implement all.
see here ArduinoOTA/ArduinoOTA.h at master · JAndrassy/ArduinoOTA · GitHub

aster94:
No library for the HTTPClient on arduino?

Here's one:

pert:
Here's one:
GitHub - arduino-libraries/ArduinoHttpClient: Arduino HTTP Client library

it is in Library Manager. last time I checked, it didn't support F() macro, what is strange because HTTP is about long strings

thanks to both of you I will use the library you suggested!

why is Ciao funny?

P.S: I don't know, it is like calling a class "Hello", I made a smile reading it :slight_smile:

pert, i was thinking again to your suggestion

pert:
So how do you keep up with all these libraries? The answer is that you don't need to. All these libraries use a standardized interfaces of the Arduino core library's Client, Print, and Stream classes. What you do is write your library so that the user creates the Client object in their sketch and then passes it to the library. To the library code, it doesn't matter what the source of the Client object is.

You may be right and this would be the best approach for maintainability in the future.
But also this way I am not sure if all the nested #ifdef could be avoided. You say to write the library in a way that the constructor accept the client object but if i write my constructor something like:

GoProControl::GoProControl(Client client)
{
	_client = client;
}

and i call it, example with wifiNiNA:

#include <WiFiNINA.h>
#include <GoProControl.h>

WiFiClass client;
GoProControl gp(client);

i got a "no known conversion for argument 1 from 'WiFiClass' to 'Client'" and I think that the compiler is right, i am doing something wrong! Could you give me a small example of what you meant?

see link in comment #4

Juraj:
see link in comment #4

I know the key is something like this line but i don't know how to use it and I am unable to find tutorial on that constructor (class name). how is it called? maybe with the right name i could find it

aster94:
I know the key is something like this line but i don't know how to use it and I am unable to find tutorial on that constructor (class name). how is it called? maybe with the right name i could find it

C++ template. the class is then generated by compiler with provided template parameters

the WiFiOTA class which is the base class for ArduinoOTA uses only Client and UDP classes. it is not a template class

Juraj:
C++ template. the class is then generated by compiler with provided template parameters

the WiFiOTA class which is the base class for ArduinoOTA uses only Client and UDP classes. it is not a template class

mmmm there must be something i am missing, the WiFi101, WiFiNINA, esp8266 and esp32 classes are called always "WiFiClient" can't I just use this class even if it cames from different libraries?

anyway, I am still not very sure on how to use the template, should this be correct?

.h
template <class my_class_that_accept_all_kind_of_wificlient>
my_class_that_accept_all_kind_of_wificlient _client

---------------------------------------------------------------

.cpp
GoProControl::GoProControl(my_class_that_accept_all_kind_of_wificlient client)
{
	_client = client; // "client" could be any WiFiclient from the varius arduino libraries
}

the templates can much more, not only type names (not classes, it is only a name to use),
but yes template is right
you can see my_type_name_that_accept_all_kind_of_wificlient as better #define name

here
GoProControl::GoProControl(Client client)
the compiler can't copy WiFiClient into Client
use reference.
GoProControl::GoProControl(Client& client)
or the template type, then the input value can be copied into parameter

Juray i know you already explained to me, but unfortunately i am not able to achieve what you and pert suggested: I can't create a template that accept all WiFiClient
here there is my source folder

I got all kind of possible errors, where i should put the template definition ? global, inside the public or in private?

aster94:
Juray i know you already explained to me, but unfortunately i am not able to achieve what you and pert suggested: I can't create a template that accept all WiFiClient
here there is my source folder

I got all kind of possible errors, where i should put the template definition ? global, inside the public or in private?

but you only want to support the libraries which have the same names WiFiClient and WiFiUdp.
so you need only different #include at the top

Well if i could support also the WiFiEspClient and WiFIEspUdp Classes from GitHub - bportaluri/WiFiEsp: Arduino WiFi library for ESP8266 modules it would be perfect. I could do it with a couple of defines but you made me curios about using these template

aster94:
Well if i could support also the WiFiEspClient and WiFIEspUdp Classes from GitHub - bportaluri/WiFiEsp: Arduino WiFi library for ESP8266 modules it would be perfect. I could do it with a couple of defines but you made me curios about using these template

add #define WiFiClient WiFiEspClient

Juraj:
add #define WiFiClient WiFiEspClient

When you talked about template i thought you had another solution in mind, i may have misunderstood xD

Anyway thank you!

aster94:
When you talked about template i thought you had another solution in mind, i may have misunderstood xD

Anyway thank you!

I had, but here the define is good enough