Send a command to a device

Send a command to a device listening for commands.

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample


use Google\Cloud\Iot\V1\DeviceManagerClient;

 * Sends a command to a device.
 * @param string $registryId IOT Device Registry ID
 * @param string $deviceId IOT Device ID
 * @param string $command The command sent to a device
 * @param string $projectId Google Cloud project ID
 * @param string $location (Optional) Google Cloud region
function send_command_to_device(
    $location = 'us-central1'
) {
    print('Sending command to device' . PHP_EOL);

    // Instantiate a client.
    $deviceManager = new DeviceManagerClient();
    $deviceName = $deviceManager->deviceName($projectId, $location, $registryId, $deviceId);

    // Response empty on success
    $deviceManager->sendCommandToDevice($deviceName, $command);

    printf('Command sent' . PHP_EOL);

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.