├── .github └── workflows │ └── pythonpublish.yml ├── .gitignore ├── Dockerfile ├── Dockerfile-arm32v6 ├── LICENSE ├── README.md ├── enoceanmqtt-default.conf ├── enoceanmqtt.conf.sample ├── enoceanmqtt.service ├── enoceanmqtt ├── __init__.py ├── communicator.py └── enoceanmqtt.py └── setup.py /.github/workflows/pythonpublish.yml: -------------------------------------------------------------------------------- 1 | # This workflows will upload a Python Package using Twine when a release is created 2 | # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries 3 | 4 | name: Upload Python Package 5 | 6 | on: 7 | release: 8 | types: [created] 9 | 10 | jobs: 11 | deploy: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Set up Python 17 | uses: actions/setup-python@v1 18 | with: 19 | python-version: "3.x" 20 | - name: Install dependencies 21 | run: | 22 | python -m pip install --upgrade pip 23 | pip install setuptools wheel twine 24 | - name: Build and publish 25 | env: 26 | TWINE_USERNAME: __token__ 27 | TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} 28 | run: | 29 | python setup.py sdist bdist_wheel 30 | twine upload dist/* 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | include 3 | lib 4 | local 5 | share 6 | *.pyc 7 | *.log 8 | *.egg-info 9 | build 10 | man 11 | MANIFEST 12 | dist 13 | *.priv 14 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3-alpine 2 | 3 | VOLUME /config 4 | 5 | COPY . / 6 | RUN python setup.py develop 7 | 8 | WORKDIR / 9 | ENTRYPOINT ["python", "/usr/local/bin/enoceanmqtt", "/enoceanmqtt-default.conf", "/config/enoceanmqtt.conf"] 10 | -------------------------------------------------------------------------------- /Dockerfile-arm32v6: -------------------------------------------------------------------------------- 1 | FROM arm32v6/python:3.8-alpine3.12 2 | 3 | VOLUME /config 4 | 5 | COPY . / 6 | RUN python setup.py develop 7 | 8 | WORKDIR / 9 | ENTRYPOINT ["python", "/usr/local/bin/enoceanmqtt", "/enoceanmqtt-default.conf", "/config/enoceanmqtt.conf"] 10 | -------------------------------------------------------------------------------- /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 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 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 | {project} Copyright (C) {year} {fullname} 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 | 676 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EnOcean to MQTT Forwarder # 2 | 3 | [![PyPI pyversions](https://img.shields.io/pypi/pyversions/enocean-mqtt.svg)](https://pypi.python.org/pypi/enocean-mqtt/) [![PyPI status](https://img.shields.io/pypi/status/enocean-mqtt.svg)](https://pypi.python.org/pypi/enocean-mqtt/) [![PyPI version shields.io](https://img.shields.io/pypi/v/enocean-mqtt.svg)](https://pypi.python.org/pypi/enocean-mqtt/) [![PyPI download total](https://img.shields.io/pypi/dm/enocean-mqtt.svg)](https://pypi.python.org/pypi/enocean-mqtt/) 4 | 5 | This Python module receives messages from an EnOcean interface (e.g. via USB) and publishes selected messages to an MQTT broker. 6 | 7 | You may also configure it to answer to incoming EnOcean messages with outgoing responses. The response content is also defined using MQTT requests. 8 | 9 | It builds upon the [Python EnOcean](https://github.com/kipe/enocean) library. 10 | 11 | ## Installation ## 12 | 13 | enocean-mqtt is available on [PyPI](https://pypi.org/project/enocean-mqtt/) and can be installed using pip: 14 | - `pip install enocean-mqtt` 15 | 16 | Alternatively, install the latest release directly from github: 17 | - download this repository to an arbritary directory 18 | - install it using `python setup.py develop` 19 | 20 | Afterwards, perform configuration: 21 | - adapt the `enoceanmqtt.conf.sample` file and put it to /etc/enoceanmqtt.conf 22 | - set the enocean interface port 23 | - define the MQTT broker address 24 | - define the sensors to monitor 25 | - ensure that the MQTT broker is running 26 | - run `enoceanmqtt` from within the directory of the config file or provide the config file as a command line argument 27 | 28 | ### Setup as a daemon ### 29 | 30 | Assuming you want this tool to run as a daemon, which gets automatically started by systemd: 31 | - copy the `enoceanmqtt.service` to `/etc/systemd/system/` (making only a symbolic link [will not work](https://bugzilla.redhat.com/show_bug.cgi?id=955379)) 32 | - `systemctl enable enoceanmqtt` 33 | - `systemctl start enoceanmqtt` 34 | 35 | ### Setup as a docker container ### 36 | 37 | Alternatively, instead of running a native deamon you may want to use Docker: 38 | - Mount the `/config` volume and your enocean USB device 39 | - Adapt the `enoceanmqtt.conf` file in the `/config` folder 40 | 41 | The volume mount has to point to -v /local/path/to/configfile:/config. 42 | Example docker command: 43 | 44 | `sudo docker run --name="enoceanmqtt" --device=/dev/enocean -v /volume1/docker/enocean2mqtt/config:/config volschin/enocean-mqtt:latest`. 45 | 46 | ### Define persistant device name for EnOcean interface ### 47 | 48 | If you own an USB EnOcean interface and use it together with some other USB devices you may face the situation that the EnOcean interface gets different device names depending on your plugging and unplugging sequence, such as `/dev/ttyUSB0`or `/dev/ttyUSB1`. You would need to always adapt your config file then. 49 | 50 | To solve this you can make an udev rule that assigns a symbolic name to the device. For this, create the file `/etc/udev/rules.d/99-usb.rules` with the following content: 51 | 52 | `SUBSYSTEM=="tty", ATTRS{product}=="EnOcean USB 300 DB", SYMLINK+="enocean"` 53 | 54 | After reboot, this assigns the symbolic name `/dev/enocean`. If you use a different enocean interface, you may want to check the product string by looking into `dmesg` and search for the corresponding entry here. Alternatively you can check `udevadm info -a -n /dev/ttyUSB0`, assuming that the interface is currently mapped to `ttyUSB0`. 55 | 56 | ### Using with the EnOcean Raspberry Pi Hat ### 57 | 58 | This module works with the [element14 EnOcean Raspberry Pi Hat](https://www.element14.com/community/docs/DOC-55169). The hat presents the EnOcean transceiver to the system as device `/dev/ttyAMA0`, set `enocean_port` to this device in your configuration file. 59 | 60 | Depending on your Raspberry Pi model, you may need to enable the serial port and/or disable the Linux serial console using `raspi-config`. See **Disable Linux serial console** in the [Raspberry Pi UART documentation](https://www.raspberrypi.org/documentation/configuration/uart.md) for the procedure. 61 | 62 | Additionally, for the Raspberry Pi 3, you will need to disable the built-in Bluetooth controller as there is a hardware conflict between the EnOcean Hat and the Bluetooth controller (they both use the same hardware clock.) To do this, add the following line to `/boot/config.txt` and reboot: 63 | ```ini 64 | dtoverlay=disable-bt 65 | ``` 66 | 67 | ## Configuration ## 68 | 69 | Please take a look at the provided [enoceanmqtt.conf.sample](enoceanmqtt.conf.sample) sample config file. Most should be self explaining. 70 | 71 | Multiple config files can be specified as command line arguments. Values are merged, later config files override values of the former. This is the order: 72 | 73 | * `/etc/enoceanmqtt.conf` 74 | * in Dockerfile: `/enoceanmqtt-default.conf`, compare [enoceanmqtt-default.conf](enoceanmqtt-default.conf). 75 | * any further command line argument. 76 | 77 | This can be used to split security sensitive values from the device configs. 78 | 79 | ## Usage ## 80 | 81 | ### Reading EnOcean Messages ### 82 | 83 | Every EnOcean message that a configured sensor receives will get decoded according the configured `rorg`, `func`, `type` fields. Then, the decoded content will be published to MQTT. 84 | 85 | To avoid receiving MQTT messages for specific devices you have two choinces. You may either not configure it at all, but you will still see entries in the log file then on messages fron unknown devices. Alternatively you can enter the device in the configuration and set `ignore` to 1. 86 | 87 | ### Sending EnOcean Messages ### 88 | 89 | To send EnOcean messages you prepare the packet data by sending MQTT request to specific fields. You typically configure the `default_data` property in the config file and afterwards customize/complete the packet by publishing an MQTT message to the device topic where you prefix the topic with `/req`. 90 | 91 | An example: If you want to set the valve position (set point) of a heating actuator named `heating` (e.g. with `rorg = 0xA5`, `func = 0x20`, `type = 0x01`) to 80 % you publish the integer value 80 to the topic `enocean/heating/req/SP`. This replaces the corresponding part of `default_data`. 92 | 93 | 96 | 97 | To finally trigger the sending of the packet, place an MQTT message to the device's `req/send` topic. If you want to clear the customized data buffer back to default, set the MQTT payload to `clear`. Any other payload will keep the data buffer for further send requests. 98 | 99 | ### Answering EnOcean Messages ### 100 | 101 | Similar to sending EnOceam Messages you can configure it to send a packet as an answer to in incoming EnOcean packet. For this, you configure the `answer` switch in the device's configuration section. As above, you set the `default_data` in the config file and customize the response data by publishing MQTT messages to the device topic where you prefix the topic with `/req`. 102 | 103 | ### List of device options 104 | 105 | #### persistent 106 | Publish the received EnOcean packet with the retain flag. 107 | > persistent = 1 108 | #### publish_json 109 | Publish the received EnOcean packet as a JSON-formatted message. 110 | > publish_json = True # or true or 1 111 | #### publish_rssi 112 | Publish the received RSSI. 113 | > publish_rssi = 1 114 | #### publish_date 115 | Publish the EnOcean packet received date. 116 | > publish_date = 1 117 | #### command 118 | For EEP supporting multiple commands, define the shortcut of the packet field used as command identifier. 119 | > command = CMD 120 | #### channel 121 | Group received EnOcean packet fields depending on the value of one of the fields. 122 | > channel = IO/CMD # Received data will be published to /IOx/CMDy 123 | #### log_learn 124 | Forward learn messages to MQTT. 125 | > log_learn = 1 126 | #### answer 127 | Send data as an answer to an incoming packet. 128 | > answer = 1 129 | #### direction 130 | Set the direction of the received packet for device needing an answer. 131 | > direction = 1 132 | #### default_data 133 | Default data to be sent to the device. 134 | > default_data = 0x80810408 135 | #### sender 136 | Use another sender ID to send command to the device. 137 | This ID should be in the range \[Base_ID...Base_ID+127\]. 138 | For example, if your Base_ID is 0xFFDA5580, then you can set sender to any ID between 0xFFDA5580 and 0xFFDA55FF. 139 | > sender = 0xFFDA5581 140 | -------------------------------------------------------------------------------- /enoceanmqtt-default.conf: -------------------------------------------------------------------------------- 1 | [CONFIG] 2 | enocean_port = /dev/enocean 3 | log_packets = 1 4 | mqtt_host = localhost 5 | mqtt_port = 1883 6 | mqtt_prefix = enocean/ 7 | -------------------------------------------------------------------------------- /enoceanmqtt.conf.sample: -------------------------------------------------------------------------------- 1 | ## the general section defines parameter for the mqtt broker and the enocean interface 2 | [CONFIG] 3 | enocean_port = /dev/enocean 4 | log_packets = 1 5 | 6 | mqtt_host = localhost 7 | mqtt_port = 1883 8 | mqtt_client_id = enocean # ensure that this is unique if you use multiple clients 9 | 10 | ## setting mqtt_keepalive = 0 sets the timeout to infinitive but does not work reliably 11 | ## due to an upstream issue https://github.com/eclipse/paho.mqtt.python/issues/473 12 | mqtt_keepalive = 60 13 | 14 | ## the prefix is used for the mqtt value names; this is extended by the sensor name 15 | mqtt_prefix = enocean/ 16 | 17 | ## publish received packets as single MQTT message with a JSON payload 18 | # mqtt_publish_json = true 19 | 20 | ## optionally also set mqtt_user and mqtt_pwd (don't use quotes). 21 | # mqtt_user = mqtt 22 | # mqtt_pwd = password 23 | 24 | ## enable SSL on MQTT connection 25 | ## Ensure that mqtt_host matches one of the hostnames contained in the broker's 26 | ## certificate, otherwise the client will refuse to connect. 27 | ## 28 | ## mqtt_ssl_ca_certs: CA certificates to be treated as trusted. Required if 29 | ## the MQTT broker is configured with a self-signed certificate. 30 | ## mqtt_ssl_certfile, mqtt_ssl_keyfile: Client certificate and private key. 31 | ## Only required if the broker requires clients to present a certificate. 32 | ## mqtt_ssl_insecure: Disable verification of the broker's certificate. 33 | ## WARNING: do NOT use on production systems as this is insecure! 34 | ## 35 | # mqtt_ssl = true 36 | # mqtt_ssl_ca_certs = /path/CA_files_merged.pem 37 | # mqtt_ssl_certfile = /path/client_cert.pem 38 | # mqtt_ssl_keyfile = /path/client_key.pem 39 | # mqtt_ssl_insecure = true 40 | 41 | ## Enable MQTT debugging. Requires --debug on the command line. 42 | # mqtt_debug = true 43 | 44 | ## all other sections define the sensors to monitor 45 | 46 | [switch] 47 | address = 0xfefee192 48 | rorg = 0xf6 # BS1 49 | func = 0x02 50 | type = 0x02 51 | log_learn = 1 52 | publish_rssi = 1 53 | 54 | [temperature] 55 | address = 0x01823FFA 56 | rorg = 0xA5 57 | func = 0x02 58 | type = 0x05 59 | persistent = 1 60 | 61 | [shutter] 62 | # this sensor is used for sending data 63 | # address is the destination address then 64 | address = 0x051C1FB7 65 | rorg = 0xD2 66 | func = 0x05 67 | type = 0x00 68 | 69 | [radiator] 70 | address = 0xDEADBEEF 71 | rorg = 0xD2 # VLD 72 | func = 0x01 73 | type = 0x0C 74 | log_learn = 1 75 | command = CMD 76 | # use a specific sender address when sending packets to this device 77 | sender = 0xFFDC1711 78 | 79 | [hvac_actuator] 80 | address = 0xFFDC9500 81 | rorg = 0xA5 # BS4 82 | func = 0x20 83 | type = 0x01 84 | direction = 1 85 | answer = 1 86 | # when sending, this is the data default that can be customized via MQTT 87 | default_data = 0x32790008 88 | 89 | [non_interesting] 90 | address = 0xFFD05085 91 | # received messages from this sensor will not appear as warnings in the log file 92 | ignore = 1 93 | -------------------------------------------------------------------------------- /enoceanmqtt.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=EnOcean MQTT Forwarder 3 | After=mosquitto.service 4 | 5 | [Service] 6 | Type=simple 7 | ExecStart=/usr/local/bin/enoceanmqtt 8 | Restart=always 9 | RestartSec=300 10 | WorkingDirectory=/home/pi/enoceanmqtt 11 | User=pi 12 | 13 | [Install] 14 | WantedBy=multi-user.target 15 | -------------------------------------------------------------------------------- /enoceanmqtt/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embyt/enocean-mqtt/97acf89931e2f147071c5b381235f1b106476165/enoceanmqtt/__init__.py -------------------------------------------------------------------------------- /enoceanmqtt/communicator.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 embyt GmbH. See LICENSE for further details. 2 | # Author: Roman Morawek 3 | """this class handles the enocean and mqtt interfaces""" 4 | import logging 5 | import queue 6 | import numbers 7 | import json 8 | import platform 9 | 10 | from enocean.communicators.serialcommunicator import SerialCommunicator 11 | from enocean.protocol.packet import RadioPacket 12 | from enocean.protocol.constants import PACKET, RETURN_CODE, RORG 13 | import enocean.utils 14 | import paho.mqtt.client as mqtt 15 | 16 | 17 | class Communicator: 18 | """the main working class providing the MQTT interface to the enocean packet classes""" 19 | mqtt = None 20 | enocean = None 21 | 22 | def __init__(self, config, sensors): 23 | self.conf = config 24 | self.sensors = sensors 25 | 26 | # check for mandatory configuration 27 | if 'mqtt_host' not in self.conf or 'enocean_port' not in self.conf: 28 | raise KeyError("Mandatory configuration not found: mqtt_host/enocean_port") 29 | mqtt_port = int(self.conf['mqtt_port']) if 'mqtt_port' in self.conf else 1883 30 | mqtt_keepalive = int(self.conf['mqtt_keepalive']) if 'mqtt_keepalive' in self.conf else 60 31 | 32 | # setup mqtt connection 33 | client_id = self.conf['mqtt_client_id'] if 'mqtt_client_id' in self.conf else '' 34 | self.mqtt = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id=client_id) 35 | self.mqtt.on_connect = self._on_connect 36 | self.mqtt.on_disconnect = self._on_disconnect 37 | self.mqtt.on_message = self._on_mqtt_message 38 | self.mqtt.on_publish = self._on_mqtt_publish 39 | if 'mqtt_user' in self.conf: 40 | logging.info("Authenticating: %s", self.conf['mqtt_user']) 41 | self.mqtt.username_pw_set(self.conf['mqtt_user'], self.conf['mqtt_pwd']) 42 | if str(self.conf.get('mqtt_ssl')) in ("True", "true", "1"): 43 | logging.info("Enabling SSL") 44 | ca_certs = self.conf['mqtt_ssl_ca_certs'] if 'mqtt_ssl_ca_certs' in self.conf else None 45 | certfile = self.conf['mqtt_ssl_certfile'] if 'mqtt_ssl_certfile' in self.conf else None 46 | keyfile = self.conf['mqtt_ssl_keyfile'] if 'mqtt_ssl_keyfile' in self.conf else None 47 | self.mqtt.tls_set(ca_certs=ca_certs, certfile=certfile, keyfile=keyfile) 48 | if str(self.conf.get('mqtt_ssl_insecure')) in ("True", "true", "1"): 49 | logging.warning("Disabling SSL certificate verification") 50 | self.mqtt.tls_insecure_set(True) 51 | if str(self.conf.get('mqtt_debug')) in ("True", "true", "1"): 52 | self.mqtt.enable_logger() 53 | logging.debug("Connecting to host %s, port %s, keepalive %s", 54 | self.conf['mqtt_host'], mqtt_port, mqtt_keepalive) 55 | self.mqtt.connect_async(self.conf['mqtt_host'], port=mqtt_port, keepalive=mqtt_keepalive) 56 | self.mqtt.loop_start() 57 | 58 | # setup enocean communication 59 | self.enocean = SerialCommunicator(self.conf['enocean_port']) 60 | self.enocean.start() 61 | # sender will be automatically determined 62 | self.enocean_sender = None 63 | 64 | def __del__(self): 65 | if self.enocean is not None and self.enocean.is_alive(): 66 | self.enocean.stop() 67 | 68 | 69 | #============================================================================================= 70 | # MQTT CLIENT 71 | #============================================================================================= 72 | def _on_connect(self, mqtt_client, _userdata, _flags, reason_code, _properties): 73 | '''callback for when the client receives a CONNACK response from the MQTT server.''' 74 | if reason_code == 0: 75 | logging.info("Succesfully connected to MQTT broker.") 76 | # listen to enocean send requests 77 | for cur_sensor in self.sensors: 78 | # logging.debug("MQTT subscribing: %s", cur_sensor['name']+'/req/#') 79 | mqtt_client.subscribe(cur_sensor['name']+'/req/#') 80 | else: 81 | logging.error("Error connecting to MQTT broker: %s", reason_code) 82 | 83 | def _on_disconnect(self, _mqtt_client, _userdata, _flags, reason_code, _properties): 84 | '''callback for when the client disconnects from the MQTT server.''' 85 | if reason_code == 0: 86 | logging.warning("Successfully disconnected from MQTT broker") 87 | else: 88 | logging.warning("Unexpectedly disconnected from MQTT broker: %s", reason_code) 89 | 90 | def _on_mqtt_message(self, _mqtt_client, _userdata, msg): 91 | '''the callback for when a PUBLISH message is received from the MQTT server.''' 92 | # search for sensor 93 | found_topic = False 94 | logging.debug("Got MQTT message: %s", msg.topic) 95 | 96 | # Get how to handle MQTT message 97 | try: 98 | mqtt_payload = json.loads(msg.payload) 99 | except: 100 | mqtt_payload = msg.payload 101 | 102 | if isinstance(mqtt_payload, dict): 103 | found_topic = self._mqtt_message_json(msg.topic, mqtt_payload) 104 | else: 105 | found_topic = self._mqtt_message_normal(msg) 106 | 107 | if not found_topic: 108 | logging.warning("Unexpected or erroneous MQTT message: %s: %s", msg.topic, msg.payload) 109 | 110 | def _on_mqtt_publish(self, _mqtt_client, _userdata, _mid, _reason_codes, _properties): 111 | '''the callback for when a PUBLISH message is successfully sent to the MQTT server.''' 112 | #logging.debug("Published MQTT message "+str(mid)) 113 | 114 | 115 | #============================================================================================= 116 | # MQTT TO ENOCEAN 117 | #============================================================================================= 118 | def _mqtt_message_normal(self, msg): 119 | '''Handle received PUBLISH message from the MQTT server as a normal payload.''' 120 | found_topic = False 121 | for cur_sensor in self.sensors: 122 | if cur_sensor['name']+"/" in msg.topic: 123 | # get message topic 124 | prop = msg.topic[len(cur_sensor['name']+"/req/"):] 125 | # do we face a send request? 126 | if prop == "send": 127 | found_topic = True 128 | 129 | # Clear sent data, if requested by the send message 130 | # MQTT payload is binary data, thus we need to decode it 131 | clear = False 132 | if msg.payload.decode('UTF-8') == "clear": 133 | clear = True 134 | 135 | self._send_message(cur_sensor, clear) 136 | 137 | else: 138 | # parse message content 139 | value = None 140 | try: 141 | value = int(msg.payload) 142 | except ValueError: 143 | try: 144 | value = float(msg.payload) 145 | except ValueError: 146 | logging.warning("Cannot parse int nor float value for %s: %s", 147 | msg.topic, msg.payload) 148 | # Prevent storing undefined value, as it will 149 | # trigger exception in EnOcean library 150 | break 151 | # store received data 152 | logging.debug("%s: %s=%s", cur_sensor['name'], prop, value) 153 | found_topic = True 154 | if 'data' not in cur_sensor: 155 | cur_sensor['data'] = {} 156 | cur_sensor['data'][prop] = value 157 | 158 | # The targeted sensor has been found and the MQTT message has been handled 159 | break 160 | 161 | return found_topic 162 | 163 | def _mqtt_message_json(self, mqtt_topic, mqtt_json_payload): 164 | '''Handle received PUBLISH message from the MQTT server as a JSON payload.''' 165 | found_topic = False 166 | for cur_sensor in self.sensors: 167 | if cur_sensor['name']+"/" in mqtt_topic: 168 | # get message topic 169 | prop = mqtt_topic[len(cur_sensor['name']+"/"):] 170 | # JSON payload shall be sent to '/req' topic 171 | if prop == "req": 172 | found_topic = True 173 | send = False 174 | clear = False 175 | 176 | # do we face a send request? 177 | if "send" in mqtt_json_payload.keys(): 178 | send = True 179 | # Check whether the data buffer shall be cleared 180 | if mqtt_json_payload['send'] == "clear": 181 | clear = True 182 | 183 | # Remove 'send' field as it is not part of EnOcean data 184 | del mqtt_json_payload['send'] 185 | 186 | # Parse message content 187 | for topic in tuple(mqtt_json_payload.keys()): 188 | if not isinstance(mqtt_json_payload[topic], (int,float,str)): 189 | logging.warning("Cannot parse int nor float value for %s: %s", 190 | topic, mqtt_json_payload[topic]) 191 | # Prevent storing undefined value, as it will 192 | # trigger exception in EnOcean library 193 | del mqtt_json_payload[topic] 194 | elif isinstance(mqtt_json_payload[topic], str): 195 | try: 196 | mqtt_json_payload[topic] = int(mqtt_json_payload[topic]) 197 | except ValueError: 198 | try: 199 | mqtt_json_payload[topic] = float(mqtt_json_payload[topic]) 200 | except ValueError: 201 | logging.warning("Cannot parse int nor float value for %s: %s", 202 | topic, mqtt_json_payload[topic]) 203 | # Prevent storing undefined value, as it will 204 | # trigger exception in EnOcean library 205 | del mqtt_json_payload[topic] 206 | 207 | # Append received data to cur_sensor['data']. 208 | # This will keep the possibility to pass single topic/payload as done with 209 | # normal payload, even if JSON provides the ability to pass all topic/payload 210 | # in a single MQTT message. 211 | logging.debug("%s: %s=%s", cur_sensor['name'], prop, mqtt_json_payload) 212 | if 'data' not in cur_sensor: 213 | cur_sensor['data'] = {} 214 | cur_sensor['data'].update(mqtt_json_payload) 215 | 216 | # Finally, send the message 217 | if send: 218 | self._send_message(cur_sensor, clear) 219 | 220 | # The targeted sensor has been found and the MQTT message has been handled 221 | break 222 | 223 | return found_topic 224 | 225 | def _send_message(self, sensor, clear): 226 | '''Send received MQTT message to EnOcean.''' 227 | logging.debug("Trigger message to: %s", sensor['name']) 228 | destination = [(sensor['address'] >> i*8) & 229 | 0xff for i in reversed(range(4))] 230 | 231 | # Retrieve command from MQTT message and pass it to _send_packet() 232 | command = None 233 | command_shortcut = sensor.get('command') 234 | 235 | if command_shortcut: 236 | # Check MQTT message has valid data 237 | if 'data' not in sensor: 238 | logging.warning('No data to send from MQTT message!') 239 | return 240 | # Check MQTT message sets the command field 241 | if command_shortcut not in sensor['data'] or sensor['data'][command_shortcut] is None: 242 | logging.warning( 243 | 'Command field %s must be set in MQTT message!', command_shortcut) 244 | return 245 | # Retrieve command id from MQTT message 246 | command = sensor['data'][command_shortcut] 247 | logging.debug('Retrieved command id from MQTT message: %s', hex(command)) 248 | 249 | self._send_packet(sensor, destination, command) 250 | 251 | # Clear sent data, if requested by the sent message 252 | if clear: 253 | logging.debug('Clearing data buffer.') 254 | del sensor['data'] 255 | 256 | 257 | #============================================================================================= 258 | # ENOCEAN TO MQTT 259 | #============================================================================================= 260 | def _get_command_id(self, packet, sensor): 261 | '''interpret packet to retrieve command id from VLD packets''' 262 | # Retrieve the first defined EEP profile matching sensor RORG-FUNC-TYPE 263 | # As we take the first defined profile, this suppose that command is 264 | # ALWAYS at the same offset and ALWAYS has the same size. 265 | profile = packet.eep.find_profile( 266 | packet._bit_data, sensor['rorg'], sensor['func'], sensor['type']) 267 | 268 | if profile: 269 | # Loop over profile contents 270 | for source in profile.contents: 271 | if not source.name: 272 | continue 273 | # Check the current shortcut matches the command shortcut 274 | if source['shortcut'] == sensor.get('command'): 275 | return packet.eep._get_raw(source, packet._bit_data) 276 | 277 | # If profile or command shortcut not found, 278 | # return None for default handling of the packet 279 | return None 280 | 281 | def _publish_mqtt(self, sensor, mqtt_json): 282 | '''Publish decoded packet content to MQTT''' 283 | # Publish using JSON format ? 284 | mqtt_publish_json = str(sensor.get('publish_json')) in ("True", "true", "1") 285 | 286 | # Publish RSSI ? 287 | mqtt_publish_rssi = str(sensor.get('publish_rssi')) in ("True", "true", "1") 288 | 289 | # Retain the to-be-published message ? 290 | retain = str(sensor.get('persistent')) in ("True", "true", "1") 291 | 292 | # Is grouping enabled on this sensor 293 | channel_id = sensor.get('channel') 294 | channel_id = channel_id.split('/') if channel_id not in (None, '') else [] 295 | 296 | # Handling Auxiliary data RSSI 297 | aux_data = {} 298 | if mqtt_publish_rssi: 299 | if mqtt_publish_json: 300 | # Keep _RSSI_ out of groups 301 | if channel_id: 302 | aux_data.update({"_RSSI_": mqtt_json['_RSSI_']}) 303 | else: 304 | self.mqtt.publish(sensor['name']+"/_RSSI_", mqtt_json['_RSSI_'], retain=retain) 305 | # Delete RSSI if already handled 306 | if channel_id or not mqtt_publish_json or not mqtt_publish_rssi: 307 | del mqtt_json['_RSSI_'] 308 | 309 | # Handling Auxiliary data _DATE_ 310 | if str(sensor.get('publish_date')) in ("True", "true", "1"): 311 | # Publish _DATE_ both at device and group levels 312 | if channel_id: 313 | if mqtt_publish_json: 314 | aux_data.update({"_DATE_": mqtt_json['_DATE_']}) 315 | else: 316 | self.mqtt.publish(sensor['name']+"/_DATE_", mqtt_json['_DATE_'], retain=retain) 317 | else: 318 | del mqtt_json['_DATE_'] 319 | 320 | # Publish auxiliary data 321 | if aux_data: 322 | self.mqtt.publish(sensor['name'], json.dumps(aux_data), retain=retain) 323 | 324 | # Determine MQTT topic 325 | topic = sensor['name'] 326 | for cur_id in channel_id: 327 | if mqtt_json.get(cur_id) not in (None, ''): 328 | topic += f"/{cur_id}{mqtt_json[cur_id]}" 329 | del mqtt_json[cur_id] 330 | 331 | # Publish packet data to MQTT 332 | value = json.dumps(mqtt_json) 333 | logging.debug("%s: Sent MQTT: %s", topic, value) 334 | 335 | if mqtt_publish_json: 336 | self.mqtt.publish(topic, value, retain=retain) 337 | else: 338 | for prop_name, value in mqtt_json.items(): 339 | self.mqtt.publish(f"{topic}/{prop_name}", value, retain=retain) 340 | 341 | def _read_packet(self, packet): 342 | '''interpret packet, read properties and publish to MQTT''' 343 | mqtt_json = {} 344 | # loop through all configured devices 345 | for cur_sensor in self.sensors: 346 | # does this sensor match? 347 | if enocean.utils.combine_hex(packet.sender) == cur_sensor['address']: 348 | # found sensor configured in config file 349 | 350 | # Shall the packet be published to MQTT ? 351 | if not packet.learn or str(cur_sensor.get('log_learn')) in ("True", "true", "1"): 352 | # Store RSSI 353 | # Use underscore so that it is unique and doesn't 354 | # match a potential future EnOcean EEP field. 355 | mqtt_json['_RSSI_'] = packet.dBm 356 | 357 | # Store receive date 358 | # Use underscore so that it is unique and doesn't 359 | # match a potential future EnOcean EEP field. 360 | mqtt_json['_DATE_'] = packet.received.isoformat() 361 | 362 | # Handling received data packet 363 | found_property = self._handle_data_packet( packet, cur_sensor, mqtt_json) 364 | if not found_property: 365 | logging.warning("message not interpretable: %s", cur_sensor['name']) 366 | else: 367 | self._publish_mqtt(cur_sensor, mqtt_json) 368 | else: 369 | # learn request received 370 | logging.info("learn request not emitted to mqtt") 371 | 372 | # The packet has been handled 373 | break 374 | 375 | def _handle_data_packet(self, packet, sensor, mqtt_json): 376 | # data packet received 377 | found_property = False 378 | if packet.packet_type == PACKET.RADIO and packet.rorg == sensor['rorg']: 379 | # radio packet of proper rorg type received; parse EEP 380 | direction = sensor.get('direction') 381 | 382 | # Retrieve command from the received packet and pass it to parse_eep() 383 | command = None 384 | if sensor.get('command'): 385 | command = self._get_command_id(packet, sensor) 386 | if command: 387 | logging.debug('Retrieved command id from packet: %s', hex(command)) 388 | 389 | # Retrieve properties from EEP 390 | properties = packet.parse_eep(sensor['func'], sensor['type'], direction, command) 391 | 392 | # loop through all EEP properties 393 | for prop_name in properties: 394 | found_property = True 395 | cur_prop = packet.parsed[prop_name] 396 | # we only extract numeric values, either the scaled ones 397 | # or the raw values for enums 398 | if isinstance(cur_prop['value'], numbers.Number): 399 | value = cur_prop['value'] 400 | else: 401 | value = cur_prop['raw_value'] 402 | # publish extracted information 403 | logging.debug("%s: %s (%s)=%s %s", sensor['name'], prop_name, 404 | cur_prop['description'], cur_prop['value'], cur_prop['unit']) 405 | 406 | # Store property 407 | mqtt_json[prop_name] = value 408 | 409 | return found_property 410 | 411 | 412 | #============================================================================================= 413 | # LOW LEVEL FUNCTIONS 414 | #============================================================================================= 415 | def _reply_packet(self, in_packet, sensor): 416 | '''send enocean message as a reply to an incoming message''' 417 | # prepare addresses 418 | destination = in_packet.sender 419 | 420 | self._send_packet(sensor, destination, None, True, 421 | in_packet.data if in_packet.learn else None) 422 | 423 | def _send_packet(self, sensor, destination, command=None, 424 | negate_direction=False, learn_data=None): 425 | '''triggers sending of an enocean packet''' 426 | # determine direction indicator 427 | if 'direction' in sensor: 428 | direction = sensor['direction'] 429 | if negate_direction: 430 | # we invert the direction in this reply 431 | direction = 1 if direction == 2 else 2 432 | else: 433 | direction = None 434 | # is this a response to a learn packet? 435 | is_learn = learn_data is not None 436 | 437 | # Add possibility for the user to indicate a specific sender address 438 | # in sensor configuration using added 'sender' field. 439 | # So use specified sender address if any 440 | if 'sender' in sensor: 441 | sender = [(sensor['sender'] >> i*8) & 0xff for i in reversed(range(4))] 442 | else: 443 | sender = self.enocean_sender 444 | 445 | try: 446 | # Now pass command to RadioPacket.create() 447 | packet = RadioPacket.create(sensor['rorg'], sensor['func'], sensor['type'], 448 | direction=direction, command=command, sender=sender, 449 | destination=destination, learn=is_learn) 450 | except ValueError as err: 451 | logging.error("Cannot create RF packet: %s", err) 452 | return 453 | 454 | # assemble data based on packet type (learn / data) 455 | if not is_learn: 456 | # data packet received 457 | # start with default data 458 | 459 | # Initialize packet with default_data if specified 460 | if 'default_data' in sensor: 461 | packet.data[1:5] = [(sensor['default_data'] >> i*8) & 462 | 0xff for i in reversed(range(4))] 463 | 464 | # do we have specific data to send? 465 | if 'data' in sensor: 466 | # override with specific data settings 467 | logging.debug("sensor data: %s", sensor['data']) 468 | # Set packet data payload 469 | packet.set_eep(sensor['data']) 470 | # Set packet status bits 471 | packet.data[-1] = packet.status 472 | packet.parse_eep() # ensure that the logging output of packet is updated 473 | else: 474 | # what to do if we have no data to send yet? 475 | logging.warning('sending only default data as answer to %s', sensor['name']) 476 | 477 | else: 478 | # learn request received 479 | # copy EEP and manufacturer ID 480 | packet.data[1:5] = learn_data[1:5] 481 | # update flags to acknowledge learn request 482 | packet.data[4] = 0xf0 483 | 484 | # send it 485 | logging.info("sending: %s", packet) 486 | self.enocean.send(packet) 487 | 488 | def _process_radio_packet(self, packet): 489 | # first, look whether we have this sensor configured 490 | found_sensor = False 491 | for cur_sensor in self.sensors: 492 | if 'address' in cur_sensor and \ 493 | enocean.utils.combine_hex(packet.sender) == cur_sensor['address']: 494 | found_sensor = cur_sensor 495 | break 496 | 497 | # skip ignored sensors 498 | if found_sensor and 'ignore' in found_sensor and found_sensor['ignore']: 499 | return 500 | 501 | # log packet, if not disabled 502 | if str(self.conf.get('log_packets')) in ("True", "true", "1"): 503 | logging.info("received: %s", packet) 504 | 505 | # abort loop if sensor not found 506 | if not found_sensor: 507 | logging.info("unknown sensor: %s", enocean.utils.to_hex_string(packet.sender)) 508 | return 509 | 510 | # Handling EnOcean library decision to set learn to True by default. 511 | # Only 1BS and 4BS are correctly handled by the EnOcean library. 512 | # -> VLD EnOcean devices use UTE as learn mechanism 513 | if found_sensor['rorg'] == RORG.VLD and packet.rorg != RORG.UTE: 514 | packet.learn = False 515 | # -> RPS EnOcean devices only send normal data telegrams. 516 | # Hence learn can always be set to false 517 | elif found_sensor['rorg'] == RORG.RPS: 518 | packet.learn = False 519 | 520 | # interpret packet, read properties and publish to MQTT 521 | self._read_packet(packet) 522 | 523 | # check for neccessary reply 524 | if str(found_sensor.get('answer')) in ("True", "true", "1"): 525 | self._reply_packet(packet, found_sensor) 526 | 527 | 528 | #============================================================================================= 529 | # RUN LOOP 530 | #============================================================================================= 531 | def run(self): 532 | """the main loop with blocking enocean packet receive handler""" 533 | # start endless loop for listening 534 | while self.enocean.is_alive(): 535 | # Request transmitter ID, if needed 536 | if self.enocean_sender is None: 537 | self.enocean_sender = self.enocean.base_id 538 | 539 | # Loop to empty the queue... 540 | try: 541 | # get next packet 542 | if platform.system() == 'Windows': 543 | # only timeout on Windows for KeyboardInterrupt checking 544 | packet = self.enocean.receive.get(block=True, timeout=1) 545 | else: 546 | packet = self.enocean.receive.get(block=True) 547 | 548 | # check packet type 549 | if packet.packet_type == PACKET.RADIO: 550 | self._process_radio_packet(packet) 551 | elif packet.packet_type == PACKET.RESPONSE: 552 | response_code = RETURN_CODE(packet.data[0]) 553 | logging.info("got response packet: %s", response_code.name) 554 | else: 555 | logging.info("got non-RF packet: %s", packet) 556 | continue 557 | except queue.Empty: 558 | continue 559 | except KeyboardInterrupt: 560 | logging.debug("Exception: KeyboardInterrupt") 561 | break 562 | 563 | # Run finished, close MQTT client and stop Enocean thread 564 | logging.debug("Cleaning up") 565 | self.mqtt.loop_stop() 566 | self.mqtt.disconnect() 567 | self.mqtt.loop_forever() # will block until disconnect complete 568 | self.enocean.stop() 569 | -------------------------------------------------------------------------------- /enoceanmqtt/enoceanmqtt.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) 2020 embyt GmbH. See LICENSE for further details. 3 | # Author: Roman Morawek 4 | """this is the main entry point, which sets up the Communicator class""" 5 | import logging 6 | import sys 7 | import os 8 | import traceback 9 | import copy 10 | import argparse 11 | from configparser import ConfigParser 12 | 13 | from enoceanmqtt.communicator import Communicator 14 | 15 | conf = { 16 | 'debug': False, 17 | 'config': ['/etc/enoceanmqtt.conf'], 18 | 'logfile': os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'enoceanmqtt.log') 19 | } 20 | 21 | 22 | def parse_args(): 23 | """ Parse command line arguments. """ 24 | parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS) 25 | parser.add_argument('--debug', help='enable console debugging', action='store_true') 26 | parser.add_argument('--logfile', help='set log file location') 27 | parser.add_argument('config', help='specify config file[s]', nargs='*') 28 | # parser.add_argument('--version', help='show application version', 29 | # action='version', version='%(prog)s ' + VERSION) 30 | args = vars(parser.parse_args()) 31 | # logging.info('Read arguments: ' + str(args)) 32 | return args 33 | 34 | 35 | def load_config_file(config_files): 36 | """load sensor and general configuration from given config files""" 37 | # extract sensor configuration 38 | sensors = [] 39 | global_config = {} 40 | 41 | for conf_file in config_files: 42 | config_parser = ConfigParser(inline_comment_prefixes=('#', ';'), interpolation=None) 43 | if not os.path.isfile(conf_file): 44 | logging.warning("Config file %s does not exist, skipping", conf_file) 45 | continue 46 | logging.info("Loading config file %s", conf_file) 47 | if not config_parser.read(conf_file): 48 | logging.error("Cannot read config file: %s", conf_file) 49 | sys.exit(1) 50 | 51 | for section in config_parser.sections(): 52 | if section == 'CONFIG': 53 | # general configuration is part of CONFIG section 54 | for key in config_parser[section]: 55 | global_config[key] = config_parser[section][key] 56 | else: 57 | mqtt_prefix = config_parser['CONFIG']['mqtt_prefix'] \ 58 | if 'mqtt_prefix' in config_parser['CONFIG'] else "enocean/" 59 | new_sens = {'name': mqtt_prefix + section} 60 | for key in config_parser[section]: 61 | try: 62 | if key in ('command', 'channel', 'publish_json'): 63 | new_sens[key] = config_parser[section][key] 64 | else: 65 | new_sens[key] = int(config_parser[section][key], 0) 66 | except KeyError: 67 | new_sens[key] = None 68 | sensors.append(new_sens) 69 | logging.debug("Created sensor: %s", new_sens) 70 | 71 | logging_global_config = copy.deepcopy(global_config) 72 | if "mqtt_pwd" in logging_global_config: 73 | logging_global_config["mqtt_pwd"] = "*****" 74 | logging.debug("Global config: %s", logging_global_config) 75 | 76 | return sensors, global_config 77 | 78 | 79 | def setup_logging(log_filename='', log_level=logging.INFO): 80 | """initialize python logging infrastructure""" 81 | # create formatter 82 | log_formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s') 83 | 84 | # set root logger to lowest log level 85 | logging.getLogger().setLevel(log_level) 86 | 87 | # create console and log file handlers and the formatter to the handlers 88 | log_console = logging.StreamHandler(sys.stdout) 89 | log_console.setFormatter(log_formatter) 90 | log_console.setLevel(log_level) 91 | logging.getLogger().addHandler(log_console) 92 | if log_filename: 93 | log_file = logging.FileHandler(log_filename) 94 | log_file.setLevel(log_level) 95 | log_file.setFormatter(log_formatter) 96 | logging.getLogger().addHandler(log_file) 97 | logging.info("Logging to file: %s", log_filename) 98 | 99 | 100 | def main(): 101 | """entry point if called as an executable""" 102 | # logging.getLogger().setLevel(logging.DEBUG) 103 | # Parse command line arguments 104 | conf.update(parse_args()) 105 | 106 | # setup logger 107 | setup_logging(conf['logfile'], logging.DEBUG if conf['debug'] else logging.INFO) 108 | 109 | # load config file 110 | sensors, global_config = load_config_file(conf['config']) 111 | conf.update(global_config) 112 | 113 | # start working 114 | com = Communicator(conf, sensors) 115 | try: 116 | com.run() 117 | 118 | # catch all possible exceptions 119 | except: # pylint: disable=broad-except,bare-except 120 | logging.error(traceback.format_exc()) 121 | 122 | 123 | # check for execution 124 | if __name__ == "__main__": 125 | main() 126 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (c) 2020 embyt GmbH. See LICENSE for further details. 3 | # Author: Roman Morawek 4 | """setup module for enoceanmqtt""" 5 | import setuptools 6 | 7 | # needed packages 8 | REQUIRES = [ 9 | 'enocean', 10 | 'paho-mqtt>=2', 11 | ] 12 | 13 | with open("README.md", "r") as fh: 14 | long_description = fh.read() 15 | 16 | setuptools.setup( 17 | name='enocean-mqtt', 18 | version='0.1.4', 19 | author='Roman Morawek', 20 | author_email='roman.morawek@embyt.com', 21 | description='Receives messages from an enOcean serial interface (USB) and provides selected messages to an MQTT broker.', 22 | long_description=long_description, 23 | long_description_content_type="text/markdown", 24 | url='https://github.com/embyt/enocean-mqtt', 25 | license='GPLv3', 26 | 27 | # See https://pypi.python.org/pypi?%3Aaction=list_classifiers 28 | classifiers=[ 29 | 'Development Status :: 4 - Beta', 30 | 'Intended Audience :: Developers', 31 | 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', 32 | 'Programming Language :: Python :: 3', 33 | ], 34 | keywords='enOcean MQTT IoT', 35 | packages=setuptools.find_packages(exclude=['contrib', 'docs', 'tests*']), 36 | install_requires=REQUIRES, 37 | 38 | # To provide executable scripts, use entry points in preference to the 39 | # "scripts" keyword. Entry points provide cross-platform support and allow 40 | # pip to create the appropriate form of executable for the target platform. 41 | entry_points={ 42 | 'console_scripts': [ 43 | 'enoceanmqtt=enoceanmqtt.enoceanmqtt:main', 44 | ], 45 | }, 46 | ) 47 | --------------------------------------------------------------------------------