Skip to content

Commit

Permalink
Merge branch 'feature/add_docs_to_provisioning_example' into 'master'
Browse files Browse the repository at this point in the history
example/prov_dev_client_ll_sample: Cleanups and add documentation

See merge request esp-components/esp-azure!7
  • Loading branch information
mahavirj committed Dec 19, 2018
2 parents 2a3f3cf + 01e98ac commit cd26689
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 88 deletions.
51 changes: 6 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,29 @@ Main workflow:

### 2. Azure IoT Hub

- [Get iothub connection string (primary key)](https://www.azure.cn/en-us/pricing/1rmb-trial-full/?form-type=identityauth) from the Azure IoT Hub, which will be used later. An example can be seen below:
- [Get iothub connection string (primary key)](https://azure.microsoft.com/en-in/services/iot-hub/) from the Azure IoT Hub, which will be used later. An example can be seen below:

```
HostName=yourname-ms-lot-hub.azure-devices.cn;SharedAccessKeyName=iothubowner;SharedAccessKey=zMeLQ0JTlZXVcHBVOwRFVmlFtcCz+CtbDpUPBWexbIY=
```
- For step-by-step instructions, please click [here](doc/IoT_Suite.md).

### 3. iothub-explorer
### 3. Azure CLI

- Install [Node.js](https://nodejs.org/en/);
- Install [iothub-explorer](https://www.npmjs.com/package/iothub-explorer) with command line `npm install -g iothub-explorer`.
- If failed, please check [here](http://thinglabs.io/workshop/esp8266/setup-azure-iot-hub/) for more information.
- If succeeded, please check the version information with the command lines below:
```
$ node -v
v6.9.5
$ iothub-explorer -V
1.1.6
```
- Install [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)

After that, you should be able to use iothub-explorer to manage your iot-device.
After that, you should be able to use azure CLI to manage your iot-device.

### 4. Device Connection String

- login with the **iothub connection string (primary key)** you got earlier with command lines;
- login to Azure CLI
- create your device, and get a **device connection string**. An example can be seen:

```
"HostName=esp-hub.azure-devices.net;DeviceId=yourdevice;SharedAccessKey=L7tvFTjFuVTQHtggEtv3rp+tKEJzQLLpDnO0edVGKCg=";
```

For detailed instruction, please click [Here](doc/iothub_explorer.md).
For detailed instruction, please click [Here](doc/azure_cli_iot_hub.md).

### 5. SDK

Expand All @@ -90,36 +81,6 @@ This repo uses [Git Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodu
git submodule update --init --recursive
```

### 2. Configuring your Azure IOT Hub Device Connection String, Wi-Fi and serial port

- Change to `examples/iothub_client_sample_mqtt` directory
- Run `make menuconfig` -> `Example configuration` to configure your Azure IOT Hub Device Connection String, Wi-Fi SSID and Password;
- Run `make menuconfig` -> `Serial flasher config` to configure you serial port.

### 3. Building your demo and flash to ESP device with `$make flash`.

If failed, please:

- make sure your ESP device had connected to PC with serial port;
- make sure you have selected the corrected serial port;
- command `> sudo usermod -a -G dialout $USER` can also be used.

To monitor the device output while running, run

``` bash
make monitor
```

To exit the monitor, hit Control-]

You can also run the build and monitor in onte step and run with multiple compiler threads:

``` bash
make -j4 flash monitor
```

This will build with four concurrent build processes to take advantage of more cores on your workstation.

## Checking Result

<a name="Checking_Result"></a>
Expand Down
7 changes: 7 additions & 0 deletions component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ azure-iot-sdk-c/iothub_client/src/iothub.o \
azure-iot-sdk-c/c-utility/src/http_proxy_io.o \
azure-iot-sdk-c/c-utility/src/base32.o \

ifdef CONFIG_DEVICE_COMMON_NAME
COMPONENT_OBJS += azure-iot-sdk-c/provisioning_client/src/iothub_auth_client.o
endif

COMPONENT_SRCDIRS := \
port/src \
Expand All @@ -146,3 +149,7 @@ azure-iot-sdk-c/provisioning_client/adapters \
azure-iot-sdk-c/provisioning_client/deps/utpm/src \

CFLAGS += -Wno-unused-function -Wno-missing-braces -Wno-missing-field-initializers -DHSM_TYPE_X509 -DHSM_TYPE_SAS_TOKEN

ifdef CONFIG_DEVICE_COMMON_NAME
CFLAGS += -DUSE_PROV_MODULE
endif
38 changes: 38 additions & 0 deletions doc/azure_cli_iot_hub.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Azure CLI usage

## login [any operation should login first]
```
az login
```

## list all device
```
az iot hub device-identity list --hub-name [IoTHub Name]
```

## get device connection string
```
az iot hub device-identity show-connection-string -n [IoTHub Name] -d [Device ID]
```

## create one device
```
az iot hub device-identity create -n [IoTHub Name] -d [Device ID]
```

## delete one device
```
az iot hub device-identity delete -n [IoTHub Name] -d [Device ID]
```

## monitor your device
```
az iot hub monitor-events -n [IoTHub Name] --login 'HostName=myhub.azuredevices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=12345'
```

## send message to device
```
az iot device c2d-message send -d [Device Id] -n [IoTHub Name]
```


41 changes: 0 additions & 41 deletions doc/iothub_explorer.md

This file was deleted.

18 changes: 18 additions & 0 deletions examples/iothub_client_sample_mqtt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#IoT HUB MQTT Client

# Device Configuration

Run `make menuconfig` -> `Example configuration` to configure IoT MQTT client example

Fetch IoT device connection string
```
az iot hub device-identity show-connection-string -n [IoTHub Name] -d [Device ID]
```

## Building your demo and flash to ESP device

Run the following command to flash and monitor the output

``` bash
make -j4 flash monitor
```
34 changes: 34 additions & 0 deletions examples/prov_dev_client_ll_sample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Azure Provisioning Demo

This example demonstrates X509 certificate based device access control to provisioning service.
Refer [this](https://docs.microsoft.com/en-us/azure/iot-dps/concepts-security#controlling-device-access-to-the-provisioning-service-with-x509-certificates) to learn more.

## Provisioning Setup

Follow the [step-by-step tutorial](https://docs.microsoft.com/en-us/azure/iot-dps/#step-by-step-tutorials) to setup the provisioning service.

## Device Leaf certificate and key

Copy Device Leaf certificate to `main/certs/leaf_certificate.pem` and `main/certs/leaf_private_key.pem`

## Device Configuration

Run `make menuconfig` -> `Example configuration` to configure provsioning client example

Fetch `IoT Hub Connection String` from [azure portal](https://portal.azure.com)
or through Azure CLI by using the following command:

```
az iot hub show-connection-string -n <IoT_hub_name>
```

Fetch Unique Device Provisioning Service ID Scope from azure portal

## Building your demo and flash to ESP device

Run the following command to flash and monitor the output

``` bash
make -j4 flash monitor
```

2 changes: 1 addition & 1 deletion examples/prov_dev_client_ll_sample/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ config DEVICE_COMMON_NAME
Common name of Leaf Certificate

config DPS_ID_SCOPE
string "Unique ID Scope of Device provisioning service"
string "Unique DPS ID Scope of Device provisioning service"
default "myidscope"
help
This is the unique ID scope of DPS, and can be found under "Overview"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ int prov_dev_client_ll_sample_run()
// Free all the sdk subsystem
IoTHub_Deinit();

(void)printf("Press any enter to continue:\r\n");
(void)getchar();

return 0;
Expand Down

0 comments on commit cd26689

Please sign in to comment.