Skip to content

Coap Discovery

DodaTech 1 min read

In this tutorial, you'll learn about CoAP Resource Discovery Returns Empty. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

CoAP /.well-known/core resource discovery returns no resources.

Quick Fix

Wrong

// Server does not implement /.well-known/core
Client gets 4.04 Not Found when requesting /.well-known/core.
const coap = require('coap')

const resources = {
  '/temperature': {
    'rt': 'sensor.temperature',
    'if': 'sensor',
    'ct': 50  // application/json
  },
  '/humidity': {
    'rt': 'sensor.humidity',
    'if': 'sensor',
    'ct': 50
  },
  '/actuator/valve': {
    'rt': 'actuator.valve',
    'if': 'actuator',
    'ct': 0  // text/plain
  }
}

const server = coap.createServer()

server.on('request', (req, res) => {
  if (req.url === '/.well-known/core') {
    // Build CoRE Link Format response
    const links = Object.entries(resources).map(([path, info]) => {
      return `<${path}>;rt='${info.rt}';if='${info.if}';ct=${info.ct}`
    })
    
    res.code = '2.05'
    res.setOption('Content-Format', 40)  // application/link-format
    res.end(links.join(','))
  }
})

// Client discovers resources
coap.request({
  pathname: '/.well-known/core',
  hostname: 'sensor-node'
}).on('response', (res) => {
  console.log('Available resources:')
  console.log(res.payload.toString())
  // Parse: </temperature>;rt='sensor.temperature';if='sensor';ct=50
})
Client receives all available resources in CoRE Link Format.

Prevention

CoAP resource discovery uses /.well-known/core (RFC 6690). Format: CoRE Link Format (Content-Format 40). Each resource link includes attributes: rt (resource type), if (interface), ct (content type), obs (observable), sz (max size).

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### What is CoRE Link Format?

A format for describing CoAP resources. Format: ;attr=value,;attr=value. Defined in RFC 6690.

Can I filter discovery results?

Yes. Clients can add query parameters: /.well-known/core?rt=sensor.temperature returns only temperature resources.

Do all CoAP servers support discovery?

Discovery is optional but strongly recommended. It enables machine-to-machine resource discovery without out-of-band configuration.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro