AWS IoT Device SDK for Embedded C

repository·main·Indexed 22 days ago

https://github.com/aws/aws-iot-device-sdk-embedded-c

A set of lightweight, modular C libraries for embedded devices to interact with AWS IoT services using MQTT and HTTP protocols. The SDK includes support for fleet provisioning, Greengrass local authentication, and SigV4-authenticated HTTP requests to AWS S3.

Tokens
14K
Snippets
38
Records
59
Agent score
74%

What's inside aws-iot-device-sdk-embedded-c

  1. Overview of AWS IoT Device SDK for Embedded C

    main

    The AWS IoT Device SDK for Embedded C (C-SDK) is a collection of C source files licensed under MIT that allows embedded applications to securely connect to AWS IoT Core.

    Key characteristics:

    • Portability: The libraries depend only on standard C libraries, making them portable to various operating systems including RTOS, Linux, Mac, and Windows.
    • Modular Design: Many libraries (like MQTT client and JSON parser) are decoupled, allowing you to choose or implement your own.
    • Integration: It can be built into custom firmware alongside your application code and OS.
    • Sample Usage: Demos are available for POSIX systems (using OpenSSL) and FreeRTOS (using mbedTLS).
  2. Overview of AWS IoT Device SDK for Embedded C

    main

    The AWS IoT Device SDK for Embedded C is a collection of libraries designed to help embedded devices connect to AWS IoT services. It provides core protocol implementations and high-level AWS service integrations.

    Key features include:

    • coreMQTT: MQTT protocol implementation.
    • coreHTTP: HTTP protocol implementation.
    • coreJSON: JSON parsing and generation.
    • corePKCS11: PKCS#11 interface for cryptographic operations.
    • AWS IoT Device Shadow: Support for managing device state via shadows.
    • AWS IoT Jobs: Support for managing remote device tasks.
    • AWS IoT Device Defender: Integration with device security monitoring.
    • AWS IoT Over-the-air Update Library: Support for secure firmware updates.
    • AWS IoT Fleet Provisioning: Support for large-scale device onboarding.
    • AWS SigV4: AWS Signature Version 4 signing for request authentication.
    • backoffAlgorithm: Implementation of exponential backoff for retries.
  3. MISRA C:2012 Compliance Overview

    main
    The POSIX platform implementations of transport interfaces, clock utility, and retry utils in this SDK conform to the MISRA C:2012 guidelines, with some noted exceptions. Compliance is verified using Coverity static analysis. If you are performing safety-critical audits, be aware that certain deviations exist for compatibility, platform requirements (POSIX/OpenSSL), and library usability.
  4. Core Libraries in the AWS IoT Device SDK

    main

    The C-SDK provides several specialized libraries to simplify access to AWS IoT services:

    • coreMQTT: Establishes MQTT connections (secure TLS or plaintext TCP) over a customer-implemented transport layer. Compliant with MQTT 3.1.1.
    • coreHTTP: Provides HTTP/1.1 client capabilities (GET, PUT, POST, HEAD) over a customer-implemented transport layer.
    • coreJSON: A JSON parser that enforces the ECMA-404 standard, supporting validation and nested key searching.
    • corePKCS11: An implementation of the PKCS #11 API for cryptographic operations (asymmetric keys, random number generation, hashing), useful for interfacing with hardware enclaves like TPM or HSM.
    • AWS IoT Device Shadow: Manages persistent, virtual representations of device state via JSON documents. Works with any MQTT and JSON library.
    • AWS IoT Jobs: Enables interaction with the AWS IoT Jobs service to manage device fleets (e.g., firmware updates) using MQTT topic strings.
    • AWS IoT Device Defender: Allows monitoring of security metrics and custom operational health metrics.
    • AWS IoT Fleet Provisioning: Enables provisioning devices without pre-existing certificates using MQTT APIs.
    • AWS SigV4: Implements the Signature Version 4 signing process for authenticating HTTP requests to AWS services.
    • backoffAlgorithm: A utility for calculating exponential backoff with 'Full Jitter' for retrying network operations.
  5. Choose the correct SDK branch

    main

    Depending on your stability and feature requirements, choose one of the following branches:

    • main: Continuous development. Use this for the latest features, but be aware it may contain bugs. For production, use tagged releases.
    • v4_beta_deprecated: A deprecated beta version. It receives critical bug fixes and security patches but no new features will be added. Use this only if specifically required by your existing integration.
  6. Understand the C-SDK versioning scheme

    main

    The AWS IoT Device SDK for Embedded C uses a date-based versioning scheme for the overall SDK releases in the format YYYYMM.NN:

    • YYYY: Year
    • MM: Month
    • NN: Release order within that month (e.g., 00 is the first release).

    Example: 202106.01 is the second release in June 2021.

    Note: While the SDK itself uses date-based versioning, individual libraries within the SDK maintain their own semantic versioning (X.Y.Z). You should use the semantic version of a specific library to determine the impact of updates on your application.

  7. Understand MISRA deviations in the SDK

    main

    The SDK contains several deviations from the MISRA C:2012 standard. These are categorized into three types:

    1. Ignored by Coverity Configuration: Deviations explicitly allowed via tools/coverity/misra.config. These include allowing ambiguous names (e.g., LogInfo), unused types in headers, function-like macros (e.g., assert), and C99 macro compatibility for C90 compilers.
    2. Flagged by Coverity: Violations that appear when analyzing multiple library repositories together, such as type duplication from transport_interface.h (Rule 5.6) or network context struct definitions (Rule 5.7). These are typically not violations when analyzing individual build targets.
    3. Suppressed with Coverity Comments: Deviations suppressed directly in code to allow necessary POSIX or OpenSSL functionality, such as using FD_SET, FD_ZERO, casting pointers for IP address retrieval, or using Standard Library I/O for OpenSSL PEM file reading.
  8. Generate Presigned S3 URLs

    main

    Use the presigned_url_gen.py script to generate pre-signed URLs for S3 HTTP GET and PUT requests. This is useful for providing temporary access to specific S3 objects in the HTTP demo.

    Run the script by providing the S3 bucket name and the object key. The output will be formatted as C macros that can be directly used in your project configuration.

    ./presigned_urls_gen.py --bucket <YOUR BUCKET NAME> --key <YOUR OBJECT KEY>
  9. Create an AWS IoT Thing and Register a Certificate

    main

    To begin, you must register your device in AWS IoT Core.

    1. Create a Thing: Use the AWS CLI to create a new Thing.
      aws iot create-thing --thing-name device_thing_name
    2. Register a Certificate: You can use an existing certificate or create a new one via the AWS Management Console. If using your own CA, follow the AWS documentation for registering CA certificates and creating device certificates.
    3. Attach Certificate to Thing: Link the certificate to your Thing using its ARN.
      aws iot attach-thing-principal --thing-name device_thing_name --principal <certificate-arn>
    aws iot create-thing --thing-name device_thing_name
    aws iot attach-thing-principal --thing-name device_thing_name --principal <certificate-arn>
  10. Create a Fleet Provisioning Template

    main

    A provisioning template defines how AWS IoT should create resources (like Things and Certificates) when a new device connects using a claim certificate.

    1. Navigate to AWS IoT Core > Connect many devices > Create provisioning template.
    2. Choose Provisioning devices with claim certificates and click Next.
    3. Set the status to active.
    4. Enter a template name.
    5. Select the IAM role created for AWS IoT.
    6. Select the provisioning policy created earlier.
    7. Select Don't use a pre-provisioning action.
    8. Enable the automatic thing creation option and click Next.
    9. Select or create a policy for the device's permissions (e.g., permissions for connecting to IoT, subscribing, or publishing to topics).
    10. Click Next, review the settings, and click Create the template.