diff --git a/data/components/eabb131d-8fd1-43a8-88d9-a198abfd3d42/component.js b/data/components/eabb131d-8fd1-43a8-88d9-a198abfd3d42/component.js index 66691d43..b3fbd43f 100755 --- a/data/components/eabb131d-8fd1-43a8-88d9-a198abfd3d42/component.js +++ b/data/components/eabb131d-8fd1-43a8-88d9-a198abfd3d42/component.js @@ -174,19 +174,29 @@ this.onReceive=function(head,type,payload){ //数据上报 var reply= - { - productKey:pk, - deviceName:dn, - mid:payload.id, - content:{ - topic:topic.replace("/s/","/c/")+"_reply", - payload:JSON.stringify({ - id:payload.id, - method: payload.method+"_reply", - code:0, - }) - } - }; + { + productKey:pk, + deviceName:dn, + mid:payload.id, + content:{ + topic:topic.replace("/s/","/c/")+"_reply", + payload:JSON.stringify({ + id:payload.id, + method: payload.method+"_reply", + code:0, + }) + } + }; + + var action={}; + if(!topic.endsWith("_reply")){ + //需要回复的消息 + action={ + type:"ack", + content:JSON.stringify(reply) + } + } + return { type:"report", data:{ @@ -198,10 +208,7 @@ this.onReceive=function(head,type,payload){ payload:payload } }, - action:{ - type:"ack", - content:JSON.stringify(reply) - } + action:action } } diff --git a/doc/mongodb安装配置.jpg b/doc/mongodb安装配置.jpg deleted file mode 100755 index 310826ff..00000000 Binary files a/doc/mongodb安装配置.jpg and /dev/null differ diff --git a/doc/安装Pulsar.jpg b/doc/安装Pulsar.jpg deleted file mode 100755 index 40caeb81..00000000 Binary files a/doc/安装Pulsar.jpg and /dev/null differ diff --git a/iot-common/src/main/java/cc/iotkit/common/ComponentClassLoader.java b/iot-common/src/main/java/cc/iotkit/common/ComponentClassLoader.java index f336f906..49343223 100755 --- a/iot-common/src/main/java/cc/iotkit/common/ComponentClassLoader.java +++ b/iot-common/src/main/java/cc/iotkit/common/ComponentClassLoader.java @@ -38,7 +38,8 @@ public class ComponentClassLoader { classLoader.close(); } - classLoader = URLClassLoader.newInstance(new URL[]{jarPath.toURI().toURL()}, ClassLoader.getSystemClassLoader()); + classLoader = URLClassLoader.newInstance(new URL[]{jarPath.toURI().toURL()}, + Thread.currentThread().getContextClassLoader()); classLoaders.put(name, classLoader); Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); diff --git a/iot-components/iot-mqtt-component/src/main/resources/component.js b/iot-components/iot-mqtt-component/src/main/resources/component.js index 9ccd4cf9..b3fbd43f 100755 --- a/iot-components/iot-mqtt-component/src/main/resources/component.js +++ b/iot-components/iot-mqtt-component/src/main/resources/component.js @@ -48,7 +48,7 @@ function register(payload){ var dn=arr[1]; var model=arr[2]; var pwd=md5("xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU"+auth.clientid); - if(pwd!=auth.password){ + if(pwd.toLocaleLowerCase()!=auth.password.toLocaleLowerCase()){ throw new Error("incorrect password"); } return { @@ -173,6 +173,30 @@ this.onReceive=function(head,type,payload){ } //数据上报 + var reply= + { + productKey:pk, + deviceName:dn, + mid:payload.id, + content:{ + topic:topic.replace("/s/","/c/")+"_reply", + payload:JSON.stringify({ + id:payload.id, + method: payload.method+"_reply", + code:0, + }) + } + }; + + var action={}; + if(!topic.endsWith("_reply")){ + //需要回复的消息 + action={ + type:"ack", + content:JSON.stringify(reply) + } + } + return { type:"report", data:{ @@ -183,7 +207,8 @@ this.onReceive=function(head,type,payload){ topic:topic, payload:payload } - } + }, + action:action } } diff --git a/iot-components/iot-mqtt-component/src/main/resources/converter.js b/iot-components/iot-mqtt-component/src/main/resources/converter.js deleted file mode 100755 index f4074b63..00000000 --- a/iot-components/iot-mqtt-component/src/main/resources/converter.js +++ /dev/null @@ -1,104 +0,0 @@ - -var mid=1; - -function getMid(){ - mid++; - if(mid>10000){ - mid=1; - } - return mid+""; -} - -this.decode = function (msg) { - //对msg进行解析,并返回物模型数据 - var content=msg.content; - var topic = content.topic; - var payload = content.payload; - var identifier = topic.substring(topic.lastIndexOf("/") + 1); - - if (topic.endsWith("/property/post")) { - //属性上报 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type:"property", - identifier: "report", //属性上报 - occur: new Date().getTime(), //时间戳,设备上的事件或数据产生的本地时间 - time: new Date().getTime(), //时间戳,消息上报时间 - data: payload.params, - }; - } else if (topic.indexOf("/event/") > 0) { - //事件上报 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type:"event", - identifier: identifier, - occur: new Date().getTime(), - time: new Date().getTime(), - data: payload.params, - }; - }else if(topic.endsWith("/service/property/set_reply")){ - //属性设置回复 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type:"property", - identifier: identifier, - occur: new Date().getTime(), - time: new Date().getTime(), - code: payload.code - }; - } else if (topic.endsWith("_reply")) { - //服务回复 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type:"service", - identifier: identifier, - occur: new Date().getTime(), - time: new Date().getTime(), - code: payload.code, - data: payload.data, - }; - } - return null; -}; - -this.encode = function (service,device) { - var type=service.type; - var identifier=service.identifier; - var topic="/sys/"+service.productKey+"/"+service.deviceName+"/c/service/"; - var method="thing.service."; - - if(type=="property"){ - method+="property."+identifier; - topic+="property/"+identifier; - }else if(type=="service"){ - method+=identifier; - topic+=identifier; - } - var deviceMid=getMid(); - var params={}; - for(var p in service.params){ - params[p]=service.params[p]; - } - - return { - productKey:service.productKey, - deviceName:service.deviceName, - mid:deviceMid, - content:{ - topic:topic, - payload:JSON.stringify({ - id:deviceMid, - method:method, - params:params - }) - } - } -}; \ No newline at end of file diff --git a/iot-package/src/main/resources/assemblies/standalone-package.xml b/iot-package/src/main/resources/assemblies/standalone-package.xml index 158cc0bb..7e41e334 100755 --- a/iot-package/src/main/resources/assemblies/standalone-package.xml +++ b/iot-package/src/main/resources/assemblies/standalone-package.xml @@ -3,10 +3,62 @@ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> standalone-package - tar + zip + false + + + + + ${project.parent.basedir}/iot-standalone/src/main/bin + /bin + + **/*.bat + **/*.sh + + 0755 + + unix + true + + + + + ${project.parent.basedir}/iot-standalone/src/main/resources + /config + + **/*.xml + **/*.properties + **/*.yml + + true + + + + + target + lib + + *.jar + + + + + + ${project.parent.basedir} + docs + + *.md + + 0644 + + + ${project.parent.basedir}/data/components data/components @@ -28,13 +80,6 @@ **/* - - - - lib - runtime - false - - + \ No newline at end of file diff --git a/iot-standalone/.DS_Store b/iot-standalone/.DS_Store index 43bda51d..62f3e822 100755 Binary files a/iot-standalone/.DS_Store and b/iot-standalone/.DS_Store differ diff --git a/iot-standalone/pom.xml b/iot-standalone/pom.xml index 0675cde1..ac9280db 100755 --- a/iot-standalone/pom.xml +++ b/iot-standalone/pom.xml @@ -181,6 +181,11 @@ + + org.springframework.boot + spring-boot-maven-plugin + + org.apache.maven.plugins maven-assembly-plugin diff --git a/iot-standalone/src/main/bin/start.bat b/iot-standalone/src/main/bin/start.bat new file mode 100644 index 00000000..922f335c --- /dev/null +++ b/iot-standalone/src/main/bin/start.bat @@ -0,0 +1,38 @@ +echo off + +set APP_NAME=${project.build.finalName}.jar +set LOG_IMPL_FILE=log4j2.xml +set LOGGING_CONFIG= +if exist ../config/%LOG_IMPL_FILE% ( + set LOGGING_CONFIG=-Dlogging.config=../config/%LOGGING_CONFIG% +) +set CONFIG= -Dlogging.path=../log %LOGGING_CONFIG% -Dspring.config.location=../config/ + +set DEBUG_OPTS= +if ""%1"" == ""debug"" ( + set DEBUG_OPTS= -Xloggc:../log/gc.log -verbose:gc -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../log + goto debug +) + +set JMX_OPTS= +if ""%1"" == ""jmx"" ( + set JMX_OPTS= -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9888 -Dcom.sun.management.jmxremote.ssl=FALSE -Dcom.sun.management.jmxremote.authenticate=FALSE + goto jmx +) + +echo "Starting the %APP_NAME%" +java -Xms512m -Xmx512m -server %DEBUG_OPTS% %JMX_OPTS% %CONFIG% -jar ../lib/%APP_NAME% +echo "java -Xms512m -Xmx512m -server %DEBUG_OPTS% %JMX_OPTS% %CONFIG% -jar ../lib/%APP_NAME%" +goto end + +:debug +echo "debug" +java -Xms512m -Xmx512m -server %DEBUG_OPTS% %CONFIG% -jar ../lib/%APP_NAME% +goto end + +:jmx +java -Xms512m -Xmx512m -server %JMX_OPTS% %CONFIG% -jar ../lib/%APP_NAME% +goto end + +:end +pause \ No newline at end of file diff --git a/iot-standalone/src/main/bin/start.sh b/iot-standalone/src/main/bin/start.sh new file mode 100644 index 00000000..5d0bf4bb --- /dev/null +++ b/iot-standalone/src/main/bin/start.sh @@ -0,0 +1,109 @@ +#!/bin/bash + +# 项目名称 +SERVER_NAME="${project.artifactId}" + +# jar名称 +JAR_NAME="${project.build.finalName}.jar" + +# 进入bin目录 +cd `dirname $0` +# bin目录绝对路径 +BIN_DIR=`pwd` +# 返回到上一级项目根目录路径 +cd .. +# 打印项目根目录绝对路径 +# `pwd` 执行系统命令并获得结果 +DEPLOY_DIR=`pwd` + +# 外部配置文件绝对目录,如果是目录需要/结尾,也可以直接指定文件 +# 如果指定的是目录,spring则会读取目录中的所有配置文件 +CONF_DIR=$DEPLOY_DIR/config +# SERVER_PORT=`sed '/server.port/!d;s/.*=//' config/application.properties | tr -d '\r'` +# 获取应用的端口号 +SERVER_PORT=`sed -nr '/port: [0-9]+/ s/.*port: +([0-9]+).*/\1/p' config/application.yml|head -1` + +PIDS=`ps -f | grep java | grep "$CONF_DIR" |awk '{print $2}'` +if [ "$1" = "status" ]; then + if [ -n "$PIDS" ]; then + echo "The $SERVER_NAME is running...!" + echo "PID: $PIDS" + exit 0 + else + echo "The $SERVER_NAME is stopped" + exit 0 + fi +fi + +if [ -n "$PIDS" ]; then + echo "ERROR: The $SERVER_NAME already started!" + echo "PID: $PIDS" + exit 1 +fi + +if [ -n "$SERVER_PORT" ]; then + SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l` + if [ $SERVER_PORT_COUNT -gt 0 ]; then + echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!" + exit 1 + fi +fi + +# 项目日志输出绝对路径 +LOGS_DIR=$DEPLOY_DIR/log +# 如果logs文件夹不存在,则创建文件夹 +if [ ! -d $LOGS_DIR ]; then + mkdir $LOGS_DIR +fi +STDOUT_FILE=$LOGS_DIR/catalina.log + +# JVM Configuration +JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true " +JAVA_DEBUG_OPTS="" +if [ "$1" = "debug" ]; then + JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n " +fi + +JAVA_JMX_OPTS="" +if [ "$1" = "jmx" ]; then + JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false " +fi + +JAVA_MEM_OPTS="" +BITS=`java -version 2>&1 | grep -i 64-bit` +if [ -n "$BITS" ]; then + JAVA_MEM_OPTS=" -server -Xmx512m -Xms512m -Xmn256m -Xss256k" +else + JAVA_MEM_OPTS=" -server -Xms512m -Xmx512m" +fi + +# 加载外部log4j2文件的配置 +LOG_IMPL_FILE=log4j2.xml +LOGGING_CONFIG="" +if [ -f "$CONF_DIR/$LOG_IMPL_FILE" ] +then + LOGGING_CONFIG="-Dlogging.config=$CONF_DIR/$LOG_IMPL_FILE" +fi +CONFIG_FILES=" -Dlogging.path=$LOGS_DIR $LOGGING_CONFIG -Dspring.config.location=$CONF_DIR/ " +echo -e "Starting the $SERVER_NAME ..." +nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS $CONFIG_FILES -jar $DEPLOY_DIR/lib/$JAR_NAME > $STDOUT_FILE 2>&1 & + +COUNT=0 +while [ $COUNT -lt 1 ]; do + echo -e ".\c" + sleep 1 + if [ -n "$SERVER_PORT" ]; then + COUNT=`netstat -an | grep $SERVER_PORT | wc -l` + else + COUNT=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l` + fi + if [ $COUNT -gt 0 ]; then + break + fi +done + + +echo "OK!" +PIDS=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}'` +echo "PID: $PIDS" +echo "STDOUT: $STDOUT_FILE" \ No newline at end of file diff --git a/iot-standalone/src/main/bin/stop.sh b/iot-standalone/src/main/bin/stop.sh new file mode 100644 index 00000000..28a5e2e8 --- /dev/null +++ b/iot-standalone/src/main/bin/stop.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# 项目名称 +APPLICATION="${project.artifactId}" + +# 项目启动jar包名称 +APPLICATION_JAR="${project.build.finalName}.jar" + +# 通过项目名称查找到PI,然后kill -9 pid +PID=$(ps -ef | grep "${APPLICATION_JAR}" | grep -v grep | awk '{ print $2 }') +if [[ -z "$PID" ]] +then + echo ${APPLICATION} is already stopped +else + echo kill ${PID} + kill -9 ${PID} + echo ${APPLICATION} stopped successfully +fi \ No newline at end of file diff --git a/iot-standalone/src/main/java/cc/iotkit/manager/config/EmbeddedRedisConfig.java b/iot-standalone/src/main/java/cc/iotkit/manager/config/EmbeddedRedisConfig.java index a7f22101..4f4fed3b 100755 --- a/iot-standalone/src/main/java/cc/iotkit/manager/config/EmbeddedRedisConfig.java +++ b/iot-standalone/src/main/java/cc/iotkit/manager/config/EmbeddedRedisConfig.java @@ -21,7 +21,10 @@ public class EmbeddedRedisConfig { RedisServer redisServer; String os = System.getProperty("os.name").toLowerCase(); if (os.contains("windows")) { - redisServer = RedisServer.builder().setting("maxheap 200m").build(); + redisServer = RedisServer.builder().setting("maxheap 200m") + .port(6379) + .setting("bind localhost") + .build(); } else { redisServer = new RedisServer(); } diff --git a/iot-standalone/src/main/java/cc/iotkit/manager/service/DeviceService.java b/iot-standalone/src/main/java/cc/iotkit/manager/service/DeviceService.java index 6ead0ee1..569ff268 100755 --- a/iot-standalone/src/main/java/cc/iotkit/manager/service/DeviceService.java +++ b/iot-standalone/src/main/java/cc/iotkit/manager/service/DeviceService.java @@ -150,26 +150,7 @@ public class DeviceService { //设备指令下发 deviceComponentManager.send(thingService); } - String mid = thingService.getMid(); - DeviceInfo device = deviceInfoData.findByDeviceId(deviceId); - - //保存设备日志 - ThingModelMessage thingModelMessage = ThingModelMessage.builder() - .mid(mid) - .deviceId(deviceId) - .productKey(pk) - .deviceName(dn) - .uid(device.getUid()) - .type(type) - .identifier(identifier) - .data(data) - .occurred(System.currentTimeMillis()) - .time(System.currentTimeMillis()) - .build(); - - thingModelMessageData.add(thingModelMessage); - - return mid; + return thingService.getMid(); } } diff --git a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/model/Request.java b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/model/Request.java index 9a5bc20b..91371ed7 100755 --- a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/model/Request.java +++ b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/model/Request.java @@ -20,5 +20,7 @@ public class Request { private String id; + private String method; + private Object params; } \ No newline at end of file diff --git a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ReportTest.java b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ReportTest.java index 730a806b..7bafb363 100755 --- a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ReportTest.java +++ b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ReportTest.java @@ -33,8 +33,8 @@ public class ReportTest { if (args.length == 0) { - Mqtt.brokerHost = "127.0.0.1"; -// Mqtt.brokerHost = "120.76.96.206"; +// Mqtt.brokerHost = "127.0.0.1"; + Mqtt.brokerHost = "120.76.96.206"; // Mqtt.brokerHost = "172.16.1.109"; } else { Mqtt.brokerHost = args[0]; @@ -74,6 +74,7 @@ public class ReportTest { () -> { Request request = new Request(); request.setId(UUID.randomUUID().toString()); + request.setMethod("thing.event.property.post"); Map param = new HashMap<>(); param.put("volt", Math.round(Math.random() * 100)); request.setParams(param);