【发布时间】:2020-06-30 10:56:32
【问题描述】:
正如初学 IoT Edge 开发人员所期望的那样,我开始遵循 Microsoft 教程,了解如何将自定义代码部署到 IoT Edge 服务器Tutorial: Develop a C# IoT Edge module for Linux devices。
我能够在工业英特尔 PC 上安装 Ubuntu 18.04 服务器,下载和配置 edgeHub 和 edgeAgent 模块,创建免费的 Azure 和 Docker Hub 帐户等。甚至教程中的示例代码也成功构建并部署到我的目标设备看起来一切正常,所有模块都在相互通信,等等。
在运行演示代码后,我开始修改代码以更好地满足我的最终目标,即捕获我们使用 UDP 多播/广播的工业设备产生的网络流量。显然我需要将我的 docker 映像配置为在“主机”网络模式下运行。事实上,当我告诉 azure edgeAgent 以主机模式启动模块容器时,UDP 数据包就开始进来了。
但是,现在我的示例模块不再能够连接到 iot 集线器,我完全不知所措。我也尝试在主机模式下运行 edgeHub 容器,这似乎没有任何区别。由于 ModuleClient.OpenAsync 方法,我得到的确切错误是:
Unhandled exception. System.AggregateException: One or more errors occurred. (Transient network error occurred, please retry.)
---> Microsoft.Azure.Devices.Client.Exceptions.IotHubCommunicationException: Transient network error occurred, please retry.
---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (00000005, 0xFFFDFFFF): Name or service not known
at System.Net.Dns.InternalGetHostByName(String hostName)
at System.Net.Dns.ResolveCallback(Object context)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
at System.Net.Dns.HostResolutionEndHelper(IAsyncResult asyncResult)
at System.Net.Dns.EndGetHostAddresses(IAsyncResult asyncResult)
at System.Net.Dns.<>c.<GetHostAddressesAsync>b__25_1(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Azure.Devices.Client.Transport.Mqtt.MqttTransportHandler.OpenAsyncInternal(CancellationToken cancellationToken)
at Microsoft.Azure.Devices.Client.Transport.Mqtt.MqttTransportHandler.OpenAsync(CancellationToken cancellationToken)
at Microsoft.Azure.Devices.Client.Transport.ProtocolRoutingDelegatingHandler.OpenAsync(CancellationToken cancellationToken)
at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.<>c__DisplayClass23_0.<<ExecuteWithErrorHandlingAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.ExecuteWithErrorHandlingAsync[T](Func`1 asyncOperation)
--- End of inner exception stack trace ---
at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.ExecuteWithErrorHandlingAsync[T](Func`1 asyncOperation)
at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.<>c__DisplayClass33_0.<<OpenInternalAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.EnsureOpenedAsync(CancellationToken cancellationToken)
at Microsoft.Azure.Devices.Client.InternalClient.OpenAsync()
at SampleModule.Program.Init() in /app/SampleModule/Program.cs:line 54
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at SampleModule.Program.Main(String[] args) in /app/SampleModule/Program.cs:line 26
用于连接的代码:
ITransportSettings[] settings = { mqttSetting };
ModuleClient ioTHubModuleClient = await ModuleClient.CreateFromEnvironmentAsync(settings);
await ioTHubModuleClient.OpenAsync();
Console.WriteLine("IoT Hub module client initialized.");
显然 ModuleClient 无法再找到 edgeHub(名称或服务未知?)。我知道'CreateFromEnvironmentAsync'使用由edgeAgent设置的环境变量,但哪些?有人知道这是为什么吗?非常感谢您指出开始调试此问题的正确方向!
如果我将 docker 容器改回“桥”网络,OpenAsync 方法可以完美运行,但我的 UDP 广播消息当然不再接收。
【问题讨论】:
标签: c# azure docker .net-core azure-iot-hub