Skip to content
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

Initial commit of sample #669

Merged
merged 5 commits into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
38 changes: 38 additions & 0 deletions iot/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Cloud IoT Core NodeJS Samples
Copy link
Contributor

Choose a reason for hiding this comment

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

s/NodeJS/Java

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

This folder contains NodeJS samples that demonstrate an overview of the
Copy link
Contributor

Choose a reason for hiding this comment

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

s/NodeJS/Java

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Google Cloud IoT Core platform.

## Quickstart

1. Install the gCloud CLI as described in [the device manager guide](https://cloud-dot-devsite.googleplex.com/iot/docs/device_manager_guide).
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the reference directly to the dev docsite correct ? is n't there a public whitelisted url ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is not, I also do not have the timeline for the whitelist being removed but it should be shorter than most of our whitelist alphas.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

2. Create a PubSub topic:

gcloud beta pubsub topics create projects/my-iot-project/topics/device-events

3. Add the special account `[email protected]` to that
PubSub topic from the [Cloud Developer Console](https://console.cloud.google.com)
or by using the helper script in the /scripts folder.
Copy link
Contributor

Choose a reason for hiding this comment

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

add local link to /scripts folder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


4. Create a registry:

gcloud alpha iot registries create my-registry \
--project=my-iot-project \
--region=us-central1 \
--pubsub-topic=projects/my-iot-project/topics/device-events

5. Use the `generate_keys.sh` script to generate your signing keys:
Copy link
Contributor

Choose a reason for hiding this comment

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

link to script


./generate_keys.sh

6. Create a device.

gcloud alpha iot devices create my-java-device \
--project=my-iot-project \
--region=us-central1 \
--registry=my-registry \
--public-key path=rsa_cert.pem,type=rs256

7. Connect a sample device using the sample app in the `mqtt_example` folder.
Copy link
Contributor

Choose a reason for hiding this comment

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

link to mqtt_example folder

8. Learn how to manage devices programatically with the sample app in the
`manager` folder.
Copy link
Contributor

Choose a reason for hiding this comment

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

link to manager folder


24 changes: 24 additions & 0 deletions iot/api/generate_keys.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

openssl req -x509 -newkey rsa:2048 -keyout rsa_private.pem -nodes -out \
rsa_cert.pem -subj "/CN=unused"
openssl ecparam -genkey -name prime256v1 -noout -out ec_private.pem
openssl ec -in ec_private.pem -pubout -out ec_public.pem
openssl pkcs8 -topk8 -inform PEM -outform DER -in rsa_private.pem \
-nocrypt > rsa_private_pkcs8
openssl pkcs8 -topk8 -inform PEM -outform DER -in ec_private.pem \
-nocrypt > ec_private_pkcs8
36 changes: 36 additions & 0 deletions iot/api/manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Cloud IoT Core Java Device Management example

This sample app demonstrates device management for Google Cloud IoT Core.

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

link to parent README


## Setup

Run the following command to install the libraries and build the sample with
Maven:

mvn clean compile assembly:single

## Running the sample

The following command summarizes the sample usage:

mvn exec:java \
-Dexec.mainClass="com.google.cloud.iot.examples.DeviceRegistryExample" \
-Dexec.args="-project_id=my-project-id \
-pubsub_topic=projects/my-project-id/topics/my-topic-id \
-ec_public_key_file=/path/to/ec_public.pem \
-rsa_certificate_file=/path/to/rsa_cert.pem"

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
Copy link
Contributor

Choose a reason for hiding this comment

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

using the shell script -> please provide explicit script name with link location.

run the sample as:

mvn exec:java \
-Dexec.mainClass="com.google.cloud.iot.examples.DeviceRegistryExample" \
-Dexec.args="-project_id=blue-jet-123 \
-pubsub_topic=projects/blue-jet-123/topics/device-events \
-ec_public_key_file=../ec_public.pem \
-rsa_certificate_file=../rsa_cert.pem"
82 changes: 82 additions & 0 deletions iot/api/manager/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!--
Copyright 2017 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.cloud</groupId>
<artifactId>cloudiot-manager-demo</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>cloudiot-manager-demo</name>
<url>http://maven.apache.org</url>

<!-- Start local repo -->
<repositories>
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see instructions around getting this jar installed in the local repo. It might be worth just providing this in the README.

     mvn install:install-file -Dfile=whitelisted-iot.jar -DgroupId=com.google.apis 
    -DartifactId=google-api-services-cloudiot -Dversion=v1beta1-rev20170418-1.22.0-SNAPSHOT 
    -Dpackaging=jar

and not using the local repository.
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had intended to bundle the local repo in the sample, I'll add the jar and will add an instruction.

<!-- Use a local directory for the Cloud IoT Core API dependency. -->
<repository>
<id>project.local</id>
<name>project</name>
<url>file:./repo</url>
</repository>
</repositories>
<!-- End of extra repo -->

<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-cloudiot</artifactId>
<version>v1beta1-rev20170418-1.22.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.example.cloudiot.Manage</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-cloudiot</artifactId>
<versioning>
<versions>
<version>v1beta1-rev20170418-1.22.0-SNAPSHOT</version>
</versions>
<lastUpdated>20170502215244</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata modelVersion="1.1.0">
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-cloudiot</artifactId>
<version>v1beta1-rev20170418-1.22.0-SNAPSHOT</version>
<versioning>
<snapshot>
<timestamp>20170502.215244</timestamp>
<buildNumber>1</buildNumber>
</snapshot>
<lastUpdated>20170502215244</lastUpdated>
<snapshotVersions>
<snapshotVersion>
<extension>jar</extension>
<value>v1beta1-rev20170418-1.22.0-20170502.215244-1</value>
<updated>20170502215244</updated>
</snapshotVersion>
<snapshotVersion>
<extension>pom</extension>
<value>v1beta1-rev20170418-1.22.0-20170502.215244-1</value>
<updated>20170502215244</updated>
</snapshotVersion>
</snapshotVersions>
</versioning>
</metadata>
Loading