Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of dps #99

Closed
GauravChoube opened this issue Nov 26, 2021 · 12 comments
Closed

Implementation of dps #99

GauravChoube opened this issue Nov 26, 2021 · 12 comments
Labels
area: yocto There is an issue with Yocto meta-layers

Comments

@GauravChoube
Copy link

HI ,
I am working on task where i need to enable the device provisioning in iot-hub-device-update code.
I have enable provisioning sdk from azure -ot-sdk-c by modified the install script where i added -Duse_prov_client:BOOL=ON in cmake argument of cmake for azure-iot-sdk-c as follows:

   # use_http is required for uHTTP support.
    local azureiotsdkc_cmake_options=(
        "-Duse_amqp:BOOL=OFF"
        "-Duse_http:BOOL=ON"
        "-Duse_mqtt:BOOL=ON"
        "-Duse_prov_client:BOOL=ON"  # added by me
        "-Dskip_samples:BOOL=ON"
        "-Dbuild_service_client:BOOL=OFF"
        "-Dbuild_provisioning_service_client:BOOL=OFF"
    )

I have successfully installed all dependencies.
But when i am building the iot-hub-device-update sdk , am getting following error

sudo ./scripts/build.sh -c -p linux

Building ADU Agent
* Clean build: true
* Documentation: false
* Platform layer: linux
* Content handlers: microsoft/swupdate
* Build type: Debug
* Log directory: /var/log/adu
* Logging library: zlog
* Output directory: /home/pi/iot-hub-device-update/scripts/../out
* Build unit tests: false
* Build packages: false
* Static analysis: (none)

-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--
-- CMAKE_SYSTEM_NAME=Linux
-- CMAKE_SYSTEM_VERSION=5.10.17-v7l+
-- CMAKE_HOST_SYSTEM_NAME=Linux
-- CMAKE_GENERATOR=Ninja
-- CMAKE_BUILD_TYPE=Debug
-- CMAKE_C_COMPILER=/usr/bin/cc
-- CMAKE_CXX_COMPILER=/usr/bin/c++
-- CMAKE_BINARY_DIR=/home/pi/iot-hub-device-update/out
-- CMAKE_SOURCE_DIR=/home/pi/iot-hub-device-update
-- CMAKE_BUILD_TYPE=Debug
-- CMAKE_SYSTEM_NAME=Linux
--
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Looking for include file stdint.h
-- Looking for include file stdint.h - found
-- Looking for include file stdbool.h
-- Looking for include file stdbool.h - found
-- target architecture: ARM
-- Performing Test CXX_FLAG_CXX11
-- Performing Test CXX_FLAG_CXX11 - Success
-- target architecture: ARM
-- Found OpenSSL: /usr/lib/arm-linux-gnueabihf/libcrypto.so (found version "1.1.1d")
-- target architecture: ARM
-- Found Parson: /usr/local/include/azureiot
-- target architecture: ARM
-- target architecture: ARM
-- target architecture: ARM
-- target architecture: ARM
-- Found IotHubClient: /usr/local/include/azureiot
-- target architecture: ARM
-- Boost version: 1.67.0
-- Found the following Boost libraries:
--   filesystem
--   system
-- target architecture: ARM
-- Found Git: /usr/bin/git (found version "2.20.1")
-- target architecture: ARM
-- target architecture: ARM
-- Boost version: 1.67.0
-- Found the following Boost libraries:
--   filesystem
--   system
-- Boost version: 1.67.0
-- Found the following Boost libraries:
--   filesystem
--   system
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/iot-hub-device-update/out
[48/48] Linking CXX executable bin/AducIotAgent
FAILED: bin/AducIotAgent
: && /usr/bin/c++  -Werror -fPIE -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wformat -Werror=format-security -fno-rtti -Werror -Werror -g  -pie -z relro -z now src/agent/CMakeFiles/AducIotAgent.dir/src/main.c.o src/agent/CMakeFiles/AducIotAgent.dir/src/health_management.c.o  -o bin/AducIotAgent  -Wl,-rpath,/usr/local/lib: /usr/local/lib/libaziotsharedutil.a -liothub_client_http_transport -luhttp /usr/local/lib/libaziotsharedutil.a -liothub_client_mqtt_transport /usr/local/lib/libumqtt.a -lhsm_security_client -lprov_auth_client src/agent/pnp_helper/libpnp_helper.a src/agent/adu_core_interface/libadu_core_interface.a src/utils/c_utils/libc_utils.a src/agent/device_info_interface/libdevice_info_interface.a src/utils/eis_utils/libeis_utils.a src/utils/system_utils/libsystem_utils.a /usr/local/lib/libdeliveryoptimization.so.0.4.0 /usr/local/lib/libaziotsharedutil.a src/platform_layers/linux_platform_layer/liblinux_platform_layer.a src/content_handlers/libcontent_handlers.a src/content_handlers/swupdate_handler/libswupdate_handler.a src/utils/system_utils/libsystem_utils.a -laziotsharedutil src/utils/process_utils/libprocess_utils.a /usr/local/lib/libdeliveryoptimization.so.0.4.0 /usr/local/lib/libaziotsharedutil.a src/utils/jws_utils/libjws_utils.a src/utils/crypto_utils/libcrypto_utils.a /usr/local/lib/libaziotsharedutil.a /usr/lib/arm-linux-gnueabihf/libcrypto.so /usr/local/lib/libaziotsharedutil.a src/utils/hash_utils/libhash_utils.a /usr/local/lib/libaziotsharedutil.a /usr/local/lib/libaziotsharedutil.a /usr/local/lib/libdeliveryoptimization.so.0.4.0 src/agent/pnp_helper/libpnp_helper.a -liothub_client_http_transport -liothub_client_mqtt_transport /usr/local/lib/libaziotsharedutil.a -lumqtt /usr/local/lib/libiothub_client.a /usr/local/lib/libaziotsharedutil.a -luhttp src/utils/c_utils/libc_utils.a /usr/local/lib/libaziotsharedutil.a src/logging/zlog/libzlog.a -lpthread /usr/local/lib/libparson.a /usr/local/lib/libaziotsharedutil.a -lcurl /usr/lib/arm-linux-gnueabihf/libssl.so /usr/lib/arm-linux-gnueabihf/libcrypto.so -lpthread -lm -lrt -luuid /usr/lib/arm-linux-gnueabihf/libboost_filesystem.so /usr/lib/arm-linux-gnueabihf/libboost_system.so && :
/usr/bin/ld: //usr/local/lib/libprov_auth_client.a(iothub_auth_client.c.o): in function `iothub_device_auth_create':
iothub_auth_client.c:(.text+0x4b4): undefined reference to `hsm_client_tpm_interface'
/usr/bin/ld: iothub_auth_client.c:(.text+0x5bc): undefined reference to `hsm_client_x509_interface'
/usr/bin/ld: iothub_auth_client.c:(.text+0x6e4): undefined reference to `hsm_client_key_interface'
/usr/bin/ld: //usr/local/lib/libprov_auth_client.a(iothub_security_factory.c.o): in function `iothub_security_init':
iothub_security_factory.c:(.text+0x1c0): undefined reference to `initialize_hsm_system'
/usr/bin/ld: //usr/local/lib/libprov_auth_client.a(iothub_security_factory.c.o): in function `iothub_security_deinit':
iothub_security_factory.c:(.text+0x26c): undefined reference to `deinitialize_hsm_system'
/usr/bin/ld: //usr/local/lib/libprov_auth_client.a(prov_security_factory.c.o): in function `prov_dev_security_init':
prov_security_factory.c:(.text+0x1c0): undefined reference to `initialize_hsm_system'
/usr/bin/ld: //usr/local/lib/libprov_auth_client.a(prov_security_factory.c.o): in function `prov_dev_security_deinit':
prov_security_factory.c:(.text+0x26c): undefined reference to `deinitialize_hsm_system'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

It was executed and target for raspberry pi 4 running on raspbian os.
How should i link missing library ?
Is that not build at time of building in azure-iot-sdk-c.

My final goal to achieve the device provisioning in device update code which target for raspberry pi 4
Any help will be appreciated.
Thanks in advance
regards

@asbarnes
Copy link

asbarnes commented Nov 26, 2021

Hi,

I'm doing something similar.

My cmake arguments for Azure-IoT-SDK-C are:
-Duse_amqp:BOOL=ON -Duse_http:BOOL=ON -Duse_mqtt:BOOL=ON -Dskip_samples:BOOL=OFF -Duse_prov_client:BOOL=ON -Duse_prov_client_core:BOOL=ON -Dhsm_type_sastoken:BOOL=ON

And for the device update agent I added the following libraries:

+find_package (azure_macro_utils_c REQUIRED)

target_link_libraries (

+prov_device_client

+prov_device_ll_client

+prov_auth_client

+prov_amqp_transport

+umqtt

+prov_mqtt_ws_transport

+hsm_security_client

+utpm

Here is my main diff


--- a/src/agent/src/main.c
+++ b/src/agent/src/main.c
@@ -20,6 +20,8 @@
 #include <iothub.h>
 #include <iothub_client_options.h>
 #include <iothubtransportmqtt.h>
+#include <iothub_device_client_ll.h>
+#include <azure_prov_client/iothub_security_factory.h>
 
 #ifndef ADUC_PLATFORM_SIMULATOR // DO is not used in sim mode
 #    include <do_config.h>
@@ -485,8 +487,22 @@ static void ADUC_ConnectionStatus_Callback(
 _Bool ADUC_DeviceClient_Create(ADUC_ConnectionInfo* connInfo, const ADUC_LaunchArguments* launchArgs)
 {
     IOTHUB_CLIENT_RESULT iothubResult;
+    int iothubInitResult;
     bool result = true;
 
+    // Before invoking ANY IoT Hub or DPS functionality, IoTHub_Init must be invoked.
+    if ((iothubInitResult = IoTHub_Init()) != 0)
+    {
+        Log_Error("Failure to initialize client, error=%d", iothubInitResult);
+        result = false;
+    }
+
+    if (iothub_security_init(IOTHUB_SECURITY_TYPE_SAS) != 0)
+    {
+        Log_Error("iothub_security_init failed");
+        result = false;
+    }
+
     // Create a connection to IoTHub.
     if ((g_iotHubClientHandle =
              IoTHubDeviceClient_LL_CreateFromConnectionString(connInfo->connectionString, MQTT_Protocol))

With these changes I am able to use ADU agent with DPS.
Note that the connection string format should be
HostName=<hub_name>;DeviceId=<registartion_id>;UseProvisioning=true

@GauravChoube
Copy link
Author

Hi asbarnes,
Thanks for reply
I will try above one.
but i have one problem , i getting below error after running agent code

/usr/bin/AducIotAgent: error while loading shared libraries: libcpprest.so.2.10: cannot open shared object file: No such file or directory

I have build whole code of update sdk on pi 4 ,
Do you have any idea ?

@asbarnes
Copy link

Hi,

Please check scripts/install-deps.sh. It should install cpprest.
If you are using Yocto meta-azure-device-update it is installed as part of deliveryoptimization-sdk.bb

@GauravChoube
Copy link
Author

GauravChoube commented Nov 28, 2021

Hi i have solved linking issue by using cmd

sudo ldkconfig

Here is update about implementation and problem.
i have successfully change the code of device update with device provisioning using 0x509.
Device getting register and dps got successfully by merging and linking code from dps sample directory.
but not getting mqtt error in device code.

 [I] Agent (linux; 0.6.0-public-preview) starting. [main]
2021-11-28T06:26:33.1934Z [I] Git Info: main:743bb72 [main]
2021-11-28T06:26:33.1934Z [I] Agent built with handlers: microsoft/swupdate. [main]
inside AllocateDeviceClientHandle
Provisioning API Version: 1.7.0
Info: Initiating DPS client to retrieve IoT Hub connection information
Provisioning Status: 0
Provisioning Status: 2
Registration Information received from service: devmgmtiothub.azure-devices.net!
Info: Provisioning callback indicates success.  iothubUri=devmgmtiothub.azure-devices.net, deviceId=dev_iot_001
Info: DPS successfully registered.  Continuing on to creation of IoTHub device client handle.
2021-11-28T06:26:43.5339Z [I] Initalizing PnP components. [ADUC_PnP_Components_Create]
2021-11-28T06:26:43.5339Z [I] ADUC agent started. Using IoT Hub Client SDK 1.7.0 [AzureDeviceUpdateCoreInterface_Create]
2021-11-28T06:26:43.5340Z [I] Calling ADUC_Register [ADUC_MethodCall_Register]
2021-11-28T06:26:43.5340Z [I] IoTHub Device Twin callback registered. [ADUC_DeviceClient_Create]
2021-11-28T06:26:43.5344Z [W] Failed to pass connection string to DO, error: -1 [StartupAgent]
2021-11-28T06:26:43.5344Z [I] Agent running. [main]
Error: Time:Sun Nov 28 06:26:44 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:26:44 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:26:45 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:26:47 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:26:51 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:26:59 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:27:15 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:27:45 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:28:15 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized





Error: Time:Sun Nov 28 06:28:45 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:29:16 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:29:47 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:30:18 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:30:49 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:31:19 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:31:50 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:32:19 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:32:49 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:33:19 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:33:50 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:34:21 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:34:52 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Sun Nov 28 06:35:22 2021 File:/tmp/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqttOperationCompleteCallback Line:2075 Connection Not Accepted: 0x5: Not Authorized
2021-11-28T06:35:27.2550Z [I] Agent exited with code 0 [main]
2021-11-28T06:35:27.2551Z [I] Agent is shutting down with signal 2. [ShutdownAgent]
2021-11-28T06:35:27.2551Z [I] ADUC agent stopping [AzureDeviceUpdateCoreInterface_Destroy]
2021-11-28T06:35:27.2552Z [I] Calling ADUC_Unregister [ADUC_MethodCall_Unregister]

can anyone tell me what is reason for it ?
what am i missing here ?

@GauravChoube
Copy link
Author

Hey,
I was my mistake that i entered all credential in code. Now updated and seem like code get connected to iot hub.
But now facing new problem as code getting stuck after subscription in agent and nothing happening after that.
Please find the attach the logs

Nov 29 04:50:03 raspberrypi systemd[1]: Stopped Azure Device Update Agent daemon..
Nov 29 04:50:03 raspberrypi systemd[1]: Started Azure Device Update Agent daemon..
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: Hi This is Gaurav from agentEnter into test function sucessfully2021-11-29T04:50:03.1160Z [I] Agent (linux; 0.6.0-public-preview) starting. [main]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:03.1160Z [I] Git Info: main:743bb72 [main]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:03.1160Z [I] Agent built with handlers: microsoft/swupdate. [main]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: inside AllocateDeviceClientHandle
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: Provisioning API Version: 1.7.0
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: Info: Initiating DPS client to retrieve IoT Hub connection information
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: Provisioning Status: 0
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: Provisioning Status: 2
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: Registration Information received from service: devmgmtiothub.azure-devices.net!
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: Info: Provisioning callback indicates success.  iothubUri=devmgmtiothub.azure-devices.net, deviceId=dev_iot_001
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: Info: DPS successfully registered.  Continuing on to creation of IoTHub device client handle.
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:14.7812Z [I] Initalizing PnP components. [ADUC_PnP_Components_Create]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:14.7813Z [I] ADUC agent started. Using IoT Hub Client SDK 1.7.0 [AzureDeviceUpdateCoreInterface_Create]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:14.7813Z [I] Calling ADUC_Register [ADUC_MethodCall_Register]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:14.7814Z [I] IoTHub Device Twin callback registered. [ADUC_DeviceClient_Create]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:14.7819Z [W] Failed to pass connection string to DO, error: -1 [StartupAgent]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:14.7819Z [I] Agent running. [main]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: -> 04:50:15 CONNECT | VER: 4 | KEEPALIVE: 240 | FLAGS: 128 | USERNAME: devmgmtiothub.azure-devices.net/dev_iot_001/?api-version=2020-09-30&DeviceClientType=iothubclient%2f1.7.0%20(native%3b%20Linux%3b%20armv7l)&model-id=dtmi%3aAzureDeviceUpdate%3b1 | CLEAN: 0
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: <- 04:50:16 CONNACK | SESSION_PRESENT: true | RETURN_CODE: 0x0
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:16.2355Z [D] IotHub connection status: 0, reason:6 [ADUC_ConnectionStatus_Callback]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: -> 04:50:16 SUBSCRIBE | PACKET_ID: 2 | TOPIC_NAME: $iothub/twin/res/# | QOS: 0
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: <- 04:50:16 SUBACK | PACKET_ID: 2 | RETURN_CODE: 0
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: -> 04:50:16 PUBLISH | IS_DUP: false | RETAIN: 0 | QOS: DELIVER_AT_MOST_ONCE | TOPIC_NAME: $iothub/twin/GET/?$rid=3
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: <- 04:50:17 PUBLISH | IS_DUP: false | RETAIN: 0 | QOS: DELIVER_AT_MOST_ONCE | TOPIC_NAME: $iothub/twin/res/200/?$rid=3 | PAYLOAD_LEN: 537
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0376Z [I] Processing existing Device Twin data after agent started. [ADUC_PnPDeviceTwin_Callback]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0376Z [D] Notifies components that all callback are subscribed. [ADUC_PnPDeviceTwin_Callback]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0377Z [I] DeviceInformation component is ready - reporting properties [DeviceInfoInterface_Connected]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0379Z [I] Property manufacturer changed to Contoso [RefreshDeviceInfoInterfaceData]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0380Z [I] Property model changed to Virtual-Machine [RefreshDeviceInfoInterfaceData]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0380Z [I] Property osName changed to Linux [RefreshDeviceInfoInterfaceData]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0381Z [I] Property swVersion changed to 5.10.17-v7l- [RefreshDeviceInfoInterfaceData]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0382Z [I] Property processorArchitecture changed to armv7l [RefreshDeviceInfoInterfaceData]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0628Z [I] Property processorManufacturer changed to ARM [RefreshDeviceInfoInterfaceData]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0630Z [I] Property totalMemory changed to 3919128 [RefreshDeviceInfoInterfaceData]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0631Z [I] Property totalStorage changed to 2405632 [RefreshDeviceInfoInterfaceData]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0633Z [I] No update content. Reporting Idle state. [ADUC_Workflow_HandleStartupWorkflowData]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0634Z [I] Setting UpdateState to Idle [ADUC_SetUpdateStateHelper]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0634Z [I] Reporting state: 0, Idle (0); HTTP 200; result 1, 0 [AzureDeviceUpdateCoreInterface_ReportStateAndResultAsync]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0635Z [I] UpdateAction: Idle. WorkflowId: 211129045017 [ADUC_MethodCall_Idle]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0636Z [I] Calling IdleCallback [ADUC_MethodCall_Idle]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: 2021-11-29T04:50:17.0636Z [I] Now idle. workflowId: 211129045017 [Idle]
Nov 29 04:50:17 raspberrypi AducIotAgent[4218]: -> 04:50:17 SUBSCRIBE | PACKET_ID: 4 | TOPIC_NAME: $iothub/twin/PATCH/properties/desired/# | QOS: 0


@asbarnes
Copy link

The log says Failed to pass connection string to DO - is your connection string formatted correctly?
Is UseProvisioning=true part of your connection string?

@GauravChoube
Copy link
Author

GauravChoube commented Nov 29, 2021

Hi asbarnes,
I am not using any connection string based.
I have found the same the error also coming in out of box pi image from azure

I have attached the logs from out-of-box image

Nov 29 05:48:47 raspberrypi3 systemd[1]: Stopped ADU Client service..
Nov 29 05:48:47 raspberrypi3 systemd[1]: Started ADU Client service..
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:47.8336Z [I] Agent (linux; 0.7.0-rc1-public-preview) starting. [main]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:47.8337Z [I] Agent built with handlers: microsoft/swupdate. [main]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:47.8341Z [I] Attempting to create connection to IotHub using type: ADUC_ConnType_Device  [ADUC_DeviceClient_Create]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:47.8343Z [I] Initalizing PnP components. [ADUC_PnP_Components_Create]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:47.8344Z [I] ADUC agent started. Using IoT Hub Client SDK 1.6.0 [AzureDeviceUpdateCoreInterface_Create]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:47.8345Z [I] Calling ADUC_Register [ADUC_MethodCall_Register]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:47.8345Z [I] IoTHub Device Twin callback registered. [ADUC_DeviceClient_Create]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:47.8350Z [W] Failed to pass connection string to DO, error: -1 [StartupAgent]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:47.8351Z [I] Agent running. [main]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: -> 05:48:49 CONNECT | VER: 4 | KEEPALIVE: 240 | FLAGS: 192 | USERNAME: devmgmtiothub.azure-devices.net/dev_iot_000/?api-version=2020-09-30&DeviceClientType=iothubclient%2f1.6.0%20(native%3b%20Linux%3b%20armv7l)&model-id=dtmi%3aAzureDeviceUpdate%3b1 | PWD: XXXX | CLEAN: 0
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: <- 05:48:49 CONNACK | SESSION_PRESENT: true | RETURN_CODE: 0x0
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:49.3560Z [D] IotHub connection status: 0, reason:6 [ADUC_ConnectionStatus_Callback]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: -> 05:48:49 SUBSCRIBE | PACKET_ID: 2 | TOPIC_NAME: $iothub/twin/res/# | QOS: 0
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: <- 05:48:49 SUBACK | PACKET_ID: 2 | RETURN_CODE: 0
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: -> 05:48:49 PUBLISH | IS_DUP: false | RETAIN: 0 | QOS: DELIVER_AT_MOST_ONCE | TOPIC_NAME: $iothub/twin/GET/?$rid=3
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: <- 05:48:50 PUBLISH | IS_DUP: false | RETAIN: 0 | QOS: DELIVER_AT_MOST_ONCE | TOPIC_NAME: $iothub/twin/res/200/?$rid=3 | PAYLOAD_LEN: 537
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1584Z [I] Processing existing Device Twin data after agent started. [ADUC_PnPDeviceTwin_Callback]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1585Z [D] Notifies components that all callback are subscribed. [ADUC_PnPDeviceTwin_Callback]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1585Z [I] DeviceInformation component is ready - reporting properties [DeviceInfoInterface_Connected]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1588Z [I] Property manufacturer changed to Contoso [RefreshDeviceInfoInterfaceData]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1589Z [I] Property model changed to Virtual-Machine [RefreshDeviceInfoInterfaceData]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1590Z [I] Property osName changed to Linux [RefreshDeviceInfoInterfaceData]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1590Z [I] Property swVersion changed to 4.19.88 [RefreshDeviceInfoInterfaceData]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1591Z [I] Property processorArchitecture changed to armv7l [RefreshDeviceInfoInterfaceData]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1832Z [I] Property processorManufacturer changed to ARM [RefreshDeviceInfoInterfaceData]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1834Z [I] Property totalMemory changed to 947776 [RefreshDeviceInfoInterfaceData]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1836Z [I] Property totalStorage changed to 372615 [RefreshDeviceInfoInterfaceData]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1839Z [I] No update content. Reporting Idle state. [ADUC_Workflow_HandleStartupWorkflowData]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1839Z [I] Setting UpdateState to Idle [ADUC_SetUpdateStateHelper]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1840Z [I] Reporting state: 0, Idle (0); HTTP 200; result 1, 0 [AzureDeviceUpdateCoreInterface_ReportStateAndResultAsync]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1842Z [I] UpdateAction: Idle. WorkflowId: 211129054850 [ADUC_MethodCall_Idle]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1842Z [I] Calling IdleCallback [ADUC_MethodCall_Idle]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: 2021-11-29T05:48:50.1842Z [I] Now idle. workflowId: 211129054850 [Idle]
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: -> 05:48:50 SUBSCRIBE | PACKET_ID: 4 | TOPIC_NAME: $iothub/twin/PATCH/properties/desired/# | QOS: 0
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: -> 05:48:50 PUBLISH | IS_DUP: false | RETAIN: 0 | QOS: DELIVER_AT_MOST_ONCE | TOPIC_NAME: $iothub/twin/PATCH/properties/reported/?$rid=5 | PAYLOAD_LEN: 229
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: -> 05:48:50 PUBLISH | IS_DUP: false | RETAIN: 0 | QOS: DELIVER_AT_MOST_ONCE | TOPIC_NAME: $iothub/twin/PATCH/properties/reported/?$rid=6 | PAYLOAD_LEN: 99
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: -> 05:48:50 PUBLISH | IS_DUP: false | RETAIN: 0 | QOS: DELIVER_AT_MOST_ONCE | TOPIC_NAME: $iothub/twin/PATCH/properties/reported/?$rid=7 | PAYLOAD_LEN: 231
Nov 29 05:48:51 raspberrypi3 AducIotAgent[300]: <- 05:48:50 SUBACK | PACKET_ID: 4 | RETURN_CODE: 0

@asbarnes
Copy link

As per my understanding connection string is mandatory.
You can read about my approach for this issue here - #87 (comment)

@GauravChoube
Copy link
Author

Yes , saw the post and but if suppose that was case how could i connect with iot hub in my implementation.
I simply add dps sample code part to get provision where i get the huburl and device id and
i used the IoTHubDeviceClient_LL_CreateFromDeviceAuth , then its done.

@asbarnes
Copy link

I explained it in other issue. My approach is to perform the provisioning in a different program (let's say, one of azure-iot-sdk-c examples) and then call adu-agent with minimal changes:

--- a/src/agent/src/main.c
+++ b/src/agent/src/main.c
@@ -20,6 +20,8 @@
 #include <iothub.h>
 #include <iothub_client_options.h>
 #include <iothubtransportmqtt.h>
+#include <iothub_device_client_ll.h>
+#include <azure_prov_client/iothub_security_factory.h>
 
 #ifndef ADUC_PLATFORM_SIMULATOR // DO is not used in sim mode
 #    include <do_config.h>
@@ -485,8 +487,22 @@ static void ADUC_ConnectionStatus_Callback(
 _Bool ADUC_DeviceClient_Create(ADUC_ConnectionInfo* connInfo, const ADUC_LaunchArguments* launchArgs)
 {
     IOTHUB_CLIENT_RESULT iothubResult;
+    int iothubInitResult;
     bool result = true;
 
+    // Before invoking ANY IoT Hub or DPS functionality, IoTHub_Init must be invoked.
+    if ((iothubInitResult = IoTHub_Init()) != 0)
+    {
+        Log_Error("Failure to initialize client, error=%d", iothubInitResult);
+        result = false;
+    }
+
+    if (iothub_security_init(IOTHUB_SECURITY_TYPE_SAS) != 0)
+    {
+        Log_Error("iothub_security_init failed");
+        result = false;
+    }
+
     // Create a connection to IoTHub.
     if ((g_iotHubClientHandle =
              IoTHubDeviceClient_LL_CreateFromConnectionString(connInfo->connectionString, MQTT_Protocol))

@GauravChoube
Copy link
Author

Okay you are saying its not possible without connection string.
Can you please confirm about can we do device provisioning for agent code with the help of 0x509 certificate.
As provisioning example explain in prov_client_ll_sample.

@GauravChoube
Copy link
Author

@asbarnes
Hi I have successfully implemented the dps provisioning with agent code by same i have explained without using connection string. Some dps code was present for symmetric keys. Used some part of code and mixed with x509 sample code.
finally integrated with agent code.
Thank you much for support

@eshashah-msft eshashah-msft added the area: yocto There is an issue with Yocto meta-layers label Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: yocto There is an issue with Yocto meta-layers
Projects
None yet
Development

No branches or pull requests

3 participants