(Websocket) data through wifi (without internet connection) does not work if mobile data is on

I have now read a lot about this problem and there seems to be a solution if you program an app in Java/Kotlin, which I can’t do, but I can’t find a solution to do this with codular.

I have created an app that uses the “websocket client extension”, but it seems to affect all connections and not just websockets. The app establishes a WiFi connection to a measuring device which acts as an access point and transmits measurements, but does not provide an internet connection. I have tested the app successfully on Android 6,7 and 8, but on Android 9 and 10 it does not run on most devices. The WiFi connection is established, but no data is transferred.

After a lot of experimenting I found out that this is only the case if a mobile data connection is available e.g. over 4G. If I switch the phone into flight mode (and then turn WiFi back on) or disable “mobile data” in the settings, the data transfer works fine.

The problem: The operating system from Android 9 on tries to send the data preferably over an internet connection (here 4G), and not over the WiFi connection.
Now I have found solutions to this problem, but they require that you program the app in Java/Kotlin. There you can connect a process to a network (“bindProcessToNetwork(network)”). This means that this process always sends its data over a fixed connection, in this case WiFi and not trying to use 4G.

How can I implement this in Kodular?

Or alternatively:
Is there a way to disable “mobile data” for the duration of the app running?
I only found the solution to open the appropriate menu for the user and let him do it manually. That would be a very ugly workaround.

Translated with www.DeepL.com/Translator (free version)

Maybe there is no way to disable Mobile Data (4G, 3G, 2G)
But you can enable/disable Wifi using Wifi component.

If you are connected to a Wifi network then Mobile data will not used for internet.
You can whether Wifi is connected or not with Network component
Use Is Wifi Connection block.

Thank you for your reply, but this is not the problem.
The Wifi connection does not have internet access, so the device is using the mobile data no matter what I am doing. I need to force it to use the Wifi.

Background: I built a device to measure receive levels and crosspolar decoupling of microwave radio links. It works as an Wifi access point, measures a DC voltage 4 times per second and transmitts the data by using websockets to the mobile where some calculation are done to show the result in dBm.
Works smoothly, but Android9/10 devices are not using the Wifi (with no internet) but the mobile (4G), so the connection to the websocket cannot be established because the data never reaches the Wifi device.
When the user hits the “start” button nothing happens.
If I turn off “mobile data” and Wifi is the only connections it works.

Hope it a bit clearer now.
I need a way to force the traffic to use Wifi or to disable the mobile data as long as the websocket connection is active.

1 Like