Skip to content

merging the gateways sample #1295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 38 additions & 73 deletions iot/api-client/beta-features/manager/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Cloud IoT Core Java Command Sample
# Cloud IoT Core Java Gateway Command Sample

<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=iot/api-client/manager/README.md">
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>

This sample app demonstrates sending a command to a Cloud IoT Core device.
This sample app demonstrates sending telemetry data on behalf of a device using
a Gateway.

Note that before you can run the sample, you must configure a Google Cloud
PubSub topic for Cloud IoT as described in [the parent README](../README.md).
Expand All @@ -16,81 +17,45 @@ the sample every time you run it.
Run the following command to install the libraries and build the sample with
Maven:

mvn clean compile assembly:single
mvn clean compile assembly:single

## Running the sample

The following description summarizes the sample usage:

usage: DeviceRegistryExample [--cloud_region <arg>] --command <arg>
[--data <arg>] [--device_id <arg>] [--project_id <arg>]
[--registry_name <arg>]
Cloud IoT Core Commandline Example (Device / Registry management):

--cloud_region <arg> GCP cloud region.
--command <arg> Command to run:
send-command
--data <arg> The command data (string or JSON) to send to
the specified device.
--device_id <arg> Name for your Device.
--project_id <arg> GCP cloud project name.
--registry_name <arg> Name for your Device Registry.

For example, if your project ID is `blue-jet-123`, your service account
credentials are stored in your home folder in creds.json and you have generated
your credentials using the shell script provided in the parent folder, you can
run the sample as:

mvn exec:java \
-Dexec.mainClass="com.example.cloud.iot.examples.DeviceRegistryExample" \
-Dexec.args="-project_id=blue-jet-123 \
-registry_name=your-registry-id \
-device_id=your-device-id \
-command=send-command \
-data=hello"

# Cloud IoT Core Java MQTT Command example

This sample app receives commands sent by the command app.

Note that before you can run the sample, you must configure a Google Cloud
PubSub topic for Cloud IoT Core and register a device as described in the
[parent README](../README.md).
The following command will run the sample

## Setup

Run the following command to install the dependencies using Maven:

mvn clean compile
mvn exec:java -Dexec.mainClass="com.example.cloud.iot.examples.DeviceGatewayExample"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sometimes GH flavored markdown does not render without a newline above the code line, make sure it looks good in preview


## Running the sample
The following description summarizes the sample usage:

The following command summarizes the sample usage:

usage: DeviceRegistryExample [--cloud_region <arg>] --command <arg>
[--command_data <arg>] [--device_id <arg>] [--project_id <arg>]
[--registry_name <arg>]
Cloud IoT Core Commandline Example (Device / Registry management):

--cloud_region <arg> GCP cloud region.
--command <arg> Command to run:
send-command
--command_data <arg> The command data (string or JSON) to send to
the specified device.
--device_id <arg> Name for your Device.
--project_id <arg> GCP cloud project name.
--registry_name <arg> Name for your Device Registry.

For example, if your project ID is `blue-jet-123`, your device registry is
located in the `asia-east1` region, and you have generated your
credentials using the [`generate_keys.sh`](../generate_keys.sh) script
provided in the parent folder, you can run the sample as:

mvn exec:java \
-Dexec.mainClass="com.example.cloud.iot.examples.MqttExample" \
-Dexec.args="-project_id=blue-jet-123 \
-registry_id=my-registry \
-cloud_region=asia-east1 \
-device_id=my-device \
-private_key_file=../rsa_private_pkcs8 \
-algorithm=RS256"
usage: DeviceGatewayExample [--cloud_region <arg>] --command <arg>
[--device_id <arg>] [--project_id <arg>] [--registry_name <arg>]
[--telemetry_data <arg>]
Cloud IoT Core Commandline Example (Device Gateways):

--cloud_region <arg> GCP cloud region.
--command <arg> Command to run:
send-delegate-telemetry
--device_id <arg> Name for the delegate device.
--project_id <arg> GCP cloud project name.
--registry_name <arg> Name for your Device Registry.
--telemetry_data <arg> The telemetry data (string or JSON) to send
on behalf of the delegated device.

https://cloud.google.com/iot-core

The following example shows using the sample to send the telemetry data `hello`
on behalf of the device `some-device-id`:

mvn exec:java -Dexec.mainClass="com.example.cloud.iot.examples.DeviceGatewayExample" \
-Dexec.args="-cloud_region=us-central1 \
-project_id=blue-jet-123 \
-command=send-delegate-telemetry \
-device_id=your-device-id \
-telemetry_data=hello \
-device_id=some-device-id \
-registry_name=my-registry"

## Troubleshooting
Make sure to bind your device before trying to attach it. If your device is not
bound to the gateway, the call to attach the device will not return.
14 changes: 5 additions & 9 deletions iot/api-client/beta-features/manager/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright 2018 Google LLC
Copyright 2018 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,12 +33,6 @@
<version>1.0.8</version>
</parent>
<repositories>
<!-- Use a local directory for the Text API dependency. -->
<repository>
<id>project.local</id>
<name>project</name>
<url>file:${project.basedir}/./repo</url>
</repository>
</repositories>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
Expand Down Expand Up @@ -66,11 +60,13 @@
<artifactId>joda-time</artifactId>
<version>2.1</version>
</dependency>

<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-cloudiot</artifactId>
<version>v1-rev49-1.25.0</version>
<version>v1-rev20181120-1.27.0</version>
</dependency>

<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
Expand All @@ -79,7 +75,7 @@
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>1.22.0</version>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down
5 changes: 5 additions & 0 deletions iot/api-client/beta-features/manager/resources/ec_private.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIK9PAsoXug32KzMJiah9Nuy9yNZJdpDYfIeUt3olsRZ9oAoGCCqGSM49
AwEHoUQDQgAES+slfwEIqd6EqRy5sDtFJXzW+D+i5tDWD5EVFA0loXkisKpgEvww
fCx6xwSNatAevzpmFFqsvp6ouEop7RqRLw==
-----END EC PRIVATE KEY-----
Binary file not shown.
4 changes: 2 additions & 2 deletions iot/api-client/beta-features/manager/resources/ec_public.pem
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEJ/zj75PhGtoayWD9pm/IbXRXi9ai
RQDMFQ87sOOQIWDTxnsHFplqb8cDCtO1h5QsutcAVTPZL0CZiqIg5j7b1w==
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAES+slfwEIqd6EqRy5sDtFJXzW+D+i
5tDWD5EVFA0loXkisKpgEvwwfCx6xwSNatAevzpmFFqsvp6ouEop7RqRLw==
-----END PUBLIC KEY-----
Loading