MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.27k stars 21.45k forks source link

tutorial-nested-iot-edge.md with X.509 simulatedTemperatureSensor Module with error #93280

Closed TheRealSvc closed 1 year ago

TheRealSvc commented 2 years ago

I followed the above tutorial with two raspberry-pi's as top-layer and lower-level devices. I didn't connect using symmetric key but X.509 This is my iotedge_config.yaml:

config_version: "1.0"

iothub:
  iothub_hostname: testhub321.azure-devices.net
  iothub_name: testhub321
  ## Authentication method used by IoT Edge devices: symmetric_key or x509_certificate
  authentication_method: x509_certificate

## Root certificate used to generate device CA certificates. Optional. If not provided a self-signed CA will be generated
#certificates:
#  root_ca_cert_path: "~/iotedge/wrkdir/certs/azure-iot-svc.root.ca.cert.pem"
#  root_ca_cert_key_path: "~/iotedge/wrkdir/private/azure-iot-svc.root.ca.key.pem"

## IoT Edge configuration template to use
configuration:
  template_config_path: "./templates/tutorial/device_config.toml"
  default_edge_agent: "$upstream:443/azureiotedge-agent:1.2"

## Hierarchy of IoT Edge devices to create
edgedevices:
  device_id: top-layer
  edge_agent: "mcr.microsoft.com/azureiotedge-agent:1.2" ## Optional. If not provided, default_edge_agent will be used
  deployment: "./templates/tutorial/deploymentTopLayer.json" ## Optional. If provided, the given deployment file will be applied to the newly created device
  # hostname: "FQDN or IP" ## Optional. If provided, install.sh will not prompt user for this value nor the parent_hostname value
  child:
    - device_id: lower-layer
      deployment: "./templates/tutorial/deploymentLowerLayer.json" ## Optional. If provided, the given deployment file will be applied to the newly created device
      # hostname: "FQDN or IP" ## Optional. If provided, install.sh will not prompt user for this value nor the parent_hostname value

I created the two zip-bundles and copied the certificates over to the devices. After deploying both deploymentTopLayer.json and deploymentLowerLayer.json, the top-layer device seems fine. Also the lower-layer devices fetches all modules using the ApiProxi module. However the simulatedTemperatureSensor module stops with an error:

SimulatedTemperatureSensor Main() started.
Initializing simulated temperature sensor to send 500 messages, at an interval of 5 seconds.
To change this, set the environment variable MessageCount to the number of messages that should be sent (set it to -1 to send unlimited messages).
[Information]: Trying to initialize module client using transport type [Amqp_Tcp_Only].
Unhandled exception. System.AggregateException: One or more errors occurred. (Missing IOT hub name)
 ---> System.FormatException: Missing IOT hub name
   at Microsoft.Azure.Devices.Client.IotHubConnectionStringBuilder.SetIotHubName()
   at Microsoft.Azure.Devices.Client.IotHubConnectionStringBuilder.SetHostName(String hostname)
   at Microsoft.Azure.Devices.Client.IotHubConnectionStringBuilder.set_HostName(String value)
   at Microsoft.Azure.Devices.Client.IotHubConnectionStringBuilder.Create(String hostname, String gatewayHostname, IAuthenticationMethod authenticationMethod)
   at Microsoft.Azure.Devices.Client.ClientFactory.Create(String hostname, String gatewayHostname, IAuthenticationMethod authenticationMethod, ITransportSettings[] transportSettings, ClientOptions options)
   at Microsoft.Azure.Devices.Client.Edge.EdgeModuleClientFactory.CreateInternalClientFromAuthenticationMethod(String hostname, String gateway, IAuthenticationMethod authMethod, ClientOptions options)
   at Microsoft.Azure.Devices.Client.Edge.EdgeModuleClientFactory.CreateInternalClientFromEnvironmentAsync()
   at SimulatedTemperatureSensor.Program.<>c__DisplayClass18_0.<<CreateModuleClientAsync>b__1>d.MoveNext() in /home/vsts/work/1/s/edge-modules/SimulatedTemperatureSensor/src/Program.cs:line 293
--- End of stack trace from previous location where exception was thrown ---
   at SimulatedTemperatureSensor.Program.CreateModuleClientAsync(TransportType transportType, ITransientErrorDetectionStrategy transientErrorDetectionStrategy, RetryStrategy retryStrategy) in /home/vsts/work/1/s/edge-modules/SimulatedTemperatureSensor/src/Program.cs:line 272
   at SimulatedTemperatureSensor.Program.MainAsync() in /home/vsts/work/1/s/edge-modules/SimulatedTemperatureSensor/src/Program.cs:line 79
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at SimulatedTemperatureSensor.Program.Main() in /home/vsts/work/1/s/edge-modules/SimulatedTemperatureSensor/src/Program.cs:line 48
[2022-05-23 13:56:27 +00:00]: Starting Module
SimulatedTemperatureSensor Main() started.
Initializing simulated temperature sensor to send 500 messages, at an interval of 5 seconds.
To change this, set the environment variable MessageCount to the number of messages that should be sent (set it to -1 to send unlimited messages).
[Information]: Trying to initialize module client using transport type [Amqp_Tcp_Only].
Unhandled exception. System.AggregateException: One or more errors occurred. (Missing IOT hub name)
 ---> System.FormatException: Missing IOT hub name
   at Microsoft.Azure.Devices.Client.IotHubConnectionStringBuilder.SetIotHubName()
   at Microsoft.Azure.Devices.Client.IotHubConnectionStringBuilder.SetHostName(String hostname)
   at Microsoft.Azure.Devices.Client.IotHubConnectionStringBuilder.set_HostName(String value)
   at Microsoft.Azure.Devices.Client.IotHubConnectionStringBuilder.Create(String hostname, String gatewayHostname, IAuthenticationMethod authenticationMethod)
   at Microsoft.Azure.Devices.Client.ClientFactory.Create(String hostname, String gatewayHostname, IAuthenticationMethod authenticationMethod, ITransportSettings[] transportSettings, ClientOptions options)
   at Microsoft.Azure.Devices.Client.Edge.EdgeModuleClientFactory.CreateInternalClientFromAuthenticationMethod(String hostname, String gateway, IAuthenticationMethod authMethod, ClientOptions options)
   at Microsoft.Azure.Devices.Client.Edge.EdgeModuleClientFactory.CreateInternalClientFromEnvironmentAsync()
   at SimulatedTemperatureSensor.Program.<>c__DisplayClass18_0.<<CreateModuleClientAsync>b__1>d.MoveNext() in /home/vsts/work/1/s/edge-modules/SimulatedTemperatureSensor/src/Program.cs:line 293
--- End of stack trace from previous location where exception was thrown ---
   at SimulatedTemperatureSensor.Program.CreateModuleClientAsync(TransportType transportType, ITransientErrorDetectionStrategy transientErrorDetectionStrategy, RetryStrategy retryStrategy) in /home/vsts/work/1/s/edge-modules/SimulatedTemperatureSensor/src/Program.cs:line 272
   at SimulatedTemperatureSensor.Program.MainAsync() in /home/vsts/work/1/s/edge-modules/SimulatedTemperatureSensor/src/Program.cs:line 79
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at SimulatedTemperatureSensor.Program.Main() in /home/vsts/work/1/s/edge-modules/SimulatedTemperatureSensor/src/Program.cs:line 48

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

shwetamathur7 commented 2 years ago

@TheRealSvc Thanks for your feedback. We will investigate and update the thread.

asergaz commented 2 years ago

Hello @TheRealSvc , in the tutorial step:

On the lower layer device, it will ask for the hostname and parent's hostname. Supply the appropriate IP or FQDN for each prompt. You can use either, but be consistent in your choice across devices.

Can you share what you selected for hostname and parent_hostname ?

Thanks!

TheRealSvc commented 2 years ago

Hi, sure, on the lower-layer device i chose:

hostname: lower-layer parent_hostname: top-layer

I can ping top-layer without problem from the lower-layer host device.

TheRealSvc commented 2 years ago

also, when i do sudo iotedge check, i get this

Configuration checks
--------------------
√ aziot-edged configuration is well-formed - OK
√ container engine is installed and functional - OK
√ config.yaml has correct hostname - OK
√ config.yaml has correct parent_hostname - OK
× config.yaml parent hostname is resolvable from inside container - Error
    Failed to resolve parent hostname top-layer
× config.yaml has correct URIs for daemon mgmt endpoint - Error
    Unable to find image 'top-layer/azureiotedge-diagnostics:1.2.0-rc4' locally
    docker: Error response from daemon: pull access denied for top-layer/azureiotedge-diagnostics, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
    See 'docker run --help'.
× container time is close to host time - Error
    Could not query local time inside container

One thing is interesting: I added a custom python module to the lower-layer device and that works. So telemetry is send to the Iothub. Mhhh.

asergaz commented 2 years ago

× config.yaml parent hostname is resolvable from inside container - Error

Most probably the error is here. Your container (simulatedTemperatureSensor Module) does not recognize parent_hostname FQDN. You can check Docker container create options and my hint is that you will need to configure the DNS to be able to find that FQDN inside your container. See also: How to configure container create options for IoT Edge modules.

Can you also check the simulatedTemperatureSensor logs? iotedge logs <container name>

Thanks.

TheRealSvc commented 2 years ago

I tried to use the IP as the parent_hostname. No success. Most of the simulatedTemperatureSensor logs i've provided above. Sorry if that wasn't clear. Today i'am a bit limited. Tomorrow i'll try to modify the DNS settings. But since my own module runs, i probably won't spend too much time to get the simulatedTemperatureSensor module running.

asergaz commented 2 years ago

@TheRealSvc thank you! I will try this on my side as well. Will let the case open for 1-2 more days so we can validate if this is an issue in the doc or in the product. @PatAltimore fyi.

TheRealSvc commented 2 years ago

@asergaz thank you, i just fiddled a bit with the DNS settings but to no avail. I will leave it, since i have no trouble with my own modules. Anyways here's the log-output when i manually start the docker container:

sudo docker run  8be190288a00
[2022-05-27 08:16:28 +00:00]: Starting Module
SimulatedTemperatureSensor Main() started.
Initializing simulated temperature sensor to send 500 messages, at an interval of 5 seconds.
To change this, set the environment variable MessageCount to the number of messages that should be sent (set it to -1 to send unlimited messages).
[Information]: Trying to initialize module client using transport type [Amqp_Tcp_Only].
Unhandled exception. System.AggregateException: One or more errors occurred. (Environment variable IOTEDGE_WORKLOADURI is required.)
 ---> System.InvalidOperationException**: Environment variable IOTEDGE_WORKLOADURI is required.**
   at Microsoft.Azure.Devices.Client.Edge.EdgeModuleClientFactory.CreateInternalClientFromEnvironmentAsync()
   at SimulatedTemperatureSensor.Program.<>c__DisplayClass18_0.<<CreateModuleClientAsync>b__1>d.MoveNext() in /home/vsts/work/1/s/edge-modules/SimulatedTemperatureSensor/src/Program.cs:line 293
--- End of stack trace from previous location where exception was thrown ---
   at SimulatedTemperatureSensor.Program.CreateModuleClientAsync(TransportType transportType, ITransientErrorDetectionStrategy transientErrorDetectionStrategy, RetryStrategy retryStrategy) in /home/vsts/work/1/s/edge-modules/SimulatedTemperatureSensor/src/Program.cs:line 272
   at SimulatedTemperatureSensor.Program.MainAsync() in /home/vsts/work/1/s/edge-modules/SimulatedTemperatureSensor/src/Program.cs:line 79
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at SimulatedTemperatureSensor.Program.Main() in /home/vsts/work/1/s/edge-modules/SimulatedTemperatureSensor/src/Program.cs:line 48 

Maybe it's of use for you.

PatAltimore commented 1 year ago

Hi @TheRealSvc,

I'm doing some cleanup of old open issues. We've rewritten the nested tutorial to use a new az iot edge devices create command. It's reduced several issues with configuration. Just an FYI. I'm going to close this issue.

Thanks, Pat

please-close