0
votes

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?

1
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.idan
Thanks. Changing this to port 1883, the client seems to establish the connection, though the IOT platform dashboard is still showing the device as disconnected. I will attempt to publish events from the device and see if they are reflected on the dashboard.zcleghern
no, events type do not need to be defined. Did you set the connection settings on "TLS Optional" in the IoT Dashboard? You can do that by: Security > Connection Security > Secutity Level set on TLS Optionalidan
just to make sure, you have set the event ID to 1 and not "1". Mind the quotes that will make the value a char/string.idan
the value 1 in the topic is not related to the error that you are seeing. The ID is actually the messageID (or packetID),is set by the client when QoS >0,on SUBSCRIBE, UNUSBSCRIBE, and PUBLISH packets. Generally this is set by the client library and is not commonly wrong. The only invalid value is 0. Here you have the full description for that: docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/… I guess you can control it from here, make sure messageID if not 0: public Publish(string topicName, byte[] messageData, ushort messageID, QoS qos, bool retain)idan

1 Answers

1
votes

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