带有MQTT 8883端口的Azure设备资源管理器。 [英] Azure Device Explorer with MQTT 8883 port .
问题描述
你好......
     我想从windows cmd行向设备浏览器woth mqtt protocal发送消息。
为此我写了python代码
import paho.mqtt.client as mqttClient
import time
import ssl
def on_connect(client,userdata,flags,rc):
if rc == 0:
print("连接到经纪人")
global Connected #Use全局变量
Connected = True #Signal connection
else:
print(" Connection failed")
Connected = False #global变量用于连接状态
broker_address =" iotdemo-1-maestrotek.azure-devices.net"
port = 8883
device_id =" Test"
user = broker_address + device_id
password =" SharedAccessSignature sr = iotdemo-1-maestrotek.azure-devices.net& sig = qiOel62NJu85FzXuS5dai1qaAkvA1YR0KSNJEoEdSkQ%3D& se = 1582197613& skn = iothubowner"
client = mqttClient.Client(" Python")#create new instance
client.username_pw_set(user,password)#set username&password
client.tls_set(" C:\\root_ca.crt",tls_version = ssl.PROTOCOL_TLSv1_2)
client.tls_insecure_set(False)
client.on_connect = on_connect #attach函数回调
客户端.connect(broker_address,port)#connect to broker
client.loop_start()#start循环
而Connected!= True:#Wait for connection
time.sleep(0.1)
try:
而True:
client.publish(" devices /" + device_id +" / messages / events /", " {id = 123}",qos = 1)
除KeyboardInterrupt外:
client.disconnect()
client.loop_stop()
它给出了错误:...
Traceback(最近一次调用最后一次):
文件"new.py",第32行,< module>
&NBSP; client.connect(HubName,port = 8883)
文件"C:\Users\Copa数据India \ AppData \本地\程序员\ @Python \Python37 \lib \ site-packages \ paho \mqtt \client.py"",行839,在连接中$
&NBSP; return self.reconnect()
文件"C:\Users\Copa数据India \ AppData \本地\程序员\ @Python \Python37 \lib \ site-packages \ paho \mqtt \client.py"",行994,重新连接
&NBSP; sock.do_handshake()
文件"C:\Users\Copa Data India \ AppData \ Local \ Program\Python \Python37 \lib\ssl.py",第1117行,在do_handshake中$
&NBSP; self._sslobj.do_handshake()
ssl.SSLCertVerificationError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败:无法获得本地颁发者证书(_ssl.c:1056)
请纠正我......
< blockquote>
您好,
您是否利用以下文档为您提供帮助?
我的月球拍摄是你没有正确设置用户名:
"用于 < span style ="font-weight:600 ; font-family:'Segoe UI',SegoeUI,'Segoe WP','Helvetica Neue',Helvetica,Tahoma,Arial,sans-serif; font-size:16px">用户名 字段,
使用 {iothubhostname} / {device_id} /?api-version = 2018-06-30
,其中 {iothubhostname}
是
物联网中心的完整CName。"
****请注意** **:您在此线程上共享了与您的iothub的连接字符串。请确保您续订它,因为这会导致IoHub上的不必要消耗或由于恶意使用连接字符串而导致服务中断。
谢谢!
$
Hello...
I want to send message to device explorer woth mqtt protocal from the windows cmd line .
For this i write python code
import paho.mqtt.client as mqttClient import time import ssl def on_connect(client, userdata, flags, rc): if rc == 0: print("Connected to broker") global Connected #Use global variable Connected = True #Signal connection else: print("Connection failed") Connected = False #global variable for the state of the connection broker_address = "iotdemo-1-maestrotek.azure-devices.net" port = 8883 device_id = "Test" user = broker_address + device_id password = "SharedAccessSignature sr=iotdemo-1-maestrotek.azure-devices.net&sig=qiOel62NJu85FzXuS5dai1qaAkvA1YR0KSNJEoEdSkQ%3D&se=1582197613&skn=iothubowner" client = mqttClient.Client("Python") #create new instance client.username_pw_set(user,password) #set username and password client.tls_set("C:\\root_ca.crt",tls_version=ssl.PROTOCOL_TLSv1_2) client.tls_insecure_set(False) client.on_connect= on_connect #attach function to callback client.connect(broker_address,port) #connect to broker client.loop_start() #start the loop while Connected != True: #Wait for connection time.sleep(0.1) try: while True: client.publish("devices/" + device_id + "/messages/events/", "{id=123}", qos=1) except KeyboardInterrupt: client.disconnect() client.loop_stop()
It gives the error:...
Traceback (most recent call last):File "new.py", line 32, in <module>
client.connect(HubName, port=8883)
File "C:\Users\Copa Data India\AppData\Local\Programs\Python\Python37\lib\site-packages\paho\mqtt\client.py", line 839, in connect
return self.reconnect()
File "C:\Users\Copa Data India\AppData\Local\Programs\Python\Python37\lib\site-packages\paho\mqtt\client.py", line 994, in reconnect
sock.do_handshake()
File "C:\Users\Copa Data India\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1117, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)
Please correct me...
Hello,
Did you leverage the following doc to help you on this?
My moon shot is that you are not setting the username correctly:
"For the Username field, use
{iothubhostname}/{device_id}/?api-version=2018-06-30
, where{iothubhostname}
is the full CName of the IoT hub."****PLEASE NOTE****: You shared a connection string to your iothub on this thread. Make sure you renew it as this can cause unwanted consumption on your IoHub or disruptions to your service due to malicious use of the connection string.
Thanks!
这篇关于带有MQTT 8883端口的Azure设备资源管理器。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!