eclipse-californium / californium

CoAP/DTLS Java Implementation
https://www.eclipse.org/californium/
Other
729 stars 364 forks source link

Requests are send over cellular data instead of WiFi #1053

Closed logo17 closed 5 years ago

logo17 commented 5 years ago

I'm having the issue that all CoAP requests are being send over cellular data network even if I'm conected to the CoAP server via WiFi. According to Android documentation I can use bindProcessToNetwork (https://developer.android.com/reference/android/net/ConnectivityManager.html#bindProcessToNetwork(android.net.Network)) however it only works one time, if for some reason the CoAP server gets disconnected the remaining request will be send over cellular data .

Also Android documentation says:

Using individually bound Sockets created by Network.getSocketFactory().createSocket() and performing network-specific host name resolutions via Network#getAllByName is preferred to calling bindProcessToNetwork.

Is there a way to implement the request with californium with that specific implementation using sockets?

Thanks in advance.

Version: org.eclipse.californium:californium-core:2.0.0-M13

boaks commented 5 years ago

I'm having the issue that all CoAP requests are being send over cellular data network even if I'm conected to the CoAP server via WiFi.

Strange, that's not my experience. Anyway, See UDPConnector and UdpMulticastConnector how to setup your own Socket.

logo17 commented 5 years ago

I forgot to mention that the CoAP server does not have internet connection, that’s why Android gives priority to cellular data.

boaks commented 5 years ago

I forgot to mention that the CoAP server does not have internet connection

FMPOV, a CoAP server offers a CoapEndpoint with an Connector, which has a DatagramSocket bound to one of the host's network interfaces (or all interfaces). So what does "internet connection" mean?

logo17 commented 5 years ago

According to Android documentation for enableNetwork:

Note: Network communication may not use Wi-Fi even if Wi-Fi is connected; traffic may instead be sent through another network, such as cellular data, Bluetooth tethering, or Ethernet. For example, traffic will never use a Wi-Fi network that does not provide Internet access.

So the CoAP server that I'm connecting in the Android application does not provide internet connection, so all the requests for the android application are sent via TYPE_MOBILLE network.

What I want to do is use the WiFi network in the Android application to send all the CoAP requests even if it has cellular data enabled.

boaks commented 5 years ago

As I already wrote, your described behaviour doesn't match my experience. In Android Settings - WLAN - Extended, there is a switch to enable/disable the use of cellular when wlan is bad. My be you enabled it? Then disable it. You issue seems to be more Android specific. I'm no Android expert, and though I didn't have the behaviour on my Android Device, it's hard to find out, what's wrong on your side. May be you try in parallel to clarify the common Android setup for your details in a Android Forum?

logo17 commented 5 years ago

Is there a way that I can specify the network interface en0 for the CoapClient?

logo17 commented 5 years ago

Already fixed it. Thanks

boaks commented 5 years ago

@logo17

May be it's for others also interesting, how you solved it.

logo17 commented 5 years ago

What I did was specify the wlan0 interface in the CoAP Client Uri.. now all the request are being send by that interface.

Selvam-bestea commented 4 years ago

@logo17 can you share your code

KishCom commented 3 years ago

Adding to this closed issue for anyone else who hits on this while searching for a solution. No action required from Californium maintainers.

Problem: Californium built for Android with both cellular and WiFi radios are enabled and connected binds/sends data over the cellular network instead of the WiFi (because the WiFi has been connected to a device running a CoAP server that does not have internet yet -- think like: provisioning a new IoT device). Interestingly Google Pixel and other AOSP-based Android builds seem to be the only ones affected, Samsung Galaxy and LG G# devices do not exhibit the issue.

Changing COAP_NETWORK_INTERFACES did not appear to help. I solved it by using ConnectivityManager.bindProcessToNetwork to bind my activity to a specific network interface. A great example of how to do this can be found here.