• Home
Name Date Size #Lines LOC

..--

config/12-May-2024-386257

.gitignoreD12-May-2024159 119

MakefileD12-May-20248.4 KiB274204

READMED12-May-20243 KiB8059

client-coap.cD12-May-20246.6 KiB241189

client-coap.hD12-May-2024740 306

client.cD12-May-20244.1 KiB14773

server-coap.cD12-May-20246.6 KiB224167

server-coap.hD12-May-2024609 256

server.cD12-May-20244.2 KiB15076

README

1Example of libcoap running on lwIP
2==================================
3
4To run the server example, do
5
6    $ make
7    $ sudo ./server                 # No TinyDTLS support
8       or
9    $ sudo ./server-dtls            # With TinyDTLS support
10
11(and in a second terminal)
12
13    $ sudo ip a a dev tap0 192.168.113.1/24
14
15and query `coap://192.168.113.2/time?ticks` with any coap tool,
16or query `coap://192.168.113.2/.well-known/core`.
17(If server-dtls is running, you can use coaps:// as appropriate.)
18
19This will
20
21* download lwip and lwip-contrib from the upstream git sources
22* build the server application
23* run the server application, creating a virtual network device tap0 (unless
24  that exists)
25* configure your network interface to make the server accessible.
26
27* return the appropriate response from the server to the client.
28
29The server supports the following options
30"-k PSK" option where PSK defines the DTLS PSK to use (default is "secretPSK").
31         (Only works for server-dtls.)
32"-v level" option where logging "level" can be 0 to 7 (default is 4).
33"-V level" option where DTLS logging "level" can be 0 to 7 (default is 3).
34           (Only works for server-dtls.)
35
36The server creates a resource for 'time' with a query 'ticks'.  This is
37reported for `.well-known/core`. The work flow for adding more resources does
38not differ from regular libcoap usage. If you seem to run out of memory
39creating the resources, tweak the number of pre-allocated resources
40in `config/lwippools.h`.
41
42To run the client example
43
44    $ make
45    $ sudo ./client                 # No TinyDTLS support
46       or
47    $ sudo ./client-dtls            # With TinyDTLS support
48
49As client (or client-dtls) tries to connect to coap://libcoap.net/, the tap0
50interface will need IP forwarding enabled
51
52    $ sudo sysctl -w net.ipv4.conf.default.forwarding=1
53
54Then you will need IP forwarding enabled on your public interface
55(where eth0 is replaced by your public facing interface name)
56for response packets
57
58    $ sudo sysctl -w net.eth0.conf.default.forwarding=1
59
60As well as the interface connecting to the internet will need a NAT rule to
61masquerade the internal IP address (192.168.114.2) to the IP of the outgoing
62interface (where eth0 is replaced by your public facing interface name)
63
64    $ iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
65
66The client supports the following options
67"-k PSK" option where PSK defines the DTLS PSK to use (default is "secretPSK").
68         (Only works for client-dtls.)
69"-u id" option where id defines the DTLS id to use (default is "abc").
70         (Only works for client-dtls.)
71"-v level" option where logging "level" can be 0 to 7 (default is 4).
72"-V level" option where DTLS logging "level" can be 0 to 7 (default is 3).
73           (Only works for client-dtls.)
74
75The client supports an optional parameter which is the CoAP URI to connect to
76.e.g "coap://libcoap.net/.well-known/core".  The default
77is "coap://libcoap.net/" for client and client-dtls.
78Using "coaps://libcoap.net" will establish a DTLS session if there is
79DTLS support compiled in (client-dtls).
80