RZ/G2L - Home Automation

RZ/G2L - Home Automation

Introduction

The user guide outlines the procedures and instructions for deploying the Home Automation use case on the RZ/G2L evaluation kit using AWS Greengrass.

The Home Automation application on the RZ/G2L facilitates the monitoring and control of light and fan devices, while also regularly measuring temperature and relative humidity. The application sends the collected temperature and humidity data to the AWS cloud database using internet from USB wireless or ethernet interface. Users can be able to manage appliances remotely using a web user interface.

Assumption:
Before going through the following steps, please make sure that RZ Gateway Linux environment preparation was completed.

Architecture Description

The architecture diagram presented below illustrates the AWS services utilized in the cloud and the RZ/G2L EVK. This diagram features two environments: the AWS cloud and the RZ/G2L EVK. Both environments are interconnected through internet communication protocols, like MQTT.

image-20251024-032046.png

Peripheral Setup

image-20251028-234240.png

a. Insert the previously prepared microSD card into the microSD card slot.

b. Connect the LAN cable to the Ethernet connector.

c. Connect the USB serial cable to the serial port. The other end is to be connected to a Windows PC.

d. Connect US082-HS3001EVZ PMOD sensor to PMOD1 - Type-2A connector.

e. Connect Wi-Fi USB module (TP-Link Archer TX1U nano) to USB 1 connector [optional].

f. Enable SW3 and SW4 switches to enable I2C communication to read sensor data.

image-20251027-022636.png

g. Connect the Type-C USB cable to the power connector port. Two green LED will light up.

h. Power up the board by pressing 1 second the Power button.
After successfully booting up the board, on serial console, log in under root account:

smarc-rzg2l login: root

Note: if using Wi-Fi connectivity, please refer to RZ/G2L - Home Automation section.

Optional Setup: LED Light and Fan control

With Home Automation sample demo user can control LED light and Fan motor control.
An external circuit is necessary for the application to simulate light with an LED from GPIO-12 and to control a fan using a DC motor from GPIO-13.

The LED can be operated directly via GPIO-12, but the DC motor requires a greater current from GPIO-13 to operate.

The system requires an increased voltage for current amplification through the use of an external circuit. As illustrated below, modify the jumper CN4 from positions 2 - 4 to 4 - 6 in order to adjust the voltage from 3.3V to 5V

image-20251027-023642.png
image-20251027-023740.png

Use the below Darlington pair connections with resistors, transistors and diodes to amplify the load current to drive DC motor.

image-20251027-023917.png

Required Components:

No.

Component Name

Quantity

1

BC547 Transistor

2

2

LED (1.8V)

1

3

DC Motor (3.3V - 12V)

1

4

1K Resistor

2

5

Diode 1N4007

1

Step 1 - Infrastructure Setup

Step 1.1 - AWS Credentials Preparation

AWS Credentials are necessary to establish the Home Automation use case environment on the cloud and the RZ/G2L EVK. The user must create an AWS account and log into the AWS Management Console using either the root account or an existing IAM user with administrative rights. If the user does not have an IAM user, follow the steps outlined below to create one:

  • Navigate to the IAM service.

  • Create a new IAM user (if not have) and ensure Programmatic access is enabled during creation. This will provide an AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.

  • Attach appropriate policies to this IAM user to grant the necessary permissions.

image-20251024-033245.png
  1. Install AWS CLI on Host machine from AWS Documentation.

  2. Export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as environment variables on Host Machine.

  3. Run following AWS cli command to generate AWS_SESSION_TOKEN for 36 hours duration
    On Host Machine:

$ aws sts get-session-token --duration-seconds 129600

Command result:

{ "Credentials": { "AccessKeyId": "123...", "SecretAccessKey": "...", "SessionToken": "...", "Expiration": "2025-07-30T23:47:00Z" } }
  1. Copy and save the temporary AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN for further use.

Step 1.2 - Setup Home Automation use case infrastructure

The Home automation application requires the setup of infrastructure on the AWS cloud and on the RZ/G2L Device. On the RZ/G2L device, the application collects temperature and relative humidity data and stream them to cloud database through Greengrass v2 component and device shadow service. On the AWS Cloud, use the web UI interface to interact with the application using an EC2 instance. The web UI interface monitor and manages the appliances remotely through device shadow service. Device shadow updates state change to Home automation application by publishing the desired states via an MQTT topic. Similarly, reports the home appliance manual change state to cloud via device shadow MQTT topics from the Greengrass component. The entire infrastructure is configured using the Ansible tool, which requires AWS credentials for access and setup on the AWS cloud.

On the RZ/G2L EVK:

  1. Download from GitHub page, the ha-g2l-vlp-v1.1.zip file

  2. Copy ha-g2l-vlp-v1.1.zip file to RZ/G2L /home/root

  3. Extract the zip file and remove the zip file

# unzip ha-g2l-vlp-v1.1.zip # rm ha-g2l-vlp-v1.1.zip

Note: If you created your AWS account before June 20, 2025 and would like to use AWS Timestream for Live Analytics instead of InfluxDB 3, please replace ha-g2l-vlp-v1.1.zip with ha-g2l-vlp-v1.0.zip.

ha-g2l-vlp-v1.1.zip: for AWS accounts created after June 20, 2025.
ha-g2l-vlp-v1.0.zip: for AWS accounts create before June 20, 2025 and want to use AWS Timestream for Live Analytics instead of InfluxDB 3.

 

  1. Change directory to scripts

cd ~/ home_automation/scripts/
  1. Open config.yaml configuration file and configure the aws parameters. If required, user can change the names of iot parameters.

image-20251024-060149.png
  1. Run home_automation.sh

./home_automation.sh

Note: script can also be executed by providing AWS credentials and AWS region as arguments.

./home_automation.sh <AWS_ACCESS_KEY_ID> <AWS_SECRET_ACCESS_KEY> <AWS_SESSION_TOKEN> <AWS_REGION>
  1. The script will execute 30 to 40 minutes to setup the infrastructure on RZ/G2L Device and AWS cloud.

  2. During the execution of the script, it generates logs for each step. The user can review the logs sequentially as outlined below and validate the installation.

Setup on RZ/G2L EVK:

  • Check the configuration details

image-20251024-060339.png
  • Verifying and installing dependencies packages required for setup

image-20251024-060410.png
  • Install Greengrass v2 on RZ/G2L EVK

image-20251024-060435.png
  • Create IoT policy, IAM role, IAM policies and attach policies to IAM role

image-20251024-060503.png
  • Below log shows the summary of Home Automation client installation setup on AWS cloud

image-20251024-060532.png
  • Starts executing step-2, Setting up Home Automation server using Ansible

image-20251024-060650.png
  • Create EC2 instance key pair

image-20251024-060716.png
  • Create and Launch EC2 instance

image-20251024-060742.png
  • Associate elastic IP to EC2 instance

image-20251024-060803.png
  • Connect EC2 instance with ssh

image-20251024-060834.png
  • Create Timestream database

image-20251024-060859.png
  • Deploy FastAPI server into EC2

image-20251024-060923.png
  • Deploy React app to EC2

image-20251024-060946.png
  • Create S3 bucket policies to access S3 bucket

image-20251024-061015.png
  • Deploy home automation Greengrass component

image-20251024-061047.png
  • On Successful completion of Step-2, the below output is shown

image-20251024-061111.png

If the installation is successful, the above message will be shown on RZ/G2L EVK UART console.

Step 2 - Execute Home Automation use case

This section details the steps to execute Home automation application on the RZ/G2L EVK. The RZ/G2L EVK should be connected with web UI application through AWS Greengrass V2. The web UI application shows the appliances and sensor data if and only if the RZ/G2L is actively connected with AWS cloud.
In order to access the Home automation devices, we must use the web UI interface through a browser. To launch the web UI application, a public IP address is required. Once the infrastructure has been established, the Ansible tool records the public IP in home_automation/scripts/ansible_start/instance_ip.txt.

On RZ/G2L EVK:

cat ~/home_automation/scripts/ansible_start/instance_ip.txt

98.89.148.129 (for e.g.)

  1. Open the browser and type the URL: <http://<instance_ip>>
    For e.g. http:// 98.89.148.129

image-20251024-062213.png
  1. The web application opens log-in page. Enter username as “user” and Password as “1234” and click on log-in.

  2. Upon opening, if the RZ/G2L device is actively connected to cloud the web application presents
    • Appliances and its states
    • Sensors and its data.

image-20251024-062303.png
  1. Upon opening, if the RZ/G2L device is actively not connected to cloud the web application won’t show devices status.

image-20251024-062331.png
  1. Users can toggle the appliances light and fan using toggle button and see the ON/OFF state change from web UI application from remote location. Similarly, users can observe the appliances state change when the appliances are ON/OFF locally at home.

image-20251024-062351.png
  1. Users can observe the temperature and relative humidity sensors data from web UI graphs.
    • Temperature Sensor graph

    image-20251024-062414.png


    • Relative humidity sensor graph

    image-20251024-062432.png
  2. Users can observe logs from /greengrass/v2/logs/HomeAutomationGreengrassComponent.log

image-20251024-062454.png

Note - USB Wi-Fi Device Connection

On RZ/G2L EVK, when the TP-LINK Archer TX1U Nano USB Wi-Fi device is connected, the drivers are loaded automatically and creates wlan0 interface. When wlan0 interface is created, usb-wifi@wlan0.service service will be started and reads SSID and password from /opt/usb-wifi/wifi_credentials.txt and try to establish connection.

Follow below steps to setup Wi-Fi connectivity after the system boots up

  1. Power on the RZ/G2L device and login.

  2. Connect TP-Link USB Wi-Fi adapter to RZ/G2L.

  3. Configure SSID and Password in /opt/usb-wifi/wifi_credentials.txt file.

image-20251024-062909.png
  1. Reboot the RZ/G2L device.

  2. In the next boot, the device connects to Wi-Fi.