1.下载源码包
到官网下载源码:https://libcoap.net/install.html
解压源码包:unzip libcoap-main.zip
2. 安装必要的工具
brew install autoconf
brew install automake
brew install pkg-config
brew install libtool
brew install doxygen
3. 编译
cd libcoap-main/
./autogen.sh
./configure --disable-manpages --disable-dtls
以上添加的两个 disable 是因为未能解决依赖的 a2x 工具以及 tls 相关库,如果你解决了就可以不添加了。
make
make install
4. 运行示例
刚 make insll 完,可能需要开一个新的终端,以下命令才可以顺利执行。
启动服务端:coap-server -A 127.0.0.1 -p 5683
使用客户端执行 get 方法:coap-client -m get coap://127.0.0.1/.well-known/core
客户端的输出:</>;title="General Info";ct=0,</time>;if="clock";rt="ticks";title="Internal Clock";ct=0;obs,</async>;ct=0,</example_data>;title="Example Data";ct=0;obs