Skip to content

CoAP Observe Not Sending Notifications

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about CoAP Observe Not Sending Notifications. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

CoAP observe (subscribe) requests do not receive updates when the resource changes.

Quick Fix

Wrong

// Server does not send observe notifications
client.on('response', (res) => {
  console.log(res.payload)  // Only first response
})
Client receives the initial response but no subsequent updates.
// Server — must send separate responses via observe
server.observe = function(resource, req, res) {
  const observer = res.observe(resource)
  
  // Send updates when resource changes
  setInterval(() => {
    const newData = JSON.stringify({ value: Math.random() })
    observer.write(newData)  // Sends 2.05 to all observers
  }, 5000)
}

// Client — enable observe flag
const req = coap.request({
  hostname: 'sensor',
  pathname: '/temperature',
  observe: true,  // GET with Observe flag
  confirmable: true
})

req.on('response', (res) => {
  if (res.code === '2.05') {
    console.log('Update:', res.payload.toString())
  }
})

req.end()
Client receives updates every 5 seconds as resource changes.

Prevention

CoAP Observe enables pub/sub for CoAP resources. Clients register with a GET containing Observe: 0. The server sends notifications on resource changes. Use NON messages for frequent updates. Notifications include an Observe counter (sequence number). Clients can detect reconnects by Observe number reset.

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

FAQ

### How does Observe registration work?

Client sends GET with Observe option (value 0). Server responds with 2.05 containing Observe sequence number. Future updates carry new Observe numbers.

Can I cancel an observation?

Yes. Client sends a GET with Observe: 1 (deregister). Or the server removes observers after timeout.

What happens if Observer disconnects?

CoAP over UDP has no persistent connection. The server deregisters observers when notification fails (NACK/timeout) after multiple retries.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro