├── .gitignore ├── LICENSE ├── README.md ├── doc ├── Circuit.jpg ├── Circuit_LEDs.jpg ├── OpenBulb.jpg └── screenshot.png └── tradfri-java ├── .classpath ├── .project ├── .settings ├── org.eclipse.jdt.core.prefs └── org.eclipse.m2e.core.prefs ├── Californium.properties ├── nbactions.xml ├── pom.xml └── src └── main ├── java └── org │ └── thingml │ └── tradfri │ ├── LightBulb.java │ ├── Main.java │ ├── TradfriBulbListener.java │ ├── TradfriConstants.java │ ├── TradfriGateway.java │ ├── TradfriGatewayListener.java │ └── ui │ ├── BulbPanel.form │ ├── BulbPanel.java │ ├── LoggingPanel.form │ ├── LoggingPanel.java │ ├── MainFrame.form │ └── MainFrame.java └── resources └── logo.png /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | dependency-reduced-pom.xml 8 | buildNumber.properties 9 | .mvn/timing.properties 10 | 11 | # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) 12 | !/.mvn/wrapper/maven-wrapper.jar 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ThingML-Tradfri 2 | 3 | The goal of the project is to provide an event-based ThingML / JAVA API to monitor and control IKEA TRÅDFRI smart bulbs. It is currently in an early developement stage but comes with a GUI which allow monitoring and controlling the different types of TRÅDFRI bulbs. 4 | 5 | ![Screenshot](doc/screenshot.png "Screenshot") 6 | 7 | To compile the tradfri-java project, run `mvn clean install` 8 | 9 | To run the GUI, run `mvn exec:java` 10 | 11 | ## IKEA TRÅDFRI LED Color Bulbs 12 | 13 | IKEA recently released variable color bulbs. The Identification for the bulb I have got is "TRADFRI bulb E27 CWS opal 600lm" which, for now, only seem to be sold as a set with one remote control. There are not a lot of details on the box on what these bulbs are capable of. Let's open one to see how they work and what they can do. 14 | 15 | ![Open Color Bulb](doc/OpenBulb.jpg "Open Color Bulb") 16 | 17 | Using the remote control only allows dimming and cycling through 9 colors: 18 | 19 | ![#f03c15](https://placehold.it/15/f1e0b5/000000?text=+) ![#c5f015](https://placehold.it/15/f5faf6/000000?text=+) ![#1589F0](https://placehold.it/15/efd275/000000?text=+) ![#f03c15](https://placehold.it/15/ebb63e/000000?text=+) ![#c5f015](https://placehold.it/15/e78834/000000?text=+) ![#1589F0](https://placehold.it/15/da5d41/000000?text=+) ![#f03c15](https://placehold.it/15/d9337c/000000?text=+) ![#c5f015](https://placehold.it/15/c984bb/000000?text=+) ![#1589F0](https://placehold.it/15/6c83ba/000000?text=+) 20 | 21 | The first 3 colors correspond to the the 3 whites of the variable color temperature bulbs. 22 | 23 | Using the IKEA App allows selecting 11 more colors for a total of 20: 24 | 25 | ![#dcf0f8](https://placehold.it/15/dcf0f8/000000?text=+) ![#eaf6fb](https://placehold.it/15/eaf6fb/000000?text=+) ![#f5faf6](https://placehold.it/15/f5faf6/000000?text=+) ![#f2eccf](https://placehold.it/15/f2eccf/000000?text=+) ![#f1e0b5](https://placehold.it/15/f1e0b5/000000?text=+) ![#f1e0b5](https://placehold.it/15/f1e0b5/000000?text=+) ![#efd275](https://placehold.it/15/efd275/000000?text=+) ![#ebb63e](https://placehold.it/15/ebb63e/000000?text=+) ![#e78834](https://placehold.it/15/e78834/000000?text=+) ![#e57345](https://placehold.it/15/e57345/000000?text=+) ![#da5d41](https://placehold.it/15/da5d41/000000?text=+) ![#dc4b31](https://placehold.it/15/dc4b31/000000?text=+) ![#e491af](https://placehold.it/15/e491af/000000?text=+) ![#e8bedd](https://placehold.it/15/e8bedd/000000?text=+) ![#d9337c](https://placehold.it/15/d9337c/000000?text=+) ![#c984bb](https://placehold.it/15/c984bb/000000?text=+) ![#8f2686](https://placehold.it/15/8f2686/000000?text=+) ![#4a418a](https://placehold.it/15/4a418a/000000?text=+) ![#6c83ba](https://placehold.it/15/6c83ba/000000?text=+) ![#a9d62b](https://placehold.it/15/a9d62b/000000?text=+) ![#d6e44b](https://placehold.it/15/d6e44b/000000?text=+) (See further down for hex codes) 26 | 27 | When setting colors through the gateway only those 20 colors can be set using the hex code on property "5706". Trying anything else defaults back to the normal white color ("f1e0b5"). However more colors can be set by providing the COLOR_X and COLOR_Y on properties "5709" and "5710" respectively. Using X and Y the bulb will display a lot more colors but it does not cover the full spectrum and the maximum brightness varies greatly depending on the selected color. No deep green and no cyan are the most obvious missing colors. 28 | 29 | ![LED arrangement](doc/Circuit_LEDs.jpg "LED arrangement") 30 | 31 | Looking at the LEDs which are being used explains why the whole spectrum is not covered. The bulb has four different LED types: warm white, greenish yellow, red and blue. The RGB values I have put on the picture are aproximate but give a good idea of the color of each type of LED. 32 | 33 | ### JSON 34 | 35 | Here is an example JSON: 36 | ```json 37 | { 38 | "9001": "", 39 | "9002": 1514722258, 40 | "9020": 1514722619, 41 | "9003": 65557, 42 | "9054": 0, 43 | "5750": 2, 44 | "9019": 1, 45 | "3": { 46 | "0": "IKEA of Sweden", 47 | "1": "TRADFRI bulb E27 CWS opal 600lm", 48 | "2": "", 49 | "3": "1.3.002", 50 | "6": 1 51 | }, 52 | "3311": [ 53 | { 54 | "5851": 1, 55 | "5850": 1, 56 | "5707": 47822, 57 | "5708": 65279, 58 | "5709": 11469, 59 | "5710": 3277, 60 | "5706": "4a418a", 61 | "9003": 0 62 | } 63 | ] 64 | } 65 | ``` 66 | 67 | Here are the Hex code for each of the preset colors: 68 | - ![#dcf0f8](https://placehold.it/15/dcf0f8/000000?text=+) `#dcf0f8` 69 | - ![#eaf6fb](https://placehold.it/15/eaf6fb/000000?text=+) `#eaf6fb` 70 | - ![#f5faf6](https://placehold.it/15/f5faf6/000000?text=+) `#f5faf6` X [Cold White] 71 | - ![#f2eccf](https://placehold.it/15/f2eccf/000000?text=+) `#f2eccf` 72 | - ![#f1e0b5](https://placehold.it/15/f1e0b5/000000?text=+) `#f1e0b5` X [Normal White] 73 | - ![#efd275](https://placehold.it/15/efd275/000000?text=+) `#efd275` X [Warm White] 74 | - ![#ebb63e](https://placehold.it/15/ebb63e/000000?text=+) `#ebb63e` X 75 | - ![#e78834](https://placehold.it/15/e78834/000000?text=+) `#e78834` X 76 | - ![#e57345](https://placehold.it/15/e57345/000000?text=+) `#e57345` 77 | - ![#da5d41](https://placehold.it/15/da5d41/000000?text=+) `#da5d41` X 78 | - ![#dc4b31](https://placehold.it/15/dc4b31/000000?text=+) `#dc4b31` 79 | - ![#e491af](https://placehold.it/15/e491af/000000?text=+) `#e491af` 80 | - ![#e8bedd](https://placehold.it/15/e8bedd/000000?text=+) `#e8bedd` 81 | - ![#d9337c](https://placehold.it/15/d9337c/000000?text=+) `#d9337c` X 82 | - ![#c984bb](https://placehold.it/15/c984bb/000000?text=+) `#c984bb` X 83 | - ![#8f2686](https://placehold.it/15/8f2686/000000?text=+) `#8f2686` 84 | - ![#4a418a](https://placehold.it/15/4a418a/000000?text=+) `#4a418a` 85 | - ![#6c83ba](https://placehold.it/15/6c83ba/000000?text=+) `#6c83ba` X 86 | - ![#a9d62b](https://placehold.it/15/a9d62b/000000?text=+) `#a9d62b` 87 | - ![#d6e44b](https://placehold.it/15/d6e44b/000000?text=+) `#d6e44b` 88 | 89 | 90 | 91 | ## IKEA Variable Temperature Bulbs 92 | 93 | These bulbs have two sets of LEDs which allow for different color temperatures. The remote control and IKEA App allow cycling through 3 different shades of white: 94 | 95 | - ![#f03c15](https://placehold.it/15/f1e0b5/000000?text=+) `#f1e0b5` [A combination of the warm and cold LEDs] 96 | - ![#c5f015](https://placehold.it/15/f5faf6/000000?text=+) `#f5faf6` [Only cold white LEDs] 97 | - ![#1589F0](https://placehold.it/15/efd275/000000?text=+) `#efd275` [Only warm white LEDs] 98 | 99 | Only these 3 colors are possible when setting the color using the hex value but like for the color bulbs, using the X and Y paramenters allow for any possible color between the warm and the cold white. 100 | 101 | Here is an example JSON: 102 | ```json 103 | { 104 | "9001": "Spot Jaune", 105 | "9002": 1514653535, 106 | "9020": 1514739948, 107 | "9003": 65555, 108 | "9054": 0, 109 | "5750": 2, 110 | "9019": 1, 111 | "3": { 112 | "0": "IKEA of Sweden", 113 | "1": "TRADFRI bulb E27 WS opal 980lm", 114 | "2": "", 115 | "3": "1.2.217", 116 | "6": 1 117 | }, 118 | "3311": [ 119 | { 120 | "5851": 254, 121 | "5850": 1, 122 | "5711": 250, 123 | "5709": 24933, 124 | "5710": 24691, 125 | "5706": "f5faf6", 126 | "9003": 0 127 | } 128 | ] 129 | } 130 | ``` 131 | ## References 132 | 133 | - ZigBee Light Link user guide: https://www.nxp.com/docs/en/user-guide/JN-UG-3091.pdf 134 | - Java Implementation and some documentation from the eclipse/smarthome project (class TradfriColor has algorithms to convert between RGB and XYZ color): https://github.com/eclipse/smarthome/tree/master/extensions/binding/org.eclipse.smarthome.binding.tradfri 135 | - Discussion on ha-bridge with a lot of info: https://github.com/bwssytems/ha-bridge/issues/570 136 | - https://hackaday.com/2017/02/06/reverse-engineering-ikeas-new-smart-bulbs/ 137 | - https://hackaday.com/2017/06/14/ikea-tradfri-hacking/ 138 | - http://tradfri.blogspot.no/2017/04/teardown-of-ikea-tradfri-bulb-led1623g12.html 139 | 140 | 141 | -------------------------------------------------------------------------------- /doc/Circuit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffleurey/ThingML-Tradfri/e4c8a8bbe48e36d364b9fd1c574e6a1e292bb58e/doc/Circuit.jpg -------------------------------------------------------------------------------- /doc/Circuit_LEDs.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffleurey/ThingML-Tradfri/e4c8a8bbe48e36d364b9fd1c574e6a1e292bb58e/doc/Circuit_LEDs.jpg -------------------------------------------------------------------------------- /doc/OpenBulb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffleurey/ThingML-Tradfri/e4c8a8bbe48e36d364b9fd1c574e6a1e292bb58e/doc/OpenBulb.jpg -------------------------------------------------------------------------------- /doc/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffleurey/ThingML-Tradfri/e4c8a8bbe48e36d364b9fd1c574e6a1e292bb58e/doc/screenshot.png -------------------------------------------------------------------------------- /tradfri-java/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /tradfri-java/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | tradfri 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /tradfri-java/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 3 | org.eclipse.jdt.core.compiler.compliance=1.5 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.5 6 | -------------------------------------------------------------------------------- /tradfri-java/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /tradfri-java/Californium.properties: -------------------------------------------------------------------------------- 1 | #Californium CoAP Properties file 2 | #Tue Oct 03 12:42:23 CEST 2017 3 | HTTP_SERVER_SOCKET_BUFFER_SIZE=8192 4 | UDP_CONNECTOR_OUT_CAPACITY=2147483647 5 | CONGESTION_CONTROL_ALGORITHM=Cocoa 6 | USE_CONGESTION_CONTROL=false 7 | ACK_TIMEOUT=2000 8 | MAX_ACTIVE_PEERS=150000 9 | TCP_CONNECT_TIMEOUT=10000 10 | NOTIFICATION_CHECK_INTERVAL_COUNT=100 11 | MAX_MESSAGE_SIZE=1024 12 | MID_TRACKER_GROUPS=16 13 | DEDUPLICATOR=DEDUPLICATOR_MARK_AND_SWEEP 14 | TCP_CONNECTION_IDLE_TIMEOUT=10 15 | COAP_PORT=5683 16 | ACK_TIMEOUT_SCALE=2.0 17 | PREFERRED_BLOCK_SIZE=512 18 | NETWORK_STAGE_RECEIVER_THREAD_COUNT=1 19 | PROTOCOL_STAGE_THREAD_COUNT=16 20 | MAX_TRANSMIT_WAIT=93000 21 | USE_STRICT_RESPONSE_MATCHING=false 22 | UDP_CONNECTOR_RECEIVE_BUFFER=0 23 | EXCHANGE_LIFETIME=247000 24 | HTTP_SERVER_SOCKET_TIMEOUT=100000 25 | CROP_ROTATION_PERIOD=2000 26 | UDP_CONNECTOR_DATAGRAM_SIZE=2048 27 | MAX_RETRANSMIT=4 28 | MAX_PEER_INACTIVITY_PERIOD=600 29 | MAX_RESOURCE_BODY_SIZE=2048 30 | NOTIFICATION_CHECK_INTERVAL=86400000 31 | LEISURE=5000 32 | HTTP_CACHE_RESPONSE_MAX_AGE=86400 33 | BLOCKWISE_STATUS_LIFETIME=300000 34 | UDP_CONNECTOR_SEND_BUFFER=0 35 | MID_TACKER=GROUPED 36 | TCP_WORKER_THREADS=1 37 | HEALTH_STATUS_PRINT_LEVEL=FINEST 38 | NETWORK_STAGE_SENDER_THREAD_COUNT=1 39 | NON_LIFETIME=145000 40 | TOKEN_SIZE_LIMIT=8 41 | HTTP_PORT=8080 42 | MARK_AND_SWEEP_INTERVAL=10000 43 | HEALTH_STATUS_INTERVAL=60 44 | ACK_RANDOM_FACTOR=1.4 45 | NSTART=1 46 | USE_RANDOM_MID_START=true 47 | HTTP_CACHE_SIZE=32 48 | PROBING_RATE=1.0 49 | NOTIFICATION_REREGISTRATION_BACKOFF=2000 50 | COAP_SECURE_PORT=5684 51 | -------------------------------------------------------------------------------- /tradfri-java/nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | run 5 | 6 | jar 7 | 8 | 9 | process-classes 10 | org.codehaus.mojo:exec-maven-plugin:1.2.1:exec 11 | 12 | 13 | -classpath %classpath org.thingml.tradfri.ui.MainFrame 14 | java 15 | 16 | 17 | 18 | debug 19 | 20 | jar 21 | 22 | 23 | process-classes 24 | org.codehaus.mojo:exec-maven-plugin:1.2.1:exec 25 | 26 | 27 | -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath org.thingml.tradfri.ui.MainFrame 28 | java 29 | true 30 | 31 | 32 | 33 | profile 34 | 35 | jar 36 | 37 | 38 | process-classes 39 | org.codehaus.mojo:exec-maven-plugin:1.2.1:exec 40 | 41 | 42 | -classpath %classpath org.thingml.tradfri.ui.MainFrame 43 | java 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /tradfri-java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.thingml 4 | tradfri-java 5 | 0.9.0-SNAPSHOT 6 | IKEA Tradfri Gateway 7 | Java Gateway for the IKEA Tradfri smart lighting 8 | 9 | Tellu IoT 10 | 11 | 12 | 13 | 1.7 14 | 1.7 15 | 16 | 17 | 18 | src/main/java 19 | 20 | 21 | 22 | org.apache.maven.plugins 23 | maven-compiler-plugin 24 | 3.1 25 | 26 | 1.7 27 | 1.7 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | org.codehaus.mojo 36 | exec-maven-plugin 37 | 38 | 39 | 40 | java 41 | 42 | 43 | 44 | 45 | org.thingml.tradfri.ui.MainFrame 46 | 47 | 48 | 49 | 50 | maven-assembly-plugin 51 | 52 | 53 | 54 | org.thingml.tradfri.ui.MainFrame 55 | 56 | 57 | 58 | jar-with-dependencies 59 | 60 | 61 | 62 | 63 | make-assembly 64 | 65 | package 66 | 67 | 68 | single 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | org.json 79 | org.json 80 | chargebee-1.0 81 | 82 | 83 | org.eclipse.californium 84 | californium-core 85 | 2.0.0-M5 86 | 87 | 88 | org.eclipse.californium 89 | scandium 90 | 2.0.0-M5 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /tradfri-java/src/main/java/org/thingml/tradfri/LightBulb.java: -------------------------------------------------------------------------------- 1 | package org.thingml.tradfri; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Date; 5 | import java.util.logging.Level; 6 | import java.util.logging.Logger; 7 | 8 | import org.eclipse.californium.core.CoapResponse; 9 | import org.json.JSONArray; 10 | import org.json.JSONException; 11 | import org.json.JSONObject; 12 | 13 | public class LightBulb { 14 | 15 | private ArrayList listners = new ArrayList(); 16 | 17 | public void addLightBulbListner(TradfriBulbListener l) { 18 | listners.add(l); 19 | } 20 | public void removeLightBulbListner(TradfriBulbListener l) { 21 | listners.remove(l); 22 | } 23 | public void clearLightBulbListners() { 24 | listners.clear(); 25 | } 26 | 27 | private TradfriGateway gateway; 28 | 29 | // Immutable information 30 | private int id; 31 | private String name; 32 | 33 | private JSONObject jsonObject; 34 | 35 | public JSONObject getJsonObject() { 36 | return jsonObject; 37 | } 38 | 39 | public int getId() { 40 | return id; 41 | } 42 | 43 | public String getName() { 44 | return name; 45 | } 46 | 47 | public String getType() { 48 | return type; 49 | } 50 | 51 | public boolean isOnline() { 52 | return online; 53 | } 54 | 55 | public boolean isOn() { 56 | return on; 57 | } 58 | 59 | public void setOn(boolean on) { 60 | try { 61 | JSONObject json = new JSONObject(); 62 | JSONObject settings = new JSONObject(); 63 | JSONArray array = new JSONArray(); 64 | array.put(settings); 65 | json.put(TradfriConstants.LIGHT, array); 66 | settings.put(TradfriConstants.ONOFF, (on)?1:0); 67 | String payload = json.toString(); 68 | gateway.set(TradfriConstants.DEVICES + "/" + this.getId(), payload); 69 | 70 | } catch (JSONException ex) { 71 | Logger.getLogger(TradfriGateway.class.getName()).log(Level.SEVERE, null, ex); 72 | } 73 | this.on = on; 74 | } 75 | 76 | public int getIntensity() { 77 | return intensity; 78 | } 79 | 80 | public void setIntensity(int intensity) { 81 | try { 82 | JSONObject json = new JSONObject(); 83 | JSONObject settings = new JSONObject(); 84 | JSONArray array = new JSONArray(); 85 | array.put(settings); 86 | json.put(TradfriConstants.LIGHT, array); 87 | settings.put(TradfriConstants.DIMMER, intensity); 88 | settings.put(TradfriConstants.TRANSITION_TIME, 5); 89 | String payload = json.toString(); 90 | gateway.set(TradfriConstants.DEVICES + "/" + this.getId(), payload); 91 | 92 | } catch (JSONException ex) { 93 | Logger.getLogger(TradfriGateway.class.getName()).log(Level.SEVERE, null, ex); 94 | } 95 | this.intensity = intensity; 96 | } 97 | 98 | public String getColor() { 99 | return color; 100 | } 101 | 102 | public void sendJSONPayload(String json) { 103 | gateway.set(TradfriConstants.DEVICES + "/" + this.getId(), json); 104 | } 105 | 106 | public void setRGBColor(int r, int g, int b) { 107 | double red = r; 108 | double green = g; 109 | double blue = b; 110 | 111 | // gamma correction 112 | red = (red > 0.04045) ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : (red / 12.92); 113 | green = (green > 0.04045) ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : (green / 12.92); 114 | blue = (blue > 0.04045) ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : (blue / 12.92); 115 | 116 | // Wide RGB D65 conversion 117 | // math inspiration: http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html 118 | double X = red * 0.664511 + green * 0.154324 + blue * 0.162028; 119 | double Y = red * 0.283881 + green * 0.668433 + blue * 0.047685; 120 | double Z = red * 0.000088 + green * 0.072310 + blue * 0.986039; 121 | 122 | // calculate the xy values from XYZ 123 | double x = (X / (X + Y + Z)); 124 | double y = (Y / (X + Y + Z)); 125 | 126 | int xyX = (int) (x * 65535 + 0.5); 127 | int xyY = (int) (y * 65535 + 0.5); 128 | 129 | try { 130 | JSONObject json = new JSONObject(); 131 | JSONObject settings = new JSONObject(); 132 | JSONArray array = new JSONArray(); 133 | array.put(settings); 134 | json.put(TradfriConstants.LIGHT, array); 135 | settings.put(TradfriConstants.COLOR_X, xyX); 136 | settings.put(TradfriConstants.COLOR_Y, xyY); 137 | settings.put(TradfriConstants.TRANSITION_TIME, 5); 138 | String payload = json.toString(); 139 | gateway.set(TradfriConstants.DEVICES + "/" + this.getId(), payload); 140 | 141 | } catch (JSONException ex) { 142 | Logger.getLogger(TradfriGateway.class.getName()).log(Level.SEVERE, null, ex); 143 | } 144 | 145 | } 146 | 147 | public void setColor(String color) { 148 | try { 149 | JSONObject json = new JSONObject(); 150 | JSONObject settings = new JSONObject(); 151 | JSONArray array = new JSONArray(); 152 | array.put(settings); 153 | json.put(TradfriConstants.LIGHT, array); 154 | settings.put(TradfriConstants.COLOR, color); 155 | settings.put(TradfriConstants.TRANSITION_TIME, 5); 156 | String payload = json.toString(); 157 | gateway.set(TradfriConstants.DEVICES + "/" + this.getId(), payload); 158 | 159 | } catch (JSONException ex) { 160 | Logger.getLogger(TradfriGateway.class.getName()).log(Level.SEVERE, null, ex); 161 | } 162 | this.color = color; 163 | } 164 | private String manufacturer; 165 | private String type; 166 | private String firmware; 167 | 168 | // Status 169 | private boolean online; 170 | 171 | // State of the bulb 172 | private boolean on; 173 | private int intensity; 174 | private String color; 175 | 176 | // Dates 177 | private Date dateInstalled; 178 | private Date dateLastSeen; 179 | 180 | public String getFirmware() { 181 | return firmware; 182 | } 183 | 184 | public Date getDateInstalled() { 185 | return dateInstalled; 186 | } 187 | 188 | public Date getDateLastSeen() { 189 | return dateLastSeen; 190 | } 191 | 192 | public LightBulb(int id, TradfriGateway gateway) { 193 | this.id = id; 194 | this.gateway = gateway; 195 | } 196 | 197 | public LightBulb(int id, TradfriGateway gateway, CoapResponse response) { 198 | this.id = id; 199 | this.gateway = gateway; 200 | if (response != null) parseResponse(response); 201 | } 202 | 203 | protected void updateBulb() { 204 | CoapResponse response = gateway.get(TradfriConstants.DEVICES + "/" + id); 205 | if (response != null) parseResponse(response); 206 | } 207 | 208 | protected void parseResponse(CoapResponse response) { 209 | boolean updateListeners = false; 210 | gateway.getLogger().log(Level.INFO, response.getResponseText()); 211 | try { 212 | JSONObject json = new JSONObject(response.getResponseText()); 213 | jsonObject = json; 214 | String new_name = json.getString(TradfriConstants.NAME); 215 | if (name == null || !name.equals(new_name)) updateListeners = true; 216 | name = new_name; 217 | 218 | dateInstalled = new Date(json.getLong(TradfriConstants.DATE_INSTALLED)*1000); 219 | dateLastSeen = new Date(json.getLong(TradfriConstants.DATE_LAST_SEEN)*1000); 220 | 221 | boolean new_online = json.getInt(TradfriConstants.DEVICE_REACHABLE) != 0; 222 | if (new_online != online) updateListeners = true; 223 | online = new_online; 224 | 225 | manufacturer = json.getJSONObject("3").getString("0"); 226 | type = json.getJSONObject("3").getString("1"); 227 | firmware = json.getJSONObject("3").getString("3"); 228 | 229 | JSONObject light = json.getJSONArray(TradfriConstants.LIGHT).getJSONObject(0); 230 | 231 | if (light.has(TradfriConstants.ONOFF) && light.has(TradfriConstants.DIMMER)) { 232 | boolean new_on = (light.getInt(TradfriConstants.ONOFF) != 0); 233 | int new_intensity = light.getInt(TradfriConstants.DIMMER); 234 | if (on != new_on) updateListeners = true; 235 | if (intensity != new_intensity) updateListeners = true; 236 | on = new_on; 237 | intensity = new_intensity; 238 | } 239 | else { 240 | if (online) updateListeners = true; 241 | online = false; 242 | } 243 | if (light.has(TradfriConstants.COLOR)) { 244 | String new_color = light.getString(TradfriConstants.COLOR); 245 | if (color == null || !color.equals(new_color)) updateListeners = true; 246 | color = new_color; 247 | } 248 | } catch (JSONException e) { 249 | System.err.println("Cannot update bulb info: error parsing the response from the gateway."); 250 | e.printStackTrace(); 251 | } 252 | if (updateListeners) { 253 | for (TradfriBulbListener l : listners) l.bulb_state_changed(this); 254 | } 255 | } 256 | 257 | public String toString() { 258 | String result = "[BULB " + id + "]"; 259 | if (online) result += "\ton:" + on + "\tdim:" + intensity + "\tcolor:" + color; 260 | else result += " ********** OFFLINE *********** "; 261 | result += "\ttype: " + type + "\tname: " + name; 262 | return result; 263 | } 264 | 265 | } 266 | -------------------------------------------------------------------------------- /tradfri-java/src/main/java/org/thingml/tradfri/Main.java: -------------------------------------------------------------------------------- 1 | package org.thingml.tradfri; 2 | 3 | public class Main { 4 | 5 | protected static String gateway_ip = "10.3.1.180"; 6 | protected static String security_key = "5HV7ibb4brgWL18x"; 7 | 8 | 9 | public static void main(String[] args) { 10 | 11 | TradfriGateway gw = new TradfriGateway(gateway_ip, security_key); 12 | gw.initCoap(); 13 | gw.dicoverBulbs(); 14 | for (LightBulb b : gw.bulbs) { 15 | //b.updateBulb(); 16 | System.out.println(b.toString()); 17 | } 18 | 19 | System.exit(0); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /tradfri-java/src/main/java/org/thingml/tradfri/TradfriBulbListener.java: -------------------------------------------------------------------------------- 1 | package org.thingml.tradfri; 2 | 3 | public interface TradfriBulbListener { 4 | 5 | public void bulb_state_changed(LightBulb bulb); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /tradfri-java/src/main/java/org/thingml/tradfri/TradfriConstants.java: -------------------------------------------------------------------------------- 1 | package org.thingml.tradfri; 2 | 3 | /** 4 | * 5 | * This class builds on the constants from project https://github.com/hardillb/TRADFRI2MQTT 6 | * (by r41d) 7 | * Partly inspired by "com/ikea/tradfri/lighting/ipso/IPSOObjects.java" 8 | * Some of these values can be found in the official LwM2M registry: 9 | * http://www.openmobilealliance.org/wp/OMNA/LwM2M/LwM2MRegistry.html 10 | */ 11 | 12 | public class TradfriConstants { 13 | 14 | // Device types (contained in INSTANCE_ID = "9003" inside of array contained in LIGHT = "3311") 15 | public static final int TYPE_REMOTE = 0; 16 | public static final int TYPE_BULB = 2; 17 | // The others need to be figured out by people who own these 18 | 19 | // Top level navigation 20 | public static final String DEVICES = "15001"; // individual bulbs, remotes, motion sensors, ... 21 | public static final String GROUPS = "15004"; // also called rooms 22 | public static final String SCENE = "15005"; // also called moods 23 | public static final String NOTIFICATIONS = "15006"; // ??? 24 | public static final String TIMERS = "15010"; 25 | 26 | // Values in JSON data 27 | public static final String NAME = "9001"; // used in both devices and groups 28 | public static final String DATE_INSTALLED = "9002"; // Timestamp Epoch (seconds), The date the device was paired??? 29 | public static final String DATE_LAST_SEEN = "9020"; // Timestamp Epoch (seconds), The date the devive was seen ??? Not sure. 30 | public static final String DEVICE_REACHABLE = "9019"; // 0 or 1 seems to go to 0 after a few minutes if the device is not reachable 31 | public static final String INSTANCE_ID = "9003"; // In devices: device ID. In groups: list of device IDs 32 | public static final String HS_ACCESSORY_LINK = "9018"; // Groups have this entry 33 | public static final String IKEA_MOODS = "9068"; // Moods have this entry 34 | public static final String LIGHT = "3311"; // urn:oma:lwm2m:ext:3311 in LwM2M registry 35 | public static final String TYPE = "5750"; // "Application Type" in LwM2M registry 36 | public static final String ONOFF = "5850"; // "On/Off" in LwM2M registry 37 | public static final String DIMMER = "5851"; // "Dimmer" in LwM2M registry 38 | public static final String SCENE_ID = "9039"; // Property of rooms 39 | 40 | public static final String TRANSITION_TIME = "5712"; // not contained in LwM2M registry 41 | 42 | // Color / Temperature related, these are independent of brightness, i.e. do not change if brightness does 43 | public static final String COLOR = "5706"; 44 | public static final String COLOR_X = "5709"; 45 | public static final String COLOR_Y = "5710"; 46 | public static final String COLOR_COLD = "f5faf6"; 47 | public static final String COLOR_COLD_X = "24930"; 48 | public static final String COLOR_COLD_Y = "24694"; 49 | public static final String COLOR_NORMAL = "f1e0b5"; 50 | public static final String COLOR_NORMAL_X = "30140"; 51 | public static final String COLOR_NORMAL_Y = "26909"; 52 | public static final String COLOR_WARM = "efd275"; 53 | public static final String COLOR_WARM_X = "33135"; 54 | public static final String COLOR_WARM_Y = "27211"; 55 | 56 | 57 | // Dimmer related 58 | public static final int DIMMER_MIN = 0; 59 | public static final int DIMMER_MAX = 254; 60 | } 61 | -------------------------------------------------------------------------------- /tradfri-java/src/main/java/org/thingml/tradfri/TradfriGateway.java: -------------------------------------------------------------------------------- 1 | package org.thingml.tradfri; 2 | 3 | import java.util.ArrayList; 4 | import java.util.logging.Level; 5 | import java.util.logging.Logger; 6 | 7 | import org.eclipse.californium.core.CoapClient; 8 | import org.eclipse.californium.core.CoapResponse; 9 | import org.eclipse.californium.core.coap.MediaTypeRegistry; 10 | import org.eclipse.californium.core.network.CoapEndpoint; 11 | import org.eclipse.californium.core.network.config.NetworkConfig; 12 | import org.eclipse.californium.scandium.DTLSConnector; 13 | import org.eclipse.californium.scandium.config.DtlsConnectorConfig; 14 | import org.eclipse.californium.scandium.dtls.pskstore.StaticPskStore; 15 | import org.json.JSONArray; 16 | import org.json.JSONException; 17 | import org.json.JSONObject; 18 | 19 | 20 | public class TradfriGateway implements Runnable { 21 | 22 | /** 23 | * Gateway properties and constructor 24 | */ 25 | protected String gateway_ip; 26 | protected String security_key; 27 | protected int polling_rate = 5000; 28 | 29 | public TradfriGateway() { 30 | 31 | } 32 | 33 | public TradfriGateway(String gateway_ip, String security_key) { 34 | this.gateway_ip = gateway_ip; 35 | this.security_key = security_key; 36 | } 37 | 38 | public String getGateway_ip() { 39 | return gateway_ip; 40 | } 41 | 42 | public void setGateway_ip(String gateway_ip) { 43 | this.gateway_ip = gateway_ip; 44 | } 45 | 46 | public String getSecurity_key() { 47 | return security_key; 48 | } 49 | 50 | public void setSecurity_key(String security_key) { 51 | this.security_key = security_key; 52 | } 53 | 54 | public int getPolling_rate() { 55 | return polling_rate; 56 | } 57 | 58 | public void setPolling_rate(int polling_rate) { 59 | // between 1 and 60 seconds 60 | if (polling_rate < 1000) polling_rate = 1000; 61 | else if (polling_rate > 60000) polling_rate = 60000; 62 | this.polling_rate = polling_rate; 63 | } 64 | 65 | private boolean running = false; 66 | 67 | public boolean isRunning() { 68 | return running; 69 | } 70 | 71 | /** 72 | * Logger to be used for all console outputs, errors and exceptions 73 | */ 74 | private Logger logger = Logger.getLogger(TradfriGateway.class.getName()); 75 | public Logger getLogger() { return logger; } 76 | 77 | /** 78 | * Observer pattern for asynchronous event notification 79 | */ 80 | private ArrayList listners = new ArrayList(); 81 | public void addTradfriGatewayListener(TradfriGatewayListener l) { 82 | listners.add(l); 83 | } 84 | public void removeTradfriGatewayListener(TradfriGatewayListener l) { 85 | listners.remove(l); 86 | } 87 | public void clearTradfriGatewayListener() { 88 | listners.clear(); 89 | } 90 | 91 | /** 92 | * Gateway public API 93 | */ 94 | public void startTradfriGateway() { 95 | if (running) return; 96 | running = true; 97 | new Thread(this).start(); 98 | } 99 | 100 | public void stopTradfriGateway() { 101 | running = false; 102 | } 103 | 104 | public void run() { 105 | for (TradfriGatewayListener l : listners) l.gateway_initializing(); 106 | Logger.getLogger(TradfriGateway.class.getName()).log(Level.INFO, "Tradfri Gateway is initalizing..."); 107 | initCoap(); 108 | Logger.getLogger(TradfriGateway.class.getName()).log(Level.INFO, "Discovering Devices..."); 109 | if (dicoverBulbs()) { 110 | Logger.getLogger(TradfriGateway.class.getName()).log(Level.INFO, "Discovered " + bulbs.size() + " Bulbs."); 111 | for (TradfriGatewayListener l : listners) l.gateway_started(); 112 | try { 113 | while(running) { 114 | Thread.sleep(getPolling_rate()); 115 | Logger.getLogger(TradfriGateway.class.getName()).log(Level.INFO, "Polling bulbs status..."); 116 | for (TradfriGatewayListener l : listners) l.polling_started(); 117 | long before = System.currentTimeMillis(); 118 | for (LightBulb b : bulbs) { 119 | b.updateBulb(); 120 | //System.out.println(b.toString()); 121 | } 122 | long after = System.currentTimeMillis(); 123 | for (TradfriGatewayListener l : listners) l.polling_completed(bulbs.size(), (int)(after - before)); 124 | } 125 | } catch (InterruptedException ex) { 126 | Logger.getLogger(TradfriGateway.class.getName()).log(Level.SEVERE, null, ex); 127 | } 128 | } 129 | running = false; 130 | for (TradfriGatewayListener l : listners) l.gateway_stoped(); 131 | } 132 | 133 | 134 | 135 | // Collection of bulbs registered on the gateway 136 | ArrayList bulbs = new ArrayList(); 137 | 138 | protected boolean dicoverBulbs() { 139 | bulbs.clear(); 140 | try { 141 | CoapResponse response = get(TradfriConstants.DEVICES); 142 | if (response == null) return false; 143 | JSONArray devices = new JSONArray(response.getResponseText()); 144 | for (TradfriGatewayListener l : listners) l.bulb_discovery_started(devices.length()); 145 | for (int i = 0; i < devices.length(); i++) { 146 | response = get(TradfriConstants.DEVICES + "/" + devices.getInt(i)); 147 | if (response != null) { 148 | JSONObject json = new JSONObject(response.getResponseText()); 149 | if (json.has(TradfriConstants.TYPE) && json.getInt(TradfriConstants.TYPE) == TradfriConstants.TYPE_BULB) { 150 | LightBulb b = new LightBulb(json.getInt(TradfriConstants.INSTANCE_ID), this, response); 151 | bulbs.add(b); 152 | for (TradfriGatewayListener l : listners) l.bulb_discovered(b); 153 | } 154 | } 155 | 156 | } 157 | for (TradfriGatewayListener l : listners) l.bulb_discovery_completed(); 158 | } catch (JSONException e) { 159 | logger.log(Level.SEVERE,"Error parsing response from the Tradfri gateway", e); 160 | return false; 161 | 162 | } 163 | return true; 164 | } 165 | 166 | 167 | 168 | /** 169 | * COAPS helpers to GET and SET on the IKEA Tradfri gateway using Californium 170 | */ 171 | private CoapEndpoint coap = null; 172 | protected void initCoap() { 173 | DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(); //new InetSocketAddress(0) 174 | builder.setPskStore(new StaticPskStore("", security_key.getBytes())); 175 | coap = new CoapEndpoint(new DTLSConnector(builder.build()), NetworkConfig.getStandard()); 176 | } 177 | 178 | protected CoapResponse get(String path) { 179 | Logger.getLogger(TradfriGateway.class.getName()).log(Level.INFO, "GET: " + "coaps://" + gateway_ip + "/" + path); 180 | CoapClient client = new CoapClient("coaps://" + gateway_ip + "/" + path); 181 | client.setEndpoint(coap); 182 | CoapResponse response = client.get(1); 183 | if (response == null) { 184 | logger.log(Level.SEVERE, "Connection to Gateway timed out, please check ip address or increase the ACK_TIMEOUT in the Californium.properties file"); 185 | } 186 | return response; 187 | } 188 | 189 | protected void set(String path, String payload) { 190 | Logger.getLogger(TradfriGateway.class.getName()).log(Level.INFO, "SET: " + "coaps://" + gateway_ip + "/" + path + " = " + payload); 191 | CoapClient client = new CoapClient("coaps://" + gateway_ip + "/" + path); 192 | client.setEndpoint(coap); 193 | CoapResponse response = client.put(payload, MediaTypeRegistry.TEXT_PLAIN); 194 | if (response != null && response.isSuccess()) { 195 | //System.out.println("Yay"); 196 | } else { 197 | logger.log(Level.SEVERE, "Sending payload to " + "coaps://" + gateway_ip + "/" + path + " failed!"); 198 | } 199 | client.shutdown(); 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /tradfri-java/src/main/java/org/thingml/tradfri/TradfriGatewayListener.java: -------------------------------------------------------------------------------- 1 | package org.thingml.tradfri; 2 | 3 | import java.util.logging.Logger; 4 | 5 | /** 6 | * 7 | * @author franck 8 | */ 9 | public interface TradfriGatewayListener { 10 | 11 | public void gateway_initializing(); 12 | public void bulb_discovery_started(int total_devices); 13 | public void bulb_discovered(LightBulb b); 14 | public void bulb_discovery_completed(); 15 | public void gateway_started(); 16 | 17 | public void gateway_stoped(); 18 | 19 | public void polling_started(); 20 | public void polling_completed(int bulb_count, int total_time); 21 | } 22 | -------------------------------------------------------------------------------- /tradfri-java/src/main/java/org/thingml/tradfri/ui/BulbPanel.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | -------------------------------------------------------------------------------- /tradfri-java/src/main/java/org/thingml/tradfri/ui/BulbPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package org.thingml.tradfri.ui; 7 | 8 | import java.awt.Color; 9 | import java.awt.Font; 10 | import java.awt.Frame; 11 | import java.util.logging.Level; 12 | import java.util.logging.Logger; 13 | import javax.swing.JButton; 14 | import javax.swing.JColorChooser; 15 | import javax.swing.JDialog; 16 | import javax.swing.JOptionPane; 17 | import javax.swing.JScrollPane; 18 | import javax.swing.JTextArea; 19 | import org.json.JSONException; 20 | import org.thingml.tradfri.LightBulb; 21 | import org.thingml.tradfri.TradfriConstants; 22 | import org.thingml.tradfri.TradfriBulbListener; 23 | 24 | /** 25 | * 26 | * @author franck 27 | */ 28 | public class BulbPanel extends javax.swing.JPanel implements TradfriBulbListener { 29 | 30 | protected LightBulb bulb; 31 | protected boolean updating = true; 32 | /** 33 | * Creates new form BulbPanel 34 | */ 35 | public BulbPanel(LightBulb bulb) { 36 | this.bulb = bulb; 37 | bulb.addLightBulbListner(this); 38 | initComponents(); 39 | updatePanelContent(); 40 | } 41 | 42 | /** 43 | * This method is called from within the constructor to initialize the form. 44 | * WARNING: Do NOT modify this code. The content of this method is always 45 | * regenerated by the Form Editor. 46 | */ 47 | @SuppressWarnings("unchecked") 48 | // //GEN-BEGIN:initComponents 49 | private void initComponents() { 50 | 51 | buttonGroupTemperature = new javax.swing.ButtonGroup(); 52 | jToggleButton1 = new javax.swing.JToggleButton(); 53 | jLabel1 = new javax.swing.JLabel(); 54 | jSlider1 = new javax.swing.JSlider(); 55 | jTextFieldName = new javax.swing.JTextField(); 56 | jRadioCold = new javax.swing.JRadioButton(); 57 | jRadioNormal = new javax.swing.JRadioButton(); 58 | jRadioWarm = new javax.swing.JRadioButton(); 59 | jLabel2 = new javax.swing.JLabel(); 60 | jLabelDates = new javax.swing.JLabel(); 61 | jButton1 = new javax.swing.JButton(); 62 | jButton2 = new javax.swing.JButton(); 63 | jButton3 = new javax.swing.JButton(); 64 | 65 | setMaximumSize(new java.awt.Dimension(32767, 89)); 66 | setMinimumSize(new java.awt.Dimension(0, 89)); 67 | 68 | jToggleButton1.setText("On / Off"); 69 | jToggleButton1.addActionListener(new java.awt.event.ActionListener() { 70 | public void actionPerformed(java.awt.event.ActionEvent evt) { 71 | jToggleButton1ActionPerformed(evt); 72 | } 73 | }); 74 | 75 | jLabel1.setText("Intensity :"); 76 | 77 | jSlider1.setMaximum(255); 78 | jSlider1.setMinimum(1); 79 | jSlider1.addChangeListener(new javax.swing.event.ChangeListener() { 80 | public void stateChanged(javax.swing.event.ChangeEvent evt) { 81 | jSlider1StateChanged(evt); 82 | } 83 | }); 84 | 85 | jTextFieldName.setEditable(false); 86 | jTextFieldName.setText("[Not Connected]"); 87 | 88 | buttonGroupTemperature.add(jRadioCold); 89 | jRadioCold.setText("Cold"); 90 | jRadioCold.addActionListener(new java.awt.event.ActionListener() { 91 | public void actionPerformed(java.awt.event.ActionEvent evt) { 92 | jRadioColdActionPerformed(evt); 93 | } 94 | }); 95 | 96 | buttonGroupTemperature.add(jRadioNormal); 97 | jRadioNormal.setText("Normal"); 98 | jRadioNormal.addActionListener(new java.awt.event.ActionListener() { 99 | public void actionPerformed(java.awt.event.ActionEvent evt) { 100 | jRadioNormalActionPerformed(evt); 101 | } 102 | }); 103 | 104 | buttonGroupTemperature.add(jRadioWarm); 105 | jRadioWarm.setText("Warm"); 106 | jRadioWarm.addActionListener(new java.awt.event.ActionListener() { 107 | public void actionPerformed(java.awt.event.ActionEvent evt) { 108 | jRadioWarmActionPerformed(evt); 109 | } 110 | }); 111 | 112 | jLabel2.setText("Name :"); 113 | 114 | jLabelDates.setFont(new java.awt.Font("Dialog", 0, 10)); // NOI18N 115 | jLabelDates.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); 116 | jLabelDates.setText("Installed: Unknown - Last seen: Unknown - Firmware: Unknown"); 117 | 118 | jButton1.setFont(new java.awt.Font("Dialog", 1, 10)); // NOI18N 119 | jButton1.setText("GET"); 120 | jButton1.setMaximumSize(new java.awt.Dimension(56, 18)); 121 | jButton1.setMinimumSize(new java.awt.Dimension(56, 18)); 122 | jButton1.setPreferredSize(new java.awt.Dimension(56, 18)); 123 | jButton1.addActionListener(new java.awt.event.ActionListener() { 124 | public void actionPerformed(java.awt.event.ActionEvent evt) { 125 | jButton1ActionPerformed(evt); 126 | } 127 | }); 128 | 129 | jButton2.setFont(new java.awt.Font("Dialog", 1, 10)); // NOI18N 130 | jButton2.setText("SET"); 131 | jButton2.setMaximumSize(new java.awt.Dimension(56, 18)); 132 | jButton2.setMinimumSize(new java.awt.Dimension(56, 18)); 133 | jButton2.setPreferredSize(new java.awt.Dimension(56, 18)); 134 | jButton2.addActionListener(new java.awt.event.ActionListener() { 135 | public void actionPerformed(java.awt.event.ActionEvent evt) { 136 | jButton2ActionPerformed(evt); 137 | } 138 | }); 139 | 140 | jButton3.setText("Color"); 141 | jButton3.addActionListener(new java.awt.event.ActionListener() { 142 | public void actionPerformed(java.awt.event.ActionEvent evt) { 143 | jButton3ActionPerformed(evt); 144 | } 145 | }); 146 | 147 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); 148 | this.setLayout(layout); 149 | layout.setHorizontalGroup( 150 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 151 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 152 | .addContainerGap() 153 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 154 | .addGroup(layout.createSequentialGroup() 155 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 156 | .addComponent(jLabel1) 157 | .addComponent(jLabel2)) 158 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 159 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 160 | .addComponent(jSlider1, javax.swing.GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE) 161 | .addGroup(layout.createSequentialGroup() 162 | .addComponent(jTextFieldName) 163 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 164 | .addComponent(jButton3) 165 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 166 | .addComponent(jRadioWarm) 167 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 168 | .addComponent(jRadioNormal) 169 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 170 | .addComponent(jRadioCold)))) 171 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 172 | .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 173 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 174 | .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 175 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 176 | .addComponent(jLabelDates, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) 177 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 178 | .addComponent(jToggleButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)) 179 | ); 180 | layout.setVerticalGroup( 181 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 182 | .addComponent(jToggleButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 183 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 184 | .addGap(11, 11, 11) 185 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 186 | .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 187 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 188 | .addComponent(jRadioCold) 189 | .addComponent(jRadioNormal) 190 | .addComponent(jRadioWarm) 191 | .addComponent(jTextFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 192 | .addComponent(jButton3))) 193 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 194 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 195 | .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 196 | .addComponent(jLabel1)) 197 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 198 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 199 | .addComponent(jLabelDates) 200 | .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 201 | .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 202 | .addContainerGap()) 203 | ); 204 | }// //GEN-END:initComponents 205 | 206 | private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed 207 | if (updating) return; 208 | bulb.setOn(jToggleButton1.isSelected()); 209 | }//GEN-LAST:event_jToggleButton1ActionPerformed 210 | 211 | private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSlider1StateChanged 212 | if (updating) return; 213 | if (jSlider1.getValueIsAdjusting()) return; 214 | bulb.setIntensity(jSlider1.getValue()); 215 | }//GEN-LAST:event_jSlider1StateChanged 216 | 217 | private void jRadioWarmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioWarmActionPerformed 218 | if (updating) return; 219 | bulb.setColor(TradfriConstants.COLOR_WARM); 220 | }//GEN-LAST:event_jRadioWarmActionPerformed 221 | 222 | private void jRadioNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioNormalActionPerformed 223 | if (updating) return; 224 | bulb.setColor(TradfriConstants.COLOR_NORMAL); 225 | }//GEN-LAST:event_jRadioNormalActionPerformed 226 | 227 | private void jRadioColdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioColdActionPerformed 228 | if (updating) return; 229 | bulb.setColor(TradfriConstants.COLOR_COLD); 230 | }//GEN-LAST:event_jRadioColdActionPerformed 231 | 232 | private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed 233 | 234 | try { 235 | //JOptionPane pane = new JOptionPane(); 236 | //pane.setMessageType(JOptionPane.INFORMATION_MESSAGE); 237 | JDialog dialog = new JDialog((Frame)null, "Result of COAP GET for bulb " + bulb.getName(), false); 238 | JTextArea msg = new JTextArea(bulb.getJsonObject().toString(4) + "\n"); 239 | msg.setFont(new Font("monospaced", Font.PLAIN, 10)); 240 | msg.setLineWrap(true); 241 | msg.setWrapStyleWord(true); 242 | JScrollPane scrollPane = new JScrollPane(msg); 243 | 244 | dialog.getContentPane().add(scrollPane); 245 | dialog.setSize(350, 350); 246 | //dialog.pack(); 247 | dialog.setVisible(true); 248 | 249 | 250 | } catch (JSONException ex) { 251 | Logger.getLogger(BulbPanel.class.getName()).log(Level.SEVERE, null, ex); 252 | } 253 | }//GEN-LAST:event_jButton1ActionPerformed 254 | 255 | protected String previous_put = ""; 256 | 257 | private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed 258 | 259 | String put = JOptionPane.showInputDialog(this, "JSON to SET for bulb " + bulb.getName(), previous_put); 260 | if (put != null) { 261 | previous_put = put; 262 | bulb.sendJSONPayload(put); 263 | } 264 | 265 | }//GEN-LAST:event_jButton2ActionPerformed 266 | 267 | private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed 268 | Color c = JColorChooser.showDialog(null, "Choose a color", Color.WHITE); 269 | if (c != null) { 270 | bulb.setRGBColor(c.getRed(), c.getGreen(), c.getBlue()); 271 | } 272 | }//GEN-LAST:event_jButton3ActionPerformed 273 | 274 | 275 | // Variables declaration - do not modify//GEN-BEGIN:variables 276 | private javax.swing.ButtonGroup buttonGroupTemperature; 277 | private javax.swing.JButton jButton1; 278 | private javax.swing.JButton jButton2; 279 | private javax.swing.JButton jButton3; 280 | private javax.swing.JLabel jLabel1; 281 | private javax.swing.JLabel jLabel2; 282 | private javax.swing.JLabel jLabelDates; 283 | private javax.swing.JRadioButton jRadioCold; 284 | private javax.swing.JRadioButton jRadioNormal; 285 | private javax.swing.JRadioButton jRadioWarm; 286 | private javax.swing.JSlider jSlider1; 287 | private javax.swing.JTextField jTextFieldName; 288 | private javax.swing.JToggleButton jToggleButton1; 289 | // End of variables declaration//GEN-END:variables 290 | 291 | protected void updatePanelContent() { 292 | updating = true; 293 | jTextFieldName.setText(bulb.getName()); 294 | jTextFieldName.setToolTipText(bulb.getType()); 295 | jSlider1.setValue(bulb.getIntensity()); 296 | jToggleButton1.setSelected(bulb.isOn()); 297 | if (bulb.getColor() != null) { 298 | jRadioCold.setEnabled(true); 299 | jRadioNormal.setEnabled(true); 300 | jRadioWarm.setEnabled(true); 301 | switch(bulb.getColor()) { 302 | case TradfriConstants.COLOR_NORMAL: jRadioNormal.setSelected(true); break; 303 | case TradfriConstants.COLOR_WARM: jRadioWarm.setSelected(true); break; 304 | case TradfriConstants.COLOR_COLD: jRadioCold.setSelected(true); break; 305 | } 306 | } 307 | else { 308 | jRadioCold.setEnabled(false); 309 | jRadioNormal.setEnabled(false); 310 | jRadioWarm.setEnabled(false); 311 | } 312 | 313 | 314 | if (bulb.isOnline()) { 315 | jToggleButton1.setEnabled(true); 316 | jRadioCold.setEnabled(true); 317 | jRadioNormal.setEnabled(true); 318 | jRadioWarm.setEnabled(true); 319 | jSlider1.setEnabled(true); 320 | jLabelDates.setText("Installed: "+bulb.getDateInstalled()+" - Last seen: "+bulb.getDateLastSeen()+" - Firmware: " + bulb.getFirmware() + " [online]"); 321 | } 322 | else { 323 | jToggleButton1.setEnabled(false); 324 | jRadioCold.setEnabled(false); 325 | jRadioNormal.setEnabled(false); 326 | jRadioWarm.setEnabled(false); 327 | jSlider1.setEnabled(false); 328 | jLabelDates.setText("Installed: "+bulb.getDateInstalled()+" - Last seen: "+bulb.getDateLastSeen()+" - Firmware: " + bulb.getFirmware() + " [offline]"); 329 | } 330 | 331 | updating = false; 332 | } 333 | 334 | public void bulb_state_changed(LightBulb bulb) { 335 | if (this.bulb == bulb) updatePanelContent(); 336 | } 337 | } 338 | -------------------------------------------------------------------------------- /tradfri-java/src/main/java/org/thingml/tradfri/ui/LoggingPanel.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /tradfri-java/src/main/java/org/thingml/tradfri/ui/LoggingPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package org.thingml.tradfri.ui; 7 | 8 | import java.text.SimpleDateFormat; 9 | import java.util.Date; 10 | import java.util.logging.Handler; 11 | import java.util.logging.LogRecord; 12 | import java.util.logging.Logger; 13 | import javax.swing.SwingUtilities; 14 | import javax.swing.text.DefaultCaret; 15 | import org.thingml.tradfri.TradfriGateway; 16 | 17 | /** 18 | * 19 | * @author franck 20 | */ 21 | public class LoggingPanel extends javax.swing.JPanel { 22 | 23 | public final int maxLogSize = 2048; 24 | 25 | /** 26 | * Creates new form LoggingPanel 27 | */ 28 | public LoggingPanel() { 29 | Logger.getLogger(TradfriGateway.class.getName()).addHandler(new LoggingPanel.LogHandler()); 30 | initComponents(); 31 | } 32 | 33 | 34 | public void appendLog(String text) { 35 | jTextArea1.append(text); 36 | } 37 | 38 | /** 39 | * This method is called from within the constructor to initialize the form. 40 | * WARNING: Do NOT modify this code. The content of this method is always 41 | * regenerated by the Form Editor. 42 | */ 43 | @SuppressWarnings("unchecked") 44 | // //GEN-BEGIN:initComponents 45 | private void initComponents() { 46 | 47 | jScrollPaneLog = new javax.swing.JScrollPane(); 48 | jTextArea1 = new javax.swing.JTextArea(); 49 | jCheckBoxLog = new javax.swing.JCheckBox(); 50 | jButtonClear = new javax.swing.JButton(); 51 | jCheckBox1 = new javax.swing.JCheckBox(); 52 | 53 | jTextArea1.setEditable(false); 54 | jTextArea1.setBackground(new java.awt.Color(51, 51, 51)); 55 | jTextArea1.setColumns(20); 56 | jTextArea1.setFont(new java.awt.Font("DejaVu Sans Mono", 1, 12)); // NOI18N 57 | jTextArea1.setForeground(new java.awt.Color(0, 153, 255)); 58 | jTextArea1.setRows(5); 59 | jTextArea1.addMouseListener(new java.awt.event.MouseAdapter() { 60 | public void mouseClicked(java.awt.event.MouseEvent evt) { 61 | jTextArea1MouseClicked(evt); 62 | } 63 | }); 64 | jScrollPaneLog.setViewportView(jTextArea1); 65 | 66 | jCheckBoxLog.setSelected(true); 67 | jCheckBoxLog.setText("Auto Scroll"); 68 | jCheckBoxLog.addActionListener(new java.awt.event.ActionListener() { 69 | public void actionPerformed(java.awt.event.ActionEvent evt) { 70 | jCheckBoxLogActionPerformed(evt); 71 | } 72 | }); 73 | 74 | jButtonClear.setText("Clear Log"); 75 | jButtonClear.addActionListener(new java.awt.event.ActionListener() { 76 | public void actionPerformed(java.awt.event.ActionEvent evt) { 77 | jButtonClearActionPerformed(evt); 78 | } 79 | }); 80 | 81 | jCheckBox1.setText("Line Wrap"); 82 | jCheckBox1.addActionListener(new java.awt.event.ActionListener() { 83 | public void actionPerformed(java.awt.event.ActionEvent evt) { 84 | jCheckBox1ActionPerformed(evt); 85 | } 86 | }); 87 | 88 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); 89 | this.setLayout(layout); 90 | layout.setHorizontalGroup( 91 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 92 | .addComponent(jScrollPaneLog) 93 | .addGroup(layout.createSequentialGroup() 94 | .addContainerGap() 95 | .addComponent(jButtonClear) 96 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 250, Short.MAX_VALUE) 97 | .addComponent(jCheckBox1) 98 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 99 | .addComponent(jCheckBoxLog) 100 | .addContainerGap()) 101 | ); 102 | layout.setVerticalGroup( 103 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 104 | .addGroup(layout.createSequentialGroup() 105 | .addComponent(jScrollPaneLog, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE) 106 | .addGap(7, 7, 7) 107 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 108 | .addComponent(jCheckBoxLog) 109 | .addComponent(jButtonClear) 110 | .addComponent(jCheckBox1)) 111 | .addGap(5, 5, 5)) 112 | ); 113 | }// //GEN-END:initComponents 114 | 115 | private void jButtonClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonClearActionPerformed 116 | jTextArea1.setText(""); 117 | }//GEN-LAST:event_jButtonClearActionPerformed 118 | 119 | private void jCheckBoxLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxLogActionPerformed 120 | DefaultCaret caret = (DefaultCaret) jTextArea1.getCaret(); 121 | if (jCheckBoxLog.isSelected()) { 122 | caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); 123 | jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength()); 124 | jScrollPaneLog.setViewportView(jTextArea1); 125 | } 126 | else caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); 127 | 128 | }//GEN-LAST:event_jCheckBoxLogActionPerformed 129 | 130 | private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed 131 | jTextArea1.setLineWrap(jCheckBox1.isSelected()); 132 | }//GEN-LAST:event_jCheckBox1ActionPerformed 133 | 134 | private void jTextArea1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextArea1MouseClicked 135 | jCheckBoxLog.setSelected(false); 136 | }//GEN-LAST:event_jTextArea1MouseClicked 137 | 138 | 139 | // Variables declaration - do not modify//GEN-BEGIN:variables 140 | private javax.swing.JButton jButtonClear; 141 | private javax.swing.JCheckBox jCheckBox1; 142 | private javax.swing.JCheckBox jCheckBoxLog; 143 | private javax.swing.JScrollPane jScrollPaneLog; 144 | private javax.swing.JTextArea jTextArea1; 145 | // End of variables declaration//GEN-END:variables 146 | 147 | class LogHandler extends Handler { 148 | 149 | StringBuilder b = new StringBuilder(); 150 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); 151 | 152 | 153 | @Override 154 | public void publish(LogRecord record) { 155 | final String msg = "[" + sdf.format(new Date(record.getMillis())) + "] [" +record.getLevel().getName() + "] " + record.getMessage() + "\n" ; 156 | SwingUtilities.invokeLater(new Runnable() { 157 | public void run() { 158 | appendLog(msg); 159 | } 160 | }); 161 | } 162 | 163 | @Override 164 | public void flush() { 165 | 166 | } 167 | 168 | @Override 169 | public void close() throws SecurityException { 170 | SwingUtilities.invokeLater(new Runnable() { 171 | public void run() { 172 | appendLog("[CLOSED]"); 173 | } 174 | }); 175 | } 176 | 177 | } 178 | 179 | } 180 | -------------------------------------------------------------------------------- /tradfri-java/src/main/java/org/thingml/tradfri/ui/MainFrame.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 |
221 | -------------------------------------------------------------------------------- /tradfri-java/src/main/java/org/thingml/tradfri/ui/MainFrame.java: -------------------------------------------------------------------------------- 1 | package org.thingml.tradfri.ui; 2 | 3 | import java.util.prefs.Preferences; 4 | import org.thingml.tradfri.LightBulb; 5 | import org.thingml.tradfri.TradfriGateway; 6 | import org.thingml.tradfri.TradfriGatewayListener; 7 | 8 | /** 9 | * 10 | * @author franck 11 | */ 12 | public class MainFrame extends javax.swing.JFrame implements TradfriGatewayListener { 13 | 14 | Preferences prefs = Preferences.userRoot().node(this.getClass().getName()); 15 | 16 | /** 17 | * Creates new form MainFrame 18 | */ 19 | public MainFrame() { 20 | initComponents(); 21 | jTextFieldIP.setText(prefs.get("TradfriGatewayIP", "10.3.1.85")); //192.168.1.13 22 | jTextFieldIP.setText(prefs.get("TradfriGatewayIP", "192.168.1.13")); // 23 | // jTextFieldKey.setText(prefs.get("TradfriGatewayKey", "kQxkI7S6Ao4rgwYC")); // 5HV7ibb4brgWL18x 24 | jTextFieldKey.setText(prefs.get("TradfriGatewayKey", "5HV7ibb4brgWL18x")); // 5HV7ibb4brgWL18x 25 | gateway.addTradfriGatewayListener(this); 26 | jButtonStop.setEnabled(false); 27 | } 28 | 29 | /** 30 | * This method is called from within the constructor to initialize the form. 31 | * WARNING: Do NOT modify this code. The content of this method is always 32 | * regenerated by the Form Editor. 33 | */ 34 | @SuppressWarnings("unchecked") 35 | // //GEN-BEGIN:initComponents 36 | private void initComponents() { 37 | 38 | jPanel1 = new javax.swing.JPanel(); 39 | jLabel1 = new javax.swing.JLabel(); 40 | jTextFieldIP = new javax.swing.JTextField(); 41 | jButtonConnect = new javax.swing.JButton(); 42 | jLabel2 = new javax.swing.JLabel(); 43 | jTextFieldKey = new javax.swing.JTextField(); 44 | jProgressBarDiscover = new javax.swing.JProgressBar(); 45 | jLabel3 = new javax.swing.JLabel(); 46 | jLabel4 = new javax.swing.JLabel(); 47 | jCheckBoxShowOnlyOnline = new javax.swing.JCheckBox(); 48 | jLabel5 = new javax.swing.JLabel(); 49 | jTextFieldPRate = new javax.swing.JTextField(); 50 | jButtonStop = new javax.swing.JButton(); 51 | jSplitPane1 = new javax.swing.JSplitPane(); 52 | jScrollPaneBulbs = new javax.swing.JScrollPane(); 53 | jPanelBulbs = new javax.swing.JPanel(); 54 | loggingPanel1 = new org.thingml.tradfri.ui.LoggingPanel(); 55 | 56 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 57 | setTitle("IKEA Tradfri Test Application - Tellu IoT"); 58 | 59 | jLabel1.setText("Gateway IP:"); 60 | 61 | jTextFieldIP.setText("10.3.1.85"); 62 | 63 | jButtonConnect.setText("Start"); 64 | jButtonConnect.addActionListener(new java.awt.event.ActionListener() { 65 | public void actionPerformed(java.awt.event.ActionEvent evt) { 66 | jButtonConnectActionPerformed(evt); 67 | } 68 | }); 69 | 70 | jLabel2.setText("Security Key:"); 71 | 72 | jTextFieldKey.setText("kQxkI7S6Ao4rgwYC"); 73 | 74 | jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/logo.png"))); // NOI18N 75 | 76 | jLabel4.setText("Discovery Progress:"); 77 | 78 | jCheckBoxShowOnlyOnline.setText("Show Only Online Bulbs"); 79 | 80 | jLabel5.setText("Polling Rate:"); 81 | 82 | jTextFieldPRate.setText("5000"); 83 | 84 | jButtonStop.setText("Stop"); 85 | jButtonStop.addActionListener(new java.awt.event.ActionListener() { 86 | public void actionPerformed(java.awt.event.ActionEvent evt) { 87 | jButtonStopActionPerformed(evt); 88 | } 89 | }); 90 | 91 | javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); 92 | jPanel1.setLayout(jPanel1Layout); 93 | jPanel1Layout.setHorizontalGroup( 94 | jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 95 | .addGroup(jPanel1Layout.createSequentialGroup() 96 | .addComponent(jLabel3) 97 | .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 98 | .addComponent(jLabel5) 99 | .addComponent(jLabel4) 100 | .addComponent(jLabel1) 101 | .addComponent(jLabel2)) 102 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 103 | .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 104 | .addGroup(jPanel1Layout.createSequentialGroup() 105 | .addComponent(jProgressBarDiscover, javax.swing.GroupLayout.DEFAULT_SIZE, 338, Short.MAX_VALUE) 106 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 107 | .addComponent(jButtonConnect) 108 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 109 | .addComponent(jButtonStop)) 110 | .addComponent(jTextFieldIP) 111 | .addComponent(jTextFieldKey) 112 | .addGroup(jPanel1Layout.createSequentialGroup() 113 | .addComponent(jTextFieldPRate) 114 | .addGap(18, 18, 18) 115 | .addComponent(jCheckBoxShowOnlyOnline))) 116 | .addContainerGap()) 117 | ); 118 | jPanel1Layout.setVerticalGroup( 119 | jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 120 | .addGroup(jPanel1Layout.createSequentialGroup() 121 | .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 122 | .addGroup(jPanel1Layout.createSequentialGroup() 123 | .addComponent(jLabel3) 124 | .addGap(0, 0, Short.MAX_VALUE)) 125 | .addGroup(jPanel1Layout.createSequentialGroup() 126 | .addContainerGap() 127 | .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 128 | .addComponent(jLabel1) 129 | .addComponent(jTextFieldIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 130 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 131 | .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 132 | .addComponent(jLabel2) 133 | .addComponent(jTextFieldKey, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 134 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 135 | .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 136 | .addComponent(jCheckBoxShowOnlyOnline) 137 | .addComponent(jLabel5) 138 | .addComponent(jTextFieldPRate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 139 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 140 | .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 141 | .addComponent(jProgressBarDiscover, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) 142 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 143 | .addComponent(jButtonConnect) 144 | .addComponent(jButtonStop)) 145 | .addComponent(jLabel4)))) 146 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 147 | ); 148 | 149 | jSplitPane1.setDividerLocation(200); 150 | jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); 151 | 152 | jPanelBulbs.setLayout(new javax.swing.BoxLayout(jPanelBulbs, javax.swing.BoxLayout.PAGE_AXIS)); 153 | jScrollPaneBulbs.setViewportView(jPanelBulbs); 154 | 155 | jSplitPane1.setLeftComponent(jScrollPaneBulbs); 156 | jSplitPane1.setRightComponent(loggingPanel1); 157 | 158 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 159 | getContentPane().setLayout(layout); 160 | layout.setHorizontalGroup( 161 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 162 | .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 163 | .addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE) 164 | ); 165 | layout.setVerticalGroup( 166 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 167 | .addGroup(layout.createSequentialGroup() 168 | .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 169 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 170 | .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE)) 171 | ); 172 | 173 | pack(); 174 | }// //GEN-END:initComponents 175 | 176 | TradfriGateway gateway = new TradfriGateway(); 177 | 178 | private void jButtonConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConnectActionPerformed 179 | gateway.setGateway_ip(jTextFieldIP.getText()); 180 | gateway.setSecurity_key(jTextFieldKey.getText()); 181 | prefs.put("TradfriGatewayIP", jTextFieldIP.getText().trim()); 182 | prefs.put("TradfriGatewayKey", jTextFieldKey.getText().trim()); 183 | gateway.startTradfriGateway(); 184 | jButtonConnect.setEnabled(false); 185 | }//GEN-LAST:event_jButtonConnectActionPerformed 186 | 187 | private void jButtonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStopActionPerformed 188 | gateway.stopTradfriGateway(); 189 | jButtonStop.setEnabled(false); 190 | }//GEN-LAST:event_jButtonStopActionPerformed 191 | 192 | /** 193 | * @param args the command line arguments 194 | */ 195 | public static void main(String args[]) { 196 | 197 | /* Create and display the form */ 198 | java.awt.EventQueue.invokeLater(new Runnable() { 199 | public void run() { 200 | MainFrame frame = new MainFrame(); 201 | frame.pack(); 202 | frame.setVisible(true); 203 | } 204 | }); 205 | } 206 | 207 | // Variables declaration - do not modify//GEN-BEGIN:variables 208 | private javax.swing.JButton jButtonConnect; 209 | private javax.swing.JButton jButtonStop; 210 | private javax.swing.JCheckBox jCheckBoxShowOnlyOnline; 211 | private javax.swing.JLabel jLabel1; 212 | private javax.swing.JLabel jLabel2; 213 | private javax.swing.JLabel jLabel3; 214 | private javax.swing.JLabel jLabel4; 215 | private javax.swing.JLabel jLabel5; 216 | private javax.swing.JPanel jPanel1; 217 | private javax.swing.JPanel jPanelBulbs; 218 | private javax.swing.JProgressBar jProgressBarDiscover; 219 | private javax.swing.JScrollPane jScrollPaneBulbs; 220 | private javax.swing.JSplitPane jSplitPane1; 221 | private javax.swing.JTextField jTextFieldIP; 222 | private javax.swing.JTextField jTextFieldKey; 223 | private javax.swing.JTextField jTextFieldPRate; 224 | private org.thingml.tradfri.ui.LoggingPanel loggingPanel1; 225 | // End of variables declaration//GEN-END:variables 226 | 227 | @Override 228 | public void gateway_initializing() { 229 | jTextFieldIP.setEditable(false); 230 | jTextFieldKey.setEditable(false); 231 | jCheckBoxShowOnlyOnline.setEnabled(false); 232 | } 233 | 234 | @Override 235 | public void bulb_discovery_started(int total_devices) { 236 | jProgressBarDiscover.setMaximum(total_devices); 237 | jProgressBarDiscover.setValue(1); 238 | } 239 | 240 | @Override 241 | public void bulb_discovered(LightBulb b) { 242 | jProgressBarDiscover.setValue(jProgressBarDiscover.getValue()+1); 243 | if (b.isOnline() || !jCheckBoxShowOnlyOnline.isSelected()) { 244 | BulbPanel p = new BulbPanel(b); 245 | jPanelBulbs.add(p); 246 | jPanelBulbs.revalidate(); 247 | jPanelBulbs.repaint(); 248 | } 249 | } 250 | 251 | @Override 252 | public void bulb_discovery_completed() { 253 | 254 | } 255 | 256 | @Override 257 | public void gateway_started() { 258 | jButtonStop.setEnabled(true); 259 | } 260 | 261 | @Override 262 | public void gateway_stoped() { 263 | jButtonStop.setEnabled(false); 264 | jButtonConnect.setEnabled(true); 265 | jTextFieldIP.setEditable(true); 266 | jTextFieldKey.setEditable(true); 267 | jCheckBoxShowOnlyOnline.setEnabled(true); 268 | jPanelBulbs.removeAll(); 269 | jPanelBulbs.revalidate(); 270 | jPanelBulbs.repaint(); 271 | } 272 | 273 | @Override 274 | public void polling_started() { 275 | 276 | } 277 | 278 | @Override 279 | public void polling_completed(int bulb_count, int total_time) { 280 | 281 | } 282 | } 283 | -------------------------------------------------------------------------------- /tradfri-java/src/main/resources/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffleurey/ThingML-Tradfri/e4c8a8bbe48e36d364b9fd1c574e6a1e292bb58e/tradfri-java/src/main/resources/logo.png --------------------------------------------------------------------------------