1

I have trouble with connecting to a local web interface (192.168.10.13:3671) that are connected to my KNX network from the emulator/phone in Android Studio. I've tried to connect to the same web interface with a already developed app called KNXwizard and that works, but I see in the code that that app uses AsyncTask.

Always getting this error: Error creating KNXnet/IP tunneling link: tuwien.auto.calimero.KNXException: connecting from /192.168.163.198:3671 to /192.168.10.13:3671: socket failed: EPERM (Operation not permitted)

I've checked this posts

Socket failed 1

Socket failed 2

Tried everything there, added permissions to my AndroidManifest.xml, uninstalled, used physical phone etc. But nothing works.

It could be my code, I've tried searching for an alternative method for AsyncTask. So it could be that the code is written wrong. Hope someone could help me out.

MainActivity:

public class MainActivity extends AppCompatActivity {

private static InetSocketAddress local = new InetSocketAddress("192.168.163.198", 3671);
private static InetSocketAddress server = new InetSocketAddress("192.168.10.13",
        KNXnetIPConnection.DEFAULT_PORT);





Button btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btn = (Button)findViewById(R.id.button);

    ExecutorService executorService = Executors.newSingleThreadExecutor();




    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            executorService.execute(new Runnable() {
                @Override
                public void run() {


                    //doInBackground
                    System.out.println("This example establishes a tunneling connection to the KNXnet/IP server " + server);

                    // A KNX tunneling link supports NAT (Network Address Translation) if required.
                    // We also indicate that the KNX installation uses twisted-pair (TP) medium, with TP1 being the most common.
                    // KNXNetworkLink is the base interface implemented by all supported Calimero links to a KNX network.
                    try (KNXNetworkLink knxLink = KNXNetworkLinkIP.newTunnelingLink(local, server, false, TPSettings.TP1)) {
                        System.out.println("Connection established to server " + knxLink.getName());
                        System.out.println("Close connection again");
                    } catch (KNXException | InterruptedException e) {
                        // KNXException: all Calimero-specific checked exceptions are subtypes of KNXException

                        // InterruptedException: longer tasks that might block are interruptible, e.g., connection procedures. In
                        // such case, an instance of InterruptedException is thrown.
                        // If a task got interrupted, Calimero will clean up its internal state and resources accordingly.
                        // Any deviation of such behavior, e.g., where not feasible, is documented in the Calimero API.

                        System.out.println("Error creating KNXnet/IP tunneling link: " + e);

                    }
                }


            });
        }


    });
}
Alexander
  • 55
  • 8
  • What api level are you testing on? – javdromero May 25 '21 at 20:31
  • `android { compileSdkVersion 30 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.example.myapplication" minSdkVersion 23 targetSdkVersion 30 versionCode 1 versionName "1.0"` – Alexander May 25 '21 at 20:50
  • Just because you're using Android Studio to develop your app and start an AVD doesn't mean that it's Android Studio itself that's performing the connection. The AVD emulator is actually a part of the standard Android SDK, Android Studio just provides a nice GUI over the top of it. If you want, you can follow the advice in [this article](https://medium.com/michael-wallace/how-to-install-android-sdk-and-setup-avd-emulator-without-android-studio-aeb55c014264) to install the SDK and setup an AVD without using Android Studio. – Hoppeduppeanut May 26 '21 at 00:26
  • `I have trouble with connecting to a web server....` Please edit your post and inform us right away where your server is running on. You can also delete some comments. – blackapps May 26 '21 at 07:26

1 Answers1

0

I figured it out. It was a stupid mistake with the IP address, should have seen that before. I just change the IP address to that I have on the phone I was connected to (192.168.10.15).

Alexander
  • 55
  • 8