【问题标题】:Trouble connecting NodeMCU to Microsoft Azure IoT Hub将 NodeMCU 连接到 Microsoft Azure IoT 中心时出现问题
【发布时间】:2017-06-09 15:10:57
【问题描述】:

我正在尝试通过 MQTT 协议将运行最新 NodeMCU 版本的 ESP8266 连接到 Microsoft Azure IoT Hub。

看起来这是可能的,就像这里显示的那样......

http://thinglabs.io/workshop/esp8266/sending-d2c-messages/

就我从 MS Azure 帮助中看到的而言,我使用的是正确的语法...

https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support

与 ThingLabs 中使用 NodeMCU 创建 SAS 令牌的示例不同,我遵循 MS 文档并使用设备资源管理器生成了 SAS 令牌,用于测试目的。

我的LUA代码如下...

-- Create variables

DEVICE = "testdevice"
IOTHUB = "mynewiothub.azure-devices.net"
PORT = 8883
USER = IOTHUB.."/"..DEVICE.."/api-version=2016-11-14"
PASS = "SharedAccessSignature sr=mynewiothub.azure-devices.net%2Fdevices%2Ftestdevice&sig=Roa5P8BPiGj...v2Vu%2Bm1j9sas%3D&se=1485704099"

-- Create an MQTT Client

azure = mqtt.Client(DEVICE, 60, USER, PASS)

-- Connect to IoTHub via MQTT

azure:connect(IOTHUB, PORT, 1, 0, 
    -- Callback for a successful connection
    function(client)
        print("Connected")     
    end,
    -- Error callback, if connection fails
    function(client, reason)
        print("Error Connecting: "..reason)
    end
)

响应始终为 Error Connecting: -5,其转换为“没有代理在侦听指定的 IP 地址和端口”。

我怀疑 NodeMCU 正在与 SSL(端口 8883)连接作斗争。所以我确保我能够使用以下代码建立 HTTPS 连接(在验证 SSL 根证书之后),这有效但没有帮助。

http.get("https://example.com/info", nil,
function (code, resp)
     print(code, resp)
end)

我似乎无法让它工作! @Marcel Stör - 有什么想法吗?

非常感谢。

【问题讨论】:

    标签: azure lua mqtt esp8266 nodemcu


    【解决方案1】:

    我遇到了同样的错误Error Connecting: -5,我已经在 ESP 上设置了时间,它修复了这个错误。

    你会在http://thinglabs.io/workshop/esp8266/sending-d2c-messages/(正如你提到的那样)上找到一些关于 sntp 的信息。

    【讨论】:

      猜你喜欢
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-06
      • 2018-01-10
      • 1970-01-01
      • 2023-01-27
      相关资源
      最近更新 更多