65.9K
CodeProject 正在变化。 阅读更多。
Home

使用 Microsoft Azure IoT Suite 设置 Intel® Edison 板

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1投票)

2015 年 10 月 8 日

CPOL

4分钟阅读

viewsIcon

10898

使用 Microsoft Azure IoT Suite 设置 Intel® Edison 板

获取新的 Intel® 物联网开发者套件,这是一套完整的软硬件解决方案,可让开发人员利用 Intel® Galileo 和 Intel® Edison 板创建令人兴奋的新解决方案。请访问 Intel® 物联网开发者中心

在开始将 Intel® Edison 板连接到 Azure 之前,您需要确保已安装最新的操作系统映像。为此,请按照 Intel 官方文档门户上的 入门说明 进行操作。按照标准的 Intel® Edison 设置说明操作后,您需要 与设备建立串行连接。建立与 Intel® Edison 板的串行连接(命令行)后,您就可以按照以下说明安装 Azure IoT SDK。

开始之前…

  • 确保您已运行 configure_edison --setup 命令来设置您的开发板
  • 确保您的 Intel® Edison 板已通过本地 Wi-Fi 网络上线(这应该在 configure_edison 设置期间发生)

在您的 Intel® Edison 上安装 Git

Git 是一个广泛使用的分布式版本控制工具,我们需要在开发板上安装 Git 才能克隆 Azure IoT SDK 并本地构建它。为此,我们必须先添加包含 Git 的扩展包。Intel® Edison 构建的 Yocto Project Linux 使用 opkg 管理器,该管理器默认不包含 Git 支持。

  1. 首先,在您的 Intel® Edison 板命令行上,使用 vi 将以下内容添加到您的 base-feeds
    $ vi /etc/opkg/base-feeds.conf
  2. 将以下行添加到 base-feeds.conf 文件
    src/gz all <a href="http://repo.opkg.net/edison/repo/all" rel="nofollow">http://repo.opkg.net/edison/repo/all</a>
    
    src/gz edison <a href="http://repo.opkg.net/edison/repo/edison" rel="nofollow">http://repo.opkg.net/edison/repo/edison</a>
    
    src/gz core2-32 <a href="http://repo.opkg.net/edison/repo/core2-32" rel="nofollow">http://repo.opkg.net/edison/repo/core2-32</a>
  3. esc 键退出,键入 SHIFT+:,然后键入 wq,然后按 Enter。如果您不熟悉 vi 编辑,请阅读此文
  4. 接下来,在命令行上更新和升级您的 opkg base-feeds
    $ opkg update
  5. 您应该会看到以下内容

将 Azure IoT SDK 下载到您的 Intel® Edison 板

  1. 在您的 Intel® Edison 板上,使用 Git 并直接使用以下命令克隆 Azure SDK 存储库。我们建议使用位于 /home/root 的默认文件夹
    $ opkg install git
    $ git clone git@github.com:Azure/azure-iot-suite-sdks.git
  2. 系统可能会提示您向设备添加 RSA 密钥,请回复 yes

备用部署方法

  1. 如果您因任何原因无法直接将 Azure IoT SDK 克隆到您的开发板,您可以将存储库克隆到您的 PC / Mac / Linux 桌面,然后使用 FileZilla 或 SCP 通过网络将文件传输到您的 Intel® Edison 板。
  2. 对于 FileZilla,在您的 Intel® Edison 上运行 wpa_cli status 以查找您的 IP 地址,然后使用“sftp://your.ip.address”,密码为“root”,并使用您的 Intel® Edison 密码通过 FileZilla 建立 SFTP 连接。完成此操作后,您可以直接通过网络拖放文件。

在 Intel® Edison 上构建 Azure IoT SDK

我们要向自己证明我们已成功构建 Azure IoT SDK。为此,我们将构建一个依赖于 SDK 的示例应用程序。为此,我们需要更新示例 AMPQ 应用中的凭据,以匹配我们的 Azure IoT Hub 应用程序的凭据。当我们构建 Azure IoT SDK 时,示例 C 应用程序会自动构建,我们需要在构建 SDK 时将凭据包含到示例应用中,以便在构建后可以使用它们。

  1. 使用 vi 或其他文本编辑器按照以下方式编辑“/c/iothub_client/samples/iothub_client_sample_amqp/iothub_client_sample_amqp.c
    • IoT Hub 连接(也称为 connectionString)字符串占位符替换为您的信息,如下所示(static const char* ....)。完成后,结果应如下所示的连接字符串,其中用您的凭据替换了方括号中的占位符。
    • 重要提示:用您的凭据替换方括号中的项目,否则示例将无法正常工作。

      static const char* connectionString = "HostName=[YOUR-HOST-NAME];CredentialType=SharedAccessKey;CredentialScope=Device;DeviceId=[YOUR-DEVICE-ID];SharedAccessKey=[YOUR-ACCESS-KEY];

  2. 在终端中,输入 /c/build_all/linux 并执行以下步骤
    $ opkg install util-linux-libuuid-dev
    
    $ ./build_proton.sh
    
    $ ./build.sh

更新 ldconfig 缓存

在构建 Azure IoT SDK 时,我们需要先构建一个名为 Qpid Proton 的依赖项。但是,在继续测试和构建我们的 C 语言示例之前,我们需要将生成的库注册到 ldconfig。为此,我们需要先找到 Proton 库的位置,然后将其复制到 Yocto 中的 /lib 文件夹。

  1. 通过运行以下终端命令将 libqpid-proton.so.2 添加到共享库
    $ find -name 'libqpid-proton.so.2'
    将此命令给出的目录复制到剪贴板。
  2. $ cp [directory_to_libqpid-proton.so.2] /lib
    [directory_to_libqpid-proton.so.2] 替换为第一个步骤中 find 命令的结果。
  3. $ ldconfig
    这将自动更新缓存;这是一个单行命令。
  4. $ ldconfig -v | grep "libqpid-p*"
    如果操作成功,您将看到列出的“libqpid-proton.so.2”。
  5. 现在我们已将 Qpid Proton 添加到 ldcache,我们可以构建依赖于 Proton 的示例 C 项目
    • 导航回: /c/iothub_client/samples/iothub_client_sample_amqp/iothub_client_sample_amqp/linux
    • 运行“make -f makefile.linux”
    • 运行“./iothub_client_sample_amqp”
  6. 结果应如下所示
    # ./iothub_client_sample_amqp 
    
    hub_client/samples/iothub_client_sample_amqp/linux#
    
    Starting the IoTHub client sample AMQP... 
    
    IoTHubClient_SetNotificationCallback...successful.
    
    IoTHubClient_SendTelemetryAsync accepted data for transmission to IoT Hub.
    
    IoTHubClient_SendTelemetryAsync accepted data for transmission to IoT Hub.
    
    IoTHubClient_SendTelemetryAsync accepted data for transmission to IoT Hub.
    
    IoTHubClient_SendTelemetryAsync accepted data for transmission to IoT Hub.
    
    IoTHubClient_SendTelemetryAsync accepted data for transmission to IoT Hub.
    
    Press any key to exit the application.
    
    Confirmation[0] received for message tracking id = 0 with result =
    
    IOTHUB_CLIENT_CONFIRMATION_OK
    
    Confirmation[1] received for message tracking id = 1 with result =
    
    IOTHUB_CLIENT_CONFIRMATION_OK
    
    Confirmation[2] received for message tracking id = 2 with result =
    
    IOTHUB_CLIENT_CONFIRMATION_OK
    
    Confirmation[3] received for message tracking id = 3 with result =
    
    IOTHUB_CLIENT_CONFIRMATION_OK
    
    Confirmation[4] received for message tracking id = 4 with result =
    
    IOTHUB_CLIENT_CONFIRMATION_OK
    
© . All rights reserved.