Choose between wifi and ethernet settings at start

Hi all,
i have created an application that can connect to the network in both wifi and ethernet modes.
To do this I used various libraries and functions.
I now use the #ifdef preprocessor instructions to configure the 2 modes when compile, loading only the necessary libraries, and perform all the program handling depending on the wifi or ethernet mode.
I would like to make it possible to configure the system at start-up for one mode or the other without necessarily having to include all the libraries and fill the program with If Then.
Is there any way I can do this?

Thanks in advance

Lenny.

Can you just have two separate sets of code , and up load the one you need ?

I can’t see how you can do such a thing after compiling as the libraries are compiled in with your code .

Unfortunately, I would like to do this after loading the sketch.

I don’t think you can , but are you short of memory and can’t include both libraries ?
If you can , you can select your setup in a menu or use say a digital input to choose the setup choice .

“ if blah de blah is HIGH then setup Wi-Fi “ or get the code to look for the source automatically

could be done if the microprocessor has sufficient flash and sram to hold the program code and static/dynamic data
on start up you could configure both WiFi and Ethernet and then select either automatically or under user control which is to be used at various points during program execution

recently had an application on an ESP32 where both WiFi and BLE were used at different stages of system control - the same wireless hardware is used for both therefore they cannot be used at the same time
however, it did require the ESP32 Partition Scheme to be set to "Huge App (3MB no OTA/1MB SPIFFS)" - th BLE library in particular is very large

you can do a wifi scan and see if the access point name you would connect to is available

Thanks for the suggestion, but I was hoping to be able to create 2 separate sections in the code for wifi and ethernet by loading only the libraries and modules required for the required configuration. It is possible that the application is always used in one mode, wifi for example, but at some point it fails and the ethernet has to be active.
I am afraid that there is no alternative to include both settings.

That can only happen at compile time. If you want both libraries available at runtime then they both have to be compiled in. This is a microcontroller, not a windows system. You can't just load a library when you need it. Where would you load it from?

the code is stored and is executed in/from flash. from where to where would you like to 'load it'?

possible on a Raspberry Pi or similar microcontroller with a suitable operating system and storage
many langiages have system calls to run other executable programs e.g. ProcessBuilder in Java

you could create serveral executables which are a excuted as required, e.g. to communicate over WiFi or Ethrnet
information could be passed between processes, e.g. using named pipes in Java

Thank you for your reply but I am afraid it will become too complicated. :slightly_smiling_face:
I will try to load everything in memory and hope that there are no incompatibilities between the libraries.

reasonable approach!
if you find problems such as running out of flash or SRAM you either rethink the design or move to a more powerful microcontroller
did you ever tell us which microcontroller you are using at the moment?

there are WiFi ad Ethernet libraries which are basically one library and others which will not work together. what Arduino do you have and what libraries do you use?

if you decide on runtime you will need both libraries.
Which microcontroller are you using?

I am working with a Portenta H7 so I don't think I will have any problems with memory space, it was mainly to make a neater and cleaner job.
The libraries I use are these, I haven't tried loading them all at the same time yet.

#ifdef CONN_WIFI
  #include <ArduinoHttpClient.h>
  #include <WiFi.h>
  #include <WiFiUdp.h>
#endif

#include <Arduino_PortentaBreakout.h>
#include "SDMMCBlockDevice.h"
#include "FATFileSystem.h"
#include "RPC.h"
#include <arduino-timer.h>
#include "HeartBeat.h"
#include <TimeLib.h>
#include "NextionX2.h"

#ifdef CONN_ETH
  #include <EthernetUdp.h>
#endif

on H7 in the Mbed Core the Ethernet and WiFi library are one library with two 'facades'

Thank you, I will look into this matter.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.