Search code examples
iosxamarinibm-cloudmqttwatson-iot

Can't connect to IBM IOT Platform from Xamarin app


I have tried using both HTTP and MQTT to connect to IBM IOT platform from an ios device running a Xamarin application with no luck so far.

Right now I'm using the OPENNETCF MQTT package to connect using MQTT, but it seems stuck on "Connecting". I don't see any change to the device status while looking at the IOT Platform website.

My code to connect looks like this:

public async Task ConnectOpenNETCF() {

            if (mclient == null) {
                mclient = new MQTTClient("orgid.messaging.internetofthings.ibmcloud.com", 8883);
                string id = "d:orgid:ios:test01";
                await mclient.ConnectAsync(id, "use-token-auth", "the generated token");

                if (mclient.IsConnected)
                    Console.WriteLine("Client is connected.");
                else
                    Console.WriteLine("Client is not connected. " + mclient.ConnectionState);
            } else {
                Console.WriteLine("Status: " + mclient.ConnectionState);
            }


        }

Where orgid is the 6 character organization id that IOT platform generated, ios is the device type, and test01 is the device name. Am I doing something incorrectly? Where can I get more information besides the ConnectionState of the MQTT client?


Solution

  • for the mclient you need to pass also the useSSL flag to "true" as you requested the connection over secure port (8883). By default the connection security settings are on TLS with token so you need to use SSL. If you don't want that, then I guess you can set the settings on TLS optional, change the port to 1883 and you would the able to use the code as it is. events type do You can set the connection settings on "TLS Optional" in the IoT Dashboard. You can do that by: Security > Connection Security > Secutity Level set on TLS Optional