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的配置



4.0.0
xlink.xagent
xagent-ptp-demo
0.0.1
xagent-ptp-demo
http://maven.apache.org

<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/>



org.pf4j
pf4j
2.0.0


xlink.xagent
xagent-api
0.0.3
system
${project.basedir}/lib/xagent-api-0.0.3.jar


io.netty
netty-all
4.1.8.Final


redis.clients
jedis
2.9.0



org.apache.commons
commons-dbcp2
2.1


org.apache.derby
derby
10.12.1.1


com.google.code.gson
gson
2.8.1


com.squareup.okhttp3
okhttp
3.9.0


log4j
log4j
1.2.16






commons-lang
commons-lang
2.6


com.alibaba
fastjson
1.2.28









false
src/main/java

**/*.java



src/main/resources




org.apache.maven.plugins
maven-compiler-plugin

1.8
1.8



org.apache.maven.plugins
maven-antrun-plugin
1.6


unzip jar file
package






run





maven-assembly-plugin
2.3



src/main/assembly/assembly.xml


false

target/plugin-classes/META-INF/MANIFEST.MF




make-assembly
package

attached





org.apache.maven.plugins
maven-jar-plugin
2.4



${plugin.id}
${plugin.class}
${plugin.version}
${plugin.provider}
${plugin.dependencies}





maven-deploy-plugin

true



第二步:创建配置类

可以创建一个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

posted on 2019-07-10 10:10  wolf12  阅读(550)  评论(0)    收藏  举报