IoT Gateway Examples

The Gateway examples demonstrate how to:

This section assumes that you have downloaded the example repository and that the iot-edge directory is your current directory.

Authenticate the Gateway After Manual Registration

This example starts the Gateway, and authenticates it. The Gateway must have an asymmetric key pair for signing. This is provided in the /path/to/iot-edge/examples/resources directory. The source code for this example is in /path/to/iot-edge/cmd/gateway/main.go .

Before you run the example, register the Gateway manually (using manual-gateway as the ID):

  1. Start the Gateway:

    cd /path/to/iot-edge
    ./run.sh gateway \
    --name "manual-gateway" \
    --url "http://am.localtest.me:8080/openam" \
    --audience "/" \
    --realm "/" \
    --tree "auth-tree" \
    --kid "pop.cnf" \
    --key "$(pwd)/examples/resources/eckey1.key.pem" \
    --address ":5683" \
    --debug
    commandline options
      url: http://am.localtest.me:8080/openam
      realm: /
      tree: auth-tree
      name: manual-gateway
      address: :5683
      key: /path/to/iot-edge/examples/resources/eckey1.key.pem
      kid: pop.cnf
      certificate:
      timeout 5s
      debug: true
    IoT Gateway server started.

    The Gateway is now started and has authenticated itself to AM.

  2. In a separate terminal window, connect a Thing to the Gateway.

  3. To stop the gateway process, press Ctrl+C in the terminal window where the process is running.

Authenticate the Gateway With Dynamic Registration

This example registers an identity for the Gateway, then starts the Gateway, and authenticates it. The Gateway must have an asymmetric key pair for signing, and a CA-signed X.509 certificate that contains the key pair’s public key. This is provided in the /path/to/iot-edge/examples/resources directory. The source code for this example is in /path/to/iot-edge/cmd/gateway/main.go :

  1. Start the Gateway:

    cd /path/to/iot-edge
    ./run.sh gateway \
    --name "dynamic-gateway" \
    --url "http://am.localtest.me:8080/openam" \
    --audience "/" \
    --realm "/" \
    --tree "reg-tree" \
    --key "$(pwd)/examples/resources/eckey1.key.pem" \
    --cert "$(pwd)/examples/resources/dynamic-gateway.cert.pem" \
    --address ":5683" \
    --debug
    commandline options
    	url: http://am.localtest.me:8080/openam
    	realm: /
    	tree: reg-tree
    	name: dynamic-gateway
    	address: :5683
    	key: /path/to/iot-edge/examples/resources/eckey1.key.pem
    	kid:
    	certificate: /path/to/iot-edge/examples/resources/dynamic-gateway.cert.pem
    	timeout 5s
    	debug: true
    IoT Gateway server started.

    The Gateway is now registered, with the ID dynamic-gateway, and has started and authenticated itself to AM.

  2. In a separate terminal window, connect a Thing to the Gateway.

  3. To stop the gateway process, press Ctrl+C in the terminal window where the process is running.

Connect a Thing to the Gateway

This example connects a Thing to the Gateway. When the Thing has connected, it can authenticate to AM and request an access token. The source code for this example is in /path/to/iot-edge/examples/thing/simple/main.go .

Before you run the example, register the Thing manually (using gateway-thing as the Thing’s ID). Then, run the thing/simple example to connect the Thing to the Gateway:

cd /path/to/iot-edge
./run.sh example "thing/simple" \
-name "gateway-thing" \
-url "coap://:5683"
Creating Thing gateway-thing... Done
Requesting access token... RequestAccessToken response:  {
    "access_token":"vHJDYCBkOjih90PWGAw0KcsCzpU",
    "scope":"publish",
    "token_type":"Bearer",
    "expires_in":3599
}
Done
Access token: vHJDYCBkOjih90PWGAw0KcsCzpU
Expires in: 3599
Scope(s): [publish]

 ______     __  __
/\  __ \   /\ \/ /
\ \ \/\ \  \ \  _"-.
 \ \_____\  \ \_\ \_\
  \/_____/   \/_/\/_/