Show Contents

# 8. Run the example

To see the AWS Greengrass group running:

1. Make sure the Greengrass core device is connected to the Internet.
2. Make sure the Greengrass core software is running in your device. To launch it, follow the steps at 5. Run Greengrass core in your device.
3. Launch the robot arm and switch devices binaries. You can run both samples in the same Linux PC, or you can use two different machines (one per device).

    ~> cd <parent_absolute_path>/aws-iot-device-sdk-cpp-<x.y.z>/build/bin
    ~> ./robot-arm-sample
    ~> ./switch-sample

4. To see the messages published by your Lambda functions, subscribe to all topics:
   1. Go to the AWS IoT console.
   2. In the navigation pane, select Test.
   3. Enter # in the Subscription topic text field to subscribe to all topics.
5. You can control the robot arm state from the switch sample.

- Type 1 and press enter to switch the robot arm on.
- Type 0 and press enter to switch the robot arm off.

>     ~> ./switch-sample
>     [INFO] Thu Jun  8 22:00:15 2017
>     :314 [Discover] [139633896474496] Discover Read from Network Succeeded!
>     [INFO] Thu Jun  8 22:00:15 2017
>     :314 [Sample - Switch] [139633896474496] GGC connectivity information found for this Device!!

>     [INFO] Thu Jun  8 22:00:15 2017
>     :315 [Sample - Switch] [139633896474496] Attempting Connect with:
>     GGC Endpoint : 192.168.123.456
>     GGC Endpoint Port : 8883

>     [INFO] Thu Jun  8 22:00:15 2017
>     :315 [Sample - Switch] [139633896474496] Using CA at : /home/user/aws/aws-iot-device-sdk-cpp/build-native/bin/cb27a25e-405a-45ea-9140-9fd17e04c5cc_root_ca1.pem

>     [INFO] Thu Jun  8 22:00:15 2017
>     :690 [Network Read] [139633851291392] Network Connect Response. Success : SDK Code 0.
>     [INFO] Thu Jun  8 22:00:16 2017
>     :190 [Sample - Switch] [139633896474496] Connected to GGC arn:aws:iot:us-west-2:ABCDEFG1234567:thing/GGC_Thing in Group cb27a25e-405a-45ea-9140-9fd17e04c5cc!!

>     Please enter 1 (turn on) or 0 (turn off) to control the robot arm, q to quit:

6. You can remotely control the robot arm state from the cloud by publishing a message in the topic /topic/update:

- To turn on, publish

> >     {"state":"on"}

- To turn off, publish:

> >     {"state":"off"}

7. Every time the robot arm state changes from the switch or the cloud:
   1. The robot arm device prints out the state change.

       ~> ./robot-arm-sample
       [INFO] Thu Jun  8 22:00:22 2017
       :334 [Discover] [140425788536704] Discover Read from Network Succeeded!
       [INFO] Thu Jun  8 22:00:22 2017
       :334 [Sample - RobotArm] [140425788536704] GGC connectivity information found for this Device! 400

       [INFO] Thu Jun  8 22:00:22 2017
       :334 [Sample - RobotArm] [140425788536704] Attempting Connect with:
       GGC Endpoint : 192.168.123.456
       GGC Endpoint Port : 8883

       [INFO] Thu Jun  8 22:00:22 2017
       :334 [Sample - RobotArm] [140425788536704] Using CA at : /home/user/aws/aws-iot-device-sdk-cpp/build-native/bin/cb27a25e-405a-45ea-9140-9fd17e04c5cc_root_ca1.pem

       [INFO] Thu Jun  8 22:00:22 2017
       :727 [Network Read] [140425743353600] Network Connect Response. Success : SDK Code 0.
       [INFO] Thu Jun  8 22:00:23 2017
       :227 [Sample - RobotArm] [140425788536704] Connected to GGC arn:aws:iot:us-west-2:ABCDEFG1234567:thing/GGC_Thing in Group cb27a25e-405a-45ea-9140-9fd17e04c5cc!!

       Sending Inital State -------
       {"state":{"reported":{"myState":"off"}}}

       Waiting for an update!
       -- Published state to /topic/metering (Should be routed to uptimelambda!) --
       ------- Robot Arm State --------
       on

   2. The robot arm is configured to synchronize its local shadow with the cloud shadow. This means robot arm cloud shadow is automatically updated. You should see the shadow state in the Test console.
   3. A message is published to the topic /topic/metering with the current state of the robot arm.

© 2018 Digi International Inc. All rights reserved.
8. Run the example updated on 22 January 2018 02:43:38 PM