下载
笔者一开始通过在网上搜索,直接下载的wakaama源码包。
为接下来的编译埋了坑:cmake会提示如下错误。
CMake Error at wakaama.cmake:104 (message):
lwm2mclient_tinydtls: tinydtls support requested, but submodule not checked out
Call Stack (most recent call first):
examples/client/CMakeLists.txt:33 (target_sources_shared)
![](https://img-blog.csdnimg.cn/img_convert/534a707a7de758135b8bce3bd2652357.png)
通过阅读sdk中的README.md文档后得知:
## Checking out the code
### Using Wakaama as library
```
git clone https://github.com/eclipse/wakaama.git
```
### Working on WakaamaWhen working on Wakaama itself, or intending to run the example client application, submodules must be checked out:
```
git clone --recurse-submodules https://github.com/eclipse/wakaama.git
```
所以正确的做法是安装git然后clone:
git clone --recurse-submodules https://github.com/eclipse/wakaama.git
编译
参考网上给的编译步骤:
cmake example/client
make
由于笔者用的是原生ubuntu 16.04,没有编译需要的cmake,需要安装。
The program 'cmake' is currently not installed. You can install it by typing:
sudo apt install cmake
![](https://img-blog.csdnimg.cn/img_convert/9ebc46fc3b8c114c9b6f7acaf560c467.png)
参考:CMAKE工具学习 - 清风(Breeze.Wu) - 博客园 (cnblogs.com)
由于wakaama编译对cmake版本有要求,需要高于3.13,建议下载官网最新源码包,编译安装。笔者先是用apt安装的,默认版本太低为3.5.1。
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
CMake 3.13 or higher is required. You are running version 3.5.1
-- Configuring incomplete, errors occurred!
配置cmake编译环境时又有个坑:提示缺少OpenSSL,需要安装libssl-dev库,而不是禁掉,否则会影响wakaama的编译
./configure
![](https://img-blog.csdnimg.cn/img_convert/ba1185ed998dbd5a76a618ee764d4cd6.png)
CMake Error at Utilities/cmcurl/CMakeLists.txt:608 (message):
Could not find OpenSSL. Install an OpenSSL development package or
configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.
-- Configuring incomplete, errors occurred!
openssl问题参考:(33条消息) 在Linux中安装Cmake过程中,遇到有关于openSSL的问题_monopolizing的博客-CSDN博客_cmake openssl
openssl version -a
sudo apt-get install libssl-dev
./configure
make -j4
sudo make install
cmake --version
![](https://img-blog.csdnimg.cn/img_convert/4d59d66f204df645617ab3f968bb04e6.png)
cmake已成功更新到3.25.2版本。继续编译wakaama源码,又报了缺少git的错误。
![](https://img-blog.csdnimg.cn/img_convert/331ccd43bb20f3cce58008a28ea5a0b7.png)
如下指令安装git:
sudo apt install git
git --version
继续编译wakaama源码,由于笔者是下载的压缩包源码,编译会报一开始提到的错误。重新clone代码
git clone --recurse-submodules https://github.com/eclipse/wakaama.git
再编译,cmake已经成功了。
peter@peter-vm-pc:~/wakaama_clt$ cmake examples/client/
-- The C compiler identification is GNU 5.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- lwm2mclient: Endiannes not set, defaulting to little endian
-- lwm2mclient: Default CoAP block size not set, using 1024
-- lwm2mclient_tinydtls: Endiannes not set, defaulting to little endian
-- lwm2mclient_tinydtls: Default CoAP block size not set, using 1024
-- Found Git: /usr/bin/git (found version "2.7.4")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/peter/wakaama_clt
make阶段又报错了
cc1: error: -Werror=absolute-value: no option -Wabsolute-value
一开始尝试将gcc升级到最新版本,问题没有解决。经查找源码,发现是在wakaama.cmake文件中将参数-Werror=absolute-value自动分发给了各个子模块,将其disable后继续编译。
![](https://img-blog.csdnimg.cn/img_convert/c540943cb21d9b3a2718322568fd644c.png)
至此client编译成功了,可执行lwm2mclient /?验证。
peter@peter-vm-pc:~/wakaama_clt$ ./lwm2mclient /?
Usage: lwm2mclient [OPTION]
Launch a LWM2M client.
Options:
-n NAME Set the endpoint name of the Client. Default: testlwm2mclient
-l PORT Set the local UDP port of the Client. Default: 56830
-h HOST Set the hostname of the LWM2M Server to connect to. Default: localhost
-p PORT Set the port of the LWM2M Server to connect to. Default: 5683
-4 Use IPv4 connection. Default: IPv6 connection
-t TIME Set the lifetime of the Client. Default: 300
-b Bootstrap requested.
-c Change battery level over time.
-S BYTES CoAP block size. Options: 16, 32, 64, 128, 256, 512, 1024. Default: 1024
出于简单粗暴,笔者另外拷贝了一份源码,单独编译了server模块。
peter@peter-vm-pc:~/wakaama_svr$ cmake examples/server/
-- lwm2mserver: Endiannes not set, defaulting to little endian
-- lwm2mserver: Default CoAP block size not set, using 1024
-- Configuring done
-- Generating done
-- Build files have been written to: /home/peter/wakaama_svr
peter@peter-vm-pc:~/wakaama_svr$ make
[100%] Built target lwm2mserver
peter@peter-vm-pc:~/wakaama_svr$ ./lwm2mserver /?
Usage: lwm2mserver [OPTION]
Launch a LWM2M server on localhost.
Options:
-4 Use IPv4 connection. Default: IPv6 connection
-l PORT Set the local UDP port of the Server. Default: 5683
-S BYTES CoAP block size. Options: 16, 32, 64, 128, 256, 512, 1024. Default: 1024
测试
【服务端】
./lwm2mserver -4
>
#客户端连接后log
194 bytes received from [127.0.0.1]:56830
44 02 D4 B6 B6 D4 47 77 B2 72 64 11 28 39 6C 77 D.....Gw.rd.(9lw
6D 32 6D 3D 31 2E 31 0D 04 65 70 3D 50 65 74 65 m2m=1.1..ep=Pete
72 4C 77 6D 32 6D 54 65 73 74 03 62 3D 55 06 6C rLwm2mTest.b=U.l
74 3D 33 30 30 FF 3C 2F 3E 3B 72 74 3D 22 6F 6D t=300.</>;rt="om
61 2E 6C 77 6D 32 6D 22 3B 63 74 3D 31 31 30 2C a.lwm2m";ct=110,
3C 2F 31 3E 3B 76 65 72 3D 31 2E 31 2C 3C 2F 31 </1>;ver=1.1,</1
2F 30 3E 2C 3C 2F 32 2F 30 3E 2C 3C 2F 33 2F 30 /0>,</2/0>,</3/0
3E 2C 3C 2F 34 2F 30 3E 2C 3C 2F 35 2F 30 3E 2C >,</4/0>,</5/0>,
3C 2F 36 2F 30 3E 2C 3C 2F 37 2F 30 3E 2C 3C 2F </6/0>,</7/0>,</
33 31 30 32 34 3E 3B 76 65 72 3D 31 2E 30 2C 3C 31024>;ver=1.0,<
2F 33 31 30 32 34 2F 31 30 3E 2C 3C 2F 33 31 30 /31024/10>,</310
32 34 2F 31 31 3E 2C 3C 2F 33 31 30 32 34 2F 31 24/11>,</31024/1
32 3E 2>
New client #0 registered.
Client #0:
name: "PeterLwm2mTest"
version: "1.1"
binding: "UDP"
lifetime: 300 sec
objects: /1 (1.1), /1/0, /2/0, /3/0, /4/0, /5/0, /6/0, /7/0, /31024 (1.0), /31024/10, /31024/11, /31024/12,
【客户端】
peter@peter-vm-pc:~/wakaama_clt$ ./lwm2mclient -n PeterLwm2mTest -4
Trying to bind LWM2M Client to port 56830
LWM2M Client "PeterLwm2mTest" started on port 56830
> Opening connection to server at 127.0.0.1:5683
-> State: STATE_REGISTERING
13 bytes received from [127.0.0.1]:5683
64 41 D4 B6 B6 D4 47 77 82 72 64 01 30 dA....Gw.rd.0
-> State: STATE_READY