CoAP · Study deck

CoAP Methods and Multicast

Picture a caretaker using a small panel to read a tank level and change an alarm limit.

Broker Bex is your guide for this deck.

methods
Broker Bex, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Apply CoAP REST methods (GET, POST, PUT, DELETE) with proper idempotency semantics for IoT resource manipulation
  • Implement CoAP servers and clients using Python (aiocoap) and Arduino (ESP32) for sensor data exchange
  • Configure CoAP multicast addressing for group operations and network-wide resource discovery via /.well-known/core
  • Demonstrate how the CoAP Observe extension enables server-push notifications, reducing energy consumption by up to 99% compared to polling
iotclass.org

Major section

Start With the Device Menu

A read must not alter the device.

  • A repeated update must not create a second record by accident.
  • The action comes first; the message choice must preserve its meaning.
  • A protocol is a shared set of rules for exchanging messages.
  • Constrained Application Protocol (CoAP) is a compact web-style protocol for small devices and links.
iotclass.org

Major section

Start With the Device Menu (continued)

A gateway is a device that joins unlike networks.

  • If many devices receive the same request, prove that the result stays bounded and that replies do not swamp the link.
  • This first menu does not settle every transport or security choice.
  • The deeper sections compare methods, group delivery, updates, and related message systems so the final design matches the action rather than a familiar label.
iotclass.org

Major section

Phoebe's Field Notes: When a Full CR2032 Cannot Supply the Pulse

The mathematical gist.: The chapter's CR2032 model holds 2,430 J at 3.00 V, but the radio sees $V_{load}=V_{oc}-IR$.

  • A 20 mA pulse through 15 ohm loses 0.30 V and reaches 2.70 V; at 100 ohm it loses 2.00 V and reaches only 1.00 V.

Numbers to remember

20 mAA 20 mA pulse through 15 ohm loses 0.30 V
15 ohmA 20 mA pulse through 15 ohm loses 0.30 V
0.30 VA 20 mA pulse through 15 ohm loses 0.30 V
iotclass.org

Major section

For Beginners: What is CoAP?

You might send a long email with lots of details, or you might send a quick text message with just the essential information.

  • Both get the message across, but text messages are faster and use less data especially important when you have limited battery or a slow connection.
  • CoAP is like the text message version of web communication for IoT devices.
  • That works great for powerful computers and smartphones with strong batteries and fast internet.

Numbers to remember

4 bytesCoAP uses just 4 bytes for its header.
iotclass.org

Major section

For Beginners: What is CoAP? (continued)

Regular websites use HTTP, which is like sending detailed emails with lots of extra information in headers and metadata.

  • But tiny sensors running on coin batteries can't afford that luxury.
  • CoAP strips away all the unnecessary extras and keeps just the essential parts: what you want to do, which resource you're accessing, and the actual data.
  • The magic is that CoAP still works like the web you know.
iotclass.org

Major section

CoAP Request Methods and Multicast

"CoAP has four magic words that do everything!" announced the microcontroller. "GET means 'tell me your value.': PUT means 'change your setting to this.': POST means 'do this action.' And: DELETE means 'remove this thing.'".

  • Temperature Terry demonstrated: "When the dashboard sends me a GET, I reply with my temperature.
  • When someone sends a PUT to change my sampling rate from 10 to 30 seconds, I update my setting and confirm.
  • the battery loved that. "One multicast GET instead of fifty individual GETs means I save 98% of my radio energy for discovery.
iotclass.org

Major section

Key Insights

The simulator comparisons become a protocol choice only after interaction pattern and device constraints are considered together.

  • The branches describe fit, not a universal winner.
  • Having chosen an interaction model, the next question is what that choice costs on the wire.
Protocol selection decision tree for choosing CoAP, MQTT, or HTTP from interaction pattern and device constraints.
Protocol selection decision tree for choosing CoAP, MQTT, or HTTP from interaction pattern and device constraints.
iotclass.org

Major section

Multicast Support

Once a single exchange is clear, scale the same resource model to a group.

  • Multicast helps discovery without changing what GET means.
  • Unicast increases request count and sequential time with every device; multicast holds the outbound request count at one but still receives one response per participating endpoint.
  • That distinction explains why discovery benefits from multicast while state-changing commands still need per-device authorization, outcome tracking, and retry decisions.
iotclass.org

Major section

Learning Points

The resource type says what the endpoint represents, the interface says how a client should interact with it, content format says what representation to expect, and obs advertises notification support.

  • The experiments below summarize ways to change that contract; each change should be checked in both the advertisement and the behavior of the discovered resource.
  • Service versioning support.

Key terms

Standard Endpoint - /.well-known/core
Standard Endpoint - /.well-known/core is CoAP convention (RFC 6690) 3.
Resource discovery
Resource discovery is useful only if a client can interpret an advertisement rather than merely find a URI.
CoAP resource link format field breakdown for a temperature sensor advertisement.
CoAP resource link format field breakdown for a temperature sensor advertisement.
iotclass.org

Major section

Protocol Comparison

The feature tour is complete: methods name the operation, discovery finds resources, and Observe changes polling into push.

  • Total message overhead directly affects both bandwidth and battery life.
  • With CR2032 battery (675 mWh = 2,430 J): CoAP enables 7.7 years vs HTTP's 0.8 years of TX-only battery life.

Why it matters

Because sleep current, computation, retries, and battery behavior are excluded, carry forward the comparative conclusion—protocol overhead matters—not the projected years as a deployment promise.

CoAP versus HTTP overhead for a 5-byte temperature reading, comparing total on-wire bytes, daily radio energy, and TX-only CR2032 battery life.
CoAP versus HTTP overhead for a 5-byte temperature reading, comparing total on-wire bytes, daily radio energy, and TX-only CR2032 battery life.
iotclass.org

Deck summary

Key takeaways

A read must not alter the device.

  • A gateway is a device that joins unlike networks.
  • The mathematical gist.: The chapter's CR2032 model holds 2,430 J at 3.00 V, but the radio sees $V_{load}=V_{oc}-IR$.
  • You might send a long email with lots of details, or you might send a quick text message with just the essential information.
  • Regular websites use HTTP, which is like sending detailed emails with lots of extra information in headers and metadata.
iotclass.org

Retrieval practice

Recall check 1 of 6

Broker Bex says: answer from memory, then check your reasoning.

Q1Which of the following CoAP method properties is correct?

APOST is idempotent because calling it twice with the same payload produces the same result
BGET, PUT, and DELETE are idempotent; POST is not
CDELETE is not idempotent because the resource no longer exists after the first call
DCoAP methods differ from HTTP in that PUT is not idempotent in CoAP
Show answer

Answer: B Correct!

iotclass.org

Retrieval practice

Recall check 2 of 6

Broker Bex says: answer from memory, then check your reasoning.

Q2A developer is implementing a CoAP server for a smart thermostat. The thermostat should allow reading current temperature, updating the target temperature, and resetting to factory defaults. The developer writes: PUT /temperature to read values, POST /target to update settings, and GET /reset to perform factory reset. What's wrong with this design?

ANothing is wrong - these are all valid CoAP methods being used correctly
BShould use GET /temperature to read, PUT /target to update, and POST /reset for factory reset
CShould use OBSERVE /temperature to read continuously, DELETE /target to update, and PUT /reset for factory reset
DCoAP methods are interchangeable - only the URI path matters for determining the operation
Show answer

Answer: B Correct!

iotclass.org

Retrieval practice

Recall check 3 of 6

Broker Bex says: answer from memory, then check your reasoning.

Q3Complete the CoAP PUT request to update a resource:

Arequest = Message(code=PUT, uri='coap://device.local/led')
Brequest = Message(code=POST, uri='coap://device.local/led')
Crequest = Request(method='PUT', url='coap://device.local/led')
Drequest = coap.put('coap://device.local/led')
Show answer

Answer: A CoAP uses code=PUT for resource updates (like HTTP PUT).

iotclass.org

Retrieval practice

Recall check 4 of 6

Broker Bex says: answer from memory, then check your reasoning.

Q4A facility manager is deploying a new CoAP-based building automation system. There are 200 sensors from 3 different manufacturers. The installer wants to avoid manually configuring each sensor's IP address into the central management system. Which CoAP feature enables automatic sensor onboarding?

ACoAP Observe - sensors automatically register with the management system
BDTLS authentication - sensors authenticate themselves to the management system
CBlock-wise transfer - sensors send their configuration in blocks during setup
DResource discovery at /.well-known/core using a multicast query
Show answer

Answer: D Correct!

iotclass.org

Retrieval practice

Recall check 5 of 6

Broker Bex says: answer from memory, then check your reasoning.

Q5An IoT architect is designing a smart parking system. Parking sensors detect car presence and need to update a central server. The system has these requirements: (1) Sensors are battery-powered with 5-year target life, (2) Updates are infrequent (only when state changes: car arrives/leaves), (3) No broker infrastructure exists, (4) Each sensor needs a unique addressable endpoint for maintenance. Which protocol best fits these requirements?

AMQTT with QoS 1 - reliable delivery and efficient for infrequent updates
BCoAP.
CHTTP REST API - familiar to developers and provides addressable endpoints
DWebSocket - bidirectional communication for real-time updates
Show answer

Answer: B Correct!

iotclass.org

Retrieval practice

Recall check 6 of 6

Broker Bex says: answer from memory, then check your reasoning.

Q6Place each CoAP multicast responsibility where it lives so you can discover many constrained servers without causing an acknowledgement storm.

AScoped Group Address
BNON Multicast GET
CEligible Servers Evaluate
DLeisurely Unicast Replies
Show answer

Answer: A Place each CoAP multicast responsibility where it lives so you can discover many constrained servers without causing an acknowledgement storm.

iotclass.org

Print reference

Answers

Answer key.

  1. B · Correct!
  2. B · Correct!
  3. A · CoAP uses code=PUT for resource updates (like HTTP PUT).
  4. D · Correct!
  5. B · Correct!
  6. A · Place each CoAP multicast responsibility where it lives so you can discover many constrained servers without causing an acknowledgement storm.
iotclass.org