CAD | USD

Rapidly Deploy Sensor-Based Industrial Strength IoT Devices on Amazon Web Services

By Stephen Evanczuk

Contributed By Digi-Key's North American Editors

Endpoint devices for the Industrial Internet of Things (IIoT) provide the essential interface between cloud-based resources and industrial processes. In linking the periphery with the cloud, however, an IIoT device needs to address escalating requirements for performance, connectivity, sensor integration, security, and reliability within the device itself, as well as between the device and cloud.

Specialized services such as Amazon IoT Core and Amazon FreeRTOS have helped meet those key requirements on the cloud side. However, connecting with those services on the device side can present additional complications for IIoT developers just getting started with cloud services and their many interfaces and protocols. These developers still have to be responsive to edge application sensing and processing requirements, as well cost, power, performance, and space constraints.

This article briefly discusses the use of cloud-based resources and how they’ve evolved, and then introduces a full cloud kit based on an RX65N microcontroller from Renesas. It shows how this microcontroller and reference design can be used in combination with its associated software package to rapidly implement sensor-based IIoT devices for integration with the Amazon Web Services (AWS) cloud.

Utilizing cloud resources

Although other cloud service providers are slowly catching up, AWS remains the leading provider of cloud-based scalable serverless and server-based computing, storage and software-as-a-service (SaaS) offerings. Organizations routinely use these services in enterprise scale applications that can grow with changing demand and draw on a broad array of SaaS packages, all mediated through uniform, platform wide middleware services for communications, notification, security, data storage, and nearly any practical computing need.

For enterprises deploying large-scale IoT applications, utilizing these services to analyze IIoT data from vehicles, equipment, buildings and manufacturing plants offers clear advantages for enhancing insight and control of physical assets, processes and practices. For developers, however, the process of connecting an IIoT device to AWS or any other cloud services can seem less clear because of the apparent gap between resource-constrained real-time IoT designs in the periphery and scalable virtual services in the cloud.

To bridge this gap, major cloud service providers offer a connecting set of capabilities designed to reconcile the broad differences between IoT devices and cloud services. For AWS, these capabilities are contained in the AWS IoT Core, which serves as a gateway not only to the full AWS platform but also to IoT-specific application level services for data storage, analytics, visualization, and machine learning (Figure 1).

Diagram of AWS IoT provides the service interface between IIoT sensors in the field and the broader AWS platformFigure 1: AWS IoT provides the service interface between IIoT sensors in the field and the broader AWS platform of services used to analyze sensor data for industrial applications such as the fleet management application suggested here. (Image source: AWS)

Beyond these capabilities, the integration of the FreeRTOS open source real-time operating system (RTOS) with AWS IoT offers an important advantage in dealing with lifecycle requirements for system update and maintenance.

As with any other enterprise level offering, AWS IoT services specify an extensive set of interface requirements and protocols for device onboarding, authentication, and message interchange. Although consistent with requirements for the broader AWS platform, the specialized nature of the IoT environment means that even experienced AWS developers can face a significant learning curve in integrating a device with AWS IoT Core and associated AWS IoT services. In addition, developers at any level of experience face the familiar challenges of implementing an IoT design that meets continued demand for higher performance, lower power consumption, and better security.

Against this array of challenges, the Renesas RTK5RX65N0S01000BE RX65N Cloud Kit offers a ready solution for rapidly deploying IIoT devices on AWS.

Comprehensive platform

The RX65N Cloud Kit provides a complete reference design and development platform for deploying and evaluating IIoT devices with AWS IoT cloud services. Along with a comprehensive software development package, the kit contains three hardware boards including a target board with a Renesas R5F565NEDDFP 32-bit microcontroller that is certified for Amazon FreeRTOS, a Wi-Fi board, and a Renesas Cloud Option board with USB connections and a set of sensors typically needed in an IIoT application.

Based on the Renesas RXv2 32-bit processor core, the R5F565NEDDFP microcontroller provides 640 kilobytes (Kbytes) of RAM, 32 Kbytes of data flash, and 2 megabytes (Mbytes) of code flash. In this microcontroller, code flash memory can be configured in a linear mode where it operates as a single address space, or in dual mode where it operates as two separate memory areas. Dual mode enables more reliable over-the-air (OTA) updates as it loads new firmware into an unoccupied bank and validates its integrity and authenticity before rebooting the system.

Along with its memory support, the R5F565NEDDFP and other members of the RX65N family integrate an extensive set of functional blocks, including an IEEE-754 floating point unit (FPU) and memory protection unit (MPU). Among their external interfaces, RX65N microcontrollers include two multi-channel 12-bit analog-to-digital converters (ADCs), a two-channel 12-bit digital-to-analog converter (DAC), and industrial communications interfaces including Ethernet, Controller Area Network (CAN), and multiple serial interfaces including I2C, quad SPI, and a multi-channel Serial Communications Interface (SCI) supporting I2C and SPI.

Sensor hardware interface

Besides providing an evaluation platform, the Renesas Cloud Kit demonstrates the relative ease of integration of the RX65N microcontroller with IIoT sensors. In this case, the kit's Cloud Option board includes a set of three sensors:

  • Renesas’ ISL29035 (ISL29035IROZ-T7) digital light sensor for ambient/infrared light measurement
  • Bosch Sensortec’s BMI160 MEMS sensor for three-axis acceleration and gyroscopic measurement
  • Bosch Sensortec’s BME680 MEMS sensor for gas, temperature, humidity, and pressure measurements

Because all three sensors provide an I2C serial interface, integration with the microcontroller is simply a matter of connecting the devices to a shared I2C bus. The Cloud Option board schematic demonstrates this straightforward hardware interface (Figure 2).

Diagram of Renesas Cloud Option board reference design schematic (click to enlarge)Figure 2: Included in the Renesas RX65N Cloud Kit, the Renesas Cloud Option board reference design schematic illustrates the simple hardware interface needed to connect its three sensors to a shared I2C serial bus. (Image source: Renesas)

Using compatible connectors available on the Cloud Option board, developers can also extend the kit's hardware functionality with PMOD and Grove add-on boards.

Software development

Although the advanced microcontrollers and sensors used in IIoT devices simplify hardware design, software design can be significantly more complex. Along with software requirements for the IIoT system, developers face requirements for interfacing with cloud-based resources such as AWS IoT Core and AWS platform services. In this case, these requirements are addressed through a pair of AWS software development kits (SDKs) targeting device and cloud services.

At the application level, IoT software developers interact with AWS services through the standard AWS SDK. At this level, interactions with devices and their data occur through those same services, mediated by AWS messaging and notification services common to both AWS and AWS IoT services as mentioned below.

At the device level, developers work with a device (or “Thing”) SDK to connect to AWS IoT services. Specific requests and responses between devices and AWS services are mediated by a message broker that manages exchanges using the ISO standard publish-subscribe (pub/sub) messaging protocol Message Queuing Telemetry Transport (MQTT) (Figure 3).

Diagram of use of separate SDKs for devices and for applicationsFigure 3: Implementation of IIoT applications involves use of separate SDKs for devices and for applications, but both rely on a set of uniform, platform-wide mechanisms for messaging, notification and other underlying capabilities. (Image source: AWS)

As the device sends MQTT messages with data payloads, a rules engine invokes additional AWS platform services according to a set of expressions written by the developer in a syntax based on structured query language (SQL). For example, the rule shown in Listing 1 can republish the payload generated by the SQL expression (SELECT * FROM 'iot/test) to another MQTT queue (my-mqtt-topic) if an inference model (my-model) called by the Amazon machine learning services function (machinelearning_predict()) classifies the data as belonging to some specific label (predictedLabel=1).

Copy
{
  "sql": "SELECT * FROM 'iot/test' where machinelearning_predict('my-model', 'arn:aws:iam::123456789012:role/my-iot-aml-role', *).predictedLabel=1",
  "ruleDisabled": false,
  "awsIotSqlVersion": "2016-03-23",
  "actions": [{
    "republish": {
        "roleArn": "arn:aws:iam::123456789012:role/my-iot-role",
        "topic": "my-mqtt-topic"
    }
  }]
}

Listing 1: The AWS rules engine invokes AWS services and routes data using SQL-like selection rules, designated actions and associated metadata. (Code source: AWS)

Device shadows

While the AWS IoT rules engine provides a loosely coupled processing capability, the AWS IoT Device Shadow service helps decouple the IoT application from the health of the IoT device. Device shadows hold state information about a physical IoT device. Consequently, if an IoT device loses connectivity or otherwise breaks the connection with AWS, cloud-based services can use the device shadow to continue operating based on the last received data without needing to build their own device data caching mechanisms. Conversely, the AWS IoT Greengrass edge service lets IoT devices continue to virtually interact with the cloud during intermittent breaks in cloud services. Here, Greengrass continues operating in edge devices to maintain device shadows and provide the necessary subset of cloud services needed to maintain IoT device operation.

Although device shadows hold device state, the Device Shadow service is more than a simple caching mechanism. It also provides a common interface for applications to send requests to IoT devices. Because it is tied into the MQTT pub/sub mechanism, data updates and requests result in automatic notification of all devices and applications that subscribe to the MQTT queues associated with each device shadow.

At the implementation level, the Device Shadow service uses a simple JSON document format that holds data and metadata associated with each physical device. Working through the device SDK, software on the IoT device can transmit a new JSON document that updates the reported state in the device shadow with its most recent data. Conversely, a host or mobile-based IoT application can update the device shadow with new desired values. For example, for an IIoT device currently displaying a green LED or green light on a display, an application can update the device shadow to request a change to red and even receive a report showing the delta between desired and reported states (Listing 2).

Copy
{
    "state": {
        "desired": {
            "color": "RED",
            "state": "STOP"
        },
        "reported": {
            "color": "GREEN",
            "engine": "ON"
        },
        "delta": {
            "color": "RED",
            "state": "STOP"
        }
    },
    "metadata": {
        "desired": {
            "color": {
                "timestamp": 12345
            },
            "state": {
                "timestamp": 12345
            },
            "reported": {
                "color": {
                    "timestamp": 12345
                },
                "engine": {
                    "timestamp": 12345
                }
            },
            "delta": {
                "color": {
                    "timestamp": 12345
                },
                "state": {
                    "timestamp": 12345
                }
            }
        },
        "version": 17,
        "timestamp": 123456789
    }
}

Listing 2: An AWS device shadow is a JSON document that contains device metadata and data, including values for both reported and desired device states as well as the delta between the two states. (Code source: AWS)

While services such as device shadows and rules engines support integration with applications and the broader AWS platform, a centerpiece in the AWS IoT service is its integration of Amazon FreeRTOS. This open source RTOS extends the popular open source FreeRTOS kernel with an extensive set of libraries. Along with libraries for common services such as logging, Amazon FreeRTOS adds libraries for AWS IoT services. These libraries include AWS IoT Device Shadow, AWS IoT Greengrass (gdd), and AWS IoT Device Defender for device security monitoring. In addition, Amazon enhances FreeRTOS with libraries for many middleware services, including secure sockets, Transport Layer Security (TLS), Public Key Cryptography Standard (PKCS) #11, an OTA agent, Bluetooth, Wi-Fi, and MQTT message exchange.

Simple deployment

Renesas helps developers gain experience quickly with its Cloud Kit and connectivity with AWS IoT services. After setting up the Cloud Kit board set, users need to install the Renesas Eclipse-based e2 studio integrated development environment (IDE) and the Renesas CC-RX compiler. Using e2 studio and the CC-RX compiler, developers can quickly import and compile Amazon FreeRTOS as well as the Renesas open source RX65N Cloud Kit sample code.

Renesas provides associated documentation that provides a step-by-step description of setting up AWS IoT and authentication credentials required to make any connection to AWS. After this relatively quick setup procedure, the demonstration program needs to be run to monitor sensor data sent by the device as MQTT messages and view the messages using an MQTT display client available through the AWS IoT console.

Custom software development

Besides providing an immediate demonstration of IoT device integration with AWS IoT, the Renesas sample code also serves as a reference design for custom applications. Even with this code availability, however, one of the challenges developers will face in their custom projects is dealing with the large number of configurations associated with Amazon FreeRTOS and the related AWS IoT services. Each service requires specification of many associated parameters like queue lengths and message sizes.

Although the Renesas sample code includes prebuilt FreeRTOS configurations for its demonstrations, custom code developers will need to work through configuration options for each service, library, and utility. Renesas developed the Smart Configurator to simplify this process. Available as both an e2 studio plugin and a standalone application, the Smart Configurator lets developers examine and modify settings for each configuration group through a graphical user interface (GUI) (Figure 4).

Image of Renesas Smart Configurator (click to enlarge)Figure 4: The Renesas Smart Configurator offers a simple GUI for examining and modifying the many configuration settings associated with the many libraries and services supported in Amazon FreeRTOS. (Image source: Renesas)

For the code, developers can take advantage of the complete source provided in the Renesas RX65N Cloud Kit code repository. The sample routines included in this repository demonstrate key design patterns for working with each AWS IoT service through the MQTT-based messaging mechanisms.

To demonstrate the AWS IoT Device Shadow service, for example, an included module (aws_shadow_lightbulb_on_off.c) and associated header files illustrate how software running on the IoT device creates JSON documents, initializes queues, and sends device update messages to the Device Shadow service. Although the full software architecture is rather involved, this sample module shows how a basic data structure and a few lines of code can be used to change the color of a light (reported color green in the JSON document shown in Listing 1) by setting the appropriate shadow device JSON document attribute to the new color (desired color red in Listing 1). After initializing the device shadow, the code creates a task that alternates the desired color between two states (red and green) by issuing a new desired state request using the function prvGenerateDesiredJSON() to generate the new JSON document with the alternate color state (Listing 3).

Copy
#define shadowDemoDESIRED_JSON      \
    "{"                             \
    "\"state\":{"                   \
    "\"desired\":{"                 \
    "\"%s\":\"%s\""                 \
    "}"                             \
    "},"                            \
    "\"clientToken\": \"token-%d\"" \
    "}"
 
 ...
 
static uint32_t prvGenerateDesiredJSON( ShadowQueueData_t * const pxShadowQueueData,
                                        const char * const pcTaskName,
                                        uint8_t ucBulbState )
{
    /* Map cBulbState to strings. */
    static const char * const pColors[ 2 ] = { "green", "red" };
 
    /* Generate JSON. */
    return ( uint32_t ) snprintf( ( char * ) pxShadowQueueData->pcUpdateBuffer, 
                                  shadowDemoBUFFER_LENGTH,
                                  shadowDemoDESIRED_JSON,
                                  pcTaskName,
                                  pColors[ ucBulbState ],
                                  ( int ) xTaskGetTickCount() );
}
 
 ...
 
   /* Keep changing the desired state of light bulb periodically. */
    for( ; ; )
    {
        configPRINTF( ( "%s changing desired state.\r\n", pxShadowTaskParam->cTaskName ) );
 
        /* Toggle the desired state and generate a new JSON document. */
        ucBulbState = !( ucBulbState );
        xShadowQueueData.ulDataLength = prvGenerateDesiredJSON( &xShadowQueueData,
                                                                pxShadowTaskParam->cTaskName,
                                                                ucBulbState );
 
        /* Add the new desired state to the update queue. */
        if( xQueueSendToBack( xUpdateQueue, &xShadowQueueData, shadowDemoSEND_QUEUE_WAIT_TICKS ) == pdTRUE )
        {
            /* If the new desired state was successfully added, wait for notification that the update completed. */
            configASSERT( ulTaskNotifyTake( pdTRUE, shadowDemoNOTIFY_WAIT_MS ) == 1 );
            configPRINTF( ( "%s done changing desired state.\r\n", pxShadowTaskParam->cTaskName ) );
        }
        else
        {
            configPRINTF( ( "Update queue full, deferring desired state change.\r\n" ) );
        }
 
        vTaskDelayUntil( &xLastWakeTime, shadowDemoSEND_UPDATE_MS );
    }

Listing 3: This snippet of sample code in the Renesas RX65N Cloud Kit code repository demonstrates the basic design pattern for using a JSON document defined in shadowDemoDESIRED_JSON and instantiated by the prvGenerateDesiredJSON() function to modify the desired state of a device shadow using an update queue. (Code source: Renesas)

Conclusion

With its broad set of offerings, a commercial cloud service such as AWS is an attractive platform for developers building large-scale IIoT applications, particularly those that need to work with other enterprise applications. For developers, however, dealing with both IoT device design and cloud integration challenges often leads to unexpected delays in development and deployment.

Based on the Renesas RX65N microcontroller, the Renesas RX65N Cloud Kit provides a complete IIoT sensor device and reference design. Used in combination with its associated software package, the Renesas Cloud Kit provides a flexible, rapid development platform for implementing sensor-based IIoT devices for integration with AWS.

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of Digi-Key Electronics or official policies of Digi-Key Electronics.

About this author

Stephen Evanczuk

Stephen Evanczuk has more than 20 years of experience writing for and about the electronics industry on a wide range of topics including hardware, software, systems, and applications including the IoT. He received his Ph.D. in neuroscience on neuronal networks and worked in the aerospace industry on massively distributed secure systems and algorithm acceleration methods. Currently, when he's not writing articles on technology and engineering, he's working on applications of deep learning to recognition and recommendation systems.

About this publisher

Digi-Key's North American Editors