This simple command-line application demonstrates how to invoke Google IOT API from PHP. These samples are best seen in the context of the Official API Documentation.
- Enable APIs - Enable the IOT API and create a new project or select an existing project.
- Download The Credentials - Click "Go to credentials" after enabling the APIs. Click
"New Credentials"
and select "Service Account Key". Create a new service account, use the JSON key type, and
select "Create". Once downloaded, set the environment variable
GOOGLE_APPLICATION_CREDENTIALSto the path of the JSON key that was downloaded. - Clone the repo and cd into this directory
$ git clone https://github.com/GoogleCloudPlatform/php-docs-samples
$ cd php-docs-samples/iot
-
Install dependencies via Composer. Run
php composer.phar install(if composer is installed locally) orcomposer install(if composer is installed globally). -
Run
php iot.php. The following commands are available:bind-device-to-gateway (Beta feature) Bind a device to a gateway. create-es-device Create a new device with the given id, using ES256 for authentication. create-gateway (Beta feature) Create a new gateway with the given id. create-registry Creates a registry and returns the result. create-rsa-device Create a new device with the given id, using RS256 for authentication. create-unauth-device Create a new device without authentication. delete-device Delete the device with the given id. delete-gateway (Beta feature) Delete the gateway with the given id. delete-registry Deletes the specified registry. get-device Retrieve the device with the given id. get-device-configs Lists versions of a device config in descending order (newest first). get-device-state Retrieve a device's state blobs. get-iam-policy Retrieves IAM permissions for the given registry. get-registry Retrieves a device registry. help Displays help for a command list Lists commands list-devices List all devices in the registry. list-devices-for-gateway List devices for the given gateway. list-gateways List gateways for the given registry. list-registries List all registries in the project. patch-es-device Patch device with ES256 public key. patch-rsa-device Patch device with RSA256 certificate. send-command-to-device Sends a command to a device. set-device-config Set a device's configuration. set-device-state Sets the state of a device. set-iam-policy Sets IAM permissions for the given registry to a single role/member. unbind-device-from-gateway (Beta feature) Unbind a device from a gateway. Example:$ php iot.php create-registry my-registry my-pubsub-topic Creating Registry Id: my-registry, Name: projects/my-project/locations/us-central1/registries/my-registry
-
Run
php iot.php COMMAND --helpto print information about the usage of each command.
- See CONTRIBUTING.md
- See LICENSE