iot平台异构对接文档
iot平台异构对接文档
准备工作
- 平台提供的XAgent开发指南.pdf
- demo程序xagent-ptp-demo
- 平台上添加产品得到产品id和key
- 部署时需要插件的基础程序《xlink-xagent.zip》
第一步:添加新产品
添加新产品得到产品ID和产品key
1创建产品
2创建数据端点
3注册设备
第一步:创建插件工程
创建一个maven工程,并引入java 包xlink-xagent.jar,xagent-api-x.y.z.jar,
netty-buffer-4.1.8.Final.jar, netty-common.4.1.8.Final.jar, pf4j-2.0.0.jar。
在打包ptp插件时,前面提到的引入的jar包都不需要添加进去。
pom.xml的配置
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>xlink.xagent</groupId>
<artifactId>xagent-ptp-demo</artifactId>
<version>0.0.1</version>
<name>xagent-ptp-demo</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<plugin.id>ptp_demo</plugin.id>
<plugin.class>xlink.xagent.ptp.demo.main.ILockPlugin</plugin.class>
<plugin.version>0.0.1</plugin.version>
<plugin.provider>xlink</plugin.provider>
<plugin.dependencies/>
</properties>
<dependencies>
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>xlink.xagent</groupId>
<artifactId>xagent-api</artifactId>
<version>0.0.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/xagent-api-0.0.3.jar</systemPath>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.8.Final</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
<!--xagent appliaction dependency -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.12.1.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.9.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.slf4j</groupId>-->
<!--<artifactId>slf4j-log4j12</artifactId>-->
<!--<version>1.7.5</version>-->
<!--</dependency>-->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.28</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.apache.tomcat</groupId> -->
<!-- <artifactId>tomcat-util</artifactId> -->
<!-- <version>9.0.1</version> -->
<!-- </dependency> -->
<!--xagent appliaction dependency end-->
</dependencies>
<build>
<resources>
<resource>
<filtering>false</filtering>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>unzip jar file</id>
<phase>package</phase>
<configuration>
<target>
<unzip src="target/${artifactId}-${version}.${packaging}"
dest="target/plugin-classes"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptors>
<descriptor>
src/main/assembly/assembly.xml
</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifestFile>target/plugin-classes/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifestEntries>
<Plugin-Id>${plugin.id}</Plugin-Id>
<Plugin-Class>${plugin.class}</Plugin-Class>
<Plugin-Version>${plugin.version}</Plugin-Version>
<Plugin-Provider>${plugin.provider}</Plugin-Provider>
<Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
第二步:创建配置类
可以创建一个PtpConfig.java文件,在插件启动类中使用。设置必填的配置
public class ProductConfig {
//产品id
public static final String PRODUCT_ID = "1607d4ba3a9a00011607d4ba3a9a2201";
//产吕key
public static final String PRODUCT_KEY = "6a67e0a37ab925d5953544d5dcd893ca";
//PTP插件服务的端口
public static final int SERVER_PORT = 33799;
//PTP与设备的心跳时间,如果设备端在指定时间60秒内没有与PTP通讯,PTP会自动断掉与此设备的连接。
public static final int SERVER_HEART_SECONDS = 60;
//TCP的通讯模式。
public static final PtpServerStrategy SERVER_STRATEGY = PtpServerStrategy.TCP;
}
第三步:创建解码器
创建一个私有协议的解码器,用于解析厂商私有协议,必须实现IPtpDecoder接口
public class Decoder implements IPtpDecoder {
private static final Logger logger = LoggerFactory.getLogger(Decoder.class);
@Override
public void doDecode(ByteBuf in, List<Object>
out) throws PtpException {
int size = in.readableBytes();
byte[] data = new byte[size];
in.readBytes(data);
// TODO
out.add(new
DemoMessage(Unpooled.wrappedBuffer(data)));
}
}
第四步:创建编码器
创建一个私有协议的编码器,用于编码厂商私有协议,必须实现IPtpEncoder接口
public class Encoder implements IPtpEncoder {
private static final Logger logger = LoggerFactory.getLogger(Encoder.class);
@Override
public ByteBuf doEncode(ByteBufAllocator
byteBufAllocator, IPtpMessage message,
List<Object> out) {
DemoMessage demoMsg = (DemoMessage)
message;
ByteBuf buf = demoMsg.toValue();
out.add(buf);
return demoMsg.toValue();
}
}
第五步:创建处理器
创建业务处理器,用于处理厂商业务,必须实现IPtpProtocolProcessor
public class DemoProcessor implements
IPtpProtocolProcessor {
@Override
public void process(PtpServer server, int
channelId, Object msg) {
IPtpMessage iPtpMsg = (IPtpMessage)msg;
// TODO
}
@Override
public void channelBuild(int channelId) {
// TODO channel
}
@Override
public void channelClose(int channelId) {
// TODO channel
}
}
第六步:创建插件启动类
创建插件启动类,必须继承Plugin类;该类包含两个主要类PtpServer和XagentApi,其中
XagentApi主要用于操作上行数据,如上报数据端点;PtpServer主要用于操作下行数据,
如给设备下发数据
public class ILockPlugin extends Plugin {
private static final Logger logger = LoggerFactory.getLogger(ILockPlugin.class);
// ptp server 对象
public static PtpServer ptpServer;
// xagent操作对象
private static XagentApi xagent;
private PluginWrapper wrapper;
public ILockPlugin(PluginWrapper wrapper) {
super(wrapper);
this.wrapper = wrapper;
}
@Override
public void start() {
try {
xagent = this.wrapper.getPluginManager().getExtensions(XagentApi.class).get(0);
logger.info("start demo plugin,trtrt");
ptpServer =
xagent.createServer(
this.wrapper.getPluginId(),
ProductConfig.PRODUCT_ID,//产品ID
ProductConfig.PRODUCT_KEY,//产品key
ProductConfig.SERVER_PORT,//PTP端口
new Decoder(), //解码器
new Encoder(),//编码器
new BusinessLogicProcessor(), //处理器
ProductConfig.SERVER_HEART_SECONDS,
ProductConfig.SERVER_STRATEGY);//PTP与设备的通讯协议
xagent.setDatapointSetListener(new DatapointDataHandler());//数据上报与下报处理器
ptpServer.startServer();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static PtpServer getPtpServer() {
return ptpServer;
}
public static XagentApi getXagentApi() {
return xagent;
}
}
第七步: PTP插件工程打包
使用maven的install命令,生成一个jar包。jar包根目录下至少包含三个文件夹: 放置java的class文件 lib,放置ptp插件需要使用到的第三方依赖包(如果没有使用依赖包,可以省略) META-INF,用于放置MANIFEST.MF文件
第八步:部署容器运行环境
- 插件部署在厂商服务器下,需要部署该运行环境
- 插件部署在云端,不需要部署该运行环境,只需提供插件包到云端
第九步:部署插件
1打成的jar包放到的plugins目录
2如果要在一台服务器启动多个插件,需要修改099
启动./start.sh
PTP调试模式
开发者在开发阶段,可使用调试模式,调试模式的启动有别于正常启动,具体如下,以下 使用开发工具为idea
配置Debug参数
-Dpf4j.mode=development
-Dpf4j.pluginsDir=target
-Dnport=3099 //自定义基础插件的端口
-config_file=lib/xagent/config/config.properties
总结
本对接方式是采用插件代理服务方式实现设备与MQTT服务器的通讯,优点:接入灵活,可以不依赖平台,设备厂家自主接入。缺点:1有一定的开发工作量。2随着新产品类型的增加,插件服务也会随之增多,不好管理。
iot平台异构对接文档的更多相关文章
- 001-Java®语言规范、Java平台标准版文档、JVM概述
一.概述 相关api地址:JDK10 JDK 9 JDK 8 JDK 7 JDK 6 Java语言和虚拟机规范: https://docs.oracle.com/javase/spec ...
- ECO开放平台对接文档说明
应用集成: http://open.teewon.net:1000/static/index.html#/docs/flow/integrate统一认证集成文档: http://open.teewon ...
- 【IoT平台技术对接分享】如何上传正确的消息推送证书
消息推送应用实现消息推送的接口,部署证书,同时上传根证书到平台. 目前消息推送失败,很大一部分原因是证书上传不对.推荐小伙伴们使用下面的方法导出证书. 推送:平台调用应用服务器的restful接口将数 ...
- EasyNVR无插件直播流媒体服务器云端集中管控的EasyNVS云管理平台安装使用文档
EasyNVS - EasyNVR云端集中管理服务 EasyNVS云管理平台是一套专门用于集中化管理EasyNVR 的解决方案. EasyNVR 采用主动注册的方式接入到 EasyNVS, 再由 Ea ...
- linux平台的office文档转pdf(程序员的菜)
需要材料: 1. Openoffice3.4(我是32位的centos,可以根据自己的系统下载指定的openoffice软件包) 下载地址:http://sourceforge.net/projec ...
- OpenPAI大规模人工智能平台安装部署文档
环境要求: 如果需要图形界面,需要在Ubuntu系统安装,否则centos系统安装时是没有问题的(web端和命令行进行任务提交) 安装过程需要有另外一台控制端机器(注意:区别于集群所在的任何一台服务器 ...
- 这些.NET开源项目你知道吗?.NET平台开源文档与报表处理组件集合(三)
在前2篇文章这些.NET开源项目你知道吗?让.NET开源来得更加猛烈些吧 和这些.NET开源项目你知道吗?让.NET开源来得更加猛烈些吧!(第二辑)中,大伙热情高涨.再次拿出自己的私货,在.NET平台 ...
- .NET平台开源文档与报表处理组件包括Execel PDF Word等
在前2篇文章这些.NET开源项目你知道吗?让.NET开源来得更加猛烈些吧 和这些.NET开源项目你知道吗?让.NET开源来得更加猛烈些吧!(第二辑)中,大伙热情高涨.再次拿出自己的私货,在.NET平台 ...
- 基于MVC4+EasyUI的Web开发框架经验总结(8)--实现Office文档的预览
在博客园很多文章里面,曾经有一些介绍Office文档预览查看操作的,有些通过转为PDF进行查看,有些通过把它转换为Flash进行查看,但是过程都是曲线救国,真正能够简洁方便的实现Office文档的预览 ...
随机推荐
- MySQL中的sys系统数据库是干嘛的
mysql5.7增加了sys 系统数据库,通过这个库可以快速的了解系统的元数据信息 这个库确实可以方便DBA发现数据库的很多信息,解决性能瓶颈都提供了巨大帮助 这个库在mysql5.7中是默认存在 ...
- Jetson TX2介绍
Jetson TX2是NIVDIA瞄准人工智能在Jetson TK1和TX1推出后的升级 TX2的GPU和CPU都进行了升级,内存增加到了8GB.存储增加到了32GB,支持Wifi和蓝牙,编解码支持H ...
- ylbtech-SQL-W3School-高级:SQL NOT NULL 约束
ylbtech-SQL-W3School-高级:SQL NOT NULL 约束 1.返回顶部 1. SQL NOT NULL 约束 NOT NULL 约束强制列不接受 NULL 值. NOT NULL ...
- php中如何传递Session ID
一般通过在各个页面之间传递的唯一的 Session ID,并通过 Session ID 提取这个用户在服务器中保存的 Session 变量,来跟踪一个用户.常见的 Session ID 传送方法主要有 ...
- 阶段5 3.微服务项目【学成在线】_day05 消息中间件RabbitMQ_3.RabbitMQ研究-工作原理
Producer生产者 Consumer:消费者 组成部分说明如下: Broker:消息队列服务进程,此进程包括两个部分:Exchange和Queue. Exchange:消息队列交换机,按一定的规则 ...
- 一百三十七:CMS系统之发布帖子前台布局
把前面配置好的ueditor的文件复制到static下 把ueditor蓝图导入,注册 初始化ueditor //初始化ueditor$(function () { var ue = UE.getEd ...
- Nonce
Nonce是或Number once的缩写,在密码学中Nonce是一个只被使用一次的任意或非重复的随机数值. 在加密技术中的初始向量和加密散列函数都发挥着重要作用,在各类验证协议的通信应用中确保验证信 ...
- webview的学习总结:
1.1: Weview常见的坑 及其 内存泄漏的解决方案: WebView 1. WebView常见的坑 API 16之前版本存在远程代码执行漏洞,该漏洞源自于程序没有正确限制使用WebView.ad ...
- Flutter 底部导航栏bottomNavigationBar
实现一个底部导航栏,包含3到4个功能标签,点击对应的导航标签可以切换到对应的页面内容,并且页面抬头显示的内容也会跟着改变. 实际上由于手机屏幕大小的限制,底部导航栏的功能标签一般在3到5个左右,如果太 ...
- Introduction - Supervised Learning
摘要: 本文是吴恩达 (Andrew Ng)老师<机器学习>课程,第一章<绪论:初识机器学习>中第3课时<监督学习>的视频原文字幕.为本人在视频学习过程中逐字逐句记 ...