Wiznet makers

Aimee0

Published October 29, 2024 ©

17 UCC

10 WCC

8 VAR

0 Contests

0 Followers

0 Following

W55RP20 COAP Server example

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

COMPONENTS Hardware components

WIZnet - W55RP20

x 1


PROJECT DESCRIPTION

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.

# 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.

/* 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.

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

 

Build & Run

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

Execute libcoap client program and run coap client.

Wireshark packet capture.

 

 

Documents
  • W55RP20 coap server example

Comments Write