---
title: "W55RP20 COAP Server example"
url: "https://maker.wiznet.io/Aimee0/projects/w55rp20-coap-server-example/"
markdown_url: "https://maker.wiznet.io/Aimee0/projects/w55rp20-coap-server-example/md"
type: "WCC: WIZnet Created Content"
author: "Aimee"
author_url: "https://maker.wiznet.io/Aimee0/"
original_author: "Aimee"
published: "2024-10-29"
language: "en"
hardware: ["WIZnet W55RP20"]
likes: 0
views: 700
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# W55RP20 COAP Server example

> This is an example of acting as an COAP server using W55RP20-EVB-Pico.

Original author: Aimee

## Components

- **WIZnet W55RP20** x 1 ([docs](https://wiznet.io/products/ionic-chips/w55rp20))

## Documents and links

- [W55RP20 coap server example](https://github.com/WIZnet-ioNIC/WIZnet-PICO-COAP_C/tree/main/examples/coap_server) (code)

## Article

github link : <https://github.com/WIZnet-ioNIC/WIZnet-PICO-COAP_C/tree/main/examples/coap_server>

#### How to test COAP server example

**Setup board configuration**

Setup board to W55RP20_EVB_PICO in CMakeLists.txt in WIZnet-PICO-COAP_C/ directory.

```plaintext
# Set board
#set(BOARD_NAME WIZnet_Ethernet_HAT)
#set(BOARD_NAME W5100S_EVB_PICO)
#set(BOARD_NAME W5500_EVB_PICO)
set(BOARD_NAME W55RP20_EVB_PICO)
#set(BOARD_NAME W5100S_EVB_PICO2)
#set(BOARD_NAME W5500_EVB_PICO2)
```

**Setup network settings**

Setup network configuration such as IP in 'w5x00_coap_server.c' which is the COAP Server example in 'WIZnet-PICO-COAP_C/examples/coap_server/' directory.

```plaintext
/* Network */
static wiz_NetInfo g_net_info =
    {
        .mac = {0x00, 0x08, 0xDC, 0x12, 0x34, 0x56}, // MAC address
        .ip = {192, 168, 11, 2},                     // IP address
        .sn = {255, 255, 255, 0},                    // Subnet Mask
        .gw = {192, 168, 11, 1},                     // Gateway
        .dns = {8, 8, 8, 8},                         // DNS server
        .dhcp = NETINFO_STATIC                       // DHCP enable/disable
};
```

**Setup coap server configuration**

Setup coap server configuration in 'endpoints.c' in 'WIZnet-PICO-COAP_C/examples/coap_server/' directory.

```plaintext
static const coap_endpoint_path_t path_well_known_core = {2, {".well-known", "core"}};
static int handle_get_well_known_core(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo)
{
    return coap_make_response(scratch, outpkt, (const uint8_t *)rsp, strlen(rsp), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT);
}
 ...
const coap_endpoint_t endpoints[] =
{
    {COAP_METHOD_GET, handle_get_well_known_core, &path_well_known_core, "ct=40"},
    {COAP_METHOD_GET, handle_get_example_data, &path_example_data, "ct=0"},
    {COAP_METHOD_PUT, handle_put_example_data, &path_example_data, NULL},
    {(coap_method_t)0, NULL, NULL, NULL}
};
```

**Setup coap client program**

Download libcoap program

```
$ git clone https://github.com/obgm/libcoap.git
$ cd libcoap
$ git checkout main
```

Build libcoap program

```
$ cmake -E remove_directory build
$ cmake -E make_directory build
$ cd build
$ cmake .. -DENABLE_TESTS=ON
$ cmake --build .
$ cd Debug
```

If the build is successful, the programs coap-server.exe and coap-client.exe will appear as shown below.

[![1-1](https://private-user-images.githubusercontent.com/150221423/370624876-22446f1c-0754-4bf7-bf21-5a1921986933.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzAxNzU1NTAsIm5iZiI6MTczMDE3NTI1MCwicGF0aCI6Ii8xNTAyMjE0MjMvMzcwNjI0ODc2LTIyNDQ2ZjFjLTA3NTQtNGJmNy1iZjIxLTVhMTkyMTk4NjkzMy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSz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Run**

If the COAP Server example works normally , you can see the network information.

![](https://maker.wiznet.io/upload/ckeditor5/50543170%5F1730208614%2Epng)

Execute libcoap client program and run coap client.

![](https://maker.wiznet.io/upload/ckeditor5/50543170%5F1730208648%2Epng)

Wireshark packet capture.

![](https://maker.wiznet.io/upload/ckeditor5/50543170%5F1730208689%2Epng)

---

Source: https://maker.wiznet.io/Aimee0/projects/w55rp20-coap-server-example/
