🚀 CoAP Server

Union Shield IoT Platform

✅ 服务状态: 正常运行
CoAP 服务器已启动并准备接受设备连接
服务器地址 coap://coap.union-shield.com:5683
协议版本 CoAP (RFC 7252)
传输协议 UDP
端口 5683
认证方式 deviceName + authKey → JWT Token

📋 可用资源

⚡ 快速开始

使用 Python aiocoap 库连接 CoAP 服务器:

import asyncio
from aiocoap import *
import json

async def connect():
    context = await Context.create_client_context()

    # 1. 设备认证
    auth_req = Message(
        code=POST,
        uri='coap://coap.union-shield.com:5683/auth',
        payload=json.dumps({
            'deviceName': 'YOUR_DEVICE_NAME',
            'authKey': 'YOUR_AUTH_KEY'
        }).encode()
    )

    auth_resp = await context.request(auth_req).response
    token = json.loads(auth_resp.payload)['token']

    # 2. 发送数据
    send_req = Message(
        code=POST,
        uri=f'coap://coap.union-shield.com:5683/storage/ts?token={token}',
        payload=json.dumps({
            'temperature': 25.5,
            'humidity': 60
        }).encode()
    )

    await context.request(send_req).response

asyncio.run(connect())
查看 aiocoap 文档