Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to Implement Global Switching Between Wi-Fi and GSM for WebSocket Connections. #910

Open
SwapB5632 opened this issue Sep 23, 2024 · 3 comments

Comments

@SwapB5632
Copy link

SwapB5632 commented Sep 23, 2024

@Links2004 I am working on a project using ESP32 and the WebSockets library, where I need to switch between Wi-Fi and GSM networks dynamically. I would like to globally define WEBSOCKETS_NETWORK_TYPE to control whether the WebSocket connection uses Wi-Fi (NETWORK_WIFI) or GSM (NETWORK_GSM) without modifying the core WebSocket library files.

Currently, I am using TinyGSM for GSM and WiFi.h for Wi-Fi. I would like to know the best approach to handle this globally so that I can toggle between Wi-Fi and GSM by simply setting WEBSOCKETS_NETWORK_TYPE in the project.

for reference kindly check the screenshot.
image

@Links2004
Copy link
Owner

Links2004 commented Sep 23, 2024

WEBSOCKETS_NETWORK_TYPE is designed to be overridden by global compiler defines.
for platform.io this looks like this:

build_flags =
    -D WEBSOCKETS_NETWORK_TYPE=NETWORK_W5100

the part you showing is the auto detection if nothing is defined by the user / compiler flags yet.

@SwapB5632
Copy link
Author

@Links2004 thanks for your response.

but is there any solution to Switch between Wi-Fi and GSM dynamically.

@Links2004
Copy link
Owner

Links2004 commented Sep 23, 2024

what exactly do you mean by dynamically during runtime of the code on a µC?
if yes then there is currently no way implemented to do this, since all the network types do is switching the TCP stack at compile time.

the "easiest" way that I see is to write a wrapper class for the TCP server/client that does the switching inside this wrapper.

I really wished that the arduino framework had a "interface" class that defined the TCP server / client functions, but thats not the cases which makes it next to impossible to do this generic for all the different TCP stacks of all the µC out there.

there is a other option for lwip based µC (example ESP), but not sure how easy it is.
the lwip framework allows you the add new network interfaces to it.
with that the switching will be route based on the lwip side and the "WiFiClient" will happy use any interface for its traffic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants