Skip to content

Commit

Permalink
IoT MQTT Tests (#966)
Browse files Browse the repository at this point in the history
* Adds MQTT device tests and example of configuration retrieval

* Fixes compilation

* Changes RSA certs to not expire, updates manager with setConfig, adds tests.

* Updates MQTT client dependency to use latest version from Maven central.

* Removes unused scripts and updates sample quickstart instructions.

* Updates flaky tests in vision beta.
  • Loading branch information
gguuss authored and lesv committed Dec 22, 2017
1 parent 4b646f9 commit 7ce7079
Show file tree
Hide file tree
Showing 17 changed files with 401 additions and 420 deletions.
34 changes: 8 additions & 26 deletions iot/api-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,17 @@ Google Cloud IoT Core platform.

## Quickstart

1. Install the gCloud CLI as described in [the Cloud IoT Core documentation](https://cloud.google.com/iot/docs/how-tos/getting-started#set_up_the_google_cloud_sdk_and_gcloud).
2. Create a PubSub topic:

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

3. Add the special account `cloud-iot@system.gserviceaccount.com` with the role `Publisher` to that
PubSub topic from the [Cloud Developer Console](https://console.cloud.google.com)
or by using the helper script in the [/scripts](./scripts) folder.

4. Create a registry:

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

5. Use the [`generate_keys.sh`](generate_keys.sh) script to generate your signing keys:
1. From the [Google Cloud IoT Core section](https://console.cloud.google.com/iot/)
of the Google Cloud console, create a device registry.
2. Use the [`generate_keys.sh`](generate_keys.sh) script to generate your signing keys:

./generate_keys.sh

6. Create a device.
3. Add a device using the file `rsa_cert.pem`, specifying RS256_X509 and using the
text copy of the public key starting with the ----START---- block of the certificate.

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

7. Connect a sample device using the sample app in the [`mqtt_example`](./mqtt_example) folder.
8. Learn how to manage devices programatically with the sample app in the
`manager` folder.
4. Connect a device using the HTTP or MQTT device samples in the [manager](./manager) folder.

5. Programmattically control device configuration and using the device manager sample in the [manager](./manager) folder.
53 changes: 53 additions & 0 deletions iot/api-client/manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,56 @@ To publish state messages, run the sample as follows:
gcloud beta pubsub subscriptions pull --auto-ack \
projects/my-iot-project/subscriptions/my-subscription
```

# Cloud IoT Core Java MQTT example

This sample app publishes data to Cloud Pub/Sub using the MQTT bridge provided
as part of Google Cloud IoT Core.

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).

## Setup

Run the following command to install the dependencies using Maven:

mvn clean compile

## Running the sample

The following command summarizes the sample usage:

mvn exec:java \
-Dexec.mainClass="com.example.cloud.iot.examples.MqttExample" \
-Dexec.args="-project_id=my-iot-project \
-registry_id=my-registry \
-device_id=my-device \
-private_key_file=rsa_private_pkcs8 \
-algorithm=RS256"

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 [`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 \
-device_id=my-device \
-private_key_file=../rsa_private_pkcs8 \
-algorithm=RS256"

## Reading the messages written by the sample client

1. Create a subscription to your topic.

gcloud beta pubsub subscriptions create \
projects/your-project-id/subscriptions/my-subscription \
--topic device-events

2. Read messages published to the topic

gcloud beta pubsub subscriptions pull --auto-ack \
projects/my-iot-project/subscriptions/my-subscription
5 changes: 5 additions & 0 deletions iot/api-client/manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
</properties>

<dependencies>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
Expand Down
32 changes: 16 additions & 16 deletions iot/api-client/manager/resources/rsa_cert.pem
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
-----BEGIN CERTIFICATE-----
MIIC+DCCAeCgAwIBAgIJAMLUy4Aee8f0MA0GCSqGSIb3DQEBCwUAMBExDzANBgNV
BAMMBnVudXNlZDAeFw0xNzEyMTIyMDQ3MTNaFw0xODAxMTEyMDQ3MTNaMBExDzAN
BgNVBAMMBnVudXNlZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAN1a
GQVrF7J5cp7ZJral+7MgYfmOaK4Or5sROZVFIxG40vejWHLEwAf49yHWHzJdpxYu
qvCDiBKct+hJEhUJtPKMHyaJpsJnQiEscbgGz7djPYF/iw2I1BTdnryaRQEw9DGD
y2VglH/Er3CdC/XiMXSUaqoE7cj0+7oAc3g+kECeizs8gzwHaYsMWSW2+hnHT9Jr
3IiaTTVGU7RAaGQ1LrQBd0Pw9BloT3hvkvkDW/s+pVSbKpBdAco7gFqeI05z3Mxe
DsSSVhZKk5FUr0TFhXsgCj/cbynjVweKbdC4pvEAAQS3QJ3vObW/1bQ9AtINRwJo
53sNY78fAYUXb3PzY1kCAwEAAaNTMFEwHQYDVR0OBBYEFMPDOmjBcDsco3k72yae
xlKoSWBQMB8GA1UdIwQYMBaAFMPDOmjBcDsco3k72yaexlKoSWBQMA8GA1UdEwEB
/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAHP3R+K2GJRroODe+sQseqh3EiS6
ykb8celznOrEan5VvGGgwxvtDcumh1hmAtgxDFs2IZJMz4RPWmmssQrPtew41s8y
Hxi2843EsUfTpj41LxXWOyTIf8yrnXKqnwVcEWjTN4XdBdJdHM0K6B9v8VruR6bj
PJcN/fhP1oT29HBPfgEeJeHJP+lpTlXOAkdSR+GhIrbg2HNIdhXkKxWtqc5bmcmH
NI65zGFn96gPGwYiKM8zb/muJDu6oOsmtwLuaHdxiNy18bzG7dlA9/FNyMSTCPLr
KxTNeE+hz+PEl9C0TCuFMh++0xU/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ICATE-----
52 changes: 26 additions & 26 deletions iot/api-client/manager/resources/rsa_private.pem
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDdWhkFaxeyeXKe
2Sa2pfuzIGH5jmiuDq+bETmVRSMRuNL3o1hyxMAH+Pch1h8yXacWLqrwg4gSnLfo
SRIVCbTyjB8miabCZ0IhLHG4Bs+3Yz2Bf4sNiNQU3Z68mkUBMPQxg8tlYJR/xK9w
nQv14jF0lGqqBO3I9Pu6AHN4PpBAnos7PIM8B2mLDFkltvoZx0/Sa9yImk01RlO0
QGhkNS60AXdD8PQZaE94b5L5A1v7PqVUmyqQXQHKO4BaniNOc9zMXg7EklYWSpOR
VK9ExYV7IAo/3G8p41cHim3QuKbxAAEEt0Cd7zm1v9W0PQLSDUcCaOd7DWO/HwGF
F29z82NZAgMBAAECggEBAKMHcfhQqRJ1apteWqoZ1ClZR2/zmFviSypN5HhxhGPQ
Gen0b/ePu9PjZbmRKEcDPUYUNyiP58+1h6pY7y15icE+vM64gY8bWFRwlI0yzxhF
yo4vby4XwgRgOkK06O/4q1IwvMS8/oKgTYsG0EFYSI6RpYH1wWDKNwEGxgUhJ0O/
YxTlFpEObuBg+aILeEemU6+QoULwNgfCqVUEkbSZFy5Z9D66PdRoiLum6FmwICBd
rChr06ACqCxuiFhMb1VoHPinIvJNZeLClUGShi9R/hgUZfZxddpNKDtEjZGFWgNw
dVpDFbpVLsqiV+B2TlfX10u9RnWoVi5r8Iv3gMdpqqUCgYEA82c9rm/fEi7fp03U
Y5C1z1YX/7UP+bbsOEZi6BsnJOSptbnBt0g4Ph0TRIbWsAAjd9psU3rSK73U8kso
6xCRe05RzhXWbnl80TUGQpLFcAlZd7R6eXe9kESGu+sheIXGcRJnzM6CFykerkhV
nGp29t/sQBVggqBm7/o8oJg1cLcCgYEA6M608xHaMr1Xw+hEdYqAnxJ4nLwG5G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Bn2dFS/G7kUs0ybH2JZTp3
Y68lnY3mzfQCX4J83I81aAXU+IhHK7n1hegVGP47dVZ2iizaib+ubX0JCaa0pwHe
K/geI+vcK7WNa3LKXL70OmZO0ToscdUC5jVKFCohmDo9+oecOndQ8OkjLkZMiBDG
oOwoxIvf1KkQ7VyFYgnOBA==
-----END PRIVATE KEY-----
Binary file modified iot/api-client/manager/resources/rsa_private_pkcs8
Binary file not shown.
Loading

0 comments on commit 7ce7079

Please sign in to comment.