技术标签: libcoap NB-IOT coap centos IOT
COAP(Constrained Application Protocol)是一种在物联网世界的类web协议,它的详细规范定义在 RFC 7252。CoAP是一种应用层协议,它运行于UDP协议之上而不是像HTTP那样运行于TCP之上。COAP名字翻译来就是“受限应用协议”,顾名思义,使用在资源受限的物联网设备上。物联网设备的ram,rom都通常非常小,运行TCP和HTTP是不可以接受的。CoAP协议非常小巧,最小的数据包仅为4字节,其是一个好的解决方案。
COAP协议特点
1 COAP协议网络传输层由TCP改为UDP。
2 它基于REST,server的资源地址和互联网一样也有类似url的格式,客户端同样有POST,GET,PUT,DELETE方法来访问server,对HTTP做了简化。
3 COAP是二进制格式的,HTTP是文本格式的,COAP比HTTP更加紧凑。
4 轻量化,COAP最小长度仅仅4B,一个HTTP的头都几十个B了。
5 支持可靠传输,数据重传,块传输。 确保数据可靠到达。
6 支持IP多播, 即可以同时向多个设备发送请求。
7 非长连接通信,适用于低功耗物联网场景。
COAP消息类型
COAP 采用的的类似于http的请求响应工作模式,它总共有四种不同的消息类型
开源的Coap源码比较多,具体见链接。
因用在linux系统,选择libcoap。
系统:linux centos7
终端运行
安装目录一般放到/usr/local
cd /usr/local
git clone http://github.com/obgm/libcoap
cd libcoap
./autogen.sh
./configure -enable-documentation=no -enable-tests=no
但是还是提示程序中缺少 a2x错误,需要执行
./configure -enable-documentation=no -enable-manpages=no
稍后提示
checking for OpenSSL... yes
checking for compatible OpenSSL version (>= 1.1.0)... no
configure: error: ==> OpenSSL 1.0.1e too old. OpenSSL >= 1.1.0 required for suitable DTLS support build.
OpenSSL 1.0.1e is too old,需要升级.
查看当前版本
openssl version
或者使用
yum info openssl
在升级之前检查一下openssl的路径
which openssl
因为需要在升级openssl之后,我们需要使用软链接将其链接回此路径
1.下载与解压
安装目录一般放到/usr/local
cd /usr/local
wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz
tar -xzf openssl-1.1.0f.tar.gz
2.编译与安装
如果没有安装gcc可能会报错,可以直接使用yum安装一下gcc
yum install gcc
cd openssl-1.1.0f
./config
make
make install
3.尝试运行/usr/local/bin/openssl version
应该会出现下面的这个错误:
/usr/local/bin/openssl: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory
4.下面为相关的解决办法:
备份
mv /usr/bin/openssl /usr/bin/openssl.OFF
mv /usr/include/openssl /usr/include/openssl.OFF
创建链接至libssl
将安装好的openssl 的openssl命令软连到/usr/bin/openssl
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
将安装好的openssl 的openssl目录软连到/usr/include/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
echo “/usr/local/openssl/lib”>>/etc/ld.so.conf
ldconfig -v
openssl version –a
还是提示:
/usr/local/bin/openssl: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory
5.创建链接至新的openssl
ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/
ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/
ln -s /usr/local/bin/openssl /usr/bin/openssl_latest
6.检查openssl_latest的版本号是否是新的版本
openssl_latest version
OpenSSL 1.1.0f 25 May 2017
7.重命名旧的openssl文件名,并且将新的文件名改为openssl
cd /usr/bin/
mv openssl openssl_old
mv openssl_latest openssl
8、至此更新完成
再次用openssl version命令查看openssl的版本
[root@localhost bin]# openssl version
OpenSSL 1.1.0f 25 May 2017
OpenSSL安装成功之后,依然提示版本过低
[root@localhost bin]# openssl version
OpenSSL 1.1.0f 25 May 2017
[root@localhost bin]# cd /root/libcoap
[root@localhost libcoap]# ./configure -enable-documentation=no -enable-tests=no
...............
checking whether the linker accepts -Wl,--version-script=./libcoap-2.map... yes
checking for GnuTLS... no
checking for OpenSSL... yes
checking for compatible OpenSSL version (>= 1.1.0)... no
configure: error: ==> OpenSSL 1.0.1e too old. OpenSSL >= 1.1.0 required for suitable DTLS support build.
[root@localhost libcoap]# pkg-config --modversion openssl
1.0.1e
查看libcoap中的configure文件发现,系统查找路径使用的pkg-configure
[root@localhost libcoap]# echo $PKG_CONFIG_PATH
[root@localhost libcoap]#
[root@localhost libcoap]# find / -name pkgconfig
/root/LNMP/lnmp1.4-full/src/openssl-1.0.2l/.openssl/lib/pkgconfig
/usr/lib64/pkgconfig
/usr/share/pkgconfig
/usr/local/lib64/pkgconfig
/usr/local/freetype/lib/pkgconfig
[root@localhost libcoap]#
[root@localhost libcoap]# pkg-config --modversion openssl
1.0.1e
[root@localhost libcoap]# export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib64/pkgconfig
[root@localhost libcoap]# pkg-config --modversion openssl
1.1.0f
[root@localhost libcoap]# ./configure -enable-documentation=no -enable-tests=no
libcoap configuration summary:
libcoap package version : "4.2.0"
libcoap library version : "1.0.1"
libcoap API version : "2"
libcoap DTLS lib extn : "-openssl"
host system : "x86_64-unknown-linux-gnu"
build DTLS support : "yes"
--> OpenSSL around : "yes" (found OpenSSL 1.1.0f)
OPENSSL_CFLAGS : " "
OPENSSL_LIBS : "-lssl -lcrypto "
build doxygen pages : "no"
build man pages : "no"
build unit test binary : "no"
build examples : "yes"
build with gcov support : "no"
编译和安装
make
make install
错误备注:
make
collect2: error: ld returned 1 exit status
make[1]: *** [coap-client] 错误 1
make[1]: 离开目录“/root/libcoap/examples”
make: *** [install-recursive] 错误 1
这个错误时Openssl版本更改错误,不能直接复制新版本openssl.pc覆盖就版本的
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/root/libcoap/examples”
make[1]: 离开目录“/root/libcoap/examples”
[root@localhost libcoap]# cd ./example
bash: cd: ./example: 没有那个文件或目录
[root@localhost libcoap]# cd ./examples
[root@localhost examples]# ./coap-server
另开启一个终端:
[root@localhost ~]# cd ./libcoap/examples
[root@localhost examples]# ./coap-client
lt-coap-client v4.2.0 -- a small CoAP implementation
Copyright (C) 2010-2019 Olaf Bergmann <[email protected]> and others
TLS Library: OpenSSL - runtime 1.1.0f, libcoap built for 1.1.0f
Usage: lt-coap-client [-a addr] [-b [num,]size] [-e text] [-f file] [-l loss]
[-m method] [-o file] [-p port] [-r] [-s duration] [-t type]
[-v num] [-A type] [-B seconds] [-K interval] [-N] [-O num,text]
[-P addr[:port]] [-T token] [-U]
[[-k key] [-u user]]
[[-c certfile] [-C cafile] [-R root_cafile]] URI
URI can be an absolute URI or a URI prefixed with scheme and host
General Options
-a addr The local interface address to use
-b [num,]size Block size to be used in GET/PUT/POST requests
(value must be a multiple of 16 not larger than 1024)
If num is present, the request chain will start at
block num
-e text Include text as payload (use percent-encoding for
non-ASCII characters)
-f file File to send with PUT/POST (use '-' for STDIN)
-l list Fail to send some datagrams specified by a comma
separated list of numbers or number ranges
(for debugging only)
-l loss% Randomly fail to send datagrams with the specified
probability - 100% all datagrams, 0% no datagrams
-m method Request method (get|put|post|delete|fetch|patch|ipatch),
default is 'get'
-o file Output received data to this file (use '-' for STDOUT)
-p port Listen on specified port
-r Use reliable protocol (TCP or TLS)
-s duration Subscribe to / Observe resource for given duration
in seconds
-t type Content format for given resource for PUT/POST
-v num Verbosity level (default 3, maximum is 9). Above 7,
there is increased verbosity in GnuTLS logging
-A type Accepted media type
-B seconds Break operation after waiting given seconds
(default is 90)
-K interval send a ping after interval seconds of inactivity
(TCP only)
-N Send NON-confirmable message
-O num,text Add option num with contents text to request
-P addr[:port] Use proxy (automatically adds Proxy-Uri option to
request)
-T token Include specified token
-U Never include Uri-Host or Uri-Port options
PSK Options (if supported by underlying (D)TLS library)
-k key Pre-shared key for the specified user
-u user User identity for pre-shared key mode
PKI Options (if supported by underlying (D)TLS library)
-c certfile PEM file containing both CERTIFICATE and PRIVATE KEY
This argument requires (D)TLS with PKI to be available
-C cafile PEM file containing the CA Certificate that was used to
sign the certfile. This will trigger the validation of
the server certificate. If certfile is self-signed (as
defined by '-c certfile'), then you need to have on the
command line the same filename for both the certfile and
cafile (as in '-c certfile -C certfile') to trigger
validation
-R root_cafile PEM file containing the set of trusted root CAs that
are to be used to validate the server certificate.
The '-C cafile' does not have to be in this list and is
'trusted' for the verification.
Alternatively, this can point to a directory containing
a set of CA PEM files
Examples:
coap-client -m get coap://[::1]/
coap-client -m get coap://[::1]/.well-known/core
coap-client -m get coap+tcp://[::1]/.well-known/core
coap-client -m get coaps://[::1]/.well-known/core
coap-client -m get coaps+tcp://[::1]/.well-known/core
coap-client -m get -T cafe coap://[::1]/time
echo -n 1000 | coap-client -m put -T cafe coap://[::1]/time -f -
[root@localhost examples]# ./coap-client -m get coap://127.0.0.1/
This is a test server made with libcoap (see https://libcoap.net)
Copyright (C) 2010--2019 Olaf Bergmann <[email protected]> and others
说明安装成功
也可以再谷歌浏览器中安装copper插件,具体见教程链接
输入相应的地址,使用get可以获得一下信息(备注:这是云服务器测试图)
安装的难点是小白型详细介绍资料极少,报错不知道如何处理。
文章浏览阅读1.3k次。1、题目1090:路径打印时间限制:1 秒内存限制:32 兆特殊判题:否提交:1319解决:230题目描述:给你一串路径,譬如:a\b\ca\d\eb\cstd\你把这些路径中蕴含的目录结构给画出来,子目录直接列在父目录下面,并比父目录向右缩一格,就像这样:a b c d eb cstd同一级的需要按字母顺序_打印目录结构 leetcode
文章浏览阅读591次。There is a wonderful tutorial Building SAP Fiori-like UIs with SAPUI5 in 10 Exercises written by Bertram Ganz.In this blog, I will show step by step how to package the UI5 application built by this tutorial as a native application into your Android device_fiori发布安卓
文章浏览阅读182次。目录第7章 1 不用额外变量交换两个整数的值(士 ★☆☆☆) 2 不用任何比较判断找出两个数中较大的数(校★★★☆) 3 只用位运算不用算术运算实现整数的加减乘除运算 4 整数的二进制表达中有多少个1 5 在其他数都出现偶数次的数组中找到出现奇数次的数 6 在其他数都出现A次的数组中找到只出现一次的数第8章 1 转圈打印矩阵 2 将正方形矩阵顺时针转动90度 3 之..._if (map.containskey(xor)) { int pre = map.get(xor); mosts[i] = pre =
文章浏览阅读152次。AC自动机上的dp
文章浏览阅读871次。C++中 sprintf函数的用法1.常用方式sprintf函数的功能与printf函数的功能基本一样,只是它把结果输出到指定的字符串中了,看个例子就明白了:例:将”test 1 2”写入数组s中#include<stdio.h>int main(int argc, char *avgv[]){ char s[40]; sprintf(s,"%s%d..._sprintf %c
文章浏览阅读2.2k次。医院门诊系统,挂号预约系统,有四个角色(管理员,医生,护士,普通用户)_医院预约挂号er图
文章浏览阅读818次。如果要跑通demo首先: 服务端我是用 intellij idea 开发的。如果用其他软件打跑不起来就用 intellij其次: 要将手机跟电脑连在同个网络下最后: Constants的ip地址要填写上电脑的ip地址实现功能:客户端连接服务端,客户端发数据到服务端,客户端收到服务端发来的数据服务端收到客户端发的数据,服务端发数据给客户端贴部分核心代码客户端连接服务端:首先客户端连接服务端必须要在线程里(后面的是 ip地址 跟端口,端口是服务端的socke..._android socket客户端下载
文章浏览阅读1.3k次,点赞4次,收藏7次。壁纸在文末先上几张美化后的照片 主题链接win 10 美化相信很多人都厌倦了win10原装主题了,陈旧的窗口边框,一如既往的图标,老掉牙的窗口样式和菜单栏……算了,就不吐槽了,直接上教程吧!前方高能第零步关掉杀毒软件(新手建议卸载),这点非常重要,如某数字,某讯,某霸,如果关掉以后放心不下自己电脑的安全,以下文章请勿食用!(后果自负)第一步破解原装win10系统主题。友..._win10联想 自带主题
文章浏览阅读57次。 Lazy Load 是一个用 JavaScript 编写的 jQuery 插件. 它可以延迟加载长页面中的图片. 在浏览器可视区域外的图片不会被载入, 直到用户将页面滚动到它们所在的位置. 这与图片预加载的处理方式正好是相反的.在包含很多大图片长页面中延迟加载图片可以加快页面加载速度. 浏览器将会在加载可见图片之后即进入就绪状态. 在某些情况下还可以帮助降低服务器负担。一、下载和引用 ..._jq.lazyload.js配置
文章浏览阅读404次。一.cmake升级https://cmake.org/download/ #cmake下载地址 yum install jsoncpp-0.10.5-2.el7.x86_64.rpm jsoncpp-devel-0.10.5-2.el7.x86_64.rpm -y yum install cmake3-3.6.1-2.el7.x86_64.rpm cmake3-data-3.6.1-2.el7.noarch.rpm -y二.mysql编译安装升级gcctar zxf mysql-boost-_172.25.2.1
文章浏览阅读737次。标题中的英文首字母大写比较规范,但在python实际使用中均为小写。1.Numpy中的matrix1.1 创建matrix对象numpy.matrix方法的参数可以为ndarray对象numpy.matrix方法的参数也可以为字符串str,示例如下:import numpy as npm = np.matrix("1 2 3;4 5 6; 7 ..._numpy线性代数运算
文章浏览阅读3.7k次。源码方式,搭建LAMP环境。_this software is subject to the php license, available in this | | distribut