无法将NodeMCU连接到Microsoft Azure IoT中心 [英] Trouble connecting NodeMCU to Microsoft Azure IoT Hub

查看:136
本文介绍了无法将NodeMCU连接到Microsoft Azure IoT中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过MQTT协议将运行最新NodeMCU版本的ESP8266连接到Microsoft Azure IoT中心.

I am trying to connect my ESP8266, running the latest NodeMCU build, to a Microsoft Azure IoT Hub via MQTT Protocol.

这似乎是可能的,如此处所示...

It appears that this is possible, as it is shown here...

http://thinglabs.io/workshop/esp8266/sending-d2c-消息/

据我从MS Azure帮助中所看到的,我使用的语法正确.

I am using the correct syntax as far as I can see from the MS Azure help...

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

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

Unlike the example in ThingLabs, which creates a SAS token using NodeMCU, I have followed the MS document and generated a SAS token using the Device Explorer, for testing purposes.

我的LUA代码如下...

My LUA code is as follows...

-- 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地址和端口上侦听".

The response is always Error Connecting: -5 which translates to "There is no broker listening at the specified IP Address and Port".

我怀疑NodeMCU正在努力应对SSL(端口8883)连接.因此,我确保可以使用以下代码建立HTTPS连接(在验证SSL根证书之后),该方法有效,但无济于事.

I suspected that NodeMCU was struggling with the SSL (port 8883) connection. So I ensured that I was able to make HTTPS connections (after verifying the SSL root certificate) with the following code, this worked but did not help.

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

我似乎无法使它正常工作! @MarcelStör-有什么想法吗?

I cannot seem to get this to work! @Marcel Stör - any thoughts?

非常感谢.

推荐答案

我遇到了相同的错误Error Connecting: -5,我在ESP上设置了时间,并且可以解决此错误.

I had the same error Error Connecting: -5 , I have set the time on the ESP and it fix this error.

您将在 http://thinglabs.io/上找到有关sntp的一些信息. workshop/esp8266/sending-d2c-messages/(如您所说).

这篇关于无法将NodeMCU连接到Microsoft Azure IoT中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆