Skip to content

Latest commit

 

History

History
206 lines (147 loc) · 8.19 KB

File metadata and controls

206 lines (147 loc) · 8.19 KB
page_type description languages products
sample
Connecting a Realtek Ameba D device to Azure IoT using the Azure SDK for Embedded C
c
azure-iot
azure-iot-pnp
azure-iot-dps
azure-iot-hub

How to Setup and Run Azure SDK for Embedded C IoT Hub Client on Realtek AmebaD

Introduction

This is a guide outlining how to run an Azure SDK for Embedded C IoT Hub telemetry sample on an Realtek AmebaD development board.

What is Covered

  • Configuration instructions for the Arduino IDE to compile a sample using the Azure SDK for Embedded C.
  • Configuration, build, and run instructions for the IoT Hub telemetry sample.

The following was run on Windows 10 and Ubuntu Desktop 20.04 environments, with Arduino IDE 1.8.12 and Realtek Boards module 3.0.7.

Prerequisites

  • Have an Azure account created.

  • Have an Azure IoT Hub created.

  • Have a logical device created in your Azure IoT Hub using the authentication type "Symmetric Key".

    NOTE: Device keys are used to automatically generate a SAS token for authentication, which is only valid for one hour.

  • Have the latest Arduino IDE installed.

  • Install the USB drivers for the Realtek AmebaD board.

  • Have the Realtek AmebaD board packages installed on Arduino IDE. Realtek boards are not natively supported by Arduino IDE, so you need to add them manually.

    • Realtek boards are not natively supported by Arduino IDE, so you need to add them manually.
    • Follow the instructions in the official Realtek AmebaD page.
  • Have one of the following interfaces to your Azure IoT Hub set up:

    NOTE: This guide demonstrates use of the Azure CLI and does NOT demonstrate use of Azure IoT Explorer.

Setup and Run Instructions

  1. Run the Arduino IDE.

  2. Install the Azure SDK for Embedded C library.

    • On the Arduino IDE, go to menu Sketch, Include Library, Manage Libraries....
    • Search for and install azure-sdk-for-c.
  3. Open the Realtek AmebaD sample.

    • On the Arduino IDE, go to menu File, Examples, azure-sdk-for-c.
    • Click on az_realtek_amebaD to open the sample.
  4. Configure the Realtek AmebaD sample.

    Enter your Azure IoT Hub and device information into the sample's iot_configs.h.

  5. Connect the Realtek AmebaD board to your USB port.

  6. On the Arduino IDE, select the board and port.

    • Go to menu Tools, Board and select Ameba ARM (32-bits) Boards/RTL8722DM/RTL8722CSM.
    • Go to menu Tools, Port and select the port to which the microcontroller is connected.
  7. Upload the sketch.

    • Go to menu Sketch and click on Upload.
  8. Monitor the MCU (microcontroller) locally via the Serial Port.

    • Go to menu Tools, Serial Monitor.

      If you perform this step right away after uploading the sketch, the serial monitor will show an output similar to the following upon success:

      Connecting to WIFI SSID buckaroo
      .......................WiFi connected, IP address:
      192.168.1.123
      Setting time using SNTP..............................done!
      Current time: Thu May 28 02:55:05 2020
      Client ID: mydeviceid
      Username: myiothub.azure-devices.net/mydeviceid/?api-version=2018-06-30&DeviceClientType=c%2F1.0.0
      Password: SharedAccessSignature sr=myiothub.azure-devices.net%2Fdevices%2Fmydeviceid&sig=placeholder-password&se=1590620105
      MQTT connecting ... connected.
      
  9. Monitor the telemetry messages sent to the Azure IoT Hub using the connection string for the policy name iothubowner found under "Shared access policies" on your IoT Hub in the Azure portal.

    $ az iot hub monitor-events --login <your Azure IoT Hub owner connection string in quotes> --device-id <your device id>
    Expected telemetry output:

    Starting event monitor, filtering on device: mydeviceid, use ctrl-c to stop...
    {
        "event": {
            "origin": "mydeviceid",
            "payload": "payload"
        }
    }
    {
        "event": {
            "origin": "mydeviceid",
            "payload": "payload"
        }
    }
    {
        "event": {
            "origin": "mydeviceid",
            "payload": "payload"
        }
    }
    {
        "event": {
            "origin": "mydeviceid",
            "payload": "payload"
        }
    }
    {
        "event": {
            "origin": "mydeviceid",
            "payload": "payload"
        }
    }
    {
        "event": {
            "origin": "mydeviceid",
            "payload": "payload"
        }
    }
    ^CStopping event monitor...

Certificates - Important to know

The Azure IoT service certificates presented during TLS negotiation shall always be validated, on the device, using the appropriate trusted root CA certificate(s).

The Azure SDK for C Arduino library automatically installs the root certificate used in the United States regions, and adds it to the Arduino sketch project when the library is included.

For other regions (and private cloud environments), please use the appropriate root CA certificate.

Additional Information

For important information and additional guidance about certificates, please refer to this blog post from the security team.

Troubleshooting

  • The error policy for the Embedded C SDK client library is documented here.
  • File an issue via Github Issues.
  • Check previous questions or ask new ones on StackOverflow using the azure and c tags.

Contributing

This project welcomes contributions and suggestions. Find more contributing details here.

License

This Azure SDK for C Arduino library is licensed under MIT license.

Azure SDK for Embedded C is licensed under the MIT license.