Skip to content

Commit 1d58096

Browse files
authored
Adds IOT samples (GoogleCloudPlatform#581)
1 parent 8594b56 commit 1d58096

26 files changed

+4306
-0
lines changed

iot/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Google IOT PHP Sample Application
2+
3+
[![Open in Cloud Shell][shell_img]][shell_link]
4+
5+
[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png
6+
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googlecloudplatform/php-docs-samples&page=editor&working_dir=iot
7+
8+
## Description
9+
10+
This simple command-line application demonstrates how to invoke Google
11+
IOT API from PHP. These samples are best seen in the context of the
12+
[Official API Documentation](https://cloud.google.com/iot/docs).
13+
14+
## Build and Run
15+
1. **Enable APIs** - [Enable the IOT API](
16+
https://console.cloud.google.com/flows/enableapi?apiid=iot.googleapis.com)
17+
and create a new project or select an existing project.
18+
2. **Download The Credentials** - Click "Go to credentials" after enabling the APIs. Click
19+
"New Credentials"
20+
and select "Service Account Key". Create a new service account, use the JSON key type, and
21+
select "Create". Once downloaded, set the environment variable `GOOGLE_APPLICATION_CREDENTIALS`
22+
to the path of the JSON key that was downloaded.
23+
3. **Clone the repo** and cd into this directory
24+
```
25+
$ git clone https://github.com/GoogleCloudPlatform/php-docs-samples
26+
$ cd php-docs-samples/iot
27+
```
28+
4. **Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md).
29+
Run `php composer.phar install` (if composer is installed locally) or `composer install`
30+
(if composer is installed globally).
31+
5. Run `php iot.php`. The following commands are available:
32+
33+
```
34+
create-es-device Create a new device with the given id, using ES256 for authentication.
35+
create-registry Creates a registry and returns the result.
36+
create-rsa-device Create a new device with the given id, using RS256 for authentication.
37+
create-unauth-device Create a new device without authentication.
38+
delete-device Delete the device with the given id.
39+
delete-registry Deletes the specified registry.
40+
get-device Retrieve the device with the given id.
41+
get-device-configs Lists versions of a device config in descending order (newest first).
42+
get-device-state Retrieve a device's state blobs.
43+
get-iam-policy Retrieves IAM permissions for the given registry.
44+
get-registry Retrieves a device registry.
45+
help Displays help for a command
46+
list Lists commands
47+
list-devices List all devices in the registry.
48+
list-registries List all registries in the project.
49+
patch-es-device Patch device with ES256 public key.
50+
patch-rsa-device Patch device with RSA256 certificate.
51+
set-device-config Patch device with RSA256 certificate.
52+
set-device-state Sets the state of a device.
53+
set-iam-policy Sets IAM permissions for the given registry to a single role/member. ```
54+
55+
Example:
56+
57+
```
58+
$ php iot.php create-registry my-registry my-pubsub-topic
59+
Creating Registry
60+
Id: my-registry, Name: projects/my-project/locations/us-central1/registries/my-registry
61+
```
62+
63+
64+
6. Run `php iot.php COMMAND --help` to print information about the usage of each command.
65+
66+
## Contributing changes
67+
68+
* See [CONTRIBUTING.md](../../CONTRIBUTING.md)
69+
70+
## Licensing
71+
72+
* See [LICENSE](../../LICENSE)

iot/composer.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "google/iot-sample",
3+
"type": "project",
4+
"require": {
5+
"google/cloud": "dev-master as 0.53.0",
6+
"symfony/console": "^3.3"
7+
},
8+
"autoload": {
9+
"files": [
10+
"src/create_es_device.php",
11+
"src/create_registry.php",
12+
"src/create_rsa_device.php",
13+
"src/create_unauth_device.php",
14+
"src/delete_device.php",
15+
"src/delete_registry.php",
16+
"src/get_iam_policy.php",
17+
"src/get_device.php",
18+
"src/get_device_state.php",
19+
"src/get_device_configs.php",
20+
"src/get_registry.php",
21+
"src/list_devices.php",
22+
"src/list_registries.php",
23+
"src/patch_es.php",
24+
"src/patch_rsa.php",
25+
"src/set_device_config.php",
26+
"src/set_device_state.php",
27+
"src/set_iam_policy.php"
28+
]
29+
},
30+
"require-dev": {
31+
"phpunit/phpunit": "^5"
32+
}
33+
}

0 commit comments

Comments
 (0)