调用方法 open 时出现 DeviceClient 错误

问题描述

我使用的是来自 this page 的 Android 示例代码

刚刚将第 29 行的 connstring@H_404_4@ 的内容替换为 client.open();

我正在使用 SAS 身份验证。

一个错误是尝试调用 Connected to process 20170 on device '7.3_Foldable_API_30 [emulator-5554]'. Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page. D/NetworkSecurityConfig: No Network Security Config specified,using platform default No Network Security Config specified,using platform default I/MultiDex: VM with version 2.1.0 has multidex support Installing application VM has multidex support,MultiDex support library is disabled. D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so I/TetheringManager: registerTetheringEventCallback:com.example.kttracking W/System.err: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (nop) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. D/HostConnection: HostConnection::get() New Host Connection established 0xf03da8e0,tid 20194 D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_3_0 W/System.err: Exception while opening IoTHub connection: java.io.IOException: Could not open the connection I/System.out: Shutting down... I/System.out: Message Sent: "temperature":22.84,"humidity":48.31 W/System.err: Exception while sending event: java.lang.IllegalStateException: Cannot send event from an IoT Hub client that is closed. W/Openglrenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED,retrying without... D/EGL_emulation: eglCreateContext: 0xf03f3ee0: maj 3 min 0 rcv 3 D/EGL_emulation: eglMakeCurrent: 0xf03f3ee0: ver 3 0 (tinfo 0xf0738cf0) (first time) I/Gralloc4: mapper 4.x is not supported D/HostConnection: createUnique: call HostConnection::get() New Host Connection established 0xf03f3af0,tid 20194 D/goldfish-address-space: allocate: Ask for block of size 0x100 allocate: ioctl allocate returned offset 0x3fc01c000 size 0x2000 D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_3_0 I/System.out: Message Sent: "temperature":20.74,"humidity":31.12 W/System.err: Exception while sending event: java.lang.IllegalStateException: Cannot send event from an IoT Hub client that is closed. I/System.out: Message Sent: "temperature":26.08,"humidity":43.27 W/System.err: Exception while sending event: java.lang.IllegalStateException: Cannot send event from an IoT Hub client that is closed. (第 138 行)。

每次尝试发送消息时都会出现以下错误(第 122 行)。

├── calculator
│   ├── __init__.py
│   ├── addTwo.py
│   ├── mulTwo.py
│   └── sum.py
└── main.py

解决方法

您使用的是什么协议?那是MQTT吗?另请检查您使用的设备客户端版本。

您可以做的第二件事是尝试在不同的设备上,看看问题是否仍然存在。有时某些设备确实会出现这样的问题。

,

最后我尝试了这个 https://www.mathworks.com/help/stats/classificationecoc.predict.html#bufel6_-NegLoss。它有效。