diff --git a/README.md b/README.md index 94bf674..e58c24a 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/component.mk b/component.mk index 59569cc..e80fd9a 100644 --- a/component.mk +++ b/component.mk @@ -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 \ @@ -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 diff --git a/doc/azure_cli_iot_hub.md b/doc/azure_cli_iot_hub.md new file mode 100644 index 0000000..68816ca --- /dev/null +++ b/doc/azure_cli_iot_hub.md @@ -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] +``` + + diff --git a/doc/iothub_explorer.md b/doc/iothub_explorer.md deleted file mode 100644 index 1d7ea67..0000000 --- a/doc/iothub_explorer.md +++ /dev/null @@ -1,41 +0,0 @@ -# iothub-explorer usage - -## login [any operation should login first] -``` -iothub-explorer login "HostName=chenwu-ms-lot-hub.azure-devices.cn;SharedAccessKeyName=iothubowner;SharedAccessKey=zMeLQ0JTlZXVcHBVOwRFVmlFtcCz+CtbDpUPBWexbIY=" -``` - -## list all device -``` -iothub-explorer list -``` - -## get special device detail info -``` -iothub-explorer get myFirstNodeDevice --connection-string -``` - -## create one device -``` -iothub-explorer create AirConditionDevice_001 --connection-string -``` - -## delete one device -``` -iothub-explorer delete myFirstNodeDevice -``` - -## monitor your device -``` -iothub-explorer monitor-events AirConditionDevice_001 --login 'HostName=chenwu-ms-lot-hub.azure-devices.cn;SharedAccessKeyName=iothubowner;SharedAccessKey=zMeLQ0JTlZXVcHBVOwRFVmlFtcCz+CtbDpUPBWexbIY=' -``` - -## send message to device -``` -iothub-explorer send AirConditionDevice_001 "hello,my friends!" -``` -``` -iothub-explorer send AirConditionDevice_001 quit -``` - - diff --git a/examples/iothub_client_sample_mqtt/README.md b/examples/iothub_client_sample_mqtt/README.md new file mode 100644 index 0000000..8c70ba4 --- /dev/null +++ b/examples/iothub_client_sample_mqtt/README.md @@ -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 +``` diff --git a/examples/prov_dev_client_ll_sample/README.md b/examples/prov_dev_client_ll_sample/README.md new file mode 100644 index 0000000..0845bab --- /dev/null +++ b/examples/prov_dev_client_ll_sample/README.md @@ -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 +``` + +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 +``` + diff --git a/examples/prov_dev_client_ll_sample/main/Kconfig.projbuild b/examples/prov_dev_client_ll_sample/main/Kconfig.projbuild index 89db5a4..2ad48c0 100644 --- a/examples/prov_dev_client_ll_sample/main/Kconfig.projbuild +++ b/examples/prov_dev_client_ll_sample/main/Kconfig.projbuild @@ -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" diff --git a/examples/prov_dev_client_ll_sample/main/prov_dev_client_ll_sample.c b/examples/prov_dev_client_ll_sample/main/prov_dev_client_ll_sample.c index 38d9528..bd629b8 100644 --- a/examples/prov_dev_client_ll_sample/main/prov_dev_client_ll_sample.c +++ b/examples/prov_dev_client_ll_sample/main/prov_dev_client_ll_sample.c @@ -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;