Skip to content

Latest commit

 

History

History

pnp-device-sample

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
page_type description languages products urlFragment
sample
A set of Java samples that show how a device that uses the IoT Plug and Play conventions interacts with either IoT Hub or IoT Central.
java
azure-iot-hub
azure-iot-central
azure-iot-pnp
azure-iot-pnp-device-samples-for-java

IoT Plug And Play device samples

Documentation

These samples demonstrate how a device that follows the IoT Plug and Play conventions interacts with IoT Hub or IoT Central, to:

  • Send telemetry.
  • Update read-only and read-write properties.
  • Respond to command invocation.

The samples demonstrate two scenarios:

  • An IoT Plug and Play device that implements the Thermostat model. This model has a single interface that defines telemetry, read-only and read-write properties, and commands.
  • An IoT Plug and Play device that implements the Temperature controller model. This model uses multiple components:
    • The top-level interface defines telemetry, read-only property and commands.
    • The model includes two Thermostat components, and a device information component.

Quickstarts and tutorials

To learn more about how to configure and run the Thermostat device sample with IoT Hub, see Quickstart: Connect a sample IoT Plug and Play device application running on Linux or Windows to IoT Hub.

To learn more about how to configure and run the Temperature Controller device sample with:

Configuring the samples

Both samples use environment variables to retrieve configuration.

  • If you are using a connection string to authenticate:

    • set IOTHUB_DEVICE_SECURITY_TYPE="connectionString"
    • set IOTHUB_DEVICE_CONNECTION_STRING="<connection string of your device>"
  • If you are using a DPS enrollment group to authenticate:

    • set IOTHUB_DEVICE_SECURITY_TYPE="DPS"
    • set IOTHUB_DEVICE_DPS_ID_SCOPE="<ID Scope of DPS instance>"
    • set IOTHUB_DEVICE_DPS_DEVICE_ID="<Device's ID>"
    • set IOTHUB_DEVICE_DPS_DEVICE_KEY="<Device's security key >"
    • OPTIONAL, if you do not wish to use the default endpoint "global.azure-devices-provisioning.net"
      • set IOTHUB_DEVICE_DPS_ENDPOINT="<DPS endpoint>"

Build the sample

$> cd {sample root}
$> mvn clean package

Run the sample

To run the Thermostat sample:

$> mvn exec:java -Dexec.mainClass="samples.com.microsoft.azure.sdk.iot.device.Thermostat"

To run the Temperature Controller sample:

$> mvn exec:java -Dexec.mainClass="samples.com.microsoft.azure.sdk.iot.device.TemperatureController"