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).
  4. ~> cd <parent_absolute_path>/aws-iot-device-sdk-cpp-<x.y.z>/build/bin
    ~> ./robot-arm-sample
    ~> ./switch-sample
  5. 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.
  6. 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:
  1. You can remotely control the robot arm state from the cloud by publishing a message in the topic /topic/update:
{"state":"on"}
{"state":"off"}
  1. Every time the robot arm state changes from the switch or the cloud:
    1. The robot arm device prints out the state change.
    2. ~> ./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
    3. 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.
    4. A message is published to the topic /topic/metering with the current state of the robot arm.