├── .clang-format ├── .gitignore ├── .travis.yml ├── .vscode ├── extensions.json ├── settings.json └── tasks.json ├── LICENSE ├── README.md ├── Sensormodul.code-workspace ├── doc ├── AllgemeineParameter.PNG ├── Applikationsbeschreibung-Sensor.md ├── Applikationsbeschreibung-Sensor.pdf ├── Behaglichkeit.png ├── DropdownSensor.png ├── FehlerBeideBME.png ├── InfoEeprom.PNG ├── InfoPower.PNG ├── InfoRgbLed.PNG ├── KO-Schema.txt ├── Kalibrierung.PNG ├── KalibrierungLoeschen.PNG ├── Konzept-KO-Verteilung.md ├── Luftqualitätsampel.PNG ├── OneWire.png ├── PIO2.png ├── Standardsensoren.PNG ├── Taupunkt.png ├── knx-dev-setup.md ├── knx-dev-setup.pdf ├── knx-update-setup.md └── knx-update-setup.pdf ├── include └── README ├── lib └── README ├── library.properties ├── linux ├── CMakeLists.txt ├── CMakeSettings.json └── main.cpp ├── platformio.ini ├── release ├── BuildRelease.cmd └── Sensormodul-v3.8.xml ├── src ├── Sensormodul-103.xml ├── Sensormodul-104.xml ├── Sensormodul-105.xml ├── Sensormodul.cpp ├── Sensormodul.h ├── Sensormodul.parts.xml ├── Sensormodul.share.xml ├── Sensormodul.templ.xml ├── Sensormodul.xml └── main.cpp ├── test └── README └── upload_script.py /.clang-format: -------------------------------------------------------------------------------- 1 | #Generated from Visual Studio settings 2 | --- 3 | BasedOnStyle: llvm 4 | BraceWrapping: 5 | AfterClass: true 6 | AfterControlStatement: true 7 | AfterEnum: true 8 | AfterFunction: true 9 | AfterNamespace: true 10 | AfterStruct: true 11 | AfterUnion: true 12 | BeforeCatch: true 13 | BeforeElse: true 14 | SplitEmptyFunction: false 15 | IndentBraces: false 16 | #BreakBeforeBraces: Attach 17 | BreakBeforeBraces: Custom 18 | ColumnLimit: 0 19 | IndentWidth: 4 20 | NamespaceIndentation: All 21 | TabWidth: 4 22 | DerivePointerAlignment: true 23 | IndentCaseLabels: true 24 | AllowShortFunctionsOnASingleLine: InlineOnly 25 | AllowShortIfStatementsOnASingleLine: false 26 | ConstructorInitializerIndentWidth: 4 27 | ContinuationIndentWidth: 4 28 | UseTab: Never 29 | ... 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | **/*.knxprod 7 | Restart.txt 8 | *.cppbak 9 | **/*.debug.xml 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Continuous Integration (CI) is the practice, in software 2 | # engineering, of merging all developer working copies with a shared mainline 3 | # several times a day < https://docs.platformio.org/page/ci/index.html > 4 | # 5 | # Documentation: 6 | # 7 | # * Travis CI Embedded Builds with PlatformIO 8 | # < https://docs.travis-ci.com/user/integration/platformio/ > 9 | # 10 | # * PlatformIO integration with Travis CI 11 | # < https://docs.platformio.org/page/ci/travis.html > 12 | # 13 | # * User Guide for `platformio ci` command 14 | # < https://docs.platformio.org/page/userguide/cmd_ci.html > 15 | # 16 | # 17 | # Please choose one of the following templates (proposed below) and uncomment 18 | # it (remove "# " before each line) or use own configuration according to the 19 | # Travis CI documentation (see above). 20 | # 21 | 22 | 23 | # 24 | # Template #1: General project. Test it using existing `platformio.ini`. 25 | # 26 | 27 | # language: python 28 | # python: 29 | # - "2.7" 30 | # 31 | # sudo: false 32 | # cache: 33 | # directories: 34 | # - "~/.platformio" 35 | # 36 | # install: 37 | # - pip install -U platformio 38 | # - platformio update 39 | # 40 | # script: 41 | # - platformio run 42 | 43 | 44 | # 45 | # Template #2: The project is intended to be used as a library with examples. 46 | # 47 | 48 | # language: python 49 | # python: 50 | # - "2.7" 51 | # 52 | # sudo: false 53 | # cache: 54 | # directories: 55 | # - "~/.platformio" 56 | # 57 | # env: 58 | # - PLATFORMIO_CI_SRC=path/to/test/file.c 59 | # - PLATFORMIO_CI_SRC=examples/file.ino 60 | # - PLATFORMIO_CI_SRC=path/to/test/directory 61 | # 62 | # install: 63 | # - pip install -U platformio 64 | # - platformio update 65 | # 66 | # script: 67 | # - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N 68 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "terminal.integrated.env.windows": { 3 | "PATH": "C:\\Users\\d019748\\.platformio\\penv\\Scripts;C:\\Users\\d019748\\.platformio\\penv;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Git\\cmd;C:\\Users\\d019748\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\d019748\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Git\\cmd;C:\\Users\\d019748\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\d019748\\AppData\\Local\\Programs\\Microsoft VS Code\\bin", 4 | "PLATFORMIO_CALLER": "vscode" 5 | } 6 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "Build on Linux", 8 | "type": "shell", 9 | "command": "cmake", 10 | "args": [ 11 | "--build", 12 | "linux" 13 | ], 14 | "group": "build", 15 | "problemMatcher": [] 16 | }, 17 | { 18 | "label": "Build PlatformIO", 19 | "type": "shell", 20 | "command": "${env:USERPROFILE}\\.platformio\\penv\\Scripts\\pio.exe", 21 | "args": [ 22 | "run", 23 | "-e", 24 | "build" 25 | ], 26 | "group": "build", 27 | "problemMatcher": [] 28 | }, 29 | { 30 | "label": "Upload JLINK", 31 | "type": "shell", 32 | "command": "${env:USERPROFILE}\\.platformio\\penv\\Scripts\\pio.exe", 33 | "args": [ 34 | "run", 35 | "-e", 36 | "uploadJLINK", 37 | "--target", 38 | "upload" 39 | ], 40 | "group": "build", 41 | "problemMatcher": [] 42 | }, 43 | { 44 | "label": "Upload ATMEL", 45 | "type": "shell", 46 | "command": "${env:USERPROFILE}\\.platformio\\penv\\Scripts\\pio.exe", 47 | "args": [ 48 | "run", 49 | "-e", 50 | "uploadATMEL", 51 | "--target", 52 | "upload" 53 | ], 54 | "group": "build", 55 | "problemMatcher": [] 56 | }, 57 | { 58 | "label": "Upload USB", 59 | "type": "shell", 60 | "command": "${env:USERPROFILE}\\.platformio\\penv\\Scripts\\pio.exe", 61 | "args": [ 62 | "run", 63 | "-e", 64 | "uploadUSB", 65 | "--target", 66 | "upload" 67 | ], 68 | "group": "build", 69 | "problemMatcher": [] 70 | }, 71 | { 72 | "label": "MultiplyChannels", 73 | "type": "shell", 74 | "command": "${env:USERPROFILE}\\bin\\MultiplyChannels.exe", 75 | "args": [ 76 | "create", 77 | "--Debug", 78 | "src/Sensormodul" 79 | ], 80 | "problemMatcher": [], 81 | "group": "test" 82 | }, 83 | { 84 | "label": "MultiplyChannels-Release", 85 | "type": "shell", 86 | "command": "release\\BuildRelease.cmd", 87 | "args": [], 88 | "problemMatcher": [], 89 | "group": "test" 90 | }, 91 | { 92 | "label": "MultiplyChannels-Beta", 93 | "type": "shell", 94 | "command": "beta\\BuildRelease.cmd", 95 | "args": [], 96 | "problemMatcher": [], 97 | "group": "test" 98 | } 99 | ] 100 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | knx-sensor 2 | === 3 | 4 | Impelemtation of an knx sensor module combined with an 80 channel knx logic module based on the [knx stack](https://github.com/thelsing/knx) from thelsing. The used knx stack allows a parametrization via ETS in general, this project requires ETS 5.6 or higher. 5 | 6 | Itis implemented for the SAMD21 version of the knx stack. Currently it uses my fork of the [knx stack](https://github.com/mumpf/knx), this will change in future. 7 | 8 | It is a PlatformIO project and needs a working ETS 5.6 (or higher) installed on the same PC. 9 | 10 | Initial installation and build instructions can be found in the [project itself](https://github.com/mumpf/knx-sensor/blob/release/doc/knx-dev-setup.md). 11 | 12 | Update instruction (for an updated firmware or application build) can be also found in the [project documentation](https://github.com/mumpf/knx-sensor/blob/release/doc/knx-update-setup.md) 13 | 14 | This project depends on following projects: 15 | 16 | * [knx-wire](https://github.com/mumpf/knx-wire) 17 | * [knx-logic](https://github.com/mumpf/knx-logic) 18 | * [knx-common](https://github.com/mumpf/knx-common) 19 | * [knx](https://github.com/mumpf/knx) 20 | 21 | Hardware to use the software with is described in [knx-user-forum/KONNEKTING](https://knx-user-forum.de/forum/projektforen/konnekting/1114105-konnekting-raum-sensormodul-temp-hum-voc-co2-onewire-buzzer?p=1460098#post1460098). 22 | 23 | With small changes it should be possible to use it on any SAMD21 board. 24 | 25 | There are application descriptions available: 26 | 27 | * [Applicasion Sensor](https://github.com/mumpf/knx-sensor/blob/release/doc/Applikationsbeschreibung-Sensor.pdf) describes features of the sensor part of application and firmware (in German). 28 | * [Application WireGateway](https://github.com/mumpf/knx-wire/blob/release/doc/Applikationsbeschreibung-Wire.pdf) describes features of the one wire part of application and firmware (in German). 29 | * [Application Logic](https://github.com/mumpf/knx-logic/blob/release/doc/Applikationsbeschreibung-Logik.pdf) describes features of the logic part of application and firmware (in German). 30 | 31 | Thanks to all, who made this project successful. 32 | -------------------------------------------------------------------------------- /Sensormodul.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | }, 6 | { 7 | "path": "../knx-wire" 8 | }, 9 | { 10 | "path": "../knx-logic" 11 | }, 12 | { 13 | "path": "../knx-common" 14 | }, 15 | { 16 | "path": "../knx" 17 | } 18 | ], 19 | "settings": { 20 | "terminal.integrated.env.windows": { 21 | "PATH": "C:\\Users\\d019748\\.platformio\\penv\\Scripts;C:\\Users\\d019748\\.platformio\\penv;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Git\\cmd;C:\\Users\\d019748\\AppData\\Local\\Programs\\Python\\Python37-32\\Scripts\\;C:\\Users\\d019748\\AppData\\Local\\Programs\\Python\\Python37-32\\;C:\\Users\\d019748\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\d019748\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\d019748\\.dotnet\\tools;C:\\Users\\d019748\\bin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Git\\cmd;C:\\Users\\d019748\\AppData\\Local\\Programs\\Python\\Python37-32\\Scripts\\;C:\\Users\\d019748\\AppData\\Local\\Programs\\Python\\Python37-32\\;C:\\Users\\d019748\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\d019748\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\d019748\\.dotnet\\tools;C:\\Users\\d019748\\bin", 22 | "PLATFORMIO_CALLER": "vscode" 23 | }, 24 | "files.associations": { 25 | "*.yaml": "home-assistant" 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /doc/AllgemeineParameter.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/AllgemeineParameter.PNG -------------------------------------------------------------------------------- /doc/Applikationsbeschreibung-Sensor.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/Applikationsbeschreibung-Sensor.pdf -------------------------------------------------------------------------------- /doc/Behaglichkeit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/Behaglichkeit.png -------------------------------------------------------------------------------- /doc/DropdownSensor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/DropdownSensor.png -------------------------------------------------------------------------------- /doc/FehlerBeideBME.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/FehlerBeideBME.png -------------------------------------------------------------------------------- /doc/InfoEeprom.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/InfoEeprom.PNG -------------------------------------------------------------------------------- /doc/InfoPower.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/InfoPower.PNG -------------------------------------------------------------------------------- /doc/InfoRgbLed.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/InfoRgbLed.PNG -------------------------------------------------------------------------------- /doc/KO-Schema.txt: -------------------------------------------------------------------------------- 1 | Sensormodul: 2 | Statisch: 3 | KO1 - KO7 (Logik) 24 Byte payload 4 | KO8 - KO19 (frei für Logik) 12 Byte payload 5 | KO20 - KO31 (WireGateway) 34 Byte payload 6 | KO32 - KO49 (frei für 1-Wire) 18 Byte payload 7 | KO50 - KO78 (Sensormodul) 44 Byte payload 8 | KO79 - KO89 (frei für Sensormodul) 13 Byte payload 9 | Dynamisch: 10 | KO90 - KO121 (32 Geräte * 1 KO) 32 * 2 Byte = 64 Byte payload (1-Wire-Geräte) 11 | KO122 - KO124 (frei) 3 Byte payload 12 | KO125 - KO421 (99 Kanäle * 3 KO) 99 * 14 Byte + 198 * 4 Byte = 1386 + 792 = 2178 Byte payload (Logikkanäle) 13 | Gesamt: 14 | 421 * 8 Byte (pro KO) + 46 Byte (Lücken) + (2178 + 64 + 40 + 34 + 24) Byte payload = 5754 Byte max. 15 | 16 | WireGateway: 17 | Statisch: 18 | KO1 - KO7 (Logik) 24 Byte payload 19 | KO8 - KO19 (frei für Logik) 12 Byte payload 20 | KO20 - KO31 (WireGateway) 34 Byte payload 21 | KO32 - KO49 (frei für 1-Wire) 18 Byte payload 22 | Dynamisch: 23 | KO50 - KO145 (96 Geräte * 1 KO) 96 * 2 Byte = 192 Byte payload (1-Wire-Geräte) 24 | KO146 - KO149 (frei) 4 Byte payload 25 | KO150 - KO446 (99 Kanäle * 3 KO) 99 * 14 Byte + 198 * 4 Byte = 1386 + 792 = 2178 Byte payload (Logikkanäle) 26 | Gesamt: 27 | 446 * 8 Byte (pro KO) + 34 Byte (Lücken) + (2178 + 192 + 34 + 24) Byte payload = 6030 Byte max. 28 | 29 | Logikmodul: 30 | Statisch: 31 | KO1 - KO7 (Logik) 24 Byte payload 32 | KO8 - KO19 (frei für Logik) 12 Byte payload 33 | Dynamisch: 34 | KO20 - KO316 (99 Kanäle * 3 KO) 99 * 14 Byte + 198 * 4 Byte = 1386 + 792 = 2178 Byte payload (Logikmodul) 35 | Gesamt: 36 | 316 * 8 Byte (pro KO) + 12 Byte (Lücken) + (2178 + 24) Byte payload = 4742 Byte max. 37 | 38 | PM: tbd 39 | 40 | Rauchmelder: tbd 41 | 42 | -------------------------------------------------------------------------------- /doc/Kalibrierung.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/Kalibrierung.PNG -------------------------------------------------------------------------------- /doc/KalibrierungLoeschen.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/KalibrierungLoeschen.PNG -------------------------------------------------------------------------------- /doc/Konzept-KO-Verteilung.md: -------------------------------------------------------------------------------- 1 | # Konzept zur Verzeitlung von Kommunikationsobjekten 2 | 3 | ## Generische KO (in jedem meiner Module) 4 | 5 | KO | Name | DPT | Bedeutung 6 | :---:|:---|---:|:-- 7 | 1 | in Betrieb | 1.002 | Meldet zyklisch auf den Bus, dass das Gerät noch funktioniert 8 | 2 | Uhrzeit | 10.001 | Eingnang zum empfangen der Uhrzeit 9 | 3 | Datum | 11.001 | Eingang zum empfangen des Datums 10 | 11 | Die KO 1-9 sind für generische KO reserviert. In weiteren Modulen darf das kleinste KO mit der Nummer 10 anfangen. 12 | 13 | ## Sensormodul 14 | 15 | KO | Name | DPT | Bedeutung 16 | :---:|:---|---:|:-- 17 | 10 | Sensorwerte anfordern | 1.016 | Beim Empfang vom Trigger (1) werden alle Sensorwerte auf den Bus gesendet. So kann man mehrere Leseanforderungen sparen. 18 | 11 | Sensorfehler | 7.001 | Gibt über eine Bitleiste an, welche Messwerte aufgrund eines aufgetretenen Fehlers nicht erfasst werden können. Falls ein ganzer Sensor ausfällt, werden mehrere Bits gleichzeitig gesetzt 19 | 12 | Diagnose | 16.001 | Nur für internen Gebrauch (Debug) 20 | 15 | Temperatur | 9.001 | Temperaturmesswert (in °C) 21 | 16 | Luftfeuchte | 9.007 | Luftfeuchte (in %) 22 | 17 | Luftdruck | 9.006 | Luftdruck (in mBar, nicht Pa!!! mBar = Pa / 100) 23 | 18 | VOC | 9.* | Voc-Messwert (einheitenlos) 24 | 19 | CO2 | 9.008 | CO2-Messwert (in ppm) 25 | 20 | CO2-VOC | 9.008 | Berechneter CO2-Messwert vom VOC (in ppm) 26 | 21 | Taupunkt | 9.001 | Berechneter Taupunkt (in °C) 27 | 22 | Behaglichkeit | 5.005 | Behaglichkeitswert, errechnet aus Luftfeuchte im Verhältnis zur Temperatur (0-2) 28 | 23 | Luftqualitätsampel | 5.005 | Luftgüte entsprechend deutscher Schulnoten (1-6) 29 | 24 | Kalibrierungsgrad | 5.001 | Kalibrierungsfortschritt vom BME680 (in %) 30 | 30 | Externe Temperatur 1 | 9.001 | Eingang für externe Temperatur 1 (in °C) 31 | 31 | Externe Temperatur 2 | 9.001 | Eingang für externe Temperatur 2 (in °C) 32 | 32 | Externe Luftfeuchte 1 | 9.007 | Eingang für externe Luftfeuchte 1 (in %) 33 | 33 | Externe Luftfeuchte 2 | 9.007 | Eingang für externe Luftfeuchte 2 (in %) 34 | 34 | Externer Lufttdruck 1 | 9.006 | Eingang für externen Luftdruck 1 (in mBar) 35 | 35 | Externer Lufttdruck 2 | 9.006 | Eingang für externen Luftdruck 2 (in mBar) 36 | 36 | Externer VOC 1 | 9.* | Eingang für externen VOC-Wert 1 (einheitenlos) 37 | 37 | Externer VOC 2 | 9.* | Eingang für externen VOC-Wert 2 (einheitenlos) 38 | 38 | Externe CO2 1 | 9.008 | Eingang für externen CO2-Wert 1 (in ppm) 39 | 39 | Externe CO2 2 | 9.008 | Eingang für externen CO2-Wert 2 (in ppm) 40 | 41 | ## Logikmodul 42 | 43 | KO | Name | DPT | Bedeutung 44 | :---:|:---|---:|:-- 45 | n | Eingang 1 | *) | Eingang 1 für einen Logikkanal 46 | n+1 | Eingang 2 | *) | Eingang 2 für einen Logikkanal 47 | n+2 | Ausgang | **) | Ausgang eines Logikkanals 48 | 49 | Beim Sensormodul in n=50 und bei 100 Kanälen gehen die KO bis 349. 50 | 51 | ## OneWire 52 | 53 | KO | Name | DPT | Bedeutung 54 | :---:|:---|---:|:-- 55 | n | Gruppe 1 | DPT 1.001 | iButton Gruppe 1 56 | n+1 | Gruppe 2 | DPT 1.001 | iButton Gruppe 2 57 | n+2 | Gruppe 3 | DPT 1.001 | iButton Gruppe 3 58 | n+3 | Gruppe 4 | DPT 1.001 | iButton Gruppe 4 59 | n+4 | Gruppe 5 | DPT 1.001 | iButton Gruppe 5 60 | n+5 | Gruppe 6 | DPT 1.001 | iButton Gruppe 6 61 | n+6 | Gruppe 7 | DPT 1.001 | iButton Gruppe 7 62 | n+7 | Gruppe 8 | DPT 1.001 | iButton Gruppe 8 63 | n+10 | OW-Gerät 1 iButton-Ausgang | DPT1.001 | Gerät ist ein iButton und sendet sein Existenz-Signal 64 | n | OW-Gerät 1 Sensor-Ausgang | DPT9.xxx | Gerät ist ein Sensor und sendet sein Messwert 65 | n | OW-Gerät 1 IO-Ein-/Ausgang | DPT5.010 | Gerät ist ein I/O und sendet den Status. Wenn dieses KO beschrieben wird, wird der Wert am Ausgang gesetzt. 66 | 67 | Beim Sensormodul können 30 OneWire-Geräte verwaltet werden. Die KO beginnen mit 350 und gehen dann bis 379 (30 KO). 68 | 69 | Beim OneWire-Gateway können 120 OneWire-Geräte verwaltet werden. Die KO beginnen mit 10 und enden mit 129 (120 KO). Logikkanäle beginnen dann mit 130 und enden bei 329. 70 | 71 | ### Wie ist ein OW-Gerät-Ausgang zu interpretieren 72 | 73 | Das KO n ist mehrfach belegt und funktioniert unterschiedlich, je nachdem, welches OneWire-Gerät angeschlossen ist. Das KO wird folgerndermaßen genutzt: 74 | 75 | #### iButton 76 | 77 | Wird beim DS18x20 als DPT1.001 genutzt. Sendet ein true, wenn der iButton am OneWire-Bus hängt, false sonst. 78 | 79 | #### Sensor 80 | 81 | Wird beim DS18x20 oder DS2438 als DPT9.xxx genutzt. Gibt den gemessenen Sensorwert aus. 82 | 83 | #### I/O 84 | 85 | Wird beim DS2408 oder DS2413 als DPT5.010 genutzt. Der Wert sendet den Status des IO-Gerätes, wobei jedes Bit im DPT5 einem Bit am Ausgang des OneWire-Devices entspricht. 86 | 87 | Wird dieses KO beschrieben, wird der Wert an den Ausgängen des OneWire-Gerätes ausgegeben. 88 | 89 | ### Beispiel 90 | 91 | Bei einem DS2408 sind Bits 0-3 als Input geschaltet, an den 4 Eingängen sind z.B. Fensterkontakte dran. Ferner sind die Bits 4-7 als Output geschaltet, da ist z.B. je eine LED dran, die anzeigt, ob das Fenster offen ist. 92 | Für einen Eingang heißt ein offener Schalter eine 1 und ein geschlossener Schalter eine 0. Für einen Ausgang heißt 1 eine leuchtene LED und eine 0 eine augeschaltete LED. 93 | Fenster 1 ist an Bit 0 (Fensterkontakt) und an Bit 4 (LED). Entsprechend ist Fenster 2 an Bit 1;5 usw. 94 | 95 | Wie sieht jetzt eine Kommunikation mit dem KO n aus? Ausgangssituation ist im Beispiel so, dass alle Fenster geschlossen sind und alle LED aus. Der DS2408 würde somit die Bitfolge 96 | 97 | BIT 76543210 98 | Wert 00000000 = 0x00 99 | 100 | an seinen Pins haben. Das KO n würde genau diesen Wert liefern, wenn man es lesen würde. Es ist der Status dieses OneWire-Gerätes. 101 | 102 | Jetzt wird Fenster 0 geöffnet, damit geht Bit 0 auf den Wert 1. Das KO n sendet diesen Wert auf den Bus: 103 | 104 | BIT 76543210 105 | Wert 00000001 = 0x01 106 | 107 | Die Logik, die diese Information auswertet, will mittels der LED anzeigen, dass das Fenster offen ist. Diese Logik schreibt nun auf das KO n den Wert 108 | 109 | BIT 76543210 110 | Wert 00010000 = 0x10 111 | 112 | Der DS2408 schaltet seinen Ausgang entsprechend und bekommt folgende Bitfolge an seinen Pins: 113 | 114 | BIT 76543210 115 | Wert 00010001 = 0x11 116 | 117 | Sobald der Wert am Pin anliegt, der DS2408 also meldet, dass er den Wert übernommen hat, wird der Status über das KO n gesendet. Der gesendete Wert ist somit 118 | 119 | BIT 76543210 120 | Wert 00010001 = 0x11 121 | -------------------------------------------------------------------------------- /doc/Luftqualitätsampel.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/Luftqualitätsampel.PNG -------------------------------------------------------------------------------- /doc/OneWire.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/OneWire.png -------------------------------------------------------------------------------- /doc/PIO2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/PIO2.png -------------------------------------------------------------------------------- /doc/Standardsensoren.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/Standardsensoren.PNG -------------------------------------------------------------------------------- /doc/Taupunkt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/Taupunkt.png -------------------------------------------------------------------------------- /doc/knx-dev-setup.md: -------------------------------------------------------------------------------- 1 | # Installation of dev-Environment for Sensormodule 2 | 3 | Only tested on Windows 10! 4 | 5 | Download and install git from [https://git-scm.com/downloads](https://git-scm.com/downloads) with default options 6 | 7 | Download and install visual studio code from [https://code.visualstudio.com/download](https://code.visualstudio.com/download) (User installer, 64 bit) 8 | 9 | Start visual studio code 10 | 11 | Go to extensions (Ctrl-Shift-X) 12 | 13 | Enter "platformio" in search field 14 | 15 | Install "PlatformIO IDE" extension 16 | 17 | Wait until installation is finished, do the necessary reload window afterwards (may take some time) 18 | 19 | Click on the new PlatformIO-Icon on the left ![PIO-Icon](PIO2.png) 20 | 21 | In "Quick Access", choose open 22 | 23 | In the new "PIO Home" tab, click on "New Project..." 24 | 25 | In the upcoming dialog, provide the name "Test", Board "Sparkfun SAMD21 Dev Breakout", Framework "Arduino" and Location "Use default location" 26 | 27 | Click "Finish" and wait until finished. Visuals Studio Code will open the newly created project afterwards. The new project is just used to create default envoronment and can be deleted afterwards. 28 | 29 | Click again the PlatformIO Icon ![PIO-Icon](PIO2.png) 30 | 31 | Again "Quick Access" appears, click "Miscellaneous->PlatformIO Core CLI" 32 | 33 | A new terminal (within Visual Studio Code) appears, the path is home of the new test project. We don't need the test project, it was just used to create all necessary path for development. 34 | From now on we work in this terminal window: 35 | 36 | cd .. 37 | 38 | You should be now in a directory ending with ...\Documents\PlatformIO\Projects 39 | 40 | git clone https://github.com/mumpf/knx.git 41 | git clone https://github.com/mumpf/knx-common.git 42 | git clone https://github.com/mumpf/knx-logic.git 43 | git clone https://github.com/mumpf/knx-wire.git 44 | git clone https://github.com/mumpf/knx-sensor.git 45 | cd knx 46 | git checkout release 47 | cd ../knx-common 48 | git checkout release 49 | cd ../knx-logic 50 | git checkout release 51 | cd ../knx-wire 52 | git checkout release 53 | cd ../knx-sensor 54 | git checkout release 55 | code Sensormodul.code-workspace 56 | 57 | Now a new instance of Visual Studio Code is started. You can close the other (previous) instance. 58 | 59 | The current board version from MASIFI is v3.1. The current version for use outdoor ist v1.3. Due to the fact, that I have to test the release with diferent versions, it might happen, that the firmware is released for any of the tested versions v2, v3 or v3.1. 60 | 61 | **Please ensure always that the released version fits to your hardware!** To do this, do the following: 62 | Find the version of your hardware board (v1, v2, v3 or v3.1). Or - if it is the outdoor module - it is v1.3. 63 | 64 | In knx-sensor, edit the file platformio.ini: 65 | - there is a line 66 | -D BOARD_MASIFI_V... 67 | - change the line to the according version of your hardware 68 | -D BOARD_MASIFI_V31 69 | or 70 | -D BOARD_MASIFI_V3 71 | or 72 | -D BOARD_MASIFI_V2 73 | or 74 | -D BOARD_MASIFI_V1 75 | or (for the outdoor module) 76 | -D BOARD_MASIFI_AUSSEN_V13 77 | 78 | - there exist different versions with CRYSTALLESS setting. 79 | Ensure that 80 | -D CRYSTALLESS 81 | is always 82 | ;-D CRYSTALLESS 83 | or the line is removed. 84 | 85 | With this firmware you get watchdog-support. 86 | With the setting 87 | -D WATCHDOG 88 | the watchdog functionality is enabled. The default is 89 | ;-D WATCHDOG 90 | which disables watchdog functionality. 91 | Press Ctrl-Shift-B, select the "**Build PlatformIO** knx-sensor" build task and press enter. 92 | 93 | Now the compiler starts, this may take a while, there will be many yellow warnings, they can be ignored. 94 | 95 | At the end, there should be a message like 96 | 97 | Linking .pio\build\build\firmware.elf 98 | Building .pio\build\build\firmware.bin 99 | Checking size .pio\build\build\firmware.elf 100 | Advanced Memory Usage is available via "PlatformIO Home > Project Inspect" 101 | RAM: [== ] 22.0% (used 7216 bytes from 32768 bytes) 102 | Flash: [====== ] 55.7% (used 145892 bytes from 262144 bytes) 103 | ============================ [SUCCESS] Took 34.60 seconds ====== 104 | 105 | Now you successfully build the Firmware for the Sensormodule, containing a ETS configurable knx stack, a logic module with 80 logic channels, a one wire module for up to 30 one wire sensors and a sensor module for up to 7 measurements (temperature, humidity, air pressure, voc value, co2 value, brightness and distance). 106 | 107 | Precompiled firmware versions are not released anymore, you have always to compile your own. 108 | 109 | ## How to upload the Firmware to your Hardware 110 | 111 | Connect your device via USB to your PC. If you are using sensormodule v3.1, you need to connect it to the KNX bus. 112 | 113 | Open (again) the file Sensormodul/src/Sensormodul.cpp 114 | 115 | Press Ctrl-Shift-B, select "**Upload USB** knx-sensor" build task and press enter. 116 | 117 | Wait until file is uploaded. 118 | 119 | ## How to build a knxprod for this firmware 120 | 121 | Open [https://github.com/mumpf/multiply-channels/releases](https://github.com/mumpf/multiply-channels/releases) 122 | 123 | Download the newest release of multiply-channels, currently it is version 2.1.2. 124 | 125 | The executable is MultiplyChannels.exe 126 | 127 | Save it to C:\Users\\\\bin (usually you have to create bin directory) 128 | 129 | If this is not your ETS-PC, install ETS5 on this PC (ETS5.7.x demo is sufficient, even any 5.6.x should do) 130 | 131 | Go to the Visual Studio Code instance, which is containing the knx-sensor project 132 | 133 | Press Ctrl-Shift-P, enter "run test task" and click the appearing "Tasks: Run Test Task" 134 | 135 | In the following dropdown select "**MultiplyChannels-Release** knx-sensor" 136 | 137 | Wait for the success message in the terminal window 138 | 139 | The freshly build 140 | 141 | * Sensormodul-v3.x.knxprod 142 | 143 | you will find in the release directory of the knx-sensor project 144 | 145 | You can import this knxprod in your ETS (minimum 5.6) like any other knxprod. 146 | 147 | ## Programming with ETS 148 | 149 | This works the same way as with all other KNX devices. There is no need anymore to program the physical address first or to transfer the complete application program after initial programming. 150 | 151 | Simply use the "Program"-Button or any programming way you are used to and ETS will do the correct thing in the fastest way possible. 152 | -------------------------------------------------------------------------------- /doc/knx-dev-setup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/knx-dev-setup.pdf -------------------------------------------------------------------------------- /doc/knx-update-setup.md: -------------------------------------------------------------------------------- 1 | # Update procedure for a new firmware or application version 2 | 3 | Only tested on Windows 10! 4 | 5 | This description is just valid, if you successfuly built and installed a firmware and application the first time according to the [dev setup](https://github.com/mumpf/knx-sensor/blob/release/doc/knx-dev-setup.md) instructions. 6 | 7 | Open Visual Studio Code. It opens with the last project you used. 8 | 9 | In case the opened project is not the sensormodule project, open "Sensormodul (Workplace)", you will find it in File->Open Recent menu. 10 | 11 | Press Ctrl-Shift-G (Opens Source Control). 12 | 13 | Below "SOURCE CONTROL PROVIDERS" you will find all projects necessary for the firmware: 14 | 15 | * knx-sensor 16 | * knx-wire 17 | * knx-logic 18 | * knx-common 19 | * knx 20 | 21 | Do for each of them the following: 22 | 23 | Click on the project name (i.e. knx-sensor). 24 | 25 | There is an additional area called "knx-sensor Git", having a text box below with a text "Message". At the end of the Git-Area you see 3 dots (...) indicating a menu. Click on these 3 dots. 26 | 27 | In the upcomming menu click on the topmost entry "Pull". 28 | 29 | As said, do this for each project. 30 | 31 | As soon as all 5 pulls are finished, continue with the build steps form the initial documentation: 32 | 33 | The current board version from MASIFI is v3.1. Due to the fact, that I have to test the release with diferent versions, it might happen, that the firmware is released for any of the tested versions v2, v3 or v3.1. 34 | 35 | **Please ensure always - with each update - that the released version fits to your hardware!** To do this, do the following: 36 | Find the version of your hardware board (v1, v2, v3 or v3.1). 37 | 38 | In knx-sensor, edit the file platformio.ini: 39 | - there is a line 40 | -DBOARD_MASIFI_V... 41 | - change the line to the according version of your hardware 42 | -DBOARD_MASIFI_V31 43 | or 44 | -DBOARD_MASIFI_V3 45 | or 46 | -DBOARD_MASIFI_V2 47 | or 48 | -DBOARD_MASIFI_V1 49 | or (for the outdoor module) 50 | -DBOARD_MASIFI_AUSSEN_V13 51 | 52 | - there exist different versions with CRYSTALLESS setting. 53 | Ensure that 54 | -DCRYSTALLESS 55 | is always 56 | ;-DCRYSTALLESS 57 | or the line is removed. 58 | 59 | - NEW for firmware version >= 2.5: You can enable watchdog-support. 60 | With the setting 61 | -DWATCHDOG 62 | the watchdog functionality is enabled. The default is 63 | ;-DWATCHDOG 64 | which disables watchdog functionality. 65 | 66 | Press Ctrl-Shift-B, select the "**Build PlatformIO** knx-sensor" build task and press enter. 67 | 68 | Now the compiler starts, this may take a while, there will be many yellow warnings, they can be ignored. 69 | 70 | At the end, there should be a message like 71 | 72 | Linking .pio\build\build\firmware.elf 73 | Building .pio\build\build\firmware.bin 74 | Checking size .pio\build\build\firmware.elf 75 | Advanced Memory Usage is available via "PlatformIO Home > Project Inspect" 76 | RAM: [== ] 22.0% (used 7216 bytes from 32768 bytes) 77 | Flash: [====== ] 55.7% (used 145892 bytes from 262144 bytes) 78 | ============================ [SUCCESS] Took 34.60 seconds ====== 79 | 80 | Now you successfully build the updated Firmware for the Sensormodule. 81 | 82 | ## How to upload the Firmware to your Hardware 83 | 84 | Connect your device via USB to your PC 85 | 86 | Open (again) the file Sensormodul/src/Sensormodul.cpp 87 | 88 | Press Ctrl-Shift-B, select "**Upload USB** knx-sensor" build task and press enter. 89 | 90 | Wait until file is uploaded. 91 | 92 | Afterwards you have to reprogram physical address (PA) and Application from ETS. 93 | 94 | ## How to build a knxprod for this firmware 95 | 96 | Here you have to do exactly the same steps as desribed in the according chapter in the knx-dev-setup.pdf document. 97 | -------------------------------------------------------------------------------- /doc/knx-update-setup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumpf/knx-sensor/30197c1c170f4aa0c912b4db99382552ccb90ab6/doc/knx-update-setup.pdf -------------------------------------------------------------------------------- /include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=knx-sensor 2 | version=3.8.0 3 | author=Waldemar Porscha 4 | maintainer=Waldemar Porscha 5 | sentence=Sensormodule for the knx stack, can be parametrized with ETS 6 | paragraph= 7 | category=Application 8 | url=https://gitlab.com/mumpf/knx-sensor 9 | architectures=* 10 | includes=Sensormodul.h 11 | -------------------------------------------------------------------------------- /linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.7) 2 | project(knx-sensormodul) 3 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") 4 | set(LIBRARIES_FROM_REFERENCES "") 5 | add_executable(knx-sensormodul 6 | ../../libraries/knx/src/knx/address_table_object.cpp 7 | ../../libraries/knx/src/knx/apdu.cpp 8 | ../../libraries/knx/src/knx/application_layer.cpp 9 | ../../libraries/knx/src/knx/application_program_object.cpp 10 | ../../libraries/knx/src/knx/association_table_object.cpp 11 | ../../libraries/knx/src/knx/bau.cpp 12 | ../../libraries/knx/src/knx/bau07B0.cpp 13 | ../../libraries/knx/src/knx/bau57B0.cpp 14 | ../../libraries/knx/src/knx/bau_systemB.cpp 15 | ../../libraries/knx/src/knx/bits.cpp 16 | ../../libraries/knx/src/knx/cemi_frame.cpp 17 | ../../libraries/knx/src/knx/data_link_layer.cpp 18 | ../../libraries/knx/src/knx/device_object.cpp 19 | ../../libraries/knx/src/knx/group_object.cpp 20 | ../../libraries/knx/src/knx/group_object_table_object.cpp 21 | ../../libraries/knx/src/knx/interface_object.cpp 22 | ../../libraries/knx/src/knx/ip_data_link_layer.cpp 23 | ../../libraries/knx/src/knx/ip_parameter_object.cpp 24 | ../../libraries/knx/src/knx/memory.cpp 25 | ../../libraries/knx/src/knx/network_layer.cpp 26 | ../../libraries/knx/src/knx/npdu.cpp 27 | ../../libraries/knx/src/knx/table_object.cpp 28 | ../../libraries/knx/src/knx/tpdu.cpp 29 | ../../libraries/knx/src/knx/tpuart_data_link_layer.cpp 30 | ../../libraries/knx/src/knx/transport_layer.cpp 31 | ../../libraries/knx/src/knx/platform.cpp 32 | main.cpp 33 | ../Sensormodul.cpp 34 | ../../libraries/knx/src/linux_platform.cpp 35 | ../../libraries/knx/src/knx_facade.cpp 36 | ../../libraries/knx/src/knx/dptconvert.cpp 37 | ../../libraries/knx/src/knx/knx_value.cpp 38 | ../../libraries/knx/src/knx/dpt.cpp) 39 | target_link_libraries(knx-sensormodul "${LIBRARIES_FROM_REFERENCES}") 40 | include_directories(../../libraries/knx/src) 41 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wno-unknown-pragmas -Wno-switch -g -O0") 42 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wno-unknown-pragmas -Wno-switch -g -O0") 43 | if(NOT CMAKE_BUILD_TYPE) 44 | SET(CMAKE_BUILD_TYPE "Debug") 45 | endif() 46 | -------------------------------------------------------------------------------- /linux/CMakeSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "WSL-Debug", 5 | "generator": "Unix Makefiles", 6 | "configurationType": "Debug", 7 | "buildRoot": "${projectDir}\\out\\build\\${name}", 8 | "installRoot": "${projectDir}\\out\\install\\${name}", 9 | "cmakeExecutable": "/usr/bin/cmake", 10 | "cmakeCommandArgs": "", 11 | "buildCommandArgs": "", 12 | "ctestCommandArgs": "", 13 | "inheritEnvironments": [ "linux_x64" ], 14 | "wslPath": "${defaultWSLPath}", 15 | "addressSanitizerRuntimeFlags": "detect_leaks=0", 16 | "variables": [] 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /linux/main.cpp: -------------------------------------------------------------------------------- 1 | #include "knx/bau57B0.h" 2 | #include "knx_facade.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | KnxFacade knx; 9 | 10 | void appSetup(); 11 | void appLoop(); 12 | 13 | int main(int argc, char **argv) 14 | { 15 | knx.platform().cmdLineArgs(argc, argv); 16 | knx.readMemory(); 17 | 18 | bool setProgmode = false; 19 | if (knx.induvidualAddress() == 0 || setProgmode) 20 | knx.progMode(true); 21 | 22 | appSetup(); 23 | 24 | knx.start(); 25 | 26 | while (1) 27 | { 28 | knx.loop(); 29 | if(knx.configured()) 30 | appLoop(); 31 | delay(10); 32 | } 33 | } -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | ;PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | default_envs = build 13 | libdeps_dir = /tmp/libdeps 14 | 15 | [env] 16 | platform = atmelsam 17 | board = zeroUSB 18 | framework = arduino 19 | ; build_type = debug 20 | build_flags = 21 | -D DEBUG_DELAY=100 22 | -D BOARD_MASIFI_V31 23 | -D SERIAL_BUFFER_SIZE=96 24 | -D SERIAL_DEBUG=SerialUSB 25 | -D SMALL_GROUPOBJECT 26 | -D WATCHDOG 27 | -D SENSORMODULE 28 | -Wno-unknown-pragmas 29 | -Wno-switch 30 | -Wno-write-strings 31 | -Wno-format-overflow 32 | -L../knx-common/src/bsec/cortex-m0plus 33 | -lalgobsec 34 | ; trace logic execution in logicmodule 35 | ;-DLOGIC_TRACE 36 | ; debug timing in knx stack 37 | ; -DDEBUG_TIMING 38 | ; debug 1-Wire-Search 39 | ; -DDebugInfoBM 40 | ; -DDebugInfoSearch 41 | ; -DONEWIRE_TRACE_SEARCH 42 | ; -DCRYSTALLESS 43 | monitor_speed = 115200 44 | lib_ldf_mode = deep+ 45 | lib_extra_dirs = 46 | ${PROJECT_DIR}/.. 47 | lib_deps = 48 | SPI 49 | Wire 50 | adafruit/Adafruit SleepyDog Library @ 1.4.0 51 | adafruit/Adafruit BME280 Library @ 2.1.2 52 | ; adafruit/Adafruit SCD30 @ ^1.0.6 53 | sparkfun/SparkFun SCD30 Arduino Library @ 1.0.14 54 | sensirion/Sensirion I2C SCD4x @ 0.3.1 55 | pololu/VL53L1X @ 1.2.1 56 | ; https://github.com/mumpf/knx.git#release 57 | 58 | ; segger jlink works just in skip pre-debug mode 59 | ; after debugger start (at first init() breakpoint) 60 | ; it needs a restart (green button in vscode) to debug 61 | ; otherwise it stops with a segfault. 62 | debug_tool = jlink 63 | ; debug_tool = atmel-ice 64 | [env:build] 65 | upload_protocol = sam-ba 66 | [env:debug] 67 | build_type = debug 68 | ; debug_build_flags = 69 | ; -Og 70 | ; -ggdb2 71 | ; -g2 72 | ; debug_build_flags = -O0 -ggdb3 -g3 73 | ; debug_init_cmds = 74 | ; target extended-remote $DEBUG_PORT 75 | ; $INIT_BREAK 76 | ; ; monitor reset 0 77 | ; $LOAD_CMDS 78 | ; ; monitor init 79 | ; monitor reset 0 80 | [env:uploadUSB] 81 | upload_protocol = sam-ba 82 | [env:uploadJLINK] 83 | upload_protocol = jlink 84 | [env:uploadATMEL] 85 | upload_protocol = atmel-ice 86 | 87 | ; board_build.core = samd 88 | ; ; change microcontroller 89 | ; board_build.mcu = samd21g18a 90 | ; ; change MCU frequency 91 | ; board_build.f_cpu = 48000000L 92 | ; ; place it into the root of project or use full path 93 | ; extra_scripts = upload_script.py 94 | ; upload_protocol = custom 95 | ; each flag in a new line 96 | ; upload_command = $UPLOADER $UPLOAD_FLAGS $SOURCES 97 | ; upload_flags = 98 | ; --info 99 | ; --port 100 | ; "$UPLOAD_PORT" 101 | ; --write 102 | ; --verify 103 | ; --reset 104 | ; -U 105 | ; true 106 | ; --erase 107 | ; ; --debug 108 | -------------------------------------------------------------------------------- /release/BuildRelease.cmd: -------------------------------------------------------------------------------- 1 | %USERPROFILE%\bin\MultiplyChannels.exe create release\Sensormodul-v3.8.xml 2 | del release\Sensormodul-*.h 3 | -------------------------------------------------------------------------------- /release/Sensormodul-v3.8.xml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /src/Sensormodul-103.xml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /src/Sensormodul-104.xml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /src/Sensormodul-105.xml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /src/Sensormodul.cpp: -------------------------------------------------------------------------------- 1 | #include "Helper.h" 2 | #include "Hardware.h" 3 | 4 | #include "Sensor.h" 5 | #include "SensorBME680.h" 6 | #include "SensorSGP30.h" 7 | #include "OneWire.h" 8 | #include "WireDevice.h" 9 | #include "OneWireDS2482.h" 10 | #include "IncludeManager.h" 11 | 12 | // Reihenfolge beachten damit die Definitionen von Sensormodul.h ... 13 | #include "Sensormodul.h" 14 | // ... auf jeden Fall Vorrang haben (beeinflussen auch die Logik) 15 | // #include "../../knx-logic/src/LogikmodulCore.h" 16 | #include "Logic.h" 17 | 18 | const uint8_t cFirmwareMajor = 3; // 0-31 19 | const uint8_t cFirmwareMinor = 8; // 0-31 20 | const uint8_t cFirmwareRevision = 0; // 0-63 21 | 22 | // Achtung: Bitfelder in der ETS haben eine gewöhnungswürdige 23 | // Semantik: ein 1 Bit-Feld mit einem BitOffset=0 wird in Bit 7(!) geschrieben 24 | #define BIT_1WIRE 1 25 | #define BIT_Temp 2 26 | #define BIT_Hum 4 27 | #define BIT_Pre 8 28 | #define BIT_Voc 16 29 | #define BIT_Co2 32 30 | #define BIT_Co2Calc 64 31 | #define BIT_LOGIC 128 32 | #define BIT_LUX 256 33 | #define BIT_TOF 512 34 | 35 | uint32_t gStartupDelay; 36 | uint32_t gHeartbeatDelay; 37 | bool gIsRunning = false; 38 | sSensorInfo gTemp; 39 | sSensorInfo gHum; 40 | sSensorInfo gPre; 41 | sSensorInfo gVoc; 42 | sSensorInfo gCo2; 43 | sSensorInfo gCo2b; 44 | sSensorInfo gDew; 45 | sSensorInfo gLux; 46 | sSensorInfo gTof; 47 | WireDevice gDevice[COUNT_1WIRE_CHANNEL]; 48 | uint16_t gCountSaveInterrupt = 0; 49 | uint32_t gSaveInterruptTimestamp = 0; 50 | bool gForceSensorRead = true; 51 | int8_t gTempOffset = 0; 52 | 53 | uint16_t gSensor = 0; 54 | Logic gLogic; 55 | OneWireDS2482 *gBusMaster; 56 | 57 | typedef bool (*getSensorValue)(MeasureType, float&); 58 | void ProcessInterrupt(); 59 | 60 | uint16_t getError() { 61 | return (uint16_t)knx.getGroupObject(LOG_KoError).value(getDPT(VAL_DPT_7)); 62 | } 63 | 64 | void setError(uint16_t iValue) { 65 | knx.getGroupObject(LOG_KoError).valueNoSend(iValue, getDPT(VAL_DPT_7)); 66 | } 67 | 68 | void sendError() { 69 | knx.getGroupObject(LOG_KoError).objectWritten(); 70 | } 71 | 72 | bool callOneWire() { 73 | return (boardWithOneWire() && ((knx.paramByte(LOG_Sensor1Wire) & LOG_Sensor1WireMask) >> LOG_Sensor1WireShift)); 74 | } 75 | 76 | void ProcessHeartbeat() 77 | { 78 | // the first heartbeat is send directly after startup delay of the device 79 | if (gHeartbeatDelay == 0 || delayCheck(gHeartbeatDelay, knx.paramInt(LOG_Heartbeat) * 1000)) 80 | { 81 | // we waited enough, let's send a heartbeat signal 82 | knx.getGroupObject(LOG_KoHeartbeat).value(true, getDPT(VAL_DPT_1)); 83 | // if there is an error, we send it with heartbeat, too 84 | if (knx.paramByte(LOG_Error) & LOG_ErrorMask) { 85 | if (getError()) sendError(); 86 | } 87 | gHeartbeatDelay = millis(); 88 | // The module prints its firmware version to the console 89 | printDebug("Firmware-Version [%d] %d.%d\n", cFirmwareMajor, cFirmwareMinor, cFirmwareRevision); 90 | // debug-helper for logic module 91 | // print("ParDewpoint: "); 92 | // println(knx.paramByte(LOG_Dewpoint)); 93 | gLogic.debug(); 94 | } 95 | } 96 | 97 | void ProcessReadRequests() { 98 | static uint8_t sCalled = 1; 99 | // the following code should be called only once 100 | gLogic.processReadRequests(); 101 | if (sCalled < 255) { 102 | 103 | // we evaluate only Bit 2 here, which holds the information about read external values on startup 104 | if (sCalled == 1 && delayCheck(gStartupDelay, sCalled * 1000)) 105 | { 106 | sCalled += 1; 107 | if (knx.paramByte(LOG_TempExtRead) & LOG_TempExtReadMask) { 108 | knx.getGroupObject(LOG_KoExt1Temp).requestObjectRead(); 109 | knx.getGroupObject(LOG_KoExt2Temp).requestObjectRead(); 110 | } 111 | } 112 | if (sCalled == 2 && delayCheck(gStartupDelay, sCalled * 1000)) 113 | { 114 | sCalled += 1; 115 | if (knx.paramByte(LOG_HumExtRead) & LOG_HumExtReadMask) { 116 | knx.getGroupObject(LOG_KoExt1Hum).requestObjectRead(); 117 | knx.getGroupObject(LOG_KoExt2Hum).requestObjectRead(); 118 | } 119 | } 120 | if (sCalled == 3 && delayCheck(gStartupDelay, sCalled * 1000)) 121 | { 122 | sCalled += 1; 123 | if (knx.paramByte(LOG_PreExtRead) & LOG_PreExtReadMask) { 124 | knx.getGroupObject(LOG_KoExt1Pre).requestObjectRead(); 125 | knx.getGroupObject(LOG_KoExt2Pre).requestObjectRead(); 126 | } 127 | } 128 | if (sCalled == 4 && delayCheck(gStartupDelay, sCalled * 1000)) 129 | { 130 | sCalled += 1; 131 | if (knx.paramByte(LOG_VocExtRead) & LOG_VocExtReadMask) { 132 | knx.getGroupObject(LOG_KoExt1VOC).requestObjectRead(); 133 | knx.getGroupObject(LOG_KoExt2VOC).requestObjectRead(); 134 | } 135 | } 136 | if (sCalled == 5 && delayCheck(gStartupDelay, sCalled * 1000)) 137 | { 138 | sCalled += 1; 139 | if (knx.paramByte(LOG_Co2ExtRead) & LOG_Co2ExtReadMask) { 140 | knx.getGroupObject(LOG_KoExt1Co2).requestObjectRead(); 141 | knx.getGroupObject(LOG_KoExt2Co2).requestObjectRead(); 142 | } 143 | } 144 | if (sCalled == 6 && delayCheck(gStartupDelay, sCalled * 1000)) 145 | { 146 | sCalled += 1; 147 | if (knx.paramByte(LOG_LuxExtRead) & LOG_LuxExtReadMask) 148 | { 149 | knx.getGroupObject(LOG_KoExt1Lux).requestObjectRead(); 150 | knx.getGroupObject(LOG_KoExt2Lux).requestObjectRead(); 151 | } 152 | } 153 | if (sCalled == 7 && delayCheck(gStartupDelay, sCalled * 1000)) 154 | { 155 | sCalled += 1; 156 | if (knx.paramByte(LOG_TofExtRead) & LOG_TofExtReadMask) 157 | { 158 | knx.getGroupObject(LOG_KoExt1Tof).requestObjectRead(); 159 | knx.getGroupObject(LOG_KoExt2Tof).requestObjectRead(); 160 | } 161 | } 162 | if (sCalled == 8) 163 | { 164 | sCalled = 255; 165 | } 166 | } 167 | } 168 | 169 | void loopSubmodules() { 170 | knx.loop(); 171 | if (callOneWire()) { 172 | gBusMaster->loop(); 173 | WireDevice::loop(); 174 | } 175 | gLogic.loop(); 176 | } 177 | 178 | // true solgange der Start des gesamten Moduls verzögert werden soll 179 | bool startupDelay() 180 | { 181 | return !delayCheck(gStartupDelay, knx.paramInt(LOG_StartupDelay) * 1000); 182 | } 183 | 184 | // this callback is used by BME680 during delays while mesauring 185 | // we implement this delay, but keep normal loop processing alive 186 | void sensorDelayCallback(uint32_t iMillis) { 187 | // printDebug("sensorDelayCallback: Called with a delay of %lu ms\n", iMillis); 188 | uint32_t lMillis = millis(); 189 | while (millis() - lMillis < iMillis) { 190 | if (gIsRunning) { 191 | ProcessHeartbeat(); 192 | ProcessInterrupt(); 193 | loopSubmodules(); 194 | } 195 | } 196 | // printDebug("sensorDelayCallback: Left after %lu ms\n", millis() - lMillis); 197 | } 198 | 199 | void AddSensorMetadata(Sensor* iSensor, uint8_t iSensorId, MeasureType iMeasureType) { 200 | // additional sensor specific metadata 201 | uint8_t lMagicWordOffset = knx.paramByte(LOG_DeleteData) & LOG_DeleteDataMask; 202 | if (iSensorId == SENS_BME680) 203 | { 204 | ((SensorBME680*)iSensor)->delayCallback(sensorDelayCallback); 205 | ((SensorBME680*)iSensor)->setMagicKeyOffset(lMagicWordOffset); 206 | } 207 | else if (iSensorId == SENS_SGP30) 208 | { 209 | ((SensorSGP30*)iSensor)->setMagicKeyOffset(lMagicWordOffset); 210 | } 211 | if (iMeasureType == Temperature) { 212 | int32_t lTempOffsetInt = (int8_t)gTempOffset; 213 | float lTempOffset = (float)lTempOffsetInt / 10.0; 214 | if (iSensor->prepareTemperatureOffset(lTempOffset)) 215 | gTempOffset = 0; // disable temp offset in software 216 | } 217 | } 218 | 219 | // Starting all required sensors, this call may be blocking (with delay) 220 | void StartSensor() 221 | { 222 | Sensor* lSensor; 223 | 224 | gSensor = 0; 225 | uint8_t lSensorId = (knx.paramByte(LOG_TempSensor) & LOG_TempSensorMask) >> LOG_TempSensorShift; 226 | if (lSensorId > 0) { 227 | gSensor |= BIT_Temp; 228 | lSensor = Sensor::factory(lSensorId, Temperature); 229 | AddSensorMetadata(lSensor, lSensorId, Temperature); 230 | } 231 | lSensorId = (knx.paramByte(LOG_HumSensor) & LOG_HumSensorMask) >> LOG_HumSensorShift; 232 | if (lSensorId > 0) 233 | { 234 | gSensor |= BIT_Hum; 235 | lSensor = Sensor::factory(lSensorId, Humidity); 236 | AddSensorMetadata(lSensor, lSensorId, Humidity); 237 | } 238 | lSensorId = (knx.paramByte(LOG_PreSensor) & LOG_PreSensorMask) >> LOG_PreSensorShift; 239 | if (lSensorId > 0) 240 | { 241 | gSensor |= BIT_Pre; 242 | lSensor = Sensor::factory(lSensorId, Pressure); 243 | AddSensorMetadata(lSensor, lSensorId, Pressure); 244 | } 245 | lSensorId = (knx.paramByte(LOG_VocSensor) & LOG_VocSensorMask) >> LOG_VocSensorShift; 246 | if (lSensorId > 0) 247 | { 248 | gSensor |= BIT_Voc | BIT_Co2Calc; 249 | lSensor = Sensor::factory(lSensorId, static_cast(Voc | Accuracy | Co2Calc)); 250 | AddSensorMetadata(lSensor, lSensorId, static_cast(Voc | Accuracy | Co2Calc)); 251 | } 252 | lSensorId = (knx.paramByte(LOG_Co2Sensor) & LOG_Co2SensorMask) >> LOG_Co2SensorShift; 253 | if (lSensorId > 0) 254 | { 255 | gSensor |= BIT_Co2; 256 | lSensor = Sensor::factory(lSensorId, Co2); 257 | AddSensorMetadata(lSensor, lSensorId, Co2); 258 | } 259 | lSensorId = (knx.paramByte(LOG_LuxSensor) & LOG_LuxSensorMask) >> LOG_LuxSensorShift; 260 | if (lSensorId > 0) 261 | { 262 | gSensor |= BIT_LUX; 263 | lSensor = Sensor::factory(lSensorId, Lux); 264 | AddSensorMetadata(lSensor, lSensorId, Lux); 265 | } 266 | lSensorId = (knx.paramByte(LOG_TofSensor) & LOG_TofSensorMask) >> LOG_TofSensorShift; 267 | if (lSensorId > 0) 268 | { 269 | gSensor |= BIT_TOF; 270 | lSensor = Sensor::factory(lSensorId, Tof); 271 | AddSensorMetadata(lSensor, lSensorId, Tof); 272 | } 273 | // now start all sensors at the correct speed 274 | Sensor::beginSensors(); 275 | } 276 | 277 | bool ReadSensorValue(MeasureType iMeasureType, float& eValue) { 278 | return Sensor::measureValue(iMeasureType, eValue); 279 | } 280 | 281 | // the entries have the same order as the KOs starting with "Ext" 282 | uint8_t gIsExternalValueValid[14] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 283 | 284 | // generic sensor processing 285 | void ProcessSensor(sSensorInfo* cData, getSensorValue fGetSensorValue, MeasureType iMeasureType, float iOffsetFactor, float iValueFactor, uint16_t iParamIndex, uint16_t iKoNumber, uint8_t iDpt) 286 | { 287 | // we process just a sensor, which is selected in ETS 288 | if ((gSensor & iMeasureType) != iMeasureType) return; 289 | 290 | bool lForce = cData->sendDelay == 0; 291 | bool lSend = lForce; 292 | 293 | // process send cycle 294 | uint32_t lCycle = knx.paramInt(iParamIndex + 1) * 1000; 295 | 296 | // we waited enough, let's send the value 297 | if (lCycle && delayCheck(cData->sendDelay, lCycle)) 298 | lSend = true; 299 | 300 | // process read cycle 301 | if (lForce || delayCheck(cData->readDelay, 5000)) 302 | { 303 | // we waited enough, let's read the sensor 304 | int32_t lOffset; 305 | if (iMeasureType == Temperature) { 306 | lOffset = (int8_t)gTempOffset; 307 | } else { 308 | lOffset = (int8_t)knx.paramByte(iParamIndex); 309 | } 310 | float lValue; 311 | bool lValid = fGetSensorValue(iMeasureType, lValue); 312 | if (lValid) { 313 | // we have now the internal sensor value, we correct it now 314 | lValue = lValue / iValueFactor; 315 | lValue += (lOffset / iOffsetFactor); 316 | // if there are external values to take into account, we do it here 317 | uint8_t lNumExternalValues = knx.paramByte(iParamIndex + 9) & 3; 318 | float lDivisor = 0.0f; 319 | float lDivident = 0.0f; 320 | float lFactor = 0.0f; 321 | uint8_t lExtKoIndex = (iKoNumber - LOG_KoTemp) * 2; 322 | if (iKoNumber > LOG_KoLux) { 323 | lExtKoIndex = (iKoNumber - LOG_KoLux + 5) * 2; 324 | } 325 | switch (lNumExternalValues) 326 | { 327 | case 2: 328 | lFactor = knx.paramByte(iParamIndex + 12) * gIsExternalValueValid[lExtKoIndex + 1]; // factor for external value 2 329 | lDivident = (float)knx.getGroupObject(lExtKoIndex + LOG_KoExt2Temp).value(getDPT(iDpt)) * lFactor; 330 | lDivisor = lFactor; 331 | case 1: 332 | lFactor = knx.paramByte(iParamIndex + 11) * gIsExternalValueValid[lExtKoIndex]; // factor for external value 1 333 | lDivident += (float)knx.getGroupObject(lExtKoIndex + LOG_KoExt1Temp).value(getDPT(iDpt)) * lFactor; 334 | lDivisor += lFactor; 335 | lFactor = knx.paramByte(iParamIndex + 10); // factor for internal value 336 | lDivident += lValue * lFactor; 337 | lDivisor += lFactor; 338 | if (lDivisor > 0.0f) lValue = lDivident / lDivisor; 339 | break; 340 | default: 341 | lDivisor = 1.0f; 342 | break; 343 | } 344 | if (lDivisor > 0.1f) { 345 | // smoothing (? glätten ?) of the new value 346 | // Formel: Value = ValueAlt + (ValueNeu - ValueAlt) / p 347 | float lValueAlt = (float)knx.getGroupObject(iKoNumber).value(getDPT(iDpt)); 348 | if (!(lForce && lValueAlt == 0.0f)) { 349 | lValue = lValueAlt + (lValue - lValueAlt) / knx.paramByte(iParamIndex + 8); 350 | } 351 | // evaluate sending conditions (relative delta / absolute delta) 352 | if (cData->lastSentValue != 0.0f) { 353 | float lDelta = 100.0f - lValue / cData->lastSentValue * 100.0f; 354 | uint8_t lPercent = knx.paramByte(iParamIndex + 7); 355 | if (lPercent > 0 && (uint8_t)round(abs(lDelta)) >= lPercent) 356 | lSend = true; 357 | float lAbsolute = knx.paramWord(iParamIndex + 5) / iOffsetFactor; 358 | if (lAbsolute > 0.0f && roundf(abs(lValue - cData->lastSentValue)) >= lAbsolute) 359 | lSend = true; 360 | } 361 | // we always store the new value in KO, even it it is not sent (to satisfy potential read request) 362 | if (lValue <= -0.01f || lValue >= 0.01f) 363 | knx.getGroupObject(iKoNumber).valueNoSend(lValue, getDPT(iDpt)); 364 | } 365 | } else { 366 | lSend = false; 367 | } 368 | cData->readDelay = millis(); 369 | } 370 | if (lSend) 371 | { 372 | if ((getError() & iMeasureType) == 0) { 373 | float lValue = (float)knx.getGroupObject(iKoNumber).value(getDPT(iDpt)); 374 | if (lValue <= -0.01f || lValue >= 0.01f) { 375 | knx.getGroupObject(iKoNumber).objectWritten(); 376 | cData->lastSentValue = lValue; 377 | } 378 | } 379 | cData->sendDelay = millis(); 380 | if (cData->sendDelay == 0) cData->sendDelay = 1; 381 | } 382 | } 383 | 384 | struct sPoint 385 | { 386 | float x; 387 | float y; 388 | }; 389 | 390 | sPoint comfort1[8] = {{17.0f, 88.8f}, {21.4f, 84.1f}, {25.0f, 60.0f}, {27.1f, 30.5f}, {25.9f, 29.5f}, {20.0f, 29.5f}, {17.1f, 48.8f}, {15.9f, 78.8f}}; 391 | sPoint comfort2[4] = {{17.5f, 74.7f}, {22.0f, 72.9f}, {24.3f, 37.6f}, {18.9f, 41.8f}}; 392 | 393 | bool InPolygon(sPoint *iPoly, uint8_t iLen, float iX, float iY) 394 | { 395 | int j = iLen - 1; 396 | bool lResult = false; 397 | for (int i = 0; i < iLen; i++) 398 | { 399 | if (((iPoly[i].y > iY) != (iPoly[j].y > iY)) && (iX < (iPoly[j].x - iPoly[i].x) * (iY - iPoly[i].y) / (iPoly[j].y - iPoly[i].y) + iPoly[i].x)) 400 | { 401 | lResult = !lResult; 402 | } 403 | j = i; 404 | } 405 | return lResult; 406 | } 407 | 408 | // static bool sTempHumValid = false; 409 | 410 | // Dewpoint is a vitual sensor and might be implemented on sensor class level, but we implement it here (easier and shorter) 411 | bool CalculateDewValue(MeasureType iMeasureType, float& eValue) { 412 | float lTemp = knx.getGroupObject(LOG_KoTemp).value(getDPT(VAL_DPT_9)); 413 | float lHum = knx.getGroupObject(LOG_KoHum).value(getDPT(VAL_DPT_9)); 414 | bool lTempHumValid = (((lTemp < 0.0f) || (lTemp > 0.0f)) && lHum > 0.0f); 415 | if (lTempHumValid) { 416 | float lLogHum = log(lHum / 100.0f); 417 | // eValue = 243.12f * ((17.62f * lTemp) / (243.12f + lTemp) + lLogHum) / ((17.62f * 243.12f) / (243.12f + lTemp) - lLogHum); 418 | eValue = 243.12f * ((17.62f * lTemp) / (243.12f + lTemp) + lLogHum) / (4283.7744 / (243.12f + lTemp) - lLogHum); 419 | } 420 | return lTempHumValid; 421 | } 422 | 423 | void CalculateComfort(bool iForce = false) 424 | { 425 | static uint32_t sMillis = 0; 426 | bool lSend = iForce; 427 | if (iForce || delayCheck(sMillis, 1000)) 428 | { 429 | sMillis = millis(); 430 | // do not calculate if underlying measures are corrupt 431 | if (getError() & (Temperature | Humidity)) return; 432 | 433 | float lTemp = roundf(knx.getGroupObject(LOG_KoTemp).value(getDPT(VAL_DPT_9))); 434 | float lHum = roundf(knx.getGroupObject(LOG_KoHum).value(getDPT(VAL_DPT_9))); 435 | bool lTempHumValid = (((lTemp < 0.0f) || lTemp > 0.0f) && lHum > 0.0f); 436 | if (lTempHumValid && (knx.paramByte(LOG_Comfort) & LOG_ComfortMask)) 437 | { 438 | // comfortzone 439 | uint8_t lComfort = 0; 440 | if (InPolygon(comfort2, 4, lTemp, lHum)) 441 | { 442 | lComfort = 2; 443 | } 444 | else if (InPolygon(comfort1, 8, lTemp, lHum)) 445 | { 446 | lComfort = 1; 447 | } 448 | if ((uint8_t)knx.getGroupObject(LOG_KoComfort).value(getDPT(VAL_DPT_5)) != lComfort) 449 | lSend = true; 450 | if (lSend) 451 | knx.getGroupObject(LOG_KoComfort).value(lComfort, getDPT(VAL_DPT_5)); 452 | } 453 | } 454 | } 455 | 456 | void CalculateAccuracy(bool iForce = false) 457 | { 458 | static uint32_t sMillis = 0; 459 | bool lSend = iForce; 460 | if (iForce || delayCheck(sMillis, 60000)) 461 | { 462 | sMillis = millis(); 463 | // do not calculate if underlying measures are corrupt 464 | if (getError() & Accuracy) return; 465 | 466 | if (knx.paramByte(LOG_Accuracy) & LOG_AccuracyMask) 467 | { 468 | // get accuracy 469 | float lAccuracyMeasure; 470 | bool lSuccess = Sensor::measureValue(Accuracy, lAccuracyMeasure); 471 | if (lSuccess) { 472 | uint8_t lAccuracy = (uint8_t)lAccuracyMeasure; 473 | uint8_t lOldAccuracy = (uint8_t)knx.getGroupObject(LOG_KoSensorAccuracy).value(getDPT(VAL_DPT_5001)); 474 | if (lOldAccuracy != lAccuracy) 475 | lSend = true; 476 | if (lSend) 477 | knx.getGroupObject(LOG_KoSensorAccuracy).value(lAccuracy, getDPT(VAL_DPT_5001)); 478 | } 479 | } 480 | } 481 | } 482 | 483 | uint8_t getAirquality(float iCurrent, float* iLimits) { 484 | uint8_t lResult = 6; 485 | for (uint8_t i = 0; i < 5; i++) 486 | { 487 | if (iCurrent < iLimits[i]) { 488 | lResult = i + 1; 489 | break; 490 | } 491 | } 492 | return lResult; 493 | } 494 | 495 | void CalculateAirquality(bool iForce = false) 496 | { 497 | static uint32_t sMillis = 0; 498 | static float sVocLimits[5] = {51.0f,101.0f,151.0f,201.0f,301.0f}; 499 | static float sCo2Limits[5] = {401.0f,701.0f,1001.0f,1401.0f,2001.0f}; 500 | 501 | bool lSend = iForce; 502 | if (iForce || delayCheck(sMillis, 5000)) 503 | { 504 | sMillis = millis(); 505 | // do not calculate if underlying measures are corrupt 506 | if (getError() & (Voc | Co2)) return; 507 | 508 | if (knx.paramByte(LOG_Airquality) & LOG_AirqualityMask) 509 | { 510 | // do not calculate if underlying measureas are not yet available 511 | float lValue = 0; 512 | 513 | // get airquality 514 | uint8_t lAirquality = 6; 515 | if ((gSensor & BIT_Co2)) { 516 | // do not calculate if underlying measureas are not yet available 517 | if (!Sensor::measureValue(Co2, lValue)) 518 | return; 519 | lValue = knx.getGroupObject(LOG_KoCo2).value(getDPT(VAL_DPT_9)); 520 | if (lValue <= 1.0) 521 | lValue = knx.getGroupObject(LOG_KoCo2b).value(getDPT(VAL_DPT_9)); 522 | lAirquality = getAirquality(lValue, sCo2Limits); 523 | } else if ((gSensor & BIT_Voc)) { 524 | if (!Sensor::measureValue(Voc, lValue)) 525 | return; 526 | lValue = knx.getGroupObject(LOG_KoVOC).value(getDPT(VAL_DPT_9)); 527 | lAirquality = getAirquality(lValue, sVocLimits); 528 | } 529 | if ((uint8_t)knx.getGroupObject(LOG_KoAirquality).value(getDPT(VAL_DPT_5)) != lAirquality) 530 | lSend = true; 531 | if (lSend) 532 | knx.getGroupObject(LOG_KoAirquality).value(lAirquality, getDPT(VAL_DPT_5)); 533 | } 534 | } 535 | } 536 | 537 | void ProcessSensors(bool iForce = false) 538 | { 539 | static uint16_t sMeasureType = BIT_Temp; 540 | static bool sForceComfort = false; 541 | static bool sForceAirquality = false; 542 | static bool sForceAccuracy = false; 543 | 544 | if (iForce) { 545 | // in case we force sending of value, we set all send delays to 0 546 | gTemp.sendDelay = 0; 547 | gHum.sendDelay = 0; 548 | gPre.sendDelay = 0; 549 | gVoc.sendDelay = 0; 550 | gCo2.sendDelay = 0; 551 | gCo2b.sendDelay = 0; 552 | gDew.sendDelay = 0; 553 | gLux.sendDelay = 0; 554 | gTof.sendDelay = 0; 555 | sForceComfort = true; 556 | sForceAirquality = true; 557 | sForceAccuracy = true; 558 | } 559 | switch (sMeasureType) 560 | { 561 | case BIT_Temp: 562 | ProcessSensor(&gTemp, ReadSensorValue, Temperature, 10.0f, 1.0f, LOG_TempOffset, LOG_KoTemp, VAL_DPT_9); 563 | break; 564 | case BIT_Hum: 565 | ProcessSensor(&gHum, ReadSensorValue, Humidity, 1.0f, 1.0f, LOG_HumOffset, LOG_KoHum, VAL_DPT_9); 566 | break; 567 | case BIT_Pre: 568 | ProcessSensor(&gPre, ReadSensorValue, Pressure, 1.0f, 100.0f, LOG_PreOffset, LOG_KoPre, VAL_DPT_9); 569 | break; 570 | case BIT_Voc: 571 | ProcessSensor(&gVoc, ReadSensorValue, Voc, 1.0f, 1.0f, LOG_VocOffset, LOG_KoVOC, VAL_DPT_9); 572 | break; 573 | case BIT_Co2: 574 | ProcessSensor(&gCo2, ReadSensorValue, Co2, 1.0f, 1.0f, LOG_Co2Offset, LOG_KoCo2, VAL_DPT_9); 575 | break; 576 | case BIT_Co2Calc: 577 | ProcessSensor(&gCo2b, ReadSensorValue, Co2Calc, 1.0f, 1.0f, LOG_Co2Offset, LOG_KoCo2b, VAL_DPT_9); 578 | break; 579 | case BIT_LOGIC: // dew value, this constant is misleading... 580 | if ((gSensor & (BIT_Temp | BIT_Hum)) == (BIT_Temp | BIT_Hum)) 581 | ProcessSensor(&gDew, CalculateDewValue, static_cast(Temperature | Humidity), 10.0f, 1.0f, LOG_DewOffset, LOG_KoDewpoint, VAL_DPT_9); 582 | break; 583 | case BIT_LUX: 584 | ProcessSensor(&gLux, ReadSensorValue, Lux, 1.0f, 1.0f, LOG_LuxOffset, LOG_KoLux, VAL_DPT_9); 585 | break; 586 | case BIT_TOF: 587 | ProcessSensor(&gTof, ReadSensorValue, Tof, 1.0f, 1.0f, LOG_TofOffset, LOG_KoTof, VAL_DPT_7); 588 | break; 589 | case 0x400: 590 | if ((gSensor & (BIT_Temp | BIT_Hum)) == (BIT_Temp | BIT_Hum)) 591 | CalculateComfort(sForceComfort); 592 | sForceComfort = false; 593 | break; 594 | case 0x800: 595 | if (gSensor & (BIT_Voc | BIT_Co2 | BIT_Co2Calc)) 596 | CalculateAirquality(sForceAirquality); 597 | sForceAirquality = false; 598 | break; 599 | case 0x1000: 600 | if (gSensor & BIT_Voc) 601 | CalculateAccuracy(sForceAccuracy); 602 | sForceAccuracy = false; 603 | break; 604 | default: 605 | sMeasureType = 1; 606 | // error processing 607 | uint8_t lError = Sensor::getError(); 608 | if (lError != getError()) { 609 | setError(lError); 610 | if (knx.paramByte(LOG_Error) & LOG_ErrorMask) 611 | sendError(); 612 | } 613 | break; 614 | } 615 | sMeasureType <<= 1; 616 | } 617 | 618 | bool processDiagnoseCommand() { 619 | char* lBuffer = gLogic.getDiagnoseBuffer(); 620 | bool lOutput = false; 621 | if (lBuffer[0] == 'v') { 622 | // Command v: retrun fimware version, do not forward this to logic, 623 | // because it means firmware version of the outermost module 624 | sprintf(lBuffer, "VER [%d] %d.%d", cFirmwareMajor, cFirmwareMinor, cFirmwareRevision); 625 | lOutput = true; 626 | } else if (lBuffer[0] == 'c') { 627 | sprintf(lBuffer, "%d00 kHz", Sensor::getMaxI2cSpeed()); 628 | lOutput = true; 629 | } else { 630 | // let's check other modules for this command 631 | lOutput = gLogic.processDiagnoseCommand(); 632 | } 633 | return lOutput; 634 | } 635 | 636 | void ProcessDiagnoseCommand(GroupObject &iKo) { 637 | // this method is called as soon as iKo is changed 638 | // an external change is expected 639 | // because this iKo also is changed within this method, 640 | // the method is called again. This might result in 641 | // an endless loop. This is prevented by the isCalled pattern. 642 | static bool sIsCalled = false; 643 | if (!sIsCalled) { 644 | sIsCalled = true; 645 | //diagnose is interactive and reacts on commands 646 | gLogic.initDiagnose(iKo); 647 | if (processDiagnoseCommand()) 648 | gLogic.outputDiagnose(iKo); 649 | sIsCalled = false; 650 | } 651 | }; 652 | 653 | void ProcessKoCallback(GroupObject &iKo) { 654 | // check if we evaluate own KO 655 | if (iKo.asap() == LOG_KoDiagnose) { 656 | ProcessDiagnoseCommand(iKo); 657 | } else if (iKo.asap() == LOG_KoRequestValues) { 658 | println("Request values called"); 659 | // print("KO-Value is "); 660 | // println((bool)iKo.value(getDpt(VAL_DPT_1))); 661 | if ((bool)iKo.value(getDPT(VAL_DPT_1))) 662 | gForceSensorRead = true; 663 | } else if (iKo.asap() >= LOG_KoExt1Temp && iKo.asap() <= LOG_KoExt2Tof) { 664 | // as soon as we receive any external sensor value, we mark this in our validity map 665 | gIsExternalValueValid[iKo.asap() - LOG_KoExt1Temp] = 1; 666 | } else { 667 | WireDevice::processKOCallback(iKo); 668 | // else dispatch to logicmodule 669 | gLogic.processInputKo(iKo); 670 | } 671 | } 672 | 673 | void ProcessInterrupt() { 674 | if (gSaveInterruptTimestamp) { 675 | printDebug("Sensormodul: SAVE-Interrupt processing started after %lu ms\n", millis() - gSaveInterruptTimestamp); 676 | gSaveInterruptTimestamp = millis(); 677 | // for the moment, we send only an Info on error object in case of an save interrumpt 678 | uint16_t lError = getError(); 679 | setError(lError | 128); 680 | sendError(); 681 | // switch off all energy intensive hardware to gain time for EEPROM write 682 | savePower(); 683 | // call according logic interrupt handler 684 | gLogic.processInterrupt(true); 685 | Sensor::saveState(); 686 | printDebug("Sensormodul: SAVE-Interrupt processing duration was %lu ms\n", millis() - gSaveInterruptTimestamp); 687 | // in case, SaveInterrupt was a false positive 688 | // we restore power and I2C-Bus 689 | // Wire.end(); 690 | // wait another 200 ms 691 | delay(2000); 692 | restorePower(); 693 | delay(1000); 694 | // Wire.begin(); 695 | // Sensor::restartSensors(); 696 | gSaveInterruptTimestamp = 0; 697 | } 698 | } 699 | 700 | 701 | void appLoop() 702 | { 703 | if (!knx.configured()) 704 | return; 705 | 706 | // handle KNX stuff 707 | if (startupDelay()) 708 | return; 709 | 710 | gIsRunning = true; 711 | ProcessInterrupt(); 712 | 713 | // at this point startup-delay is done 714 | // we process heartbeat 715 | ProcessHeartbeat(); 716 | ProcessReadRequests(); 717 | loopSubmodules(); 718 | 719 | // at Startup, we want to send all values immediately 720 | ProcessSensors(gForceSensorRead); 721 | gForceSensorRead = false; 722 | loopSubmodules(); 723 | 724 | Sensor::sensorLoop(); 725 | loopSubmodules(); 726 | } 727 | 728 | // handle interrupt from save pin 729 | void onSafePinInterruptHandler() { 730 | gCountSaveInterrupt += 1; 731 | gSaveInterruptTimestamp = millis(); 732 | } 733 | 734 | void beforeRestartHandler() { 735 | printDebug("before Restart called\n"); 736 | Sensor::saveState(); 737 | gLogic.onBeforeRestartHandler(); 738 | // we try get a clean state on I2C bus 739 | Wire.end(); 740 | } 741 | 742 | void beforeTableUnloadHandler(TableObject& iTableObject, LoadState& iNewState) { 743 | static uint32_t sLastCalled = 0; 744 | printDebug("Table changed called with state %d\n", iNewState); 745 | 746 | if (iNewState == 0) { 747 | printDebug("Table unload called\n"); 748 | if (sLastCalled == 0 || delayCheck(sLastCalled, 10000)) { 749 | Sensor::saveState(); 750 | gLogic.onBeforeTableUnloadHandler(iTableObject, iNewState); 751 | sLastCalled = millis(); 752 | } 753 | } 754 | } 755 | 756 | void appSetup(bool iSaveSupported) 757 | { 758 | // try to get rid of occasional I2C lock... 759 | // savePower(); 760 | // ledProg(true); 761 | ledInfo(true); 762 | // delay(1000); 763 | // restorePower(); 764 | ledProg(true); 765 | // check hardware availability 766 | boardCheck(); 767 | // moved to sensor lib 768 | // Wire.begin(); 769 | // Wire.setClock(400000); 770 | ledInfo(false); 771 | ledProg(false); 772 | // The module prints its firmware version to the console 773 | printDebug("Firmware-Version [%d] %d.%d\n", cFirmwareMajor, cFirmwareMinor, cFirmwareRevision); 774 | 775 | if (knx.configured()) 776 | { 777 | // 5 bit major, 5 bit minor, 6 bit revision 778 | knx.bau().deviceObject().version(cFirmwareMajor << 11 | cFirmwareMinor << 6 | cFirmwareRevision); 779 | gStartupDelay = millis(); 780 | gHeartbeatDelay = 0; 781 | gCountSaveInterrupt = 0; 782 | gTempOffset = (int8_t)knx.paramByte(LOG_TempOffset); // we handle temp offset in Sensor, if possible 783 | // GroupObject &lKoRequestValues = knx.getGroupObject(LOG_KoRequestValues); 784 | if (GroupObject::classCallback() == 0) 785 | GroupObject::classCallback(ProcessKoCallback); 786 | if (knx.getBeforeRestartCallback() == 0) knx.addBeforeRestartCallback(beforeRestartHandler); 787 | if (TableObject::getBeforeTableUnloadCallback() == 0) TableObject::addBeforeTableUnloadCallback(beforeTableUnloadHandler); 788 | StartSensor(); 789 | #ifdef SAVE_INTERRUPT_PIN 790 | if (iSaveSupported) 791 | attachInterrupt(digitalPinToInterrupt(SAVE_INTERRUPT_PIN), onSafePinInterruptHandler, FALLING); 792 | #endif 793 | gLogic.setup(false); 794 | if (callOneWire()) 795 | { 796 | bool lSearchNewDevices = knx.paramByte(LOG_IdSearch) & LOG_IdSearchMask; 797 | // Loogic should call busmaster loop as often als knx loop 798 | // Logic::addLoopCallback(WireBus::loopCallback, &gBusMaster); 799 | // gBusMaster->setup(0, lSearchNewDevices, true); 800 | gBusMaster = new OneWireDS2482(WireDevice::processNewIdCallback, WireDevice::knxLoopCallback); 801 | gBusMaster->setup(0, 0, lSearchNewDevices); 802 | gBusMaster->setupTiming( 803 | (knx.paramByte(LOG_Busmaster1RSTL) & LOG_Busmaster1RSTLMask) >> LOG_Busmaster1RSTLShift, 804 | (knx.paramByte(LOG_Busmaster1MSP) & LOG_Busmaster1MSPMask) >> LOG_Busmaster1MSPShift, 805 | (knx.paramByte(LOG_Busmaster1W0L) & LOG_Busmaster1W0LMask) >> LOG_Busmaster1W0LShift, 806 | (knx.paramByte(LOG_Busmaster1REC0) & LOG_Busmaster1REC0Mask) >> LOG_Busmaster1REC0Shift, 807 | (knx.paramByte(LOG_Busmaster1WPU) & LOG_Busmaster1WPUMask) >> LOG_Busmaster1WPUShift); 808 | 809 | // initialize all known 1-Wire-sensors from application data 810 | for (uint8_t lDeviceIndex = 0; lDeviceIndex < COUNT_1WIRE_CHANNEL; lDeviceIndex++) 811 | { 812 | // check for family information 813 | uint8_t lFamily = knx.paramByte(lDeviceIndex * WIRE_ParamBlockSize + WIRE_ParamBlockOffset + WIRE_sFamilyCode); 814 | if (lFamily > 0) 815 | { 816 | // looks strange, but all 1-wire devices are handled throug static methods after creation 817 | new WireDevice(lDeviceIndex, &gBusMaster); 818 | } 819 | } 820 | } 821 | } 822 | } -------------------------------------------------------------------------------- /src/Sensormodul.parts.xml: -------------------------------------------------------------------------------- 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 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | -------------------------------------------------------------------------------- /src/Sensormodul.templ.xml: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Sensormodul.xml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Hardware.h" 4 | 5 | void appSetup(bool iSaveSupported); 6 | void appLoop(); 7 | 8 | void setup() 9 | { 10 | SerialUSB.begin(115200); 11 | pinMode(PROG_LED_PIN, OUTPUT); 12 | digitalWrite(PROG_LED_PIN, HIGH); 13 | delay(DEBUG_DELAY); 14 | digitalWrite(PROG_LED_PIN, LOW); 15 | SerialUSB.println("Startup called..."); 16 | ArduinoPlatform::SerialDebug = &SerialUSB; 17 | 18 | #ifdef INFO_LED_PIN 19 | pinMode(INFO_LED_PIN, OUTPUT); 20 | ledInfo(true); 21 | #endif 22 | 23 | // moved to checkBoard!!! 24 | // Wire.begin(); 25 | knx.readMemory(); 26 | 27 | // pin or GPIO the programming led is connected to. Default is LED_BUILDIN 28 | knx.ledPin(PROG_LED_PIN); 29 | // is the led active on HIGH or low? Default is LOW 30 | knx.ledPinActiveOn(PROG_LED_PIN_ACTIVE_ON); 31 | // pin or GPIO programming button is connected to. Default is 0 32 | knx.buttonPin(PROG_BUTTON_PIN); 33 | // Is the interrup created in RISING or FALLING signal? Default is RISING 34 | knx.buttonPinInterruptOn(PROG_BUTTON_PIN_INTERRUPT_ON); 35 | 36 | appSetup(SAVE_INTERRUPT_PIN); 37 | 38 | // start the framework. 39 | knx.start(); 40 | ledInfo(false); 41 | } 42 | 43 | void loop() 44 | { 45 | // don't delay here to much. Otherwise you might lose packages or mess up the timing with ETS 46 | knx.loop(); 47 | 48 | // only run the application code if the device was configured with ETS 49 | if (knx.configured()) 50 | appLoop(); 51 | } -------------------------------------------------------------------------------- /test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /upload_script.py: -------------------------------------------------------------------------------- 1 | ################################################################################################ 2 | # 3 | # This script is currently not used, but kept here as an example for options to influence upload 4 | # 5 | # all env-vairables are available with pio run --target envdump 6 | # 7 | ################################################################################################ 8 | 9 | Import("env") 10 | 11 | # please keep $SOURCE variable, it will be replaced with a path to firmware 12 | 13 | # # Generic 14 | # env.Replace( 15 | # UPLOADER="C:\\Users\\d019748\\.platformio\\packages\\tool-bossac\\bossac.exe", 16 | # UPLOADCMD="$UPLOADER $UPLOADERFLAGS -w $SOURCE" 17 | # ) 18 | 19 | # # In-line command with arguments 20 | # env.Replace( 21 | # UPLOADCMD="C:\\Users\\d019748\\.platformio\\packages\\tool-bossac\\bossac.exe -v -R -w $SOURCE" 22 | # ) 23 | 24 | # Python callback 25 | def on_upload(source, target, env): 26 | firmware_path = str(source[0]) 27 | print("firmware_path {0}".format(firmware_path)) 28 | print("UPLOADCMD: {0}, UPLOADPORT: {1}".format(env.Dump("UPLOADCMD"), "leer")) # env.Dump("UPLOADPORT"))) 29 | # do something 30 | # env.Execute("executable arg1 arg2") 31 | 32 | env.Replace(UPLOADCMD=on_upload) --------------------------------------------------------------------------------