├── .gitattributes ├── .github ├── PULL_REQUEST_TEMPLATE │ └── adafruit_circuitpython_pr.md └── workflows │ ├── build.yml │ ├── failure-help-text.yml │ ├── release_gh.yml │ └── release_pypi.yml ├── .gitignore ├── .pre-commit-config.yaml ├── .readthedocs.yaml ├── CODE_OF_CONDUCT.md ├── LICENSE ├── LICENSES ├── CC-BY-4.0.txt ├── GPL-3.0-or-later.txt ├── MIT.txt └── Unlicense.txt ├── README.rst ├── README.rst.license ├── adafruit_tinylora ├── __init__.py ├── adafruit_tinylora.py ├── adafruit_tinylora_encryption.py ├── ttn_as.py ├── ttn_au.py ├── ttn_cn.py ├── ttn_eu.py └── ttn_usa.py ├── docs ├── _static │ ├── favicon.ico │ └── favicon.ico.license ├── api.rst ├── api.rst.license ├── conf.py ├── examples.rst ├── examples.rst.license ├── index.rst ├── index.rst.license └── requirements.txt ├── examples ├── tinylora_simpletest.py ├── tinylora_simpletest_si7021.py └── tinylora_simpletest_single_channel.py ├── optional_requirements.txt ├── pyproject.toml ├── requirements.txt └── ruff.toml /.gitattributes: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | .py text eol=lf 6 | .rst text eol=lf 7 | .txt text eol=lf 8 | .yaml text eol=lf 9 | .toml text eol=lf 10 | .license text eol=lf 11 | .md text eol=lf 12 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | Thank you for contributing! Before you submit a pull request, please read the following. 6 | 7 | Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html 8 | 9 | If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs 10 | 11 | Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code 12 | 13 | Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues. 14 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Build CI 6 | 7 | on: [pull_request, push] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Run Build CI workflow 14 | uses: adafruit/workflows-circuitpython-libs/build@main 15 | -------------------------------------------------------------------------------- /.github/workflows/failure-help-text.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Failure help text 6 | 7 | on: 8 | workflow_run: 9 | workflows: ["Build CI"] 10 | types: 11 | - completed 12 | 13 | jobs: 14 | post-help: 15 | runs-on: ubuntu-latest 16 | if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} 17 | steps: 18 | - name: Post comment to help 19 | uses: adafruit/circuitpython-action-library-ci-failed@v1 20 | -------------------------------------------------------------------------------- /.github/workflows/release_gh.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: GitHub Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run GitHub Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-gh@main 17 | with: 18 | github-token: ${{ secrets.GITHUB_TOKEN }} 19 | upload-url: ${{ github.event.release.upload_url }} 20 | -------------------------------------------------------------------------------- /.github/workflows/release_pypi.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: PyPI Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run PyPI Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-pypi@main 17 | with: 18 | pypi-username: ${{ secrets.pypi_username }} 19 | pypi-password: ${{ secrets.pypi_password }} 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | # Do not include files and directories created by your personal work environment, such as the IDE 6 | # you use, except for those already listed here. Pull requests including changes to this file will 7 | # not be accepted. 8 | 9 | # This .gitignore file contains rules for files generated by working with CircuitPython libraries, 10 | # including building Sphinx, testing with pip, and creating a virual environment, as well as the 11 | # MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. 12 | 13 | # If you find that there are files being generated on your machine that should not be included in 14 | # your git commit, you should create a .gitignore_global file on your computer to include the 15 | # files created by your personal setup. To do so, follow the two steps below. 16 | 17 | # First, create a file called .gitignore_global somewhere convenient for you, and add rules for 18 | # the files you want to exclude from git commits. 19 | 20 | # Second, configure Git to use the exclude file for all Git repositories by running the 21 | # following via commandline, replacing "path/to/your/" with the actual path to your newly created 22 | # .gitignore_global file: 23 | # git config --global core.excludesfile path/to/your/.gitignore_global 24 | 25 | # CircuitPython-specific files 26 | *.mpy 27 | 28 | # Python-specific files 29 | __pycache__ 30 | *.pyc 31 | 32 | # Sphinx build-specific files 33 | _build 34 | 35 | # This file results from running `pip -e install .` in a local repository 36 | *.egg-info 37 | 38 | # Virtual environment-specific files 39 | .env 40 | .venv 41 | 42 | # MacOS-specific files 43 | *.DS_Store 44 | 45 | # IDE-specific files 46 | .idea 47 | .vscode 48 | *~ 49 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | repos: 6 | - repo: https://github.com/pre-commit/pre-commit-hooks 7 | rev: v4.5.0 8 | hooks: 9 | - id: check-yaml 10 | - id: end-of-file-fixer 11 | - id: trailing-whitespace 12 | - repo: https://github.com/astral-sh/ruff-pre-commit 13 | rev: v0.3.4 14 | hooks: 15 | - id: ruff-format 16 | - id: ruff 17 | args: ["--fix"] 18 | - repo: https://github.com/fsfe/reuse-tool 19 | rev: v3.0.1 20 | hooks: 21 | - id: reuse 22 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | # Read the Docs configuration file 6 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 7 | 8 | # Required 9 | version: 2 10 | 11 | sphinx: 12 | configuration: docs/conf.py 13 | 14 | build: 15 | os: ubuntu-20.04 16 | tools: 17 | python: "3" 18 | 19 | python: 20 | install: 21 | - requirements: docs/requirements.txt 22 | - requirements: requirements.txt 23 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | # Adafruit Community Code of Conduct 8 | 9 | ## Our Pledge 10 | 11 | In the interest of fostering an open and welcoming environment, we as 12 | contributors and leaders pledge to making participation in our project and 13 | our community a harassment-free experience for everyone, regardless of age, body 14 | size, disability, ethnicity, gender identity and expression, level or type of 15 | experience, education, socio-economic status, nationality, personal appearance, 16 | race, religion, or sexual identity and orientation. 17 | 18 | ## Our Standards 19 | 20 | We are committed to providing a friendly, safe and welcoming environment for 21 | all. 22 | 23 | Examples of behavior that contributes to creating a positive environment 24 | include: 25 | 26 | * Be kind and courteous to others 27 | * Using welcoming and inclusive language 28 | * Being respectful of differing viewpoints and experiences 29 | * Collaborating with other community members 30 | * Gracefully accepting constructive criticism 31 | * Focusing on what is best for the community 32 | * Showing empathy towards other community members 33 | 34 | Examples of unacceptable behavior by participants include: 35 | 36 | * The use of sexualized language or imagery and sexual attention or advances 37 | * The use of inappropriate images, including in a community member's avatar 38 | * The use of inappropriate language, including in a community member's nickname 39 | * Any spamming, flaming, baiting or other attention-stealing behavior 40 | * Excessive or unwelcome helping; answering outside the scope of the question 41 | asked 42 | * Trolling, insulting/derogatory comments, and personal or political attacks 43 | * Promoting or spreading disinformation, lies, or conspiracy theories against 44 | a person, group, organisation, project, or community 45 | * Public or private harassment 46 | * Publishing others' private information, such as a physical or electronic 47 | address, without explicit permission 48 | * Other conduct which could reasonably be considered inappropriate 49 | 50 | The goal of the standards and moderation guidelines outlined here is to build 51 | and maintain a respectful community. We ask that you don’t just aim to be 52 | "technically unimpeachable", but rather try to be your best self. 53 | 54 | We value many things beyond technical expertise, including collaboration and 55 | supporting others within our community. Providing a positive experience for 56 | other community members can have a much more significant impact than simply 57 | providing the correct answer. 58 | 59 | ## Our Responsibilities 60 | 61 | Project leaders are responsible for clarifying the standards of acceptable 62 | behavior and are expected to take appropriate and fair corrective action in 63 | response to any instances of unacceptable behavior. 64 | 65 | Project leaders have the right and responsibility to remove, edit, or 66 | reject messages, comments, commits, code, issues, and other contributions 67 | that are not aligned to this Code of Conduct, or to ban temporarily or 68 | permanently any community member for other behaviors that they deem 69 | inappropriate, threatening, offensive, or harmful. 70 | 71 | ## Moderation 72 | 73 | Instances of behaviors that violate the Adafruit Community Code of Conduct 74 | may be reported by any member of the community. Community members are 75 | encouraged to report these situations, including situations they witness 76 | involving other community members. 77 | 78 | You may report in the following ways: 79 | 80 | In any situation, you may send an email to . 81 | 82 | On the Adafruit Discord, you may send an open message from any channel 83 | to all Community Moderators by tagging @community moderators. You may 84 | also send an open message from any channel, or a direct message to 85 | @kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, 86 | @sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. 87 | 88 | Email and direct message reports will be kept confidential. 89 | 90 | In situations on Discord where the issue is particularly egregious, possibly 91 | illegal, requires immediate action, or violates the Discord terms of service, 92 | you should also report the message directly to Discord. 93 | 94 | These are the steps for upholding our community’s standards of conduct. 95 | 96 | 1. Any member of the community may report any situation that violates the 97 | Adafruit Community Code of Conduct. All reports will be reviewed and 98 | investigated. 99 | 2. If the behavior is an egregious violation, the community member who 100 | committed the violation may be banned immediately, without warning. 101 | 3. Otherwise, moderators will first respond to such behavior with a warning. 102 | 4. Moderators follow a soft "three strikes" policy - the community member may 103 | be given another chance, if they are receptive to the warning and change their 104 | behavior. 105 | 5. If the community member is unreceptive or unreasonable when warned by a 106 | moderator, or the warning goes unheeded, they may be banned for a first or 107 | second offense. Repeated offenses will result in the community member being 108 | banned. 109 | 110 | ## Scope 111 | 112 | This Code of Conduct and the enforcement policies listed above apply to all 113 | Adafruit Community venues. This includes but is not limited to any community 114 | spaces (both public and private), the entire Adafruit Discord server, and 115 | Adafruit GitHub repositories. Examples of Adafruit Community spaces include 116 | but are not limited to meet-ups, audio chats on the Adafruit Discord, or 117 | interaction at a conference. 118 | 119 | This Code of Conduct applies both within project spaces and in public spaces 120 | when an individual is representing the project or its community. As a community 121 | member, you are representing our community, and are expected to behave 122 | accordingly. 123 | 124 | ## Attribution 125 | 126 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 127 | version 1.4, available at 128 | , 129 | and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). 130 | 131 | For other projects adopting the Adafruit Community Code of 132 | Conduct, please contact the maintainers of those projects for enforcement. 133 | If you wish to use this code of conduct for your own project, consider 134 | explicitly mentioning your moderation policy or making a copy with your 135 | own moderation policy so as to avoid confusion. 136 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Brent Rubell for Adafruit Industries 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSES/CC-BY-4.0.txt: -------------------------------------------------------------------------------- 1 | Creative Commons Attribution 4.0 International Creative Commons Corporation 2 | ("Creative Commons") is not a law firm and does not provide legal services 3 | or legal advice. Distribution of Creative Commons public licenses does not 4 | create a lawyer-client or other relationship. Creative Commons makes its licenses 5 | and related information available on an "as-is" basis. Creative Commons gives 6 | no warranties regarding its licenses, any material licensed under their terms 7 | and conditions, or any related information. Creative Commons disclaims all 8 | liability for damages resulting from their use to the fullest extent possible. 9 | 10 | Using Creative Commons Public Licenses 11 | 12 | Creative Commons public licenses provide a standard set of terms and conditions 13 | that creators and other rights holders may use to share original works of 14 | authorship and other material subject to copyright and certain other rights 15 | specified in the public license below. The following considerations are for 16 | informational purposes only, are not exhaustive, and do not form part of our 17 | licenses. 18 | 19 | Considerations for licensors: Our public licenses are intended for use by 20 | those authorized to give the public permission to use material in ways otherwise 21 | restricted by copyright and certain other rights. Our licenses are irrevocable. 22 | Licensors should read and understand the terms and conditions of the license 23 | they choose before applying it. Licensors should also secure all rights necessary 24 | before applying our licenses so that the public can reuse the material as 25 | expected. Licensors should clearly mark any material not subject to the license. 26 | This includes other CC-licensed material, or material used under an exception 27 | or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors 28 | 29 | Considerations for the public: By using one of our public licenses, a licensor 30 | grants the public permission to use the licensed material under specified 31 | terms and conditions. If the licensor's permission is not necessary for any 32 | reason–for example, because of any applicable exception or limitation to copyright–then 33 | that use is not regulated by the license. Our licenses grant only permissions 34 | under copyright and certain other rights that a licensor has authority to 35 | grant. Use of the licensed material may still be restricted for other reasons, 36 | including because others have copyright or other rights in the material. A 37 | licensor may make special requests, such as asking that all changes be marked 38 | or described. Although not required by our licenses, you are encouraged to 39 | respect those requests where reasonable. More considerations for the public 40 | : wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution 41 | 4.0 International Public License 42 | 43 | By exercising the Licensed Rights (defined below), You accept and agree to 44 | be bound by the terms and conditions of this Creative Commons Attribution 45 | 4.0 International Public License ("Public License"). To the extent this Public 46 | License may be interpreted as a contract, You are granted the Licensed Rights 47 | in consideration of Your acceptance of these terms and conditions, and the 48 | Licensor grants You such rights in consideration of benefits the Licensor 49 | receives from making the Licensed Material available under these terms and 50 | conditions. 51 | 52 | Section 1 – Definitions. 53 | 54 | a. Adapted Material means material subject to Copyright and Similar Rights 55 | that is derived from or based upon the Licensed Material and in which the 56 | Licensed Material is translated, altered, arranged, transformed, or otherwise 57 | modified in a manner requiring permission under the Copyright and Similar 58 | Rights held by the Licensor. For purposes of this Public License, where the 59 | Licensed Material is a musical work, performance, or sound recording, Adapted 60 | Material is always produced where the Licensed Material is synched in timed 61 | relation with a moving image. 62 | 63 | b. Adapter's License means the license You apply to Your Copyright and Similar 64 | Rights in Your contributions to Adapted Material in accordance with the terms 65 | and conditions of this Public License. 66 | 67 | c. Copyright and Similar Rights means copyright and/or similar rights closely 68 | related to copyright including, without limitation, performance, broadcast, 69 | sound recording, and Sui Generis Database Rights, without regard to how the 70 | rights are labeled or categorized. For purposes of this Public License, the 71 | rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 72 | 73 | d. Effective Technological Measures means those measures that, in the absence 74 | of proper authority, may not be circumvented under laws fulfilling obligations 75 | under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, 76 | and/or similar international agreements. 77 | 78 | e. Exceptions and Limitations means fair use, fair dealing, and/or any other 79 | exception or limitation to Copyright and Similar Rights that applies to Your 80 | use of the Licensed Material. 81 | 82 | f. Licensed Material means the artistic or literary work, database, or other 83 | material to which the Licensor applied this Public License. 84 | 85 | g. Licensed Rights means the rights granted to You subject to the terms and 86 | conditions of this Public License, which are limited to all Copyright and 87 | Similar Rights that apply to Your use of the Licensed Material and that the 88 | Licensor has authority to license. 89 | 90 | h. Licensor means the individual(s) or entity(ies) granting rights under this 91 | Public License. 92 | 93 | i. Share means to provide material to the public by any means or process that 94 | requires permission under the Licensed Rights, such as reproduction, public 95 | display, public performance, distribution, dissemination, communication, or 96 | importation, and to make material available to the public including in ways 97 | that members of the public may access the material from a place and at a time 98 | individually chosen by them. 99 | 100 | j. Sui Generis Database Rights means rights other than copyright resulting 101 | from Directive 96/9/EC of the European Parliament and of the Council of 11 102 | March 1996 on the legal protection of databases, as amended and/or succeeded, 103 | as well as other essentially equivalent rights anywhere in the world. 104 | 105 | k. You means the individual or entity exercising the Licensed Rights under 106 | this Public License. Your has a corresponding meaning. 107 | 108 | Section 2 – Scope. 109 | 110 | a. License grant. 111 | 112 | 1. Subject to the terms and conditions of this Public License, the Licensor 113 | hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, 114 | irrevocable license to exercise the Licensed Rights in the Licensed Material 115 | to: 116 | 117 | A. reproduce and Share the Licensed Material, in whole or in part; and 118 | 119 | B. produce, reproduce, and Share Adapted Material. 120 | 121 | 2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions 122 | and Limitations apply to Your use, this Public License does not apply, and 123 | You do not need to comply with its terms and conditions. 124 | 125 | 3. Term. The term of this Public License is specified in Section 6(a). 126 | 127 | 4. Media and formats; technical modifications allowed. The Licensor authorizes 128 | You to exercise the Licensed Rights in all media and formats whether now known 129 | or hereafter created, and to make technical modifications necessary to do 130 | so. The Licensor waives and/or agrees not to assert any right or authority 131 | to forbid You from making technical modifications necessary to exercise the 132 | Licensed Rights, including technical modifications necessary to circumvent 133 | Effective Technological Measures. For purposes of this Public License, simply 134 | making modifications authorized by this Section 2(a)(4) never produces Adapted 135 | Material. 136 | 137 | 5. Downstream recipients. 138 | 139 | A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed 140 | Material automatically receives an offer from the Licensor to exercise the 141 | Licensed Rights under the terms and conditions of this Public License. 142 | 143 | B. No downstream restrictions. You may not offer or impose any additional 144 | or different terms or conditions on, or apply any Effective Technological 145 | Measures to, the Licensed Material if doing so restricts exercise of the Licensed 146 | Rights by any recipient of the Licensed Material. 147 | 148 | 6. No endorsement. Nothing in this Public License constitutes or may be construed 149 | as permission to assert or imply that You are, or that Your use of the Licensed 150 | Material is, connected with, or sponsored, endorsed, or granted official status 151 | by, the Licensor or others designated to receive attribution as provided in 152 | Section 3(a)(1)(A)(i). 153 | 154 | b. Other rights. 155 | 156 | 1. Moral rights, such as the right of integrity, are not licensed under this 157 | Public License, nor are publicity, privacy, and/or other similar personality 158 | rights; however, to the extent possible, the Licensor waives and/or agrees 159 | not to assert any such rights held by the Licensor to the limited extent necessary 160 | to allow You to exercise the Licensed Rights, but not otherwise. 161 | 162 | 2. Patent and trademark rights are not licensed under this Public License. 163 | 164 | 3. To the extent possible, the Licensor waives any right to collect royalties 165 | from You for the exercise of the Licensed Rights, whether directly or through 166 | a collecting society under any voluntary or waivable statutory or compulsory 167 | licensing scheme. In all other cases the Licensor expressly reserves any right 168 | to collect such royalties. 169 | 170 | Section 3 – License Conditions. 171 | 172 | Your exercise of the Licensed Rights is expressly made subject to the following 173 | conditions. 174 | 175 | a. Attribution. 176 | 177 | 1. If You Share the Licensed Material (including in modified form), You must: 178 | 179 | A. retain the following if it is supplied by the Licensor with the Licensed 180 | Material: 181 | 182 | i. identification of the creator(s) of the Licensed Material and any others 183 | designated to receive attribution, in any reasonable manner requested by the 184 | Licensor (including by pseudonym if designated); 185 | 186 | ii. a copyright notice; 187 | 188 | iii. a notice that refers to this Public License; 189 | 190 | iv. a notice that refers to the disclaimer of warranties; 191 | 192 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 193 | 194 | B. indicate if You modified the Licensed Material and retain an indication 195 | of any previous modifications; and 196 | 197 | C. indicate the Licensed Material is licensed under this Public License, and 198 | include the text of, or the URI or hyperlink to, this Public License. 199 | 200 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner 201 | based on the medium, means, and context in which You Share the Licensed Material. 202 | For example, it may be reasonable to satisfy the conditions by providing a 203 | URI or hyperlink to a resource that includes the required information. 204 | 205 | 3. If requested by the Licensor, You must remove any of the information required 206 | by Section 3(a)(1)(A) to the extent reasonably practicable. 207 | 208 | 4. If You Share Adapted Material You produce, the Adapter's License You apply 209 | must not prevent recipients of the Adapted Material from complying with this 210 | Public License. 211 | 212 | Section 4 – Sui Generis Database Rights. 213 | 214 | Where the Licensed Rights include Sui Generis Database Rights that apply to 215 | Your use of the Licensed Material: 216 | 217 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, 218 | reuse, reproduce, and Share all or a substantial portion of the contents of 219 | the database; 220 | 221 | b. if You include all or a substantial portion of the database contents in 222 | a database in which You have Sui Generis Database Rights, then the database 223 | in which You have Sui Generis Database Rights (but not its individual contents) 224 | is Adapted Material; and 225 | 226 | c. You must comply with the conditions in Section 3(a) if You Share all or 227 | a substantial portion of the contents of the database. 228 | 229 | For the avoidance of doubt, this Section 4 supplements and does not replace 230 | Your obligations under this Public License where the Licensed Rights include 231 | other Copyright and Similar Rights. 232 | 233 | Section 5 – Disclaimer of Warranties and Limitation of Liability. 234 | 235 | a. Unless otherwise separately undertaken by the Licensor, to the extent possible, 236 | the Licensor offers the Licensed Material as-is and as-available, and makes 237 | no representations or warranties of any kind concerning the Licensed Material, 238 | whether express, implied, statutory, or other. This includes, without limitation, 239 | warranties of title, merchantability, fitness for a particular purpose, non-infringement, 240 | absence of latent or other defects, accuracy, or the presence or absence of 241 | errors, whether or not known or discoverable. Where disclaimers of warranties 242 | are not allowed in full or in part, this disclaimer may not apply to You. 243 | 244 | b. To the extent possible, in no event will the Licensor be liable to You 245 | on any legal theory (including, without limitation, negligence) or otherwise 246 | for any direct, special, indirect, incidental, consequential, punitive, exemplary, 247 | or other losses, costs, expenses, or damages arising out of this Public License 248 | or use of the Licensed Material, even if the Licensor has been advised of 249 | the possibility of such losses, costs, expenses, or damages. Where a limitation 250 | of liability is not allowed in full or in part, this limitation may not apply 251 | to You. 252 | 253 | c. The disclaimer of warranties and limitation of liability provided above 254 | shall be interpreted in a manner that, to the extent possible, most closely 255 | approximates an absolute disclaimer and waiver of all liability. 256 | 257 | Section 6 – Term and Termination. 258 | 259 | a. This Public License applies for the term of the Copyright and Similar Rights 260 | licensed here. However, if You fail to comply with this Public License, then 261 | Your rights under this Public License terminate automatically. 262 | 263 | b. Where Your right to use the Licensed Material has terminated under Section 264 | 6(a), it reinstates: 265 | 266 | 1. automatically as of the date the violation is cured, provided it is cured 267 | within 30 days of Your discovery of the violation; or 268 | 269 | 2. upon express reinstatement by the Licensor. 270 | 271 | c. For the avoidance of doubt, this Section 6(b) does not affect any right 272 | the Licensor may have to seek remedies for Your violations of this Public 273 | License. 274 | 275 | d. For the avoidance of doubt, the Licensor may also offer the Licensed Material 276 | under separate terms or conditions or stop distributing the Licensed Material 277 | at any time; however, doing so will not terminate this Public License. 278 | 279 | e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 280 | 281 | Section 7 – Other Terms and Conditions. 282 | 283 | a. The Licensor shall not be bound by any additional or different terms or 284 | conditions communicated by You unless expressly agreed. 285 | 286 | b. Any arrangements, understandings, or agreements regarding the Licensed 287 | Material not stated herein are separate from and independent of the terms 288 | and conditions of this Public License. 289 | 290 | Section 8 – Interpretation. 291 | 292 | a. For the avoidance of doubt, this Public License does not, and shall not 293 | be interpreted to, reduce, limit, restrict, or impose conditions on any use 294 | of the Licensed Material that could lawfully be made without permission under 295 | this Public License. 296 | 297 | b. To the extent possible, if any provision of this Public License is deemed 298 | unenforceable, it shall be automatically reformed to the minimum extent necessary 299 | to make it enforceable. If the provision cannot be reformed, it shall be severed 300 | from this Public License without affecting the enforceability of the remaining 301 | terms and conditions. 302 | 303 | c. No term or condition of this Public License will be waived and no failure 304 | to comply consented to unless expressly agreed to by the Licensor. 305 | 306 | d. Nothing in this Public License constitutes or may be interpreted as a limitation 307 | upon, or waiver of, any privileges and immunities that apply to the Licensor 308 | or You, including from the legal processes of any jurisdiction or authority. 309 | 310 | Creative Commons is not a party to its public licenses. Notwithstanding, Creative 311 | Commons may elect to apply one of its public licenses to material it publishes 312 | and in those instances will be considered the "Licensor." The text of the 313 | Creative Commons public licenses is dedicated to the public domain under the 314 | CC0 Public Domain Dedication. Except for the limited purpose of indicating 315 | that material is shared under a Creative Commons public license or as otherwise 316 | permitted by the Creative Commons policies published at creativecommons.org/policies, 317 | Creative Commons does not authorize the use of the trademark "Creative Commons" 318 | or any other trademark or logo of Creative Commons without its prior written 319 | consent including, without limitation, in connection with any unauthorized 320 | modifications to any of its public licenses or any other arrangements, understandings, 321 | or agreements concerning use of licensed material. For the avoidance of doubt, 322 | this paragraph does not form part of the public licenses. 323 | 324 | Creative Commons may be contacted at creativecommons.org. 325 | -------------------------------------------------------------------------------- /LICENSES/GPL-3.0-or-later.txt: -------------------------------------------------------------------------------- 1 | Text 2 | GNU GENERAL PUBLIC LICENSE 3 | Version 3, 29 June 2007 4 | 5 | Copyright © 2007 Free Software Foundation, Inc. 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The GNU General Public License is a free, copyleft license for software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. 14 | 15 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. 16 | 17 | To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. 18 | 19 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. 20 | 21 | Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. 22 | 23 | For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. 24 | 25 | Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. 26 | 27 | Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. 28 | 29 | The precise terms and conditions for copying, distribution and modification follow. 30 | 31 | TERMS AND CONDITIONS 32 | 33 | 0. Definitions. 34 | "This License" refers to version 3 of the GNU General Public License. 35 | 36 | "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. 37 | 38 | "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. 39 | 40 | To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. 41 | 42 | A "covered work" means either the unmodified Program or a work based on the Program. 43 | 44 | To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. 45 | 46 | To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. 47 | 48 | An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 49 | 50 | 1. Source Code. 51 | The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. 52 | A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. 53 | 54 | The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. 55 | 56 | The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. 57 | 58 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. 59 | 60 | The Corresponding Source for a work in source code form is that same work. 61 | 62 | 2. Basic Permissions. 63 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. 64 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. 65 | 66 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 67 | 68 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 69 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. 70 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 71 | 72 | 4. Conveying Verbatim Copies. 73 | You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. 74 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 75 | 76 | 5. Conveying Modified Source Versions. 77 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: 78 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date. 79 | b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". 80 | c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. 81 | d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. 82 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 83 | 84 | 6. Conveying Non-Source Forms. 85 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: 86 | a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. 87 | b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. 88 | c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. 89 | d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. 90 | e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. 91 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. 92 | 93 | A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. 94 | 95 | "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. 96 | 97 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). 98 | 99 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. 100 | 101 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 102 | 103 | 7. Additional Terms. 104 | "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. 105 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. 106 | 107 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: 108 | 109 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or 110 | b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or 111 | c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or 112 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or 113 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or 114 | f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. 115 | All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. 116 | 117 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. 118 | 119 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 120 | 121 | 8. Termination. 122 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). 123 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. 124 | 125 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. 126 | 127 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 128 | 129 | 9. Acceptance Not Required for Having Copies. 130 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 131 | 10. Automatic Licensing of Downstream Recipients. 132 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. 133 | An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. 134 | 135 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 136 | 137 | 11. Patents. 138 | A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". 139 | A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. 140 | 141 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. 142 | 143 | In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. 144 | 145 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. 146 | 147 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. 148 | 149 | A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. 150 | 151 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 152 | 153 | 12. No Surrender of Others' Freedom. 154 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 155 | 13. Use with the GNU Affero General Public License. 156 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 157 | 14. Revised Versions of this License. 158 | The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 159 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. 160 | 161 | If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. 162 | 163 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 164 | 165 | 15. Disclaimer of Warranty. 166 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 167 | 16. Limitation of Liability. 168 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 169 | 17. Interpretation of Sections 15 and 16. 170 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. 171 | -------------------------------------------------------------------------------- /LICENSES/MIT.txt: -------------------------------------------------------------------------------- 1 | MIT License Copyright (c) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice (including the next 11 | paragraph) shall be included in all copies or substantial portions of the 12 | Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 17 | OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 19 | OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /LICENSES/Unlicense.txt: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute 4 | this software, either in source code form or as a compiled binary, for any 5 | purpose, commercial or non-commercial, and by any means. 6 | 7 | In jurisdictions that recognize copyright laws, the author or authors of this 8 | software dedicate any and all copyright interest in the software to the public 9 | domain. We make this dedication for the benefit of the public at large and 10 | to the detriment of our heirs and successors. We intend this dedication to 11 | be an overt act of relinquishment in perpetuity of all present and future 12 | rights to this software under copyright law. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 17 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 18 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH 19 | THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, 20 | please refer to 21 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | .. image:: https://readthedocs.org/projects/circuitpython-tinylora/badge/?version=latest 5 | :target: https://docs.circuitpython.org/projects/tinylora/en/latest/ 6 | :alt: Documentation Status 7 | 8 | .. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg 9 | :target: https://adafru.it/discord 10 | :alt: Discord 11 | 12 | .. image:: https://github.com/adafruit/Adafruit_CircuitPython_TinyLoRa/workflows/Build%20CI/badge.svg 13 | :target: https://github.com/adafruit/Adafruit_CircuitPython_TinyLoRa/actions/ 14 | :alt: Build Status 15 | 16 | .. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json 17 | :target: https://github.com/astral-sh/ruff 18 | :alt: Code Style: Ruff 19 | 20 | **WARNING: This library is not compatible with The Things Network v3 stack. Since TTN has fully migrated to v3, this library is not longer able to communicate with TTN.** 21 | 22 | 23 | LoRaWAN/The Things Network V2, for CircuitPython. 24 | 25 | Dependencies 26 | ============= 27 | This driver depends on: 28 | 29 | * `Adafruit CircuitPython `_ 30 | * `Bus Device `_ 31 | 32 | Please ensure all dependencies are available on the CircuitPython filesystem. 33 | This is easily achieved by downloading `the Adafruit library and driver bundle `_. 34 | 35 | Installing from PyPI 36 | ==================== 37 | 38 | On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from 39 | PyPI `_. To install for current user: 40 | 41 | .. code-block:: shell 42 | 43 | pip3 install adafruit-circuitpython-tinylora 44 | 45 | To install system-wide (this may be required in some cases): 46 | 47 | .. code-block:: shell 48 | 49 | sudo pip3 install adafruit-circuitpython-tinylora 50 | 51 | To install in a virtual environment in your current project: 52 | 53 | .. code-block:: shell 54 | 55 | mkdir project-name && cd project-name 56 | python3 -m venv .venv 57 | source .venv/bin/activate 58 | pip3 install adafruit-circuitpython-tinylora 59 | 60 | Usage Example 61 | ============= 62 | 63 | Usage is described in the `learn guide for this library `_. 64 | 65 | Documentation 66 | ============= 67 | 68 | API documentation for this library can be found on `Read the Docs `_. 69 | 70 | For information on building library documentation, please check out `this guide `_. 71 | 72 | Contributing 73 | ============ 74 | 75 | Contributions are welcome! Please read our `Code of Conduct 76 | `_ 77 | before contributing to help this project stay welcoming. 78 | 79 | License 80 | ======= 81 | 82 | This library was written by ClemensRiederer. We've converted it to work with Adafruit CircuitPython and made 83 | changes so it works with the Raspberry Pi and Adafruit Feather M0/M4. We've added examples for using this library 84 | to transmit data and sensor data to The Things Network. 85 | 86 | This open source code is licensed under the LGPL license (see LICENSE for details). 87 | -------------------------------------------------------------------------------- /README.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | 3 | SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /adafruit_tinylora/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """This file is included to prevent pylint 6 | failing with the following error: no-name-in-module. 7 | note: revisit/remove this file when this pylint error has been resolved. 8 | """ 9 | -------------------------------------------------------------------------------- /adafruit_tinylora/adafruit_tinylora.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2015-2016 Ideetron B.V. 2 | # 3 | # SPDX-License-Identifier: GPL-3.0-or-later 4 | 5 | """ 6 | `adafruit_tinylora` 7 | ==================================================== 8 | CircuitPython LoRaWAN implementation for use with 9 | The Things Network. 10 | 11 | * Author(s): adafruit 12 | 13 | Implementation Notes 14 | -------------------- 15 | 16 | **Hardware:** 17 | 18 | * `Adafruit RFM95W LoRa Radio Transceiver Breakout `_ 19 | 20 | **Software and Dependencies:** 21 | 22 | * Adafruit CircuitPython firmware for the supported boards: 23 | https://github.com/adafruit/circuitpython/releases 24 | 25 | * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice 26 | """ 27 | 28 | import time 29 | from random import randint 30 | 31 | import adafruit_bus_device.spi_device 32 | from micropython import const 33 | 34 | from adafruit_tinylora.adafruit_tinylora_encryption import AES 35 | 36 | try: # typing 37 | from types import TracebackType 38 | from typing import Optional, Type, Union 39 | 40 | import busio 41 | import digitalio 42 | from typing_extensions import ( 43 | Annotated, 44 | Self, # Python <3.11 45 | TypeAlias, 46 | ) 47 | 48 | # type aliases 49 | bytearray2: TypeAlias = Annotated[bytearray, 2] 50 | bytearray4: TypeAlias = Annotated[bytearray, 4] 51 | bytearray16: TypeAlias = Annotated[bytearray, 16] 52 | 53 | registeraddress: TypeAlias = Union[const, int] 54 | except ImportError: 55 | pass 56 | 57 | 58 | __version__ = "0.0.0+auto.0" 59 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_TinyLoRa.git" 60 | 61 | # RFM Module Settings 62 | _MODE_SLEEP = const(0x00) 63 | _MODE_LORA = const(0x80) 64 | _MODE_STDBY = const(0x01) 65 | _MODE_TX = const(0x83) 66 | _TRANSMIT_DIRECTION_UP = const(0x00) 67 | # RFM Registers 68 | _REG_PA_CONFIG = const(0x09) 69 | _REG_PREAMBLE_MSB = const(0x20) 70 | _REG_PREAMBLE_LSB = const(0x21) 71 | _REG_FRF_MSB = const(0x06) 72 | _REG_FRF_MID = const(0x07) 73 | _REG_FRF_LSB = const(0x08) 74 | _REG_FEI_LSB = const(0x1E) 75 | _REG_FEI_MSB = const(0x1D) 76 | _REG_MODEM_CONFIG = const(0x26) 77 | _REG_PAYLOAD_LENGTH = const(0x22) 78 | _REG_FIFO_POINTER = const(0x0D) 79 | _REG_FIFO_BASE_ADDR = const(0x80) 80 | _REG_OPERATING_MODE = const(0x01) 81 | _REG_VERSION = const(0x42) 82 | _REG_PREAMBLE_DETECT = const(0x1F) 83 | _REG_TIMER1_COEF = const(0x39) 84 | _REG_NODE_ADDR = const(0x33) 85 | _REG_IMAGE_CAL = const(0x3B) 86 | _REG_RSSI_CONFIG = const(0x0E) 87 | _REG_RSSI_COLLISION = const(0x0F) 88 | _REG_DIO_MAPPING_1 = const(0x40) 89 | 90 | # Freq synth step 91 | _FSTEP = 32000000.0 / 524288 92 | 93 | 94 | class TTN: 95 | """TTN Class""" 96 | 97 | def __init__( 98 | self, 99 | dev_address: bytearray4, 100 | net_key: bytearray16, 101 | app_key: bytearray16, 102 | country: str = "US", 103 | ): 104 | """Interface for TheThingsNetwork 105 | :param bytearray dev_address: TTN Device Address. 106 | :param bytearray net_key: TTN Network Key. 107 | :param bytearray app_key: TTN Application Key. 108 | :param string country: TTN Region. 109 | """ 110 | self.dev_addr = dev_address 111 | self.net_key = net_key 112 | self.app_key = app_key 113 | self.region = country 114 | 115 | @property 116 | def country(self) -> str: 117 | """Returns the TTN Frequency Country.""" 118 | return self.region 119 | 120 | @property 121 | def device_address(self) -> bytearray4: 122 | """Returns the TTN Device Address.""" 123 | return self.dev_addr 124 | 125 | @property 126 | def application_key(self) -> bytearray16: 127 | """Returns the TTN Application Key.""" 128 | return self.app_key 129 | 130 | @property 131 | def network_key(self) -> bytearray16: 132 | """Returns the TTN Network Key.""" 133 | return self.net_key 134 | 135 | 136 | class TinyLoRa: 137 | """TinyLoRa Interface""" 138 | 139 | # SPI Write Buffer 140 | _BUFFER: bytearray2 = bytearray(2) 141 | 142 | def __init__( 143 | self, 144 | spi: busio.SPI, 145 | cs: digitalio.DigitalInOut, 146 | irq: digitalio.DigitalInOut, 147 | rst: digitalio.DigitalInOut, 148 | ttn_config: digitalio.DigitalInOut, 149 | channel: Optional[int] = None, 150 | ): 151 | """Interface for a HopeRF RFM95/6/7/8(w) radio module. Sets module up for sending to 152 | The Things Network. 153 | 154 | :param ~busio.SPI spi: The SPI bus the device is on 155 | :param ~digitalio.DigitalInOut cs: Chip select pin (RFM_NSS) 156 | :param ~digitalio.DigitalInOut irq: RFM's DIO0 Pin (RFM_DIO0) 157 | :param ~digitalio.DigitalInOut rst: RFM's RST Pin (RFM_RST) 158 | :param TTN ttn_config: TTN Configuration. 159 | :param int channel: Frequency Channel. 160 | """ 161 | self._irq = irq 162 | self._irq.switch_to_input() 163 | self._cs = cs 164 | self._cs.switch_to_output() 165 | self._rst = rst 166 | self._rst.switch_to_output() 167 | # Set up SPI Device on Mode 0 168 | self._device = adafruit_bus_device.spi_device.SPIDevice( 169 | spi, self._cs, baudrate=4000000, polarity=0, phase=0 170 | ) 171 | self._rst.value = False 172 | time.sleep(0.0001) # 100 us 173 | self._rst.value = True 174 | time.sleep(0.005) # 5 ms 175 | # Verify the version of the RFM module 176 | self._version = self._read_u8(_REG_VERSION) 177 | if self._version != 18: 178 | raise TypeError("Can not detect LoRa Module. Please check wiring!") 179 | # Set Frequency registers 180 | self._rfm_msb: Optional[registeraddress] = None 181 | self._rfm_mid: Optional[registeraddress] = None 182 | self._rfm_lsb: Optional[registeraddress] = None 183 | # Set datarate registers 184 | self._sf: Optional[registeraddress] = None 185 | self._bw: Optional[registeraddress] = None 186 | self._modemcfg: Optional[registeraddress] = None 187 | self.set_datarate("SF7BW125") 188 | # Set regional frequency plan 189 | if "US" in ttn_config.country: 190 | from adafruit_tinylora.ttn_usa import TTN_FREQS 191 | 192 | self._frequencies = TTN_FREQS 193 | elif ttn_config.country == "AS": 194 | from adafruit_tinylora.ttn_as import TTN_FREQS 195 | 196 | self._frequencies = TTN_FREQS 197 | elif ttn_config.country == "AU": 198 | from adafruit_tinylora.ttn_au import TTN_FREQS 199 | 200 | self._frequencies = TTN_FREQS 201 | elif ttn_config.country == "EU": 202 | from adafruit_tinylora.ttn_eu import TTN_FREQS 203 | 204 | self._frequencies = TTN_FREQS 205 | elif ttn_config.country == "CN": 206 | from adafruit_tinylora.ttn_cn import TTN_FREQS 207 | 208 | self._frequencies = TTN_FREQS 209 | else: 210 | raise TypeError("Country Code Incorrect/Unsupported") 211 | # pylint: enable=import-outside-toplevel 212 | # Set Channel Number 213 | self._channel = channel 214 | self._tx_random = randint(0, 7) 215 | if self._channel is not None: 216 | # set single channel 217 | self.set_channel(self._channel) 218 | # Init FrameCounter 219 | self.frame_counter = 0 220 | # Set up RFM9x for LoRa Mode 221 | for pair in ( 222 | (_REG_OPERATING_MODE, _MODE_SLEEP), 223 | (_REG_OPERATING_MODE, _MODE_LORA), 224 | (_REG_PA_CONFIG, 0xFF), 225 | (_REG_PREAMBLE_DETECT, 0x25), 226 | (_REG_PREAMBLE_MSB, 0x00), 227 | (_REG_PREAMBLE_LSB, 0x08), 228 | (_REG_MODEM_CONFIG, 0x0C), 229 | (_REG_TIMER1_COEF, 0x34), 230 | (_REG_NODE_ADDR, 0x27), 231 | (_REG_IMAGE_CAL, 0x1D), 232 | (_REG_RSSI_CONFIG, 0x80), 233 | (_REG_RSSI_COLLISION, 0x00), 234 | ): 235 | self._write_u8(pair[0], pair[1]) 236 | # Give the lora object ttn configuration 237 | self._ttn_config = ttn_config 238 | 239 | def __enter__(self) -> Self: 240 | return self 241 | 242 | def __exit__( 243 | self, 244 | exception_type: Optional[Type[type]], 245 | exception_value: Optional[BaseException], 246 | traceback: Optional[TracebackType], 247 | ) -> None: 248 | self.deinit() 249 | 250 | def deinit(self) -> None: 251 | """Deinitializes the TinyLoRa object properties and pins.""" 252 | self._irq = None 253 | self._rst = None 254 | self._cs = None 255 | self.frame_counter = 0 256 | self._rfm_msb = None 257 | self._rfm_mid = None 258 | self._rfm_lsb = None 259 | self._sf = None 260 | self._bw = None 261 | self._modemcfg = None 262 | 263 | def send_data( 264 | self, data: bytearray, data_length: int, frame_counter: int, timeout: int = 2 265 | ) -> None: 266 | """Function to assemble and send data 267 | :param data: data to send 268 | :param data_length: length of data to send 269 | :param frame_counter: frame counter variable, declared in code.py. 270 | :param timeout: TxDone wait time, default is 2. 271 | """ 272 | # data packet 273 | enc_data = bytearray(data_length) 274 | lora_pkt = bytearray(64) 275 | # copy bytearray into bytearray for encryption 276 | enc_data[0:data_length] = data[0:data_length] 277 | # encrypt data (enc_data is overwritten in this function) 278 | self.frame_counter = frame_counter 279 | aes = AES( 280 | self._ttn_config.device_address, 281 | self._ttn_config.app_key, 282 | self._ttn_config.network_key, 283 | self.frame_counter, 284 | ) 285 | enc_data = aes.encrypt(enc_data) 286 | # append preamble to packet 287 | lora_pkt[0] = const(_REG_DIO_MAPPING_1) 288 | lora_pkt[1] = self._ttn_config.device_address[3] 289 | lora_pkt[2] = self._ttn_config.device_address[2] 290 | lora_pkt[3] = self._ttn_config.device_address[1] 291 | lora_pkt[4] = self._ttn_config.device_address[0] 292 | lora_pkt[5] = 0 293 | lora_pkt[6] = frame_counter & 0x00FF 294 | lora_pkt[7] = (frame_counter >> 8) & 0x00FF 295 | lora_pkt[8] = 0x01 296 | # set length of LoRa packet 297 | lora_pkt_len = 9 298 | # load encrypted data into lora_pkt 299 | lora_pkt[lora_pkt_len : lora_pkt_len + data_length] = enc_data[0:data_length] 300 | # recalculate packet length 301 | lora_pkt_len += data_length 302 | # Calculate MIC 303 | mic: bytearray4 = bytearray(4) 304 | mic = aes.calculate_mic(lora_pkt, lora_pkt_len, mic) 305 | # load mic in package 306 | lora_pkt[lora_pkt_len : lora_pkt_len + 4] = mic[0:4] 307 | # recalculate packet length (add MIC length) 308 | lora_pkt_len += 4 309 | self.send_packet(lora_pkt, lora_pkt_len, timeout) 310 | 311 | def send_packet(self, lora_packet: bytearray, packet_length: int, timeout: int) -> None: 312 | """Sends a LoRa packet using the RFM Module 313 | :param bytearray lora_packet: assembled LoRa packet from send_data 314 | :param int packet_length: length of LoRa packet to send 315 | :param int timeout: TxDone wait time. 316 | """ 317 | # Set RFM to standby 318 | self._write_u8(_MODE_STDBY, 0x81) 319 | # wait for RFM to enter standby mode 320 | time.sleep(0.01) 321 | # switch interrupt to txdone 322 | self._write_u8(0x40, 0x40) 323 | # check for multi-channel configuration 324 | if self._channel is None: 325 | self._tx_random = randint(0, 7) 326 | self._rfm_lsb = self._frequencies[self._tx_random][2] 327 | self._rfm_mid = self._frequencies[self._tx_random][1] 328 | self._rfm_msb = self._frequencies[self._tx_random][0] 329 | # Set up frequency registers 330 | for pair in ( 331 | (_REG_FRF_MSB, self._rfm_msb), 332 | (_REG_FRF_MID, self._rfm_mid), 333 | (_REG_FRF_LSB, self._rfm_lsb), 334 | (_REG_FEI_LSB, self._sf), 335 | (_REG_FEI_MSB, self._bw), 336 | (_REG_MODEM_CONFIG, self._modemcfg), 337 | (_REG_PAYLOAD_LENGTH, packet_length), 338 | (_REG_FIFO_POINTER, _REG_FIFO_BASE_ADDR), 339 | ): 340 | self._write_u8(pair[0], pair[1]) 341 | # fill the FIFO buffer with the LoRa payload 342 | for packet_index in range(packet_length): 343 | self._write_u8(0x00, lora_packet[packet_index]) 344 | # switch RFM to TX operating mode 345 | self._write_u8(_REG_OPERATING_MODE, _MODE_TX) 346 | # wait for TxDone IRQ, poll for timeout. 347 | start = time.monotonic() 348 | timed_out = False 349 | while not timed_out and not self._irq.value: 350 | if (time.monotonic() - start) >= timeout: 351 | timed_out = True 352 | # switch RFM to sleep operating mode 353 | self._write_u8(_REG_OPERATING_MODE, _MODE_SLEEP) 354 | if timed_out: 355 | raise RuntimeError("Timeout during packet send") 356 | 357 | def set_datarate(self, datarate: str) -> None: 358 | """Sets the RFM Datarate 359 | :param datarate: Bandwidth and Frequency Plan 360 | """ 361 | # TODO: Convert these to enum 362 | data_rates = { 363 | "SF7BW125": (0x74, 0x72, 0x04), 364 | "SF7BW250": (0x74, 0x82, 0x04), 365 | "SF8BW125": (0x84, 0x72, 0x04), 366 | "SF9BW125": (0x94, 0x72, 0x04), 367 | "SF10BW125": (0xA4, 0x72, 0x04), 368 | "SF11BW125": (0xB4, 0x72, 0x0C), 369 | "SF12BW125": (0xC4, 0x72, 0x0C), 370 | } 371 | try: 372 | self._sf, self._bw, self._modemcfg = data_rates[datarate] 373 | except KeyError as err: 374 | raise KeyError("Invalid or Unsupported Datarate.") from err 375 | 376 | def set_channel(self, channel: int) -> None: 377 | """Sets the RFM Channel (if single-channel) 378 | :param int channel: Transmit Channel (0 through 7). 379 | """ 380 | self._rfm_msb, self._rfm_mid, self._rfm_lsb = self._frequencies[channel] 381 | 382 | def _read_into( 383 | self, address: registeraddress, buf: bytearray2, length: Optional[int] = None 384 | ) -> None: 385 | """Read a number of bytes from the specified address into the 386 | provided buffer. If length is not specified (default) the entire buffer 387 | will be filled. 388 | :param bytearray address: Register Address. 389 | :param bytearray buf: Data Buffer for bytes. 390 | :param int length: Buffer length. 391 | """ 392 | if length is None: 393 | length = len(buf) 394 | with self._device as device: 395 | # Strip out top bit to set 0 value (read). 396 | self._BUFFER[0] = address & 0x7F 397 | device.write(self._BUFFER, end=1) 398 | device.readinto(buf, end=length) 399 | 400 | def _read_u8(self, address: registeraddress) -> int: 401 | """Read a single byte from the provided address and return it. 402 | :param bytearray address: Register Address. 403 | """ 404 | self._read_into(address, self._BUFFER, length=1) 405 | return self._BUFFER[0] 406 | 407 | def _write_u8(self, address: registeraddress, val: int) -> None: 408 | """Writes to the RFM register given an address and data. 409 | :param bytearray address: Register Address. 410 | :param val: Data to write. 411 | """ 412 | with self._device as device: 413 | self._BUFFER[0] = address | 0x80 # MSB 1 to Write 414 | self._BUFFER[1] = val 415 | device.write(self._BUFFER, end=2) 416 | -------------------------------------------------------------------------------- /adafruit_tinylora/adafruit_tinylora_encryption.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2012 Bo Zhu 2 | # SPDX-FileCopyrightText: Brent Rubell for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: MIT 5 | 6 | """ 7 | `adafruit_tinylora_encryption` 8 | ====================================================== 9 | Required tinyLoRA Encryption Methods for AES and 10 | Message Integrity checks. 11 | * Author(s): adafruit 12 | """ 13 | 14 | try: # typing 15 | from typing import Annotated, List, Tuple, TypeAlias 16 | 17 | bytearray2: TypeAlias = Annotated[bytearray, 2] 18 | bytearray4: TypeAlias = Annotated[bytearray, 4] 19 | bytearray16: TypeAlias = Annotated[bytearray, 16] 20 | 21 | StateMatrix: TypeAlias = List[bytearray4] 22 | except ImportError: 23 | pass 24 | 25 | 26 | # from http://cs.ucsb.edu/~koc/cs178/projects/JT/aes.c 27 | def xtime(col: int) -> int: 28 | """xtime impl. for _mix_single_column()""" 29 | return (((col << 1) ^ 0x1B) & 0xFF) if (col & 0x80) else (col << 1) 30 | 31 | 32 | # AES S-box 33 | # NOTE(typing): Each of these 16 items is 16b, can use bytearray16 here 34 | S_BOX: Tuple[bytes, ...] = ( 35 | b"c|w{\xf2ko\xc50\x01g+\xfe\xd7\xabv", 36 | b"\xca\x82\xc9}\xfaYG\xf0\xad\xd4\xa2\xaf\x9c\xa4r\xc0", 37 | b"\xb7\xfd\x93&6?\xf7\xcc4\xa5\xe5\xf1q\xd81\x15", 38 | b"\x04\xc7#\xc3\x18\x96\x05\x9a\x07\x12\x80\xe2\xeb'\xb2u", 39 | b"\t\x83,\x1a\x1bnZ\xa0R;\xd6\xb3)\xe3/\x84", 40 | b"S\xd1\x00\xed \xfc\xb1[j\xcb\xbe9JLX\xcf", 41 | b"\xd0\xef\xaa\xfbCM3\x85E\xf9\x02\x7fP<\x9f\xa8", 42 | b"Q\xa3@\x8f\x92\x9d8\xf5\xbc\xb6\xda!\x10\xff\xf3\xd2", 43 | b"\xcd\x0c\x13\xec_\x97D\x17\xc4\xa7~=d]\x19s", 44 | b'`\x81O\xdc"*\x90\x88F\xee\xb8\x14\xde^\x0b\xdb', 45 | b"\xe02:\nI\x06$\\\xc2\xd3\xacb\x91\x95\xe4y", 46 | b"\xe7\xc87m\x8d\xd5N\xa9lV\xf4\xeaez\xae\x08", 47 | b"\xbax%.\x1c\xa6\xb4\xc6\xe8\xddt\x1fK\xbd\x8b\x8a", 48 | b"p>\xb5fH\x03\xf6\x0ea5W\xb9\x86\xc1\x1d\x9e", 49 | b"\xe1\xf8\x98\x11i\xd9\x8e\x94\x9b\x1e\x87\xe9\xceU(\xdf", 50 | b"\x8c\xa1\x89\r\xbf\xe6BhA\x99-\x0f\xb0T\xbb\x16", 51 | ) 52 | 53 | 54 | class AES: 55 | """TinyLoRA AES Implementation 56 | Functions in this implementation are from and/or derived from AES-Python 57 | (https://github.com/bozhu/AES-Python) and TinyLoRa () 58 | """ 59 | 60 | def __init__( 61 | self, 62 | device_address: bytearray4, 63 | app_key: bytearray16, 64 | network_key: bytearray16, 65 | frame_counter: int, 66 | ): 67 | self._app_key = app_key 68 | self._device_address = device_address 69 | self._network_key = network_key 70 | self.frame_counter = frame_counter 71 | 72 | def encrypt(self, aes_data: bytearray) -> bytearray: 73 | """Performs AES Encryption routine with data. 74 | :param bytearray data: Data to-be encrypted. 75 | """ 76 | self.encrypt_payload(aes_data) 77 | return aes_data 78 | 79 | def encrypt_payload(self, data: bytearray) -> None: 80 | """Encrypts data payload. 81 | :param bytearray data: Data to-be-encrypted. 82 | """ 83 | block_a = bytearray(16) 84 | # calculate required number of blocks 85 | num_blocks = len(data) // 16 86 | incomplete_block_size = len(data) % 16 87 | if incomplete_block_size != 0: 88 | num_blocks += 1 89 | 90 | data_pointer = 0 91 | block_counter = 1 92 | while block_counter <= num_blocks: 93 | block_a[0] = 0x01 94 | block_a[1] = 0x00 95 | block_a[2] = 0x00 96 | block_a[3] = 0x00 97 | block_a[4] = 0x00 98 | block_a[5] = 0x00 99 | # block from device_address, MSB first 100 | block_a[6] = self._device_address[3] 101 | block_a[7] = self._device_address[2] 102 | block_a[8] = self._device_address[1] 103 | block_a[9] = self._device_address[0] 104 | # block from frame counter 105 | block_a[10] = self.frame_counter & 0x00FF 106 | block_a[11] = (self.frame_counter >> 8) & 0x00FF 107 | block_a[12] = 0x00 108 | block_a[13] = 0x00 109 | block_a[14] = 0x00 110 | block_a[15] = block_counter 111 | # calculate S 112 | self._aes_encrypt(block_a, self._app_key) 113 | # check for last block 114 | if block_counter != num_blocks: 115 | for byte_index in range(16): 116 | data[data_pointer] ^= block_a[byte_index] 117 | data_pointer += 1 118 | else: 119 | if incomplete_block_size == 0: 120 | incomplete_block_size = 16 121 | for byte_index in range(incomplete_block_size): 122 | data[data_pointer] ^= block_a[byte_index] 123 | data_pointer += 1 124 | block_counter += 1 125 | 126 | def _aes_encrypt(self, data: bytearray, key: bytearray) -> None: 127 | """Performs 9 rounds of AES encryption on data per TinyLoRa spec. 128 | NOTE: This is not an accurate aes_encrypt impl., tinylora performs 129 | an additional key calculation after 9 rounds. 130 | :param bytearray data: Data array. 131 | :param bytearray key: Round Key Array. 132 | """ 133 | state: StateMatrix = [ 134 | bytearray(b"0000"), 135 | bytearray(b"0000"), 136 | bytearray(b"0000"), 137 | bytearray(b"0000"), 138 | ] 139 | # Copy Data to State Array for manipulation 140 | for col in range(4): 141 | for row in range(4): 142 | state[col][row] = data[row + (col << 2)] 143 | # copy key to round_key 144 | round_key = bytearray(key) 145 | self._aes_add_round_key(round_key, state) 146 | # encrypt data 9x 147 | for round_nums in range(1, 10): 148 | self._round_encrypt(state, round_key, round_nums) 149 | self._aes_sub_bytes(state) 150 | self._aes_shift_rows(state) 151 | self._aes_calculate_key(10, round_key) 152 | self._aes_add_round_key(round_key, state) 153 | for row in range(4): 154 | for col in range(4): 155 | data[col + (row << 2)] = state[row][col] 156 | 157 | def _round_encrypt(self, state: StateMatrix, key: bytearray, num_round: int) -> None: 158 | """Performs one round of AES. 159 | :param bytearray state: State array. 160 | :param bytearray key: Round key array. 161 | :param int round: AES round number. 162 | """ 163 | self._aes_sub_bytes(state) 164 | self._aes_shift_rows(state) 165 | self._aes_mix_columns(state) 166 | self._aes_calculate_key(num_round, key) 167 | self._aes_add_round_key(key, state) 168 | 169 | def _aes_calculate_key(self, num_round: int, round_key: bytearray) -> None: 170 | """Performs round key calculation per TinyLoRa's spec. 171 | :param int num_round: Round number 172 | :param bytearray round_key: Round key array. 173 | """ 174 | tmp_arr = bytearray(4) 175 | round_const = 0x01 176 | # add round_const calculation 177 | while num_round != 1: 178 | byte = round_const & 0x80 179 | round_const <<= 1 180 | round_const &= 0xFF 181 | if byte == 0x80: 182 | round_const ^= 0x1B 183 | num_round -= 1 184 | # Calculate first temp 185 | tmp_arr[0] = self._aes_sub_byte(round_key[12 + 1]) 186 | tmp_arr[1] = self._aes_sub_byte(round_key[12 + 2]) 187 | tmp_arr[2] = self._aes_sub_byte(round_key[12 + 3]) 188 | tmp_arr[3] = self._aes_sub_byte(round_key[12 + 0]) 189 | # XOR tmp_arr[0] wth round_const first 190 | tmp_arr[0] ^= round_const 191 | # then calculate new round key 192 | for row in range(4): 193 | for col in range(4): 194 | round_key[col + (row << 2)] ^= tmp_arr[col] 195 | tmp_arr[col] = round_key[col + (row << 2)] 196 | 197 | @staticmethod 198 | def _aes_add_round_key(round_key: bytearray, state: StateMatrix) -> None: 199 | """AES AddRoundKey Step: Round_Key combined with the state. 200 | :param bytearray round_key: Subkey for each round. 201 | :param bytearray state: State array. 202 | """ 203 | for col in range(4): 204 | for row in range(4): 205 | state[col][row] ^= round_key[row + (col << 2)] 206 | 207 | @staticmethod 208 | def _aes_sub_byte(sub_byte: int) -> int: 209 | """Sub-Byte Step: Used for returning specific byte 210 | from the AES S_BOX. 211 | :param byte sub_byte: byte to be replaced with S_BOX byte. 212 | """ 213 | row = (sub_byte >> 4) & 0x0F 214 | col = sub_byte & 0x0F 215 | return S_BOX[row][col] 216 | 217 | def _aes_sub_bytes(self, state: StateMatrix) -> None: 218 | """AES SubBytes Step: Replace state arr. bytes w/sub-byte from S_BOX 219 | :param bytearray s: State array. 220 | """ 221 | for col in range(4): 222 | for row in range(4): 223 | state[row][col] = self._aes_sub_byte(state[row][col]) 224 | 225 | @staticmethod 226 | def _mix_single_column(col: bytearray4) -> None: 227 | """Mixes individual columns with state array 228 | :param bytearray col: Column from statearray 229 | """ 230 | temp = col[0] ^ col[1] ^ col[2] ^ col[3] 231 | col_zero = col[0] 232 | col[0] ^= temp ^ xtime(col[0] ^ col[1]) 233 | col[1] ^= temp ^ xtime(col[1] ^ col[2]) 234 | col[2] ^= temp ^ xtime(col[2] ^ col[3]) 235 | col[3] ^= temp ^ xtime(col[3] ^ col_zero) 236 | 237 | def _aes_mix_columns(self, state: StateMatrix) -> None: 238 | """AES MixColumns Step: Multiplies each column of the state array with xtime. 239 | :param bytearray state: State array. 240 | """ 241 | for column_index in range(4): 242 | self._mix_single_column(state[column_index]) 243 | 244 | @staticmethod 245 | def _aes_shift_rows(arr: StateMatrix) -> None: 246 | """AES ShiftRows Step: State array's bytes shifted to the left. 247 | :param bytearray state: State array. 248 | """ 249 | arr[0][1], arr[1][1], arr[2][1], arr[3][1] = ( 250 | arr[1][1], 251 | arr[2][1], 252 | arr[3][1], 253 | arr[0][1], 254 | ) 255 | arr[0][2], arr[1][2], arr[2][2], arr[3][2] = ( 256 | arr[2][2], 257 | arr[3][2], 258 | arr[0][2], 259 | arr[1][2], 260 | ) 261 | arr[0][3], arr[1][3], arr[2][3], arr[3][3] = ( 262 | arr[3][3], 263 | arr[0][3], 264 | arr[1][3], 265 | arr[2][3], 266 | ) 267 | 268 | def calculate_mic( 269 | self, lora_packet: bytearray, lora_packet_length: int, mic: bytearray4 270 | ) -> bytearray4: 271 | """Calculates the validity of data messages, generates message integrity check bytearray.""" 272 | block_b = bytearray(16) 273 | key_k1 = bytearray(16) 274 | key_k2 = bytearray(16) 275 | old_data = bytearray(16) 276 | new_data = bytearray(16) 277 | block_b[0] = 0x49 278 | block_b[6] = self._device_address[3] 279 | block_b[7] = self._device_address[2] 280 | block_b[8] = self._device_address[1] 281 | block_b[9] = self._device_address[0] 282 | block_b[10] = self.frame_counter & 0x00FF 283 | block_b[11] = (self.frame_counter >> 8) & 0x00FF 284 | block_b[15] = lora_packet_length 285 | # calculate num. of blocks and blocksz of last block 286 | num_blocks = lora_packet_length // 16 287 | incomplete_block_size = lora_packet_length % 16 288 | if incomplete_block_size != 0: 289 | num_blocks += 1 290 | # generate keys 291 | self._mic_generate_keys(key_k1, key_k2) 292 | # aes encryption on block_b 293 | self._aes_encrypt(block_b, self._network_key) 294 | # copy block_b to old_data 295 | for byte_index in range(16): 296 | old_data[byte_index] = block_b[byte_index] 297 | block_counter = 1 298 | # calculate until n-1 packet blocks 299 | data_pointer = 0 300 | while block_counter < num_blocks: 301 | # copy data into array 302 | for byte_index in range(16): 303 | new_data[byte_index] = lora_packet[data_pointer] 304 | data_pointer += 1 305 | # XOR new_data with old_data 306 | self._xor_data(new_data, old_data) 307 | # aes encrypt new_data 308 | self._aes_encrypt(new_data, self._network_key) 309 | # copy new_data to old_data 310 | for byte_index in range(16): 311 | old_data[byte_index] = new_data[byte_index] 312 | # increase block_counter 313 | block_counter += 1 314 | # perform calculation on last block 315 | if incomplete_block_size == 0: 316 | for byte_index in range(16): 317 | new_data[byte_index] = lora_packet[data_pointer] 318 | data_pointer += 1 319 | # xor with key 1 320 | self._xor_data(new_data, key_k1) 321 | # xor with old data 322 | self._xor_data(new_data, old_data) 323 | # aes routine 324 | self._aes_encrypt(new_data, self._network_key) 325 | else: 326 | # copy the remaining data 327 | for byte_index in range(16): 328 | if byte_index < incomplete_block_size: 329 | new_data[byte_index] = lora_packet[data_pointer] 330 | data_pointer += 1 331 | if byte_index == incomplete_block_size: 332 | new_data[byte_index] = 0x80 333 | if byte_index > incomplete_block_size: 334 | new_data[byte_index] = 0x00 335 | # perform xor with key 2 336 | self._xor_data(new_data, key_k2) 337 | # perform xor with old data 338 | self._xor_data(new_data, old_data) 339 | self._aes_encrypt(new_data, self._network_key) 340 | # load MIC[] with data 341 | mic[0] = new_data[0] 342 | mic[1] = new_data[1] 343 | mic[2] = new_data[2] 344 | mic[3] = new_data[3] 345 | # return message integrity check array to calling method 346 | return mic 347 | 348 | def _mic_generate_keys(self, key_1: bytearray16, key_2: bytearray16) -> None: 349 | # encrypt the 0's in k1 with network key 350 | self._aes_encrypt(key_1, self._network_key) 351 | # perform gen_key on key_1 352 | # check if key_1's msb is 1 353 | msb_key = (key_1[0] & 0x80) == 0x80 354 | # shift k1 left 1b 355 | self._shift_left(key_1) 356 | # check if msb is 1 357 | if msb_key: 358 | key_1[15] ^= 0x87 359 | # perform gen_key on key_2 360 | # copy key_1 to key_2 361 | key_2[0:16] = key_1[0:16] 362 | msb_key = (key_2[0] & 0x80) == 0x80 363 | self._shift_left(key_2) 364 | # check if msb is 1 365 | if msb_key: 366 | key_2[15] ^= 0x87 367 | 368 | @staticmethod 369 | def _shift_left(data: bytearray16) -> None: 370 | """Shifts data bytearray left by 1""" 371 | for byte_index in range(16): 372 | if byte_index < 15: 373 | if (data[byte_index + 1] & 0x80) == 0x80: 374 | overflow = 1 375 | else: 376 | overflow = 0 377 | else: 378 | overflow = 0 379 | # shift 1b left 380 | data[byte_index] = ((data[byte_index] << 1) + overflow) & 0xFF 381 | 382 | @staticmethod 383 | def _xor_data(new_data: bytearray16, old_data: bytearray16) -> None: 384 | """XOR two data arrays 385 | :param bytearray new_data: Calculated data. 386 | :param bytearray old_data: data to be xor'd. 387 | """ 388 | for byte_index in range(16): 389 | new_data[byte_index] ^= old_data[byte_index] 390 | -------------------------------------------------------------------------------- /adafruit_tinylora/ttn_as.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2018 Brent Rubell for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `ttn_as` 7 | ====================================================== 8 | AS920 The Things Network Frequency Plans 9 | * Author(s): Brent Rubell 10 | """ 11 | 12 | TTN_FREQS = { 13 | 0: (0xE6, 0xCC, 0xF4), # 868.1 MHz 14 | 1: (0xE6, 0xD9, 0xC0), # 868.3 MHz 15 | 2: (0xE6, 0x8C, 0xF3), # 863.5 MHz 16 | 3: (0xE6, 0x99, 0xC0), # 867.1 MHz 17 | 4: (0xE6, 0xA6, 0x8D), # 867.3 MHz 18 | 5: (0xE6, 0xB3, 0x5A), # 867.5 MHz 19 | 6: (0xE6, 0xC0, 0x27), # 867.7 MHz 20 | 7: (0xE6, 0x80, 0x27), 21 | } # 867.9 MHz 22 | -------------------------------------------------------------------------------- /adafruit_tinylora/ttn_au.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2018 Brent Rubell for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `ttn_au` 7 | ====================================================== 8 | The Things Network Frequency Plans - AU915 9 | * Author(s): Brent Rubell 10 | """ 11 | 12 | TTN_FREQS = { 13 | 0: (0xE5, 0x33, 0x5A), # 916.8 MHz 14 | 1: (0xE5, 0x40, 0x26), # 917.0 MHz 15 | 2: (0xE5, 0x4C, 0xF3), # 917.2 MHz 16 | 3: (0xE5, 0x59, 0xC0), # 917.4 MHz 17 | 4: (0xE5, 0x66, 0x8D), # 917.6 MHz 18 | 5: (0xE5, 0x73, 0x5A), # 917.8 MHz 19 | 6: (0xE5, 0x80, 0x27), # 918.0 MHz 20 | 7: (0xE5, 0x8C, 0xF3), 21 | } # 918.2 MHz 22 | -------------------------------------------------------------------------------- /adafruit_tinylora/ttn_cn.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2018 Brent Rubell for Adafruit Industries 2 | # SPDX-FileCopyrightText: 2021 IAMLIUBO 3 | # 4 | # SPDX-License-Identifier: MIT 5 | 6 | """ 7 | `ttn_cn` 8 | ====================================================== 9 | The Things Network Frequency Plans - CN470 10 | * Author(s): IAMLIUBO 11 | """ 12 | 13 | TTN_FREQS = { 14 | 0: (0x79, 0x93, 0x33), # 486.3 MHz 15 | 1: (0x79, 0xA0, 0x00), # 486.5 MHz 16 | 2: (0x79, 0xAC, 0xCC), # 486.7 MHz 17 | 3: (0x79, 0xB9, 0x99), # 486.9 MHz 18 | 4: (0x79, 0xC6, 0x66), # 487.1 MHz 19 | 5: (0x79, 0xD3, 0x33), # 487.3 MHz 20 | 6: (0x79, 0xE0, 0x00), # 487.5 MHz 21 | 7: (0x79, 0xEC, 0xCC), 22 | } # 487.7 MHz 23 | -------------------------------------------------------------------------------- /adafruit_tinylora/ttn_eu.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2018 Brent Rubell for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `ttn_eu` 7 | ====================================================== 8 | The Things Network Frequency Plans - EU863 9 | * Author(s): Brent Rubell 10 | """ 11 | 12 | TTN_FREQS = { 13 | 0: (0xD9, 0x06, 0x8B), # 868.1 MHz 14 | 1: (0xD9, 0x13, 0x58), # 868.3 MHz 15 | 2: (0xD9, 0x20, 0x24), # 868.5 MHz 16 | 3: (0xD8, 0xC6, 0x8B), # 867.1 MHz 17 | 4: (0xD8, 0xD3, 0x58), # 867.3 MHz 18 | 5: (0xD8, 0xE0, 0x24), # 867.5 MHz 19 | 6: (0xD8, 0xEC, 0xF1), # 867.7 MHz 20 | 7: (0xD8, 0xF9, 0xBE), 21 | } # 867.9 MHz 22 | -------------------------------------------------------------------------------- /adafruit_tinylora/ttn_usa.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2018 Brent Rubell for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | """ 6 | `ttn_usa` 7 | ====================================================== 8 | The Things Network Frequency Plans - US902 9 | * Author(s): Brent Rubell 10 | """ 11 | 12 | TTN_FREQS = { 13 | 0: (0xE1, 0xF9, 0xC0), # 903.9 MHz 14 | 1: (0xE2, 0x06, 0x8C), # 904.1 MHz 15 | 2: (0xE2, 0x13, 0x20), # 904.3 MHz 16 | 3: (0xE2, 0x20, 0x26), # 904.5 MHz 17 | 4: (0xE2, 0x2C, 0xF3), # 904.7 MHz 18 | 5: (0xE2, 0x39, 0xC0), # 904.9 MHz 19 | 6: (0xE2, 0x46, 0x8C), # 905.1 MHz 20 | 7: (0xE2, 0x53, 0x59), 21 | } # 905.3 MHz 22 | -------------------------------------------------------------------------------- /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_TinyLoRa/a00b6c8e73c24b52a047c295f84ca82d778dc887/docs/_static/favicon.ico -------------------------------------------------------------------------------- /docs/_static/favicon.ico.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2018 Phillip Torrone for Adafruit Industries 2 | 3 | SPDX-License-Identifier: CC-BY-4.0 4 | -------------------------------------------------------------------------------- /docs/api.rst: -------------------------------------------------------------------------------- 1 | 2 | .. If you created a package, create one automodule per module in the package. 3 | 4 | .. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) 5 | .. use this format as the module name: "adafruit_foo.foo" 6 | 7 | API Reference 8 | ############# 9 | 10 | .. automodule:: adafruit_tinylora 11 | :members: 12 | :member-order: bysource 13 | 14 | 15 | .. automodule:: adafruit_tinylora.adafruit_tinylora 16 | :members: 17 | 18 | .. automodule:: adafruit_tinylora.adafruit_tinylora_encryption 19 | :members: 20 | 21 | .. automodule:: adafruit_tinylora.ttn_as 22 | :members: 23 | 24 | .. automodule:: adafruit_tinylora.ttn_au 25 | :members: 26 | 27 | .. automodule:: adafruit_tinylora.ttn_cn 28 | :members: 29 | 30 | .. automodule:: adafruit_tinylora.ttn_eu 31 | :members: 32 | 33 | .. automodule:: adafruit_tinylora.ttn_usa 34 | :members: 35 | -------------------------------------------------------------------------------- /docs/api.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | import datetime 6 | import os 7 | import sys 8 | 9 | sys.path.insert(0, os.path.abspath("..")) 10 | 11 | # -- General configuration ------------------------------------------------ 12 | 13 | # Add any Sphinx extension module names here, as strings. They can be 14 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 15 | # ones. 16 | extensions = [ 17 | "sphinx.ext.autodoc", 18 | "sphinxcontrib.jquery", 19 | "sphinx.ext.intersphinx", 20 | "sphinx.ext.napoleon", 21 | "sphinx.ext.todo", 22 | ] 23 | 24 | # TODO: Please Read! 25 | # Uncomment the below if you use native CircuitPython modules such as 26 | # digitalio, micropython and busio. List the modules you use. Without it, the 27 | # autodoc module docs will fail to generate with a warning. 28 | # autodoc_mock_imports = ["digitalio", "busio"] 29 | 30 | 31 | intersphinx_mapping = { 32 | "python": ("https://docs.python.org/3", None), 33 | "BusDevice": ( 34 | "https://docs.circuitpython.org/projects/busdevice/en/latest/", 35 | None, 36 | ), 37 | "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), 38 | } 39 | 40 | # Add any paths that contain templates here, relative to this directory. 41 | templates_path = ["_templates"] 42 | 43 | source_suffix = ".rst" 44 | 45 | # The master toctree document. 46 | master_doc = "index" 47 | 48 | # General information about the project. 49 | project = "Adafruit TinyLoRa Library" 50 | creation_year = "2018" 51 | current_year = str(datetime.datetime.now().year) 52 | year_duration = ( 53 | current_year if current_year == creation_year else creation_year + " - " + current_year 54 | ) 55 | copyright = year_duration + " brentru" 56 | author = "brentru" 57 | 58 | # The version info for the project you're documenting, acts as replacement for 59 | # |version| and |release|, also used in various other places throughout the 60 | # built documents. 61 | # 62 | # The short X.Y version. 63 | version = "1.0" 64 | # The full version, including alpha/beta/rc tags. 65 | release = "1.0" 66 | 67 | # The language for content autogenerated by Sphinx. Refer to documentation 68 | # for a list of supported languages. 69 | # 70 | # This is also used if you do content translation via gettext catalogs. 71 | # Usually you set "language" from the command line for these cases. 72 | language = "en" 73 | 74 | # List of patterns, relative to source directory, that match files and 75 | # directories to ignore when looking for source files. 76 | # This patterns also effect to html_static_path and html_extra_path 77 | exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] 78 | 79 | # The reST default role (used for this markup: `text`) to use for all 80 | # documents. 81 | # 82 | default_role = "any" 83 | 84 | # If true, '()' will be appended to :func: etc. cross-reference text. 85 | # 86 | add_function_parentheses = True 87 | 88 | # The name of the Pygments (syntax highlighting) style to use. 89 | pygments_style = "sphinx" 90 | 91 | # If true, `todo` and `todoList` produce output, else they produce nothing. 92 | todo_include_todos = False 93 | 94 | # If this is True, todo emits a warning for each TODO entries. The default is False. 95 | todo_emit_warnings = True 96 | 97 | napoleon_numpy_docstring = False 98 | 99 | # -- Options for HTML output ---------------------------------------------- 100 | 101 | # The theme to use for HTML and HTML Help pages. See the documentation for 102 | # a list of builtin themes. 103 | # 104 | import sphinx_rtd_theme 105 | 106 | html_theme = "sphinx_rtd_theme" 107 | 108 | # Add any paths that contain custom static files (such as style sheets) here, 109 | # relative to this directory. They are copied after the builtin static files, 110 | # so a file named "default.css" will overwrite the builtin "default.css". 111 | html_static_path = ["_static"] 112 | 113 | # The name of an image file (relative to this directory) to use as a favicon of 114 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 115 | # pixels large. 116 | # 117 | html_favicon = "_static/favicon.ico" 118 | 119 | # Output file base name for HTML help builder. 120 | htmlhelp_basename = "AdafruitTinyloraLibrarydoc" 121 | 122 | # -- Options for LaTeX output --------------------------------------------- 123 | 124 | latex_elements = { 125 | # The paper size ('letterpaper' or 'a4paper'). 126 | # 127 | # 'papersize': 'letterpaper', 128 | # The font size ('10pt', '11pt' or '12pt'). 129 | # 130 | # 'pointsize': '10pt', 131 | # Additional stuff for the LaTeX preamble. 132 | # 133 | # 'preamble': '', 134 | # Latex figure (float) alignment 135 | # 136 | # 'figure_align': 'htbp', 137 | } 138 | 139 | # Grouping the document tree into LaTeX files. List of tuples 140 | # (source start file, target name, title, 141 | # author, documentclass [howto, manual, or own class]). 142 | latex_documents = [ 143 | ( 144 | master_doc, 145 | "AdafruitTinyLoRaLibrary.tex", 146 | "AdafruitTinyLoRa Library Documentation", 147 | author, 148 | "manual", 149 | ), 150 | ] 151 | 152 | # -- Options for manual page output --------------------------------------- 153 | 154 | # One entry per manual page. List of tuples 155 | # (source start file, name, description, authors, manual section). 156 | man_pages = [ 157 | ( 158 | master_doc, 159 | "AdafruitTinyLoRalibrary", 160 | "Adafruit TinyLoRa Library Documentation", 161 | [author], 162 | 1, 163 | ) 164 | ] 165 | 166 | # -- Options for Texinfo output ------------------------------------------- 167 | 168 | # Grouping the document tree into Texinfo files. List of tuples 169 | # (source start file, target name, title, author, 170 | # dir menu entry, description, category) 171 | texinfo_documents = [ 172 | ( 173 | master_doc, 174 | "AdafruitTinyLoRaLibrary", 175 | "Adafruit TinyLoRa Library Documentation", 176 | author, 177 | "AdafruitTinyLoRaLibrary", 178 | "One line description of project.", 179 | "Miscellaneous", 180 | ), 181 | ] 182 | -------------------------------------------------------------------------------- /docs/examples.rst: -------------------------------------------------------------------------------- 1 | Simple test 2 | ------------ 3 | 4 | Ensure your device works with this simple test. 5 | 6 | .. literalinclude:: ../examples/tinylora_simpletest.py 7 | :caption: examples/tinylora_simpletest.py 8 | :linenos: 9 | 10 | Using TinyLora with a Sensor 11 | ---------------------------- 12 | 13 | Using TinyLoRa with a Si7021 Sensor 14 | 15 | .. literalinclude:: ../examples/tinylora_simpletest_si7021.py 16 | :caption: examples/tinylora_simpletest_si7021.py 17 | :linenos: 18 | 19 | Using a single Channel 20 | ---------------------- 21 | 22 | Ensure your device works with this simple test. 23 | 24 | .. literalinclude:: ../examples/tinylora_simpletest_single_channel.py 25 | :caption: examples/tinylora_simpletest_single_channel.py 26 | :linenos: 27 | -------------------------------------------------------------------------------- /docs/examples.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | 3 | Table of Contents 4 | ================= 5 | 6 | .. toctree:: 7 | :maxdepth: 4 8 | :hidden: 9 | 10 | self 11 | 12 | .. toctree:: 13 | :caption: Examples 14 | 15 | examples 16 | 17 | .. toctree:: 18 | :caption: API Reference 19 | :maxdepth: 3 20 | 21 | api 22 | 23 | .. toctree:: 24 | :caption: Tutorials 25 | 26 | 27 | .. toctree:: 28 | :caption: Related Products 29 | 30 | 31 | .. toctree:: 32 | :caption: Other Links 33 | 34 | Download from GitHub 35 | Download Library Bundle 36 | CircuitPython Reference Documentation 37 | CircuitPython Support Forum 38 | Discord Chat 39 | Adafruit Learning System 40 | Adafruit Blog 41 | Adafruit Store 42 | 43 | Indices and tables 44 | ================== 45 | 46 | * :ref:`genindex` 47 | * :ref:`modindex` 48 | * :ref:`search` 49 | -------------------------------------------------------------------------------- /docs/index.rst.license: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | sphinx 6 | sphinxcontrib-jquery 7 | sphinx-rtd-theme 8 | -------------------------------------------------------------------------------- /examples/tinylora_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | import time 5 | 6 | import board 7 | import busio 8 | import digitalio 9 | 10 | from adafruit_tinylora.adafruit_tinylora import TTN, TinyLoRa 11 | 12 | try: # typing 13 | from typing import Annotated, TypeAlias 14 | 15 | bytearray4: TypeAlias = Annotated[bytearray, 4] 16 | bytearray16: TypeAlias = Annotated[bytearray, 16] 17 | except ImportError: 18 | pass 19 | 20 | # Board LED 21 | led = digitalio.DigitalInOut(board.D13) 22 | led.direction = digitalio.Direction.OUTPUT 23 | 24 | spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 25 | 26 | # RFM9x Breakout Pinouts 27 | cs = digitalio.DigitalInOut(board.D5) 28 | irq = digitalio.DigitalInOut(board.D6) 29 | rst = digitalio.DigitalInOut(board.D4) 30 | 31 | # Feather M0 RFM9x Pinouts 32 | # cs = digitalio.DigitalInOut(board.RFM9X_CS) 33 | # irq = digitalio.DigitalInOut(board.RFM9X_D0) 34 | # rst = digitalio.DigitalInOut(board.RFM9X_RST) 35 | 36 | # TTN Device Address, 4 Bytes, MSB 37 | devaddr: bytearray4 = bytearray([0x00, 0x00, 0x00, 0x00]) 38 | 39 | # TTN Network Key, 16 Bytes, MSB 40 | nwkey: bytearray16 = bytearray( 41 | [ 42 | 0x00, 43 | 0x00, 44 | 0x00, 45 | 0x00, 46 | 0x00, 47 | 0x00, 48 | 0x00, 49 | 0x00, 50 | 0x00, 51 | 0x00, 52 | 0x00, 53 | 0x00, 54 | 0x00, 55 | 0x00, 56 | 0x00, 57 | 0x00, 58 | ] 59 | ) 60 | 61 | # TTN Application Key, 16 Bytess, MSB 62 | app: bytearray16 = bytearray( 63 | [ 64 | 0x00, 65 | 0x00, 66 | 0x00, 67 | 0x00, 68 | 0x00, 69 | 0x00, 70 | 0x00, 71 | 0x00, 72 | 0x00, 73 | 0x00, 74 | 0x00, 75 | 0x00, 76 | 0x00, 77 | 0x00, 78 | 0x00, 79 | 0x00, 80 | ] 81 | ) 82 | 83 | ttn_config = TTN(devaddr, nwkey, app, country="US") 84 | 85 | lora = TinyLoRa(spi, cs, irq, rst, ttn_config) 86 | 87 | while True: 88 | data: bytearray4 = bytearray(b"\x43\x57\x54\x46") 89 | print("Sending packet...") 90 | lora.send_data(data, len(data), lora.frame_counter) 91 | print("Packet sent!") 92 | led.value = True 93 | lora.frame_counter += 1 94 | time.sleep(1) 95 | led.value = False 96 | -------------------------------------------------------------------------------- /examples/tinylora_simpletest_si7021.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | """Using TinyLoRa with a Si7021 Sensor.""" 5 | 6 | import time 7 | 8 | import adafruit_si7021 9 | import board 10 | import busio 11 | import digitalio 12 | 13 | from adafruit_tinylora.adafruit_tinylora import TTN, TinyLoRa 14 | 15 | try: # typing 16 | from typing import Annotated, TypeAlias 17 | 18 | bytearray4: TypeAlias = Annotated[bytearray, 4] 19 | bytearray16: TypeAlias = Annotated[bytearray, 16] 20 | except ImportError: 21 | pass 22 | 23 | # Board LED 24 | led = digitalio.DigitalInOut(board.D13) 25 | led.direction = digitalio.Direction.OUTPUT 26 | 27 | # Create library object using our bus i2c port for si7021 28 | i2c = busio.I2C(board.SCL, board.SDA) 29 | sensor = adafruit_si7021.SI7021(i2c) 30 | 31 | # Create library object using our bus SPI port for radio 32 | spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 33 | 34 | # RFM9x Breakout Pinouts 35 | cs = digitalio.DigitalInOut(board.D5) 36 | irq = digitalio.DigitalInOut(board.D6) 37 | rst = digitalio.DigitalInOut(board.D4) 38 | 39 | # Feather M0 RFM9x Pinouts 40 | # cs = digitalio.DigitalInOut(board.RFM9X_CS) 41 | # irq = digitalio.DigitalInOut(board.RFM9X_D0) 42 | # rst = digitalio.DigitalInOut(board.RFM9X_RST) 43 | 44 | # TTN Device Address, 4 Bytes, MSB 45 | devaddr: bytearray4 = bytearray([0x00, 0x00, 0x00, 0x00]) 46 | 47 | # TTN Network Key, 16 Bytes, MSB 48 | nwkey: bytearray16 = bytearray( 49 | [ 50 | 0x00, 51 | 0x00, 52 | 0x00, 53 | 0x00, 54 | 0x00, 55 | 0x00, 56 | 0x00, 57 | 0x00, 58 | 0x00, 59 | 0x00, 60 | 0x00, 61 | 0x00, 62 | 0x00, 63 | 0x00, 64 | 0x00, 65 | 0x00, 66 | ] 67 | ) 68 | 69 | # TTN Application Key, 16 Bytess, MSB 70 | app: bytearray16 = bytearray( 71 | [ 72 | 0x00, 73 | 0x00, 74 | 0x00, 75 | 0x00, 76 | 0x00, 77 | 0x00, 78 | 0x00, 79 | 0x00, 80 | 0x00, 81 | 0x00, 82 | 0x00, 83 | 0x00, 84 | 0x00, 85 | 0x00, 86 | 0x00, 87 | 0x00, 88 | ] 89 | ) 90 | 91 | ttn_config = TTN(devaddr, nwkey, app, country="US") 92 | 93 | lora = TinyLoRa(spi, cs, irq, rst, ttn_config) 94 | 95 | # Data Packet to send to TTN 96 | data: bytearray4 = bytearray(4) 97 | 98 | while True: 99 | temp_val = sensor.temperature 100 | humid_val = sensor.relative_humidity 101 | print("Temperature: %0.2f C" % temp_val) 102 | print("relative humidity: %0.1f %%" % humid_val) 103 | 104 | # Encode float as int 105 | temp_val = int(temp_val * 100) 106 | humid_val = int(humid_val * 100) 107 | 108 | # Encode payload as bytes 109 | data[0] = (temp_val >> 8) & 0xFF 110 | data[1] = temp_val & 0xFF 111 | data[2] = (humid_val >> 8) & 0xFF 112 | data[3] = humid_val & 0xFF 113 | 114 | # Send data packet 115 | print("Sending packet...") 116 | lora.send_data(data, len(data), lora.frame_counter) 117 | print("Packet Sent!") 118 | led.value = True 119 | lora.frame_counter += 1 120 | time.sleep(2) 121 | led.value = False 122 | -------------------------------------------------------------------------------- /examples/tinylora_simpletest_single_channel.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # SPDX-License-Identifier: MIT 3 | 4 | import time 5 | 6 | import board 7 | import busio 8 | import digitalio 9 | 10 | from adafruit_tinylora.adafruit_tinylora import TTN, TinyLoRa 11 | 12 | try: 13 | from adafruit_tinylora.adafruit_tinylora import bytearray4, bytearray16 14 | except ImportError: 15 | pass 16 | 17 | # Board LED 18 | led = digitalio.DigitalInOut(board.D13) 19 | led.direction = digitalio.Direction.OUTPUT 20 | 21 | spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 22 | 23 | # RFM9x Breakout Pinouts 24 | cs = digitalio.DigitalInOut(board.D5) 25 | irq = digitalio.DigitalInOut(board.D6) 26 | rst = digitalio.DigitalInOut(board.D4) 27 | 28 | # Feather M0 RFM9x Pinouts 29 | # cs = digitalio.DigitalInOut(board.RFM9X_CS) 30 | # irq = digitalio.DigitalInOut(board.RFM9X_D0) 31 | # rst = digitalio.DigitalInOut(board.RFM9X_RST) 32 | 33 | # TTN Device Address, 4 Bytes, MSB 34 | devaddr: bytearray4 = bytearray([0x00, 0x00, 0x00, 0x00]) 35 | 36 | # TTN Network Key, 16 Bytes, MSB 37 | nwkey: bytearray16 = bytearray( 38 | [ 39 | 0x00, 40 | 0x00, 41 | 0x00, 42 | 0x00, 43 | 0x00, 44 | 0x00, 45 | 0x00, 46 | 0x00, 47 | 0x00, 48 | 0x00, 49 | 0x00, 50 | 0x00, 51 | 0x00, 52 | 0x00, 53 | 0x00, 54 | 0x00, 55 | ] 56 | ) 57 | 58 | # TTN Application Key, 16 Bytess, MSB 59 | app: bytearray16 = bytearray( 60 | [ 61 | 0x00, 62 | 0x00, 63 | 0x00, 64 | 0x00, 65 | 0x00, 66 | 0x00, 67 | 0x00, 68 | 0x00, 69 | 0x00, 70 | 0x00, 71 | 0x00, 72 | 0x00, 73 | 0x00, 74 | 0x00, 75 | 0x00, 76 | 0x00, 77 | ] 78 | ) 79 | 80 | ttn_config = TTN(devaddr, nwkey, app, country="US") 81 | 82 | # Broadcasting on channel 0 in US Region - 903.9 MHz 83 | lora = TinyLoRa(spi, cs, irq, rst, ttn_config, channel=0) 84 | 85 | while True: 86 | data = bytearray(b"\x43\x57\x54\x46") 87 | print("Sending packet...") 88 | lora.send_data(data, len(data), lora.frame_counter) 89 | print("Packet sent!") 90 | led.value = True 91 | lora.frame_counter += 1 92 | time.sleep(1) 93 | led.value = False 94 | -------------------------------------------------------------------------------- /optional_requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | [build-system] 6 | requires = [ 7 | "setuptools", 8 | "wheel", 9 | "setuptools-scm", 10 | ] 11 | 12 | [project] 13 | name = "adafruit-circuitpython-tinylora" 14 | description = "CircuitPython library for LoRaWAN and The Things Network." 15 | version = "0.0.0+auto.0" 16 | readme = "README.rst" 17 | authors = [ 18 | {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} 19 | ] 20 | urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_TinyLoRa"} 21 | keywords = [ 22 | "adafruit", 23 | "lorawan", 24 | "thethingsnetwork", 25 | "hardware", 26 | "micropython", 27 | "circuitpython", 28 | ] 29 | license = {text = "MIT"} 30 | classifiers = [ 31 | "Intended Audience :: Developers", 32 | "Topic :: Software Development :: Libraries", 33 | "Topic :: Software Development :: Embedded Systems", 34 | "Topic :: System :: Hardware", 35 | "License :: OSI Approved :: MIT License", 36 | "Programming Language :: Python :: 3", 37 | ] 38 | dynamic = ["dependencies", "optional-dependencies"] 39 | 40 | [tool.setuptools] 41 | packages = ["adafruit_tinylora"] 42 | 43 | [tool.setuptools.dynamic] 44 | dependencies = {file = ["requirements.txt"]} 45 | optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} 46 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | Adafruit-Blinka 6 | adafruit-circuitpython-busdevice 7 | typing_extensions 8 | -------------------------------------------------------------------------------- /ruff.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | target-version = "py38" 6 | line-length = 100 7 | 8 | [lint] 9 | preview = true 10 | select = ["I", "PL", "UP"] 11 | 12 | extend-select = [ 13 | "D419", # empty-docstring 14 | "E501", # line-too-long 15 | "W291", # trailing-whitespace 16 | "PLC0414", # useless-import-alias 17 | "PLC2401", # non-ascii-name 18 | "PLC2801", # unnecessary-dunder-call 19 | "PLC3002", # unnecessary-direct-lambda-call 20 | "E999", # syntax-error 21 | "PLE0101", # return-in-init 22 | "F706", # return-outside-function 23 | "F704", # yield-outside-function 24 | "PLE0116", # continue-in-finally 25 | "PLE0117", # nonlocal-without-binding 26 | "PLE0241", # duplicate-bases 27 | "PLE0302", # unexpected-special-method-signature 28 | "PLE0604", # invalid-all-object 29 | "PLE0605", # invalid-all-format 30 | "PLE0643", # potential-index-error 31 | "PLE0704", # misplaced-bare-raise 32 | "PLE1141", # dict-iter-missing-items 33 | "PLE1142", # await-outside-async 34 | "PLE1205", # logging-too-many-args 35 | "PLE1206", # logging-too-few-args 36 | "PLE1307", # bad-string-format-type 37 | "PLE1310", # bad-str-strip-call 38 | "PLE1507", # invalid-envvar-value 39 | "PLE2502", # bidirectional-unicode 40 | "PLE2510", # invalid-character-backspace 41 | "PLE2512", # invalid-character-sub 42 | "PLE2513", # invalid-character-esc 43 | "PLE2514", # invalid-character-nul 44 | "PLE2515", # invalid-character-zero-width-space 45 | "PLR0124", # comparison-with-itself 46 | "PLR0202", # no-classmethod-decorator 47 | "PLR0203", # no-staticmethod-decorator 48 | "UP004", # useless-object-inheritance 49 | "PLR0206", # property-with-parameters 50 | "PLR0904", # too-many-public-methods 51 | "PLR0911", # too-many-return-statements 52 | "PLR0912", # too-many-branches 53 | "PLR0913", # too-many-arguments 54 | "PLR0914", # too-many-locals 55 | "PLR0915", # too-many-statements 56 | "PLR0916", # too-many-boolean-expressions 57 | "PLR1702", # too-many-nested-blocks 58 | "PLR1704", # redefined-argument-from-local 59 | "PLR1711", # useless-return 60 | "C416", # unnecessary-comprehension 61 | "PLR1733", # unnecessary-dict-index-lookup 62 | "PLR1736", # unnecessary-list-index-lookup 63 | 64 | # ruff reports this rule is unstable 65 | #"PLR6301", # no-self-use 66 | 67 | "PLW0108", # unnecessary-lambda 68 | "PLW0120", # useless-else-on-loop 69 | "PLW0127", # self-assigning-variable 70 | "PLW0129", # assert-on-string-literal 71 | "B033", # duplicate-value 72 | "PLW0131", # named-expr-without-context 73 | "PLW0245", # super-without-brackets 74 | "PLW0406", # import-self 75 | "PLW0602", # global-variable-not-assigned 76 | "PLW0603", # global-statement 77 | "PLW0604", # global-at-module-level 78 | 79 | # fails on the try: import typing used by libraries 80 | #"F401", # unused-import 81 | 82 | "F841", # unused-variable 83 | "E722", # bare-except 84 | "PLW0711", # binary-op-exception 85 | "PLW1501", # bad-open-mode 86 | "PLW1508", # invalid-envvar-default 87 | "PLW1509", # subprocess-popen-preexec-fn 88 | "PLW2101", # useless-with-lock 89 | "PLW3301", # nested-min-max 90 | ] 91 | 92 | ignore = [ 93 | "PLR2004", # magic-value-comparison 94 | "UP030", # format literals 95 | "PLW1514", # unspecified-encoding 96 | "PLR0913", # too-many-arguments 97 | "PLR0915", # too-many-statements 98 | "PLR0917", # too-many-positional-arguments 99 | "PLR0904", # too-many-public-methods 100 | "PLR0912", # too-many-branches 101 | "PLR0916", # too-many-boolean-expressions 102 | "PLR6301", # could-be-static no-self-use 103 | "PLC0415", # import outside toplevel 104 | "PLC2701", # private import 105 | ] 106 | 107 | [format] 108 | line-ending = "lf" 109 | --------------------------------------------------------------------------------