Azure IOT 中心:ReferenceError 发送遥测数据 'Invalid transport configuration'

Azure IOT Hub: ReferenceError sending Telemetry Data 'Invalid transport configuration'

我正在练习 (https://docs.microsoft.com/en-us/learn/modules/remotely-monitor-devices-with-azure-iot-hub/4-exercise-write-code-device-telemetry?pivots=vscode-node)。当我测试我的代码以发送遥测数据时,出现以下错误。

\node_modules\azure-iot-mqtt-base\dist\mqtt_base.js:356
                    throw new ReferenceError('Invalid transport configuration');

查看代码后,我注意到在安装 azure-iot-device-mqtt@1.15.0 库时出现警告。

npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.

IoT 设备需要一个中央集线器,在我们的例子中是 Azure IoT 集线器,用于将它们的数据上传到并从中检索新的配置更新。 IoT 设备可以选择不同的传输方式来连接到 IoT Hub,如下所示 -

  • MQTT,基于 WebSocket 的 MQTT
  • AMQP,基于 WebSockets 的 AMQP
  • HTTPS

身份验证是使用对称密钥或 X.509 证书完成的,这些证书可以是自签名的或由 CA 签名的。 IoT 设备可以发送最大 256 KB 的消息。消息格式可以是文本或二进制。

我检查了你在问题中提到的模块,但没有找到任何练习或研讨会,所以我不确定你哪里出错了。

尝试 Send telemetry from an IoT Plug and Play device to Azure IoT Hub 练习。