我已经为Bacnet扫描创建了一个模块,它将响应一个设备列表及其地址。但是我在python中实现直接方法处理程序时遇到了问题。当我第一次尝试自己实现它时,我遇到了这个错误。这可能意味着我没有成功注册直接方法回调。我有一些参考资料,但它来自C#,azure docs没有帮助我找到注册回调的正确方法。对于IoTubModuleClient,有一个on_方法请求和一个receive方法请求。谢谢你的帮助
def iothub_client_scan_run():
try:
iot_client = iothub_client_init()
bacnet_scan_listener_thread = threading.Thread(target=device_method_listener, args=(iot_client,))
bacnet_scan_listener_thread.daemon = True
bacnet_scan_listener_thread.start()
while True:
time.sleep(1000)
def device_method_listener(iot_client):
while True:
# Receive the direct method request
method_request = iot_client.receive_method_request()
print (
"\nMethod callback called with:\nmethodName = {method_name}\npayload = {payload}".format(
method_name=method_request.name,
payload=method_request.payload
)
)
if method_request.name == "runBacnetScan":
response = bacnet_scan_device(method_request)
else:
response_payload = {"Response": "Direct method {} not defined".format(method_request.name)}
response_status = 404
# Send a method response indicating the method request was resolved
print('Sending method response')
iot_client.send_method_response(response)
print('Message sent!')
我能够解决我的问题或至少找到根本原因,这是我在createOptions下的网络配置。当我尝试执行NetworkMode时,似乎出现了一个问题:通过连接带连接字符串从\u edge\u环境托管并连接到IoModuleClient.connect\u。我仍在尝试调整连接配置,但至少我知道它不在代码中
相关问题 更多 >
编程相关推荐