Skip to content

Initial commit of sample #669

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 5 commits into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Checkstyle fixes.
  • Loading branch information
gguuss committed May 22, 2017
commit 889dcc101573722708fd465cdc504d42a6585c54
4 changes: 2 additions & 2 deletions iot/api/README.md → iot/api-client/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Cloud IoT Core NodeJS Samples
This folder contains NodeJS samples that demonstrate an overview of the
# Cloud IoT Core Java Samples
This folder contains Java samples that demonstrate an overview of the
Google Cloud IoT Core platform.

## Quickstart
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions iot/api/manager/pom.xml → iot/api-client/manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
<name>cloudiot-manager-demo</name>
<url>http://maven.apache.org</url>

<!-- Parent defines config for testing & linting. -->
<parent>
<artifactId>doc-samples</artifactId>
<groupId>com.google.cloud</groupId>
<version>1.0.0</version>
<relativePath>../../../</relativePath>
</parent>

<!-- Start local repo -->
<repositories>
<!-- Use a local directory for the Cloud IoT Core API dependency. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.api.services.cloudiot.v1beta1.model.NotificationConfig;
import com.google.api.services.cloudiot.v1beta1.model.PublicKeyCredential;
import com.google.common.io.Files;

import java.io.File;
import java.io.IOException;
import java.security.GeneralSecurityException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

/** Command line options for the Device Manager example */
/** Command line options for the Device Manager example. */
public class DeviceRegistryExampleOptions {
String projectId;
String pubsubTopic;
Expand All @@ -29,7 +29,7 @@ public class DeviceRegistryExampleOptions {
String cloudRegion = "us-central1";

/** Construct an DeviceRegistryExampleOptions class from command line flags. */
public static DeviceRegistryExampleOptions fromFlags(String args[]) {
public static DeviceRegistryExampleOptions fromFlags(String[] args) {
Options options = new Options();
// Required arguments
options.addOption(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.api.client.util.ExponentialBackOff;
import com.google.api.client.util.Sleeper;
import com.google.common.base.Preconditions;

import java.io.IOException;
import java.util.logging.Logger;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,27 @@
<version>1.0</version>
<name>cloudiot-mqtt-example</name>
<url>http://maven.apache.org</url>

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

<!-- Parent defines config for testing & linting. -->
<parent>
<artifactId>doc-samples</artifactId>
<groupId>com.google.cloud</groupId>
<version>1.0.0</version>
<relativePath>../../../</relativePath>
</parent>

<repositories>
<repository>
<id>Eclipse Paho Repo</id>
<url>https://repo.eclipse.org/content/repositories/paho-releases/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.eclipse.paho</groupId>
Expand All @@ -39,4 +50,5 @@
<version>1.3</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
import org.joda.time.DateTime;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;

/**
* Java sample of connecting to Google Cloud IoT Core vice via MQTT, using JWT.
*
Expand Down Expand Up @@ -46,7 +47,7 @@ private static PrivateKey loadKeyFile(String filename, String algorithm) throws
return kf.generatePrivate(spec);
}

/** Create a Cloud IoT Core JWT for the given project id, signed with the given private key */
/** Create a Cloud IoT Core JWT for the given project id, signed with the given private key. */
private static String createJwt(String projectId, String privateKeyFile, String algorithm)
throws Exception {
DateTime now = new DateTime();
Expand Down Expand Up @@ -97,9 +98,9 @@ public static void main(String[] args) throws Exception {
// connection to your device.
connectOptions.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1);

// With Google Cloud IoT Core, the username field is ignored, however it must be set for the Paho
// client library to send the password field. The password field is used to transmit a JWT to
// authorize the device.
// With Google Cloud IoT Core, the username field is ignored, however it must be set for the
// Paho client library to send the password field. The password field is used to transmit a JWT
// to authorize the device.
connectOptions.setUserName("unused");
connectOptions.setPassword(
createJwt(options.projectId, options.privateKeyFile, options.algorithm).toCharArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

/** Command line options for the MQTT example */
/** Command line options for the MQTT example. */
public class MqttExampleOptions {
String projectId;
String registryId;
Expand All @@ -20,7 +20,7 @@ public class MqttExampleOptions {
short mqttBridgePort = 8883;

/** Construct an MqttExampleOptions class from command line flags. */
public static MqttExampleOptions fromFlags(String args[]) {
public static MqttExampleOptions fromFlags(String[] args) {
Options options = new Options();
// Required arguments
options.addOption(
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion iot/api/scripts/iam.py → iot/api-client/scripts/iam.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright 2017 Google Inc. All Rights Reserved.
# 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.
Expand Down