Unable to connect to AWS IoT Services with M2MQTT

Hello everyone,

I am trying for weeks to establish a successfull connection to my AWS service. My code looks as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System.Security.Cryptography.X509Certificates;
using Android.Content.Res;
using uPLibrary.Networking.M2Mqtt;

namespace AWSTest {
class Publisher {

      //Endpoint
      private string Endpoint = "***************.iot.eu-central-1.amazonaws.com";

   //Default TLS1.2 port
      private int BrokerPort = 8883;

      //Init Mqttclient
      MqttClient myPublisherClient;

        //Load certificates=> pfx-File: Permision+Private Key, crt-File: certificate
       X509Certificate2 clientCert;
       X509Certificate caCert;

      public Publisher () {
            clientCert = new X509Certificate2("storage/emulated/0/Download/312f4c1a1e-certificate.pfx", "password");
            caCert = X509Certificate.CreateFromCertFile("storage/emulated/0/Download/certRoot.crt");
            myPublisherClient = new MqttClient(Endpoint, BrokerPort, true, caCert, clientCert, MqttSslProtocols.TLSv1_2);
        myPublisherClient.Connect("ID32324210");
            myPublisherClient.Publish("myTopic", Encoding.UTF8.GetBytes("Hallo"));

      }   
}

}

This is my publisher-class. My console throws following exception:

.
.
.
11-27 00:36:31.344 D/Mono (27780): Assembly Ref addref AWSTest[0xe8f7d3e0] -> System[0xe8f7e700]: 2
11-27 00:36:31.344 D/Mono (27780): Assembly Ref addref System[0xe8f7e700] -> mscorlib[0xe8f7d2c0]: 14
11-27 00:36:31.414 D/Mono (27780): DllImport searching in: '__Internal' ('(null)').
11-27 00:36:31.414 D/Mono (27780): Searching for 'java_interop_jnienv_call_nonvirtual_object_method_a'.
11-27 00:36:31.414 D/Mono (27780): Probing 'java_interop_jnienv_call_nonvirtual_object_method_a'.
11-27 00:36:31.414 D/Mono (27780): Found as 'java_interop_jnienv_call_nonvirtual_object_method_a'.
11-27 00:36:31.444 D/Mono (27780): Assembly Ref addref netstandard[0xe8f7ec40] -> System[0xe8f7e700]: 3
11-27 00:36:31.474 D/Mono (27780): Image addref Mono.Security[0xdcecb0c0] -> Mono.Security.dll[0xdcee8000]: 2
11-27 00:36:31.474 D/Mono (27780): Prepared to set up assembly 'Mono.Security' (Mono.Security.dll)
11-27 00:36:31.474 D/Mono (27780): Assembly Mono.Security[0xdcecb0c0] added to domain RootDomain, ref_count=1
11-27 00:36:31.474 D/Mono (27780): AOT: image 'Mono.Security.dll.so' not found: dlopen failed: library "/data/app/AWSTest.AWSTest-1/lib/arm/libaot-Mono.Security.dll.so" not found
11-27 00:36:31.484 D/Mono (27780): AOT: image '/usr/local/lib/mono/aot-cache/arm/Mono.Security.dll.so' not found: dlopen failed: library "/data/app/AWSTest.AWSTest-1/lib/arm/libaot-Mono.Security.dll.so" not found
11-27 00:36:31.484 D/Mono (27780): Config attempting to parse: 'Mono.Security.dll.config'.
11-27 00:36:31.484 D/Mono (27780): Config attempting to parse: '/usr/local/etc/mono/assemblies/Mono.Security/Mono.Security.config'.
11-27 00:36:31.484 D/Mono (27780): Assembly Ref addref System[0xe8f7e700] -> Mono.Security[0xdcecb0c0]: 2
11-27 00:36:31.484 D/Mono (27780): Assembly Ref addref Mono.Security[0xdcecb0c0] -> mscorlib[0xe8f7d2c0]: 15
11-27 00:36:31.484 D/Mono (27780): Assembly Ref addref Mono.Security[0xdcecb0c0] -> System[0xe8f7e700]: 4
Loaded assembly: Mono.Security.dll [External]
Thread started: #2
Thread started: #3
Thread started: #4
Thread started: #5
Thread started: #6
Unhandled Exception:

uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException: Exception connecting to the broker at "myPublisherClient.Connect("ID32324210");"

Thread finished: #4
Der Thread 'Unknown' (0x4) hat mit Code 0 (0x0) geendet.
Thread finished: #3
Der Thread 'Unknown' (0x3) hat mit Code 0 (0x0) geendet.
Thread finished: #5
Der Thread 'Unknown' (0x5) hat mit Code 0 (0x0) geendet.
Thread finished: #2
Der Thread 'Unknown' (0x2) hat mit Code 0 (0x0) geendet.

.
.
.

I tried to connect with this certificates on MQTT,FX and it works completely fine.

Any help is highly appreciated

Sign In or Register to comment.