질문 15개
파이썬을 통해 azure iot hub에서 메시지 수신 오류
solution-lab
0
평판 포인트
from azure.iot.device import IoTHubDeviceClient, Message
import threading
import time
CONNECTION_STRING = "HostName=ID.azure-devices.net;DeviceId=sample;SharedAccessKey=???"
def message_handler(message):
print("Received message from Azure IoT Hub:")
print(message.data.decode("utf-8"))
print("")
def main():
client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING)
client.connect()
# 메시지 핸들러 설정
client.on_message_received = message_handler
try:
# 메인 스레드가 종료되지 않도록 유지
while True:
time.sleep(1)
except KeyboardInterrupt:
print("IoTHubDeviceClient sample stopped")
if __name__ == "__main__":
main()
오류 메시지는 다음과 같습니다 .
Exception caught in background thread. Unable to handle.
['azure.iot.device.common.transport_exceptions.ConnectionDroppedError: Unexpected disconnection\n']
코드가 잘못되었거나, 추가적인 방법이 있나요?
Exchange | Exchange Server | 기타
비즈니스용 Windows | Windows Server | 사용자 환경 | 기타
비즈니스용 Windows | IT 전문가용 Windows 클라이언트 | 사용자 환경 | 기타
커뮤니티 센터 | Q&A 사이트 논의 | Q&A 시작
질문 337개
로그인하여 답변