1
aiocoap 라이브러리를 사용하여 임베디드 장치에 CoAP 요청을 보냅니다. 통신 및 기본 기능은 제대로 작동하는 것으로 보이지만 설명서에는 관찰을 활성화하는 방법이 나와 있지 않습니다. 관측 기능 은이 서버 측과 클라이언트 측 모두의 소스 코드에있는 것처럼 보입니다. 클라이언트 측이 필요합니다. 서버의 준수 상태를 생성하는 GET
요청을 : aiocoap 라이브러리로 CoAP 리소스를 관찰하는 방법은 무엇입니까?
이
내가 지금까지 무엇을 가지고import asyncio, aiocoap
@asyncio.coroutine
def coap_get_with_observe():
protocol = yield from aiocoap.Context.create_client_context()
request = aiocoap.Message(code = aiocoap.GET)
request.set_request_uri('coap://[aaaa::212:4b00:a49:e903]/sensors/temp')
# set observe bit from None to 0
request.opt.observe = 0
try:
response = yield from protocol.request(request).response
except Exception as e:
print("request failed: %s" % str(e))
else:
print("request ok: %r" % response.payload)
event_loop = asyncio.new_event_loop()
asyncio.set_event_loop(event_loop)
event_loop.create_task(coap_get_with_observe())
asyncio.get_event_loop().run_forever()
출력 : 클라이언트에서 수신
request ok: b'{"HDC_TEMP":2426}'
이 인쇄 단지 첫 번째 값 ; 후속 값도 인쇄하고 싶습니다.
그것은이 라인을 교체하는 데 도움이