すべてのプロダクト
Search
ドキュメントセンター

IoT Platform:IoT Platform へのデバイスの接続

最終更新日:Aug 21, 2026

data_model_basic_demo サンプルプログラムを使用して街灯デバイスをシミュレートし、C SDK を介して IoT Platform に接続します。

Important notes

The steps in this topic are performed as a regular user. If an operation requires administrative permissions, prefix the command with sudo.

開発環境の準備

  • デバイス側 C SDK は Linux 上で動作します。64 ビットの Ubuntu 16.04 環境でコンパイルします。

  • 必要なソフトウェア:

    make 4.1 以降、gcc 5.4.0 以降。

    インストールコマンド:

    sudo apt-get install -y build-essential make gcc

操作手順

  1. デバイス用の C SDK をダウンロードしますC SDK 4.x

  2. C SDK ファイルを解凍し、デバイス証明書情報を変更します。

    data_model_basic_demo.c をダウンロードし、/LinkSDK/demos にあるファイルを置き換えます。 次のパラメーターを更新します。

    char *product_key       = "a2***";
    char *device_name       = "device1";
    char *device_secret     = "8c684ef***";
    ...
    ...
    char  *mqtt_host = "a2***.iot-as-mqtt.cn-shanghai.aliyuncs.com";

    パラメーター

    説明

    mqtt_host

    • 新しいパブリックインスタンス: iot-cn-***.mqtt.iothub.aliyuncs.com

    • 古いパブリックインスタンス: a2***.iot-as-mqtt.cn-shanghai.aliyuncs.com

    デバイスの MQTT インジェストエンドポイントです。

    • 新しいパブリックインスタンス: [インスタンス詳細] ページで、[開発設定の表示] をクリックします。エンドポイントは [開発設定] パネルに表示されます。

    • 古いパブリックインスタンス:エンドポイントの形式は ${YourProductKey}.iot-as-mqtt.${YourRegionId}.aliyuncs.com です。

    インスタンスのエンドポイントの表示

    product_key

    a2***

    デバイスを追加した際に保存したデバイス証明書の情報です。

    また、IoT Platform コンソールの [デバイス詳細] ページで証明書を表示することもできます。 デバイス証明書を取得する

    device_name

    device1

    device_secret

    8c684ef***

  3. On the Linux virtual machine, install the required software.

    sudo apt-get install -y build-essential make gcc
  4. 変更した LinkSDK ディレクトリを Linux 仮想マシンにアップロードします。

  5. SDK のルートディレクトリ /LinkSDK で、make コマンドを実行してサンプルプログラムをコンパイルします。

    make clean
    make

    コンパイルされたバイナリ data-model-basic-demo./output に出力されます。

  6. サンプルプログラムを実行します。

    ./output/data-model-basic-demo

    出力例:

    root@xxx:~/linkSDK# ./output/data-model-basic-demo
    [1637041632.700][LK-0313] MQTT user calls aiot_mqtt_connect api, connect
    [1637041632.700][LK-032A] mqtt host: axxx.iot-as-mqtt.cn-shanghai.aliyuncs.com
    [1637041632.700][LK-0317] user name: device1&axxx,0
    [1637041632.700][LK-0318] password: 86761xxx\21D
    establish tcp connection with server(host='axxx.iot-as-mqtt.cn-shanghai.aliyuncs.com', port=[443])
    success to establish tcp, fd=3
    local port: 35604
    [1637041632.711][LK-1000] establish mbedtls connection with server(host='axxx.iot-as-mqtt.cn-shanghai.aliyuncs.com', port=[443])
    [1637041632.766][LK-1000] success to establish mbedtls connection, (cost 45252 bytes in total, max used 47988 bytes)
    [1637041632.811][LK-0313] MQTT connect success in 108 ms
    AIOT_MQTTEVT_CONNECT
    [1637041632.811][LK-0309] pub: /sys/axxx/device1/thing/event/property/post
    
    [LK-030A] > 7B 22 69 64 22 3A 22 31  22 2C 22 76 65 72 73 69 | {"id":"1","versi
    [LK-030A] > 6F 6E 22 3A 22 31 2E 30  22 2C 22 70 61 72 61 6D | on":"1.0","param
    [LK-030A] > 73 22 3A 7B 22 4C 69 67  68 74 43 75 72 72 65 6E | s":{"LightCurren
    [LK-030A] > 74 22 3A 20 31 2E 35 7D  2C 22 73 79 73 22 3A 7B | t": 1.5},"sys":{
    [LK-030A] > 22 61 63 6B 22 3A 31 7D  7D                       | "ack":1}}
    
    [1637041632.833][LK-0309] pub: /sys/axxx/device1/thing/event/property/post_reply
    
    [LK-030A] < 7B 22 63 6F 64 65 22 3A  32 30 30 2C 22 64 61 74 | {"code":200,"dat
    [LK-030A] < 61 22 3A 7B 7D 2C 22 69  64 22 3A 22 31 22 2C 22 | a":{},"id":"1","
    [LK-030A] < 6D 65 73 73 61 67 65 22  3A 22 73 75 63 63 65 73 | message":"succes
    [LK-030A] < 73 22 2C 22 6D 65 74 68  6F 64 22 3A 22 74 68 69 | s","method":"thi
    [LK-030A] < 6E 67 2E 65 76 65 6E 74  2E 70 72 6F 70 65 72 74 | ng.event.propert
    [LK-030A] < 79 2E 70 6F 73 74 22 2C  22 76 65 72 73 69 6F 6E | y.post","version
    [LK-030A] < 22 3A 22 31 2E 30 22 7D                           | ":"1.0"}
    
    [1637041632.833][LK-0A08] DM recv generic reply
    demo_dm_recv_handler, type = 0
    msg_id = 1, code = 200, data = {}, message = success
  7. IoT Platform コンソールで、パブリックインスタンスページに移動します。 デバイスのステータスを確認します。

    • [デバイス管理] > [デバイス] を選択します。[デバイス] ページで、[デバイス名] 検索ボックスに device1 を入力して目的のデバイスを検索します。デバイスのステータスが [オンライン] であることを確認します。

    • 「操作」列の [表示] をクリックします。[デバイス詳細] ページで、[TSL データ] タブ、次に [実行ステータス] をクリックします。

      data_model_basic_demo.c サンプルは、LightCurrent の値を報告します。

      [実行ステータス] タブでは、[動作電流] プロパティに [1.5 A] の値が表示され、デバイスがこのプロパティ値を正常に報告したことを示しています。

次のステップ

これで、サーバーからのデバイスメッセージをサブスクライブ できます。