Test communications - Amazon IoT Greengrass
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Amazon 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 Amazon IoT Greengrass V1 maintenance policy. We strongly recommend that you migrate to Amazon 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 Amazon Web Services Management Console, and open the DynamoDB console.

  3. Choose US East (N. Virginia) in the Amazon Web Services 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 Amazon 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 Amazon IoT Greengrass.

This is the end of the basic tutorial. You should now understand the Amazon IoT Greengrass programming model and its fundamental concepts, including Amazon 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 Amazon IoT Greengrass core device and the Amazon IoT cloud, open a terminal on the core device and run one of the following commands:

  • To shut down the Amazon IoT Greengrass core device:

    sudo halt
  • To stop the Amazon IoT Greengrass daemon:

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