esp32FOTA icon indicating copy to clipboard operation
esp32FOTA copied to clipboard

Use custom networking stack?

Open anthonyhoegberg opened this issue 1 year ago • 5 comments

So i have a question if its possible to instead of using networkclient built in to esp32 if we can use custom networking like https://github.com/govorox/SSLClient Or other Client based transports.

That way we get support for many different Wifi, Sim and Ethernet modems that implements a client class. And ssl on top of that implemented by SSLClient using those clients etc.

anthonyhoegberg avatar Sep 12 '24 01:09 anthonyhoegberg

hi, thanks for your feedback :+1:

SSLClient and NetworkClientSecure inherit from the same Arduino Client class and share the client method names used by esp32FOTA, so it should probably work.

you can experiment by modifying the include block in esp32FOTA.hpp.


#if __has_include(<SSLClient.h>)
  #include <SSLClient.h> // https://github.com/govorox/SSLClient/
  #define ClientSecure SSLClient
#elif __has_include(<NetworkClientSecure.h>)
  #include <NetworkClientSecure.h> // arduino-esp32 core 3.x
  #define ClientSecure NetworkClientSecure
#else
  #include <WiFiClientSecure.h> // // arduino-esp32 core 2.x
  #define ClientSecure WiFiClientSecure
#endif

if this works for you, feel free to submit a pull request :wink:

tobozo avatar Sep 12 '24 06:09 tobozo

the specific instance i provide needs to be configured before like sim settings etc. before i can leave control over to the update library, so just replacing the type wouldnt work? i would need to pass the network instance to be used to the library i think?

an example would be

https://github.com/vshymanskyy/TinyGSM

anthonyhoegberg avatar Sep 17 '24 02:09 anthonyhoegberg

been trying to get esp32FOTA to work with phy/transport/app layers without refactoring every OSI related function calls but failed so I guess a refactor will be needed after all

I'm testing a template that I hope will accept both custom and builtin phy/transport/app clients:

template<typename APP, typename PRES, typename PHY>
struct OSILayers
{
  OSILayers() { };
  OSILayers( APP& app, PRES& pres, PHY& phy )
    : AppClient(&app), PresClient(&pres), PhyClient(&phy) { }
  APP  AppClient;   // application (HTTP, Pubsub)
  PRES PresClient;  // Presentation (SSL, Network)
  PHY  PhyClient;   // Transport/Phy (WiFi, Ethernet, GSM)
};

HTTPClient appclient;
NetworkClientSecure presclient;
NetworkClient phyclient;
auto builtinStack = new OSILayers<HTTPClient*,NetworkClientSecure*,NetworkClient*>(&appclient, &presclient, &phyclient);

// PubSubCLient appclient;
// SSLClient presclient;
// TinyGSMClient phyclient;
// auto customStack = OSILayers<PubSubCLient*,SSLClient*,TinyGSMClient*> stackFOTA(&appclient, &presclient, &phyclient);

This OSILayers isn't connected to anything yet, but it is intended to be used from within the esp32FOTA class. Any existing code specific to the esp32 builtin network stack will have to move out of esp32FOTA class.

This creates a significant tech debt:

  1. Need to reimplement all OSI related functions (e.g. add auth headers to http) as callbacks
  2. Provide a default OSILayers instance based on arduino-esp32 built-in stacks (v2.x.x and v3.x.x) to avoid breaking existing projects, which should be ignored when a custom stack is used
  3. Create some OSILayers examples based on custom stacks
  4. Unit tests :grimacing:

tobozo avatar Sep 28 '24 16:09 tobozo

Sounds like its quite complicated to get this working if I'm correct?

anthonyhoegberg avatar Sep 30 '24 23:09 anthonyhoegberg

Hello,

I use your wonderful OTA code for all of my WiFi projects ... it's great!

I also am using TinyGSM and a cellular modem for connectivity from some Lilygo boards. Currently, to provide HTTP for my application I use code similar to this:

  // HTTP is using modem connection 0
  #if USE_HTTPS
    TinyGsmClientSecure http_client(modem,0);
    HttpClient http(http_client, server, port);
  #else
    TinyGsmClient http_client(modem,0);
    HttpClient http(http_client, server, port);
  #endif
#endif

Would there be a way that I could pass a reference to this HttpClient into the code to allow this HTTP client to be used for the OTA transactions? I just started to look through your code to see what might be possible, but don't fully understand it yet.

Thank you either way for creating such a great library!

Humancell avatar Dec 01 '24 01:12 Humancell