Test communications - AWS IoT Greengrass

AWS IoT Greengrass Version 1 no longer receives feature updates, and will receive only security patches and bug fixes until June 30, 2023. For more information, see the AWS IoT Greengrass V1 maintenance policy. We strongly recommend that you migrate to AWS IoT Greengrass Version 2, which adds significant new features and support for additional platforms.

Test communications

  1. On your computer, open two command-line windows. Just as in Module 5, one window is for the GG_Switch client device and the other is for the GG_TrafficLight client device. You use them to run the same commands that you ran in Module 5.

    Run the following commands for the GG_Switch client device:

    cd path-to-certs-folder python lightController.py --endpoint AWS_IOT_ENDPOINT --rootCA AmazonRootCA1.pem --cert switchCertId-certificate.pem.crt --key switchCertId-private.pem.key --thingName GG_TrafficLight --clientId GG_Switch

    Run the following commands for the GG_TrafficLight client device:

    cd path-to-certs-folder python trafficLight.py --endpoint AWS_IOT_ENDPOINT --rootCA AmazonRootCA1.pem --cert lightCertId-certificate.pem.crt --key lightCertId-private.pem.key --thingName GG_TrafficLight --clientId GG_TrafficLight

    Every 20 seconds, the switch updates the shadow state to G, Y, and R, and the light displays its new state.

  2. The function handler of the Lambda function is triggered on every third green light (every three minutes), and a new DynamoDB record is created. After lightController.py and trafficLight.py have run for three minutes, go to the AWS Management Console, and open the DynamoDB console.

  3. Choose US East (N. Virginia) in the AWS Region menu. This is the Region where the GG_Car_Aggregator function creates the table.

  4. In the navigation pane, choose Tables, and then choose the CarStats table.

  5. Choose View items to view the entries in the table.

    You should see entries with basic statistics on cars passed (one entry for every three minutes). You might need to choose the refresh button to view updates to the table.

  6. If the test is not successful, you can look for troubleshooting information in the Greengrass logs.

    1. Switch to the root user and navigate to the log directory. Access to AWS IoT Greengrass logs requires root permissions.

      sudo su cd /greengrass/ggc/var/log
    2. Check runtime.log for errors.

      cat system/runtime.log | grep 'ERROR'
    3. Check the log generated by the Lambda function.

      cat user/region/account-id/GG_Car_Aggregator.log

      The lightController.py and trafficLight.py scripts store connection information in the groupCA folder, which is created in the same folder as the scripts. If you receive connection errors, make sure that the IP address in the ggc-host file matches the IP address endpoint for your core.

    For more information, see Troubleshooting AWS IoT Greengrass.

This is the end of the basic tutorial. You should now understand the AWS IoT Greengrass programming model and its fundamental concepts, including AWS IoT Greengrass cores, groups, subscriptions, client devices, and the deployment process for Lambda functions running at the edge.

You can delete the DynamoDB table and the Greengrass Lambda functions and subscriptions. To stop communications between the AWS IoT Greengrass core device and the AWS IoT cloud, open a terminal on the core device and run one of the following commands:

  • To shut down the AWS IoT Greengrass core device:

    sudo halt
  • To stop the AWS IoT Greengrass daemon:

    cd /greengrass/ggc/core/ sudo ./greengrassd stop