|
| 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) |
0 commit comments