diff --git a/.project b/.project new file mode 100644 index 0000000..b1e86b6 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + JTradfri + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/JTradfri/.classpath b/JTradfri/.classpath index 7978a31..464efa0 100644 --- a/JTradfri/.classpath +++ b/JTradfri/.classpath @@ -1,9 +1,9 @@ - + - + diff --git a/JTradfri/.project b/JTradfri/.project index b33132f..a1dd118 100644 --- a/JTradfri/.project +++ b/JTradfri/.project @@ -1,7 +1,7 @@ JTradfri - Project JTradfri created by Buildship. + @@ -10,14 +10,9 @@ - - org.eclipse.buildship.core.gradleprojectbuilder - - - + org.springsource.ide.eclipse.gradle.core.nature org.eclipse.jdt.core.javanature - org.eclipse.buildship.core.gradleprojectnature diff --git a/JTradfri/.settings/gradle/org.springsource.ide.eclipse.gradle.core.import.prefs b/JTradfri/.settings/gradle/org.springsource.ide.eclipse.gradle.core.import.prefs new file mode 100644 index 0000000..3419963 --- /dev/null +++ b/JTradfri/.settings/gradle/org.springsource.ide.eclipse.gradle.core.import.prefs @@ -0,0 +1,9 @@ +#org.springsource.ide.eclipse.gradle.core.preferences.GradleImportPreferences +#Mon Dec 10 17:49:19 GMT 2018 +addResourceFilters=true +afterTasks=afterEclipseImport; +beforeTasks=cleanEclipse;eclipse; +enableAfterTasks=true +enableBeforeTasks=true +enableDependendencyManagement=true +projects=; diff --git a/JTradfri/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs b/JTradfri/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs new file mode 100644 index 0000000..41b47c5 --- /dev/null +++ b/JTradfri/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs @@ -0,0 +1,5 @@ +#org.springsource.ide.eclipse.gradle.core.preferences.GradleProjectPreferences +#Mon Dec 10 17:49:42 GMT 2018 +build.family.org.gradle.tooling.model.eclipse.HierarchicalEclipseProject=; +org.springsource.ide.eclipse.gradle.linkedresources= +org.springsource.ide.eclipse.gradle.rootprojectloc= diff --git a/JTradfri/.settings/gradle/org.springsource.ide.eclipse.gradle.refresh.prefs b/JTradfri/.settings/gradle/org.springsource.ide.eclipse.gradle.refresh.prefs new file mode 100644 index 0000000..9086995 --- /dev/null +++ b/JTradfri/.settings/gradle/org.springsource.ide.eclipse.gradle.refresh.prefs @@ -0,0 +1,8 @@ +#org.springsource.ide.eclipse.gradle.core.actions.GradleRefreshPreferences +#Mon Dec 10 17:49:36 GMT 2018 +addResourceFilters=true +afterTasks=afterEclipseImport; +beforeTasks=cleanEclipse;eclipse; +enableAfterTasks=true +enableBeforeTasks=true +useHierarchicalNames=false diff --git a/JTradfri/.settings/org.eclipse.buildship.core.prefs b/JTradfri/.settings/org.eclipse.buildship.core.prefs index 63b99a7..68a3a5b 100644 --- a/JTradfri/.settings/org.eclipse.buildship.core.prefs +++ b/JTradfri/.settings/org.eclipse.buildship.core.prefs @@ -1,7 +1,13 @@ -#Fri Jul 28 22:22:55 CEST 2017 +arguments= +auto.sync=false +build.scans.enabled=false connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(4.0.2)) -override.workspace.settings=true -gradle.user.home= connection.project.dir= +eclipse.preferences.version=1 +gradle.user.home= +java.home= +jvm.arguments= offline.mode=false -build.scans.enabled=false +override.workspace.settings=true +show.console.view=false +show.executions.view=false diff --git a/JTradfri/.settings/org.eclipse.jdt.core.prefs b/JTradfri/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..946ea62 --- /dev/null +++ b/JTradfri/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,13 @@ +# +#Mon Dec 10 17:49:36 GMT 2018 +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.source=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error diff --git a/JTradfri/gradlew b/JTradfri/gradlew old mode 100644 new mode 100755 diff --git a/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriDevice.java b/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriDevice.java index 8d52f46..5a430a6 100644 --- a/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriDevice.java +++ b/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriDevice.java @@ -7,10 +7,10 @@ import org.eclipse.californium.core.CoapHandler; import org.eclipse.californium.core.CoapResponse; -import org.eclipse.californium.core.coap.CoAP.ResponseCode; import org.json.JSONArray; import org.json.JSONObject; +import org.eclipse.californium.core.coap.CoAP.ResponseCode; import net.kappelt.JTradfri.GWConnection; /** @@ -60,6 +60,9 @@ public class TradfriDevice{ //true if it is a bulb or a light panel private Boolean isLightingDevice = false; + //true if it is a socket outlet + private Boolean isOutlet = false; + private boolean isSubscribed = false; //set once the method subsribe() is called private String manufacturer; @@ -183,6 +186,17 @@ private Boolean newInfoAvailable(String jsonInfo) { this.color = json.getJSONArray("3311").getJSONObject(0).getString("5706"); this.isLightingDevice = true; } + //onoff + if(json.has("3312") && json.getJSONArray("3312").length() > 0 && json.getJSONArray("3312").getJSONObject(0).has("5850")) { + this.onoff = json.getJSONArray("3312").getJSONObject(0).getInt("5850"); + this.isOutlet = true; + } + + //dimvalue + if(json.has("3312") && json.getJSONArray("3312").length() > 0 && json.getJSONArray("3312").getJSONObject(0).has("5851")) { + this.dimvalue = json.getJSONArray("3312").getJSONObject(0).getInt("5851"); + this.isOutlet = true; + } //name if(json.has("9001")) { @@ -267,6 +281,9 @@ public void onError() { public Boolean isLightingDevice() { return isLightingDevice; } + public Boolean isOutlet() { + return isOutlet; + } public int getDeviceID() { return deviceID; diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..38121d8 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/Eclipse-Workspace diff --git a/bin/.project b/bin/.project new file mode 100644 index 0000000..b1e86b6 --- /dev/null +++ b/bin/.project @@ -0,0 +1,17 @@ + + + JTradfri + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/bin/JTradfri-builds/JTradfri-02082017-0.0.1-snapshot-all.jar b/bin/JTradfri-builds/JTradfri-02082017-0.0.1-snapshot-all.jar new file mode 100644 index 0000000..6933537 Binary files /dev/null and b/bin/JTradfri-builds/JTradfri-02082017-0.0.1-snapshot-all.jar differ diff --git a/bin/JTradfri-builds/JTradfri-02082017-0.0.2-snapshot-all.jar b/bin/JTradfri-builds/JTradfri-02082017-0.0.2-snapshot-all.jar new file mode 100644 index 0000000..59e7405 Binary files /dev/null and b/bin/JTradfri-builds/JTradfri-02082017-0.0.2-snapshot-all.jar differ diff --git a/bin/JTradfri-builds/JTradfri-03082017-0.0.3-snapshot-all.jar b/bin/JTradfri-builds/JTradfri-03082017-0.0.3-snapshot-all.jar new file mode 100644 index 0000000..1a00ff1 Binary files /dev/null and b/bin/JTradfri-builds/JTradfri-03082017-0.0.3-snapshot-all.jar differ diff --git a/bin/jtradfri.jar b/bin/JTradfri-builds/JTradfri-06112017-0.0.5-snapshot-all.jar similarity index 93% rename from bin/jtradfri.jar rename to bin/JTradfri-builds/JTradfri-06112017-0.0.5-snapshot-all.jar index 5d5da9f..fef7b21 100644 Binary files a/bin/jtradfri.jar and b/bin/JTradfri-builds/JTradfri-06112017-0.0.5-snapshot-all.jar differ diff --git a/bin/JTradfri-builds/JTradfri-31102017-0.0.4-snapshot-all.jar b/bin/JTradfri-builds/JTradfri-31102017-0.0.4-snapshot-all.jar new file mode 100644 index 0000000..ab414fa Binary files /dev/null and b/bin/JTradfri-builds/JTradfri-31102017-0.0.4-snapshot-all.jar differ diff --git a/bin/JTradfri-builds/README.md b/bin/JTradfri-builds/README.md new file mode 100644 index 0000000..ec234ab --- /dev/null +++ b/bin/JTradfri-builds/README.md @@ -0,0 +1,13 @@ +New versions of JTradfri are published in the ./bin Folder, without a version number in their name. Upgrading shall be easier now, because you don't need to check for the new Version-Number and Build-Date. + + +This folder is just kept as an archive for previous versions. + + + + + +Neue Versionen von JTradfri werden im ./bin-Ordner veröffentlicht, ohne eine Versionsnummer in deren Namen. Updates sollten daher einfacher sein, da beim Download nicht mehr die Versionsnummer und das Builddatum ermittelt werden muss. + + +Dieser Ordner bleibt als Archiv für vorherige Versionen bestehen. \ No newline at end of file diff --git a/bin/JTradfri/.classpath b/bin/JTradfri/.classpath new file mode 100644 index 0000000..d208efd --- /dev/null +++ b/bin/JTradfri/.classpath @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/bin/JTradfri/.gitignore b/bin/JTradfri/.gitignore new file mode 100644 index 0000000..03be9c1 --- /dev/null +++ b/bin/JTradfri/.gitignore @@ -0,0 +1,3 @@ +/.gradle/ +/build/ +/bin/ diff --git a/bin/JTradfri/.project b/bin/JTradfri/.project new file mode 100644 index 0000000..b33132f --- /dev/null +++ b/bin/JTradfri/.project @@ -0,0 +1,23 @@ + + + JTradfri + Project JTradfri created by Buildship. + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.buildship.core.gradleprojectnature + + diff --git a/bin/JTradfri/.settings/org.eclipse.buildship.core.prefs b/bin/JTradfri/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000..63b99a7 --- /dev/null +++ b/bin/JTradfri/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,7 @@ +#Fri Jul 28 22:22:55 CEST 2017 +connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(4.0.2)) +override.workspace.settings=true +gradle.user.home= +connection.project.dir= +offline.mode=false +build.scans.enabled=false diff --git a/bin/JTradfri/build.gradle b/bin/JTradfri/build.gradle new file mode 100644 index 0000000..eb61595 --- /dev/null +++ b/bin/JTradfri/build.gradle @@ -0,0 +1,84 @@ +/* + * This build file was generated by the Gradle 'init' task. + * + * This generated file contains a sample Java Library project to get you started. + * For more details take a look at the Java Libraries chapter in the Gradle + * user guide available at https://docs.gradle.org/4.0.2/userguide/java_library_plugin.html + */ + +plugins { + id 'com.github.johnrengelman.shadow' version '2.0.1' + id 'java' +} + +// Apply the java plugin to add support for Java +apply plugin: 'java' +// Apply the java-library plugin to add support for Java Library +apply plugin: 'java-library' + +apply plugin: 'application' +apply plugin: 'eclipse' + +apply plugin: 'maven' + +def getDate() { + new Date().format('ddMMyyyy') +} + +version='0.0.6-snapshot' +mainClassName='net.kappelt.JTradfri.JTradfri' + + +// In this section you declare where to find the dependencies of your project +repositories { + // Use jcenter for resolving your dependencies. + // You can declare any Maven/Ivy/file repository here. + jcenter() +} + +dependencies { + // This dependency is exported to consumers, that is to say found on their compile classpath. + api 'org.apache.commons:commons-math3:3.6.1' + + // This dependency is used internally, and not exposed to consumers on their own compile classpath. + implementation 'com.google.guava:guava:21.0' + + // Use JUnit test framework + testImplementation 'junit:junit:4.12' + + // https://mvnrepository.com/artifact/com.beust/jcommander + compile group: 'com.beust', name: 'jcommander', version: '1.7' + compile "com.beust:jcommander:1.71" + + runtime group: 'com.beust', name: 'jcommander', version: '1.7' + + + // https://mvnrepository.com/artifact/org.eclipse.californium/californium-core + compile group: 'org.eclipse.californium', name: 'californium-core', version: '2.0.0-M5' + // https://mvnrepository.com/artifact/org.eclipse.californium/scandium + compile group: 'org.eclipse.californium', name: 'scandium', version: '2.0.0-M5' + // https://mvnrepository.com/artifact/org.eclipse.californium/element-connector + compile group: 'org.eclipse.californium', name: 'element-connector', version: '2.0.0-M5' + + // https://mvnrepository.com/artifact/org.json/json + compile group: 'org.json', name: 'json', version: '20170516' +} + + +sourceSets { + main { + resources { + srcDirs = ["src/main/resources"] + } + java { + srcDirs = ["src/main/java"] + } + } +} + +shadowJar { + version = "${getDate()}-${version}" + from('src/main/resources') { + into('certs') + } +} \ No newline at end of file diff --git a/bin/JTradfri/gradle/wrapper/gradle-wrapper.jar b/bin/JTradfri/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..4035e08 Binary files /dev/null and b/bin/JTradfri/gradle/wrapper/gradle-wrapper.jar differ diff --git a/bin/JTradfri/gradle/wrapper/gradle-wrapper.properties b/bin/JTradfri/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..6eee474 --- /dev/null +++ b/bin/JTradfri/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Jul 28 22:22:38 CEST 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.2-bin.zip diff --git a/bin/JTradfri/gradlew b/bin/JTradfri/gradlew new file mode 100644 index 0000000..cccdd3d --- /dev/null +++ b/bin/JTradfri/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/bin/JTradfri/gradlew.bat b/bin/JTradfri/gradlew.bat new file mode 100644 index 0000000..f955316 --- /dev/null +++ b/bin/JTradfri/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/bin/JTradfri/settings.gradle b/bin/JTradfri/settings.gradle new file mode 100644 index 0000000..6689d86 --- /dev/null +++ b/bin/JTradfri/settings.gradle @@ -0,0 +1,18 @@ +/* + * This settings file was generated by the Gradle 'init' task. + * + * The settings file is used to specify which projects to include in your build. + * In a single project build this file can be empty or even removed. + * + * Detailed information about configuring a multi-project build in Gradle can be found + * in the user guide at https://docs.gradle.org/4.0.2/userguide/multi_project_builds.html + */ + +/* +// To declare projects as part of a multi-project build use the 'include' method +include 'shared' +include 'api' +include 'services:webservice' +*/ + +rootProject.name = 'JTradfri' diff --git a/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Commands/Commandline.class b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Commands/Commandline.class new file mode 100644 index 0000000..e7ddb6a Binary files /dev/null and b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Commands/Commandline.class differ diff --git a/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Commands/TCPSocket/TcpClientHandler.class b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Commands/TCPSocket/TcpClientHandler.class new file mode 100644 index 0000000..fb546ad Binary files /dev/null and b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Commands/TCPSocket/TcpClientHandler.class differ diff --git a/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Commands/TCPSocket/TcpServer.class b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Commands/TCPSocket/TcpServer.class new file mode 100644 index 0000000..d6e3012 Binary files /dev/null and b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Commands/TCPSocket/TcpServer.class differ diff --git a/bin/JTradfri/src/main/java/net/kappelt/JTradfri/GWConnection.class b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/GWConnection.class new file mode 100644 index 0000000..05e5ee2 Binary files /dev/null and b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/GWConnection.class differ diff --git a/bin/JTradfri/src/main/java/net/kappelt/JTradfri/JTradfri.class b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/JTradfri.class new file mode 100644 index 0000000..13df18e Binary files /dev/null and b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/JTradfri.class differ diff --git a/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriDevice.class b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriDevice.class new file mode 100644 index 0000000..e7209e0 Binary files /dev/null and b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriDevice.class differ diff --git a/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriDeviceEventListener.class b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriDeviceEventListener.class new file mode 100644 index 0000000..bcbafee Binary files /dev/null and b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriDeviceEventListener.class differ diff --git a/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriGroup.class b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriGroup.class new file mode 100644 index 0000000..818ec68 Binary files /dev/null and b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriGroup.class differ diff --git a/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriGroupEventListener.class b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriGroupEventListener.class new file mode 100644 index 0000000..44ddc7f Binary files /dev/null and b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriGroupEventListener.class differ diff --git a/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriMood.class b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriMood.class new file mode 100644 index 0000000..c46fc4e Binary files /dev/null and b/bin/JTradfri/src/main/java/net/kappelt/JTradfri/Tradfri/TradfriMood.class differ diff --git a/bin/JTradfri/src/main/resources/create-keystores.sh b/bin/JTradfri/src/main/resources/create-keystores.sh new file mode 100644 index 0000000..f6e21aa --- /dev/null +++ b/bin/JTradfri/src/main/resources/create-keystores.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +KEY_STORE=keyStore.jks +KEY_STORE_PWD=endPass +TRUST_STORE=trustStore.jks +TRUST_STORE_PWD=rootPass +VALIDITY=365 + +echo "creating root key and certificate..." +keytool -genkeypair -alias root -keyalg EC -dname 'C=CA,L=Ottawa,O=Eclipse IoT,OU=Californium,CN=cf-root' \ + -ext BC=ca:true -validity $VALIDITY -keypass $TRUST_STORE_PWD -keystore $TRUST_STORE -storepass $TRUST_STORE_PWD + +echo "creating CA key and certificate..." +keytool -genkeypair -alias ca -keyalg EC -dname 'C=CA,L=Ottawa,O=Eclipse IoT,OU=Californium,CN=cf-ca' \ + -ext BC=ca:true -validity $VALIDITY -keypass $TRUST_STORE_PWD -keystore $TRUST_STORE -storepass $TRUST_STORE_PWD +keytool -keystore $TRUST_STORE -storepass $TRUST_STORE_PWD -certreq -alias ca | \ + keytool -keystore $TRUST_STORE -storepass $TRUST_STORE_PWD -alias root -gencert -validity $VALIDITY -ext BC=0 -rfc | \ + keytool -alias ca -importcert -keystore $TRUST_STORE -storepass $TRUST_STORE_PWD + +echo "creating server key and certificate..." +keytool -genkeypair -alias server -keyalg EC -dname 'C=CA,L=Ottawa,O=Eclipse IoT,OU=Californium,CN=cf-server' \ + -validity $VALIDITY -keypass $KEY_STORE_PWD -keystore $KEY_STORE -storepass $KEY_STORE_PWD +keytool -keystore $KEY_STORE -storepass $KEY_STORE_PWD -certreq -alias server | \ + keytool -keystore $TRUST_STORE -storepass $TRUST_STORE_PWD -alias ca -gencert -ext KU=dig -validity $VALIDITY -rfc > server.pem +keytool -alias server -importcert -keystore $KEY_STORE -storepass $KEY_STORE_PWD -trustcacerts -file server.pem + +echo "creating client key and certificate..." +keytool -genkeypair -alias client -keyalg EC -dname 'C=CA,L=Ottawa,O=Eclipse IoT,OU=Californium,CN=cf-client' \ + -validity $VALIDITY -keypass $KEY_STORE_PWD -keystore $KEY_STORE -storepass $KEY_STORE_PWD +keytool -keystore $KEY_STORE -storepass $KEY_STORE_PWD -certreq -alias client | \ + keytool -keystore $TRUST_STORE -storepass $TRUST_STORE_PWD -alias ca -gencert -ext KU=dig -validity $VALIDITY -rfc > client.pem +keytool -alias client -importcert -keystore $KEY_STORE -storepass $KEY_STORE_PWD -trustcacerts -file client.pem + diff --git a/bin/JTradfri/src/main/resources/handshake_keyStore.jks b/bin/JTradfri/src/main/resources/handshake_keyStore.jks new file mode 100644 index 0000000..bc4abea Binary files /dev/null and b/bin/JTradfri/src/main/resources/handshake_keyStore.jks differ diff --git a/bin/JTradfri/src/main/resources/handshake_trustStore.jks b/bin/JTradfri/src/main/resources/handshake_trustStore.jks new file mode 100644 index 0000000..1510145 Binary files /dev/null and b/bin/JTradfri/src/main/resources/handshake_trustStore.jks differ diff --git a/bin/JTradfri/src/main/resources/keyStore.jks b/bin/JTradfri/src/main/resources/keyStore.jks new file mode 100644 index 0000000..bc4abea Binary files /dev/null and b/bin/JTradfri/src/main/resources/keyStore.jks differ diff --git a/bin/JTradfri/src/main/resources/trustStore.jks b/bin/JTradfri/src/main/resources/trustStore.jks new file mode 100644 index 0000000..1510145 Binary files /dev/null and b/bin/JTradfri/src/main/resources/trustStore.jks differ diff --git a/bin/LICENSE b/bin/LICENSE new file mode 100644 index 0000000..8dada3e --- /dev/null +++ b/bin/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/bin/jtradfri.conf.example b/bin/jtradfri.conf.example deleted file mode 100644 index 8854947..0000000 --- a/bin/jtradfri.conf.example +++ /dev/null @@ -1,25 +0,0 @@ -#Comments start with the "#"-Character - -#IP or DNS-Name of the Tradfri Gateway. Required -gateway=TradfriGW.int.kappelt.net - -#PSK of the Gateway. Required -secret=Your-PSK-Here - -#JTradfri receives commands over a TCP socket -#Port of that TCP-Server, optional. Default 1505 -#port=1505 - -#Listen-Address of the TCP-Server, optional. Default 127.0.0.1 -#Set this to the IP of your PC if the TCP-Client (e.g. FHEM) isn't running on the same PC as JTradfri -#listenaddress=192.168.2.121 - -#JTradfri opens an UDP-Socket -#you can set this socket to a static port if you need to configure your firewall for this -#Optional. Default is random port -#udpport=12345 - -#JTradfri can read command interactively from the commandline -#This can be disable with the following parameter (optional, default false) -#That is necessary if JTradfri is running as a systemd-service -#nocmdline=true \ No newline at end of file diff --git a/bin/jtradfri.service b/bin/jtradfri.service deleted file mode 100644 index 9891b50..0000000 --- a/bin/jtradfri.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=JTradfri - FHEM-Tradfri Gateway Software -Wants=network.target -After=network.target - -[Service] -User=jtradfri -Group=jtradfri -Type=simple -WorkingDirectory=/opt/jtradfri -ExecStart=/usr/bin/java -jar /opt/jtradfri/jtradfri.jar -n -c /opt/jtradfri/jtradfri.conf - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/bin/tcp-protocol.md b/bin/tcp-protocol.md new file mode 100644 index 0000000..9db28fc --- /dev/null +++ b/bin/tcp-protocol.md @@ -0,0 +1,145 @@ +# Command Reference: JTradfri TCP Socket + +This is a list of commands that are available on the TCP socket of the JTradfri software. + +The TCP socket listens on port 1505 by default. This port may be changed by the `-p` parameter on the command line call of the software. +Only connections from localhost are allowed by default + +Both commands and responses are terminated by the newline character. + +## Commands for devices + +### `device::list` +This lists all devices that are connected to the gateway. It returns a JSON-Array with the device IDs and their names: `deviceList::[{"name":"Fenster Rechts","deviceid":65538},{"name":"Dev1","deviceid":65539},{"name":"Fenster Links","deviceid":65537}]`. + +### `device::update::` +This forces the software to update the values of a device. It returns nothing. +Replace device-id with the appropriate device-id of the device you want to update. + +### `device::subscribe::` +This enables observation of the state of a device. The command itself returns nothing. + +Once there was a change in any values of the device a message will be send: +``` +subscribedDeviceUpdate:::: +``` + +### `device::info::` +This returns the current buffered info of a device. Please note, that this info isn't necessarily up-to-date. The buffer either gets updated by `device::update::` or if something changes for the device and a device subscription is active. + +It returns the following: +``` +deviceInfo:::: +``` + +### `device::set::::::` + +This writes an attribute to a specified device. This command returns nothing. + +The following attributes can be set: + + +| Attribute | Values | Description | +|:---------:|:------------------:|:------------------------------------------------------------------------------:| +| onoff | 0 or 1 | Turns the device on or off | +| color | 6 digit hex number | Sets the light color of the device. The most devices only support some colors. | +| dimvalue | 0 - 254 | Sets the brightness of the device | +| name | any string | Sets the name of the device | + +### Device JSON Info +The JSON Info that is returned after subscription or an info-command looks like this, but in a single line (without whitespaces): + +``` +{ + "lastSeenAt":1501407261, + "createdAt":1492280964, + "reachabilityState":1, + "name":"Fenster Links", + "dimvalue":200, + "type":"TRADFRI bulb E27 opal 1000lm", + "deviceid":65537, + "version":"1.1.1.0-5.7.2.0", + "manufacturer":"IKEA of Sweden", + "onoff":0 +} +``` + +## Commands for groups + +### `group::list` +This lists all groups that are configured in the gateway.. +The output is a JSON-Array with the group IDs and their name: `groupList::[{"groupid":196210,"name":"Group1"},{"groupid":173540,"name":"Group2"}]`. +### `group::moodlist::` +Lists the moods that are configured for this group. It returns a JSON Array: ```moodList::::[{"moodid":201819,"groupid":196210,"name":"EVERYDAY"},{"moodid":222829,"groupid":196210,"name":"RELAX"},{"moodid":225859,"groupid":196210,"name":"FOCUS"}]``` + +### `group::update::` +This forces the software to update the values of a group. It returns nothing. +Replace group-id with the appropriate group-id of the group you want to update. + +### `group::subscribe::` +This enables observation of the state of a group. The command itself returns nothing. + +Once there was a change in any values of the device a message will be send: +``` +subscribedGroupUpdate:::: +``` + +### `group::info::` +This returns the current buffered info of a group. Please note, that this info isn't necessarily up-to-date. The buffer either gets updated by `group::update::` or if something changes for the group and a group subscription is active. + +It returns the following: +``` +groupInfo:::: +``` +#### Group JSON Info +The JSON Info that is returned after subscription or an info-command looks like this, but in a single line (without whitespaces): + +``` +{ + "createdAt":1494088484, + "mood":198884, + "groupid":173540, + "members":[ + { + "name":"Fenster Links", + "deviceid":65537 + }, + { + "deviceid":65536 + }, + { + "name":"Fenster Rechts", + "deviceid":65538 + } + ], + "name":"Wohnzimmer", + "dimvalue":200, + "onoff":0 +} +``` +### `group::mood::::moodinfo::` +This returns the information about a specified mood. The command returns `moodInfo::::` +#### Mood JSON Info +The JSON that is returned for the moodinfo is built up like that (without newlines): +``` +{ + "createdAt":1495047831, + "moodid":201819, + "groupid":196210, + "name":"EVERYDAY" +} +``` + +### `group::set::::::` + +This writes an attribute to a specified group. This command returns nothing. + +The following attributes can be set: + + +| Attribute | Values | Description | +|:---------:|:------------------:|:------------------------------------------------------------------------------:| +| onoff | 0 or 1 | Turns the device on or off | +| mood | mood id | Set the mood of the group | +| dimvalue | 0 - 254 | Sets the brightness of the device | +| name | any string | Sets the name of the device |