Connecting IoT devices
    • PDF

    Connecting IoT devices

    • PDF

    Article Summary

    Available in Classic and VPC

    After installing the certificate on the IoT device and completing the rule setting for Cloud IoT Core, you can check the process of connecting the IoT device to Cloud IoT Core and publishing and subscribing messages. For sample codes (Java, Python, Java Script) for sending messages from IoT devices, see
    Cloud IoT Core sample codes. In this guide, we will explain using some Python some sample codes.

    1. Copy the certificates downloaded on Cloud IoT Core (xxxx.caChain.pem, xxxx.cert.pem, xxxx.private.pem, rootCaCert.pem) to the IoT device.
    2. Install the correct paho-MQTT library for your version of Python.
      pip install paho-mqtt //python 2.x
      python -m pip install paho-mqtt // python 2.7.9+
      python3 -m pip install paho-mqtt //python 3.x
      
    3. Prepare and run code for sending data (mqttTSLClient.py).
      • Refer to the mqttTLSClient.py file of the Python sample code to write the code.
      • You need to modify the path of the certificate in the sample code to match the path of the certificate you downloaded.
      • A sample code to access Cloud IoT Core, repeat publish and subscribe messages 5 times, and end the program.
      • The messages are published on the factory/room1/temperature topic, and the alert topic, which is republished through Cloud IoT core, is subscribed.
    4. Check the result of running.
    Note
    • Currently, MQTT protocol TLS versions 1.0, 1.1, and 1.2 communication is supported, and Port 8883 must be used.
    • You can connect up to 10,000 devices concurrently. If you need to connect over 10,000 devices, please inquire at Contact Us .
    • The connection can be held for up to 1800 seconds. If you set keepalive, the connection automatically ends if the client does not send any of the messages of PINGREQ, PUBLISH, SUBSCRIBE, and PUBACK for 3 times as long time as the preset value. After the client has sent any of the messages of PINGREQ, PUBLISH, SUBSCRIBE, and PUBACK, the retention time is reset.
    • You can enter up to 128 characters for the MQTT Client ID.
    • Up to MQTT QoS1 is supported. QoS2 is automatically set as QoS1.
    • If you subscribe for a message by Non-Clean Session and QoS1, even if the connection to the client ends, the message published for the subscribed topic is not deleted but maintained in the queue. After reconnecting to the client, you can receive the message held in the queue. It is held for up to one hour from the time when the connection ended. If you need to set the expiry time, please contact Contact Us.

    Was this article helpful?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.