├── .codespellrc ├── .github ├── dependabot.yml └── workflows │ ├── check-arduino.yml │ ├── compile-examples.yml │ ├── report-size-deltas.yml │ ├── spell-check.yml │ └── sync-labels.yml ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── docs ├── api.md └── readme.md ├── examples ├── EventTrigger │ └── EventTrigger.ino ├── FirstConfiguration │ └── FirstConfiguration.ino ├── SendBoolean │ └── SendBoolean.ino ├── WeatherMonitor │ ├── WeatherMonitor.ino │ └── conversions.h └── WeatherMonitorStream │ ├── WeatherMonitorStream.ino │ └── conversions.h ├── keywords.txt ├── library.properties └── src ├── SigFox.cpp └── SigFox.h /.codespellrc: -------------------------------------------------------------------------------- 1 | # See: https://github.com/codespell-project/codespell#using-a-config-file 2 | [codespell] 3 | # In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: 4 | ignore-words-list = , 5 | check-filenames = 6 | check-hidden = 7 | skip = ./.git 8 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # See: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#about-the-dependabotyml-file 2 | version: 2 3 | 4 | updates: 5 | # Configure check for outdated GitHub Actions actions in workflows. 6 | # See: https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot 7 | - package-ecosystem: github-actions 8 | directory: / # Check the repository's workflows under /.github/workflows/ 9 | schedule: 10 | interval: daily 11 | -------------------------------------------------------------------------------- /.github/workflows/check-arduino.yml: -------------------------------------------------------------------------------- 1 | name: Check Arduino 2 | 3 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows 4 | on: 5 | push: 6 | pull_request: 7 | schedule: 8 | # Run every Tuesday at 8 AM UTC to catch breakage caused by new rules added to Arduino Lint. 9 | - cron: "0 8 * * TUE" 10 | workflow_dispatch: 11 | repository_dispatch: 12 | 13 | jobs: 14 | lint: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - name: Checkout repository 19 | uses: actions/checkout@v4 20 | 21 | - name: Arduino Lint 22 | uses: arduino/arduino-lint-action@v2 23 | with: 24 | compliance: specification 25 | library-manager: update 26 | # Always use this setting for official repositories. Remove for 3rd party projects. 27 | official: true 28 | project-type: library 29 | -------------------------------------------------------------------------------- /.github/workflows/compile-examples.yml: -------------------------------------------------------------------------------- 1 | name: Compile Examples 2 | 3 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows 4 | on: 5 | push: 6 | paths: 7 | - ".github/workflows/compile-examples.yml" 8 | - "library.properties" 9 | - "examples/**" 10 | - "src/**" 11 | pull_request: 12 | paths: 13 | - ".github/workflows/compile-examples.yml" 14 | - "library.properties" 15 | - "examples/**" 16 | - "src/**" 17 | schedule: 18 | # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms). 19 | - cron: "0 8 * * TUE" 20 | workflow_dispatch: 21 | repository_dispatch: 22 | 23 | jobs: 24 | build: 25 | name: ${{ matrix.board.fqbn }} 26 | runs-on: ubuntu-latest 27 | 28 | env: 29 | SKETCHES_REPORTS_PATH: sketches-reports 30 | 31 | strategy: 32 | fail-fast: false 33 | 34 | matrix: 35 | board: 36 | - fqbn: arduino:samd:mkrfox1200 37 | platforms: | 38 | - name: arduino:samd 39 | artifact-name-suffix: arduino-samd-mkrfox1200 40 | 41 | steps: 42 | - name: Checkout repository 43 | uses: actions/checkout@v4 44 | 45 | - name: Compile examples 46 | uses: arduino/compile-sketches@v1 47 | with: 48 | github-token: ${{ secrets.GITHUB_TOKEN }} 49 | fqbn: ${{ matrix.board.fqbn }} 50 | platforms: ${{ matrix.board.platforms }} 51 | libraries: | 52 | # Install the library from the local path. 53 | - source-path: ./ 54 | - name: Adafruit BMP280 Library 55 | - name: Adafruit HTU21DF Library 56 | - name: Adafruit TSL2561 57 | - name: Arduino Low Power 58 | sketch-paths: | 59 | - examples 60 | enable-deltas-report: true 61 | sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} 62 | 63 | - name: Save sketches report as workflow artifact 64 | uses: actions/upload-artifact@v4 65 | with: 66 | if-no-files-found: error 67 | path: ${{ env.SKETCHES_REPORTS_PATH }} 68 | name: sketches-report-${{ matrix.board.artifact-name-suffix }} 69 | -------------------------------------------------------------------------------- /.github/workflows/report-size-deltas.yml: -------------------------------------------------------------------------------- 1 | name: Report Size Deltas 2 | 3 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows 4 | on: 5 | push: 6 | paths: 7 | - ".github/workflows/report-size-deltas.yml" 8 | schedule: 9 | # Run at the minimum interval allowed by GitHub Actions. 10 | # Note: GitHub Actions periodically has outages which result in workflow failures. 11 | # In this event, the workflows will start passing again once the service recovers. 12 | - cron: "*/5 * * * *" 13 | workflow_dispatch: 14 | repository_dispatch: 15 | 16 | jobs: 17 | report: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: Comment size deltas reports to PRs 21 | uses: arduino/report-size-deltas@v1 22 | with: 23 | # Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow 24 | sketches-reports-source: ^sketches-report-.+ 25 | -------------------------------------------------------------------------------- /.github/workflows/spell-check.yml: -------------------------------------------------------------------------------- 1 | name: Spell Check 2 | 3 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows 4 | on: 5 | push: 6 | pull_request: 7 | schedule: 8 | # Run every Tuesday at 8 AM UTC to catch new misspelling detections resulting from dictionary updates. 9 | - cron: "0 8 * * TUE" 10 | workflow_dispatch: 11 | repository_dispatch: 12 | 13 | jobs: 14 | spellcheck: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - name: Checkout repository 19 | uses: actions/checkout@v4 20 | 21 | - name: Spell check 22 | uses: codespell-project/actions-codespell@master 23 | -------------------------------------------------------------------------------- /.github/workflows/sync-labels.yml: -------------------------------------------------------------------------------- 1 | # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md 2 | name: Sync Labels 3 | 4 | # See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows 5 | on: 6 | push: 7 | paths: 8 | - ".github/workflows/sync-labels.ya?ml" 9 | - ".github/label-configuration-files/*.ya?ml" 10 | pull_request: 11 | paths: 12 | - ".github/workflows/sync-labels.ya?ml" 13 | - ".github/label-configuration-files/*.ya?ml" 14 | schedule: 15 | # Run daily at 8 AM UTC to sync with changes to shared label configurations. 16 | - cron: "0 8 * * *" 17 | workflow_dispatch: 18 | repository_dispatch: 19 | 20 | env: 21 | CONFIGURATIONS_FOLDER: .github/label-configuration-files 22 | CONFIGURATIONS_ARTIFACT: label-configuration-files 23 | 24 | jobs: 25 | check: 26 | runs-on: ubuntu-latest 27 | 28 | steps: 29 | - name: Checkout repository 30 | uses: actions/checkout@v4 31 | 32 | - name: Download JSON schema for labels configuration file 33 | id: download-schema 34 | uses: carlosperate/download-file-action@v2 35 | with: 36 | file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json 37 | location: ${{ runner.temp }}/label-configuration-schema 38 | 39 | - name: Install JSON schema validator 40 | run: | 41 | sudo npm install \ 42 | --global \ 43 | ajv-cli \ 44 | ajv-formats 45 | 46 | - name: Validate local labels configuration 47 | run: | 48 | # See: https://github.com/ajv-validator/ajv-cli#readme 49 | ajv validate \ 50 | --all-errors \ 51 | -c ajv-formats \ 52 | -s "${{ steps.download-schema.outputs.file-path }}" \ 53 | -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" 54 | 55 | download: 56 | needs: check 57 | runs-on: ubuntu-latest 58 | 59 | strategy: 60 | matrix: 61 | filename: 62 | # Filenames of the shared configurations to apply to the repository in addition to the local configuration. 63 | # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels 64 | - universal.yml 65 | 66 | steps: 67 | - name: Download 68 | uses: carlosperate/download-file-action@v2 69 | with: 70 | file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} 71 | 72 | - name: Pass configuration files to next job via workflow artifact 73 | uses: actions/upload-artifact@v4 74 | with: 75 | path: | 76 | *.yaml 77 | *.yml 78 | if-no-files-found: error 79 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 80 | 81 | sync: 82 | needs: download 83 | runs-on: ubuntu-latest 84 | 85 | steps: 86 | - name: Set environment variables 87 | run: | 88 | # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable 89 | echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" 90 | 91 | - name: Determine whether to dry run 92 | id: dry-run 93 | if: > 94 | github.event_name == 'pull_request' || 95 | ( 96 | ( 97 | github.event_name == 'push' || 98 | github.event_name == 'workflow_dispatch' 99 | ) && 100 | github.ref != format('refs/heads/{0}', github.event.repository.default_branch) 101 | ) 102 | run: | 103 | # Use of this flag in the github-label-sync command will cause it to only check the validity of the 104 | # configuration. 105 | echo "::set-output name=flag::--dry-run" 106 | 107 | - name: Checkout repository 108 | uses: actions/checkout@v4 109 | 110 | - name: Download configuration files artifact 111 | uses: actions/download-artifact@v4 112 | with: 113 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 114 | path: ${{ env.CONFIGURATIONS_FOLDER }} 115 | 116 | - name: Remove unneeded artifact 117 | uses: geekyeggo/delete-artifact@v5 118 | with: 119 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 120 | 121 | - name: Merge label configuration files 122 | run: | 123 | # Merge all configuration files 124 | shopt -s extglob 125 | cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" 126 | 127 | - name: Install github-label-sync 128 | run: sudo npm install --global github-label-sync 129 | 130 | - name: Sync labels 131 | env: 132 | GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} 133 | run: | 134 | # See: https://github.com/Financial-Times/github-label-sync 135 | github-label-sync \ 136 | --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ 137 | ${{ steps.dry-run.outputs.flag }} \ 138 | ${{ github.repository }} 139 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | 3 | This library is the culmination of the expertise of many members of the open source community who have dedicated their time and hard work. The best way to ask for help or propose a new idea is to [create a new issue](https://github.com/arduino-libraries/SigFox/issues/new), while creating a Pull Request with your code changes allows you to share your own innovations with the rest of the community. 4 | 5 | The following are some guidelines to observe when creating issues or PRs: 6 | 7 | - Be friendly; it is important that we can all enjoy a safe space as we are all working on the same project and it is okay for people to have different ideas 8 | 9 | - [Use code blocks](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code); it helps us help you when we can read your code! On that note also refrain from pasting more than 30 lines of code in a post, instead [create a gist](https://gist.github.com/) if you need to share large snippets 10 | 11 | - Use reasonable titles; refrain from using overly long or capitalized titles as they are usually annoying and do little to encourage others to help :smile: 12 | 13 | - Be detailed; refrain from mentioning code problems without sharing your source code and always give information regarding your board and version of the library 14 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | , 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SigFox Library 2 | 3 | [![Check Arduino status](https://github.com/arduino-libraries/SigFox/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/SigFox/actions/workflows/check-arduino.yml) 4 | [![Compile Examples status](https://github.com/arduino-libraries/SigFox/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/SigFox/actions/workflows/compile-examples.yml) 5 | [![Spell Check status](https://github.com/arduino-libraries/SigFox/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/SigFox/actions/workflows/spell-check.yml) 6 | 7 | ## Description 8 | 9 | This library allows you to use the ATMEL SigFox transceiver (ATAB8520E) on the Arduino MKRFOX1200 board. For additional information on the Arduino MKR Fox 1200 board, see the [Getting Started page](https://www.arduino.cc/en/Guide/MKRFox1200) and the [product page](https://store.arduino.cc/arduino-mkr-fox-1200-1408). 10 | 11 | SigFox employs a cellular system that enables remote devices to connect using Ultra-Narrow Band (UNB) technology. It requires little energy, being termed Low-power Wide-area network (LPWAN). 12 | 13 | ## Installation 14 | 15 | ![image](https://user-images.githubusercontent.com/36513474/67494578-d9213100-f692-11e9-9cc2-e18e69ae7d3c.png) 16 | 17 | ### First Method 18 | 19 | 1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries 20 | 1. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation. 21 | 1. Then search for SigFox using the search bar. 22 | 1. Click on the text area and then select the specific version and install it. 23 | 24 | ### Second Method 25 | 26 | 1. Navigate to the Releases page. 27 | 1. Download the latest release. 28 | 1. Extract the zip file 29 | 1. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library 30 | 31 | ## Features 32 | 33 | - ### Ultra Narrowband 34 | 35 | This library enables remote devices to use UNB. The benefit of using ultra narrowband receiver is that it rejects noise and interference which may enter the receiver, enabling an acceptable signal-to-noise ratio to be achieved with a relatively weak received signal 36 | 37 | - ### LPWAN 38 | 39 | SigFox library requires Low Powered Wide Area Network. This technology connects low-bandwidth devices with low rate of bits over long ranges. 40 | 41 | - ### Good fit for small applications 42 | 43 | This library is a good fit for any application that needs to send small, infrequent bursts of data. Things like basic alarm systems, location monitoring, and simple metering are all examples of one-way systems that might make sense for this network. 44 | 45 | - ### Give back 46 | 47 | SigFox is free for everyone. The licensed document can be copied, redistributed and used in the projects, assignments or anywhere. 48 | 49 | - ### Licensed Document 50 | 51 | Library is licensed under GNU lesser General Public License. It's not allowed to make changes in the functions or anything. The user simply has to import the library in the project and can use any of its functions by just calling it. 52 | 53 | ## Functions 54 | 55 | - begin() 56 | - beginPacket() 57 | - write() 58 | - print() 59 | - endPacket() 60 | - parsePacket() 61 | - statusCode() 62 | - AtmVersion() 63 | - SigVersion() 64 | - ID() 65 | - PAC() 66 | - reset() 67 | - internalTemperature() 68 | - debug() 69 | - noDebug() 70 | - end() 71 | - peek() 72 | - available() 73 | - read() 74 | 75 | For further functions description visit [SigFox](https://www.arduino.cc/en/Reference/SigFox) 76 | 77 | ## Example 78 | 79 | There are many examples implemented where this library is used. You can find other examples from [Github-SigFox](https://github.com/arduino-libraries/SigFox/tree/master/examples) and [Arduino-Reference](https://www.arduino.cc/en/Reference/SigFox) 80 | 81 | - ### Send Boolean 82 | 83 | This sketch demonstrates how to send a simple binary data ( 0 or 1 ) using a MKR Fox 1200. If the application only needs to send one bit of information the transmission time (and thus power consumption) will be much lower than sending a full 12 bytes packet. 84 | 85 | ``` C++ 86 | #include 87 | 88 | bool value_to_send = true; 89 | 90 | #define DEBUG 1 91 | 92 | void setup() { 93 | 94 | if (DEBUG){ 95 | Serial.begin(9600); 96 | while (!Serial) {}; 97 | } 98 | 99 | if (!SigFox.begin()) { 100 | if (DEBUG){ 101 | Serial.println("Sigfox module unavailable !"); 102 | } 103 | return; 104 | } 105 | 106 | if (DEBUG){ 107 | SigFox.debug(); 108 | Serial.println("ID = " + SigFox.ID()); 109 | } 110 | 111 | delay(100); 112 | 113 | SigFox.beginPacket(); 114 | SigFox.write(value_to_send); 115 | int ret = SigFox.endPacket(); 116 | 117 | if (DEBUG){ 118 | Serial.print("Status : "); 119 | Serial.println(ret); 120 | } 121 | } 122 | 123 | void loop(){} 124 | ``` 125 | 126 | ## Contributing 127 | 128 | If you want to contribute to this project: 129 | 130 | - Report bugs and errors 131 | - Ask for enhancements 132 | - Create issues and pull requests 133 | - Tell others about this library 134 | - Contribute new protocols 135 | 136 | Please read [CONTRIBUTING.md](https://github.com/arduino-libraries/SigFox/blob/master/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. 137 | 138 | ## Credits 139 | 140 | The Library created and maintained by Arduino LLC 141 | 142 | Based on previous work by: 143 | 144 | - M. Facchin 145 | - N. Lesconnec 146 | - N. Barcucci 147 | 148 | ## Current stable version 149 | 150 | **version:** v1.0.4 151 | 152 | ## License 153 | 154 | This library is licensed under [GNU LGPL](https://www.gnu.org/licenses/lgpl-3.0.en.html). 155 | -------------------------------------------------------------------------------- /docs/api.md: -------------------------------------------------------------------------------- 1 | # Sigfox Library 2 | 3 | ## Sigfox Class 4 | 5 | ### `SigFox.begin()` 6 | 7 | #### Description 8 | 9 | Initializes the Sigfox library and module 10 | 11 | #### Syntax 12 | 13 | ``` 14 | SigFox.begin(); 15 | ``` 16 | 17 | #### Parameters 18 | None 19 | 20 | 21 | #### Returns 22 | true if correctly configured, false otherwise 23 | 24 | #### Example 25 | 26 | ``` 27 | #include 28 | #include 29 | 30 | void setup() { 31 | Serial.begin(115200); 32 | while (!Serial) {}; 33 | 34 | if (!SigFox.begin()) { 35 | Serial.println("Shield error or not present!"); 36 | return; 37 | } 38 | 39 | void loop(){ 40 | } 41 | ``` 42 | 43 | ### `SigFox.beginPacket()` 44 | 45 | #### Description 46 | 47 | Begins the process of sending a packet 48 | 49 | #### Syntax 50 | 51 | ``` 52 | SigFox.beginPacket(); 53 | ``` 54 | 55 | #### Parameters 56 | None 57 | 58 | #### Example 59 | 60 | ``` 61 | #include 62 | #include 63 | 64 | void setup() { 65 | Serial.begin(115200); 66 | while (!Serial) {}; 67 | 68 | if (!SigFox.begin()) { 69 | Serial.println("Shield error or not present!"); 70 | return; 71 | } 72 | 73 | void loop(){ 74 | SigFox.begin(); 75 | SigFox.beginPacket(); 76 | SigFox.print("123456789012"); 77 | SigFox.endPacket(); 78 | while(1); 79 | } 80 | ``` 81 | 82 | ### `SigFox.write()` 83 | 84 | #### Description 85 | 86 | Sends binary data to the SigFox's backend. This data is sent as a byte or series of bytes; to send the characters representing the digits of a number use the print() function instead. 87 | 88 | #### Syntax 89 | 90 | ``` 91 | SigFox.write(val) 92 | SigFox.write(str) 93 | SigFox.write(buf, len) 94 | ``` 95 | 96 | #### Parameters 97 | val: a value to send as a single byte 98 | 99 | str: a string to send as a series of bytes 100 | 101 | buf: an array to send as a series of bytes 102 | 103 | len: the length of the buffer 104 | 105 | ### `SigFox.print()` 106 | 107 | #### Description 108 | 109 | Sends characters data to the SigFox's backend. This data is sent as a character or series of characters; to send the binary data use the write() function instead. 110 | 111 | #### Syntax 112 | 113 | ``` 114 | SigFox.print(val) 115 | SigFox.print(str) 116 | SigFox.print(buf, len) 117 | ``` 118 | 119 | #### Parameters 120 | val: a value to send characters representing the value 121 | 122 | str: a string to send as a series of characters 123 | 124 | buf: an array to send as a series of characters 125 | 126 | len: the length of the buffer 127 | 128 | ### `SigFox.endPacket()` 129 | 130 | #### Description 131 | 132 | Called after writing SigFox data to the remote connection, completes the process of sending a packet started by beginPacket. 133 | 134 | #### Syntax 135 | 136 | ``` 137 | SigFox.endPacket(); 138 | ``` 139 | 140 | #### Return 141 | Returns an int: 1 if the packet was sent successfully, 0 if there was an error 142 | 143 | 144 | #### Example 145 | 146 | ``` 147 | #include 148 | #include 149 | 150 | void setup() { 151 | Serial.begin(115200); 152 | while (!Serial) {}; 153 | 154 | if (!SigFox.begin()) { 155 | Serial.println("Shield error or not present!"); 156 | return; 157 | } 158 | 159 | void loop() { 160 | SigFox.begin(); 161 | SigFox.beginPacket(); 162 | SigFox.print("123456789012"); 163 | int ret = SigFox.endPacket(); 164 | if (ret == 0) 165 | Serial.println("OK"); 166 | else 167 | Serial.println("KO"); 168 | while (1); 169 | } 170 | ``` 171 | 172 | ### `SigFox.parsePacket()` 173 | 174 | #### Description 175 | 176 | Checks for the presence of a SigFox packet, and reports the size. parsePacket() must be called before reading the buffer with SigFox.read(). 177 | 178 | #### Syntax 179 | 180 | ``` 181 | SigFox.parsePacket() 182 | ``` 183 | 184 | #### Parameters 185 | None 186 | 187 | 188 | #### Returns 189 | int: the size of a received SigFox packet 190 | 191 | ### `SigFox.statusCode()` 192 | 193 | #### Description 194 | 195 | Returns the protocol status code 196 | 197 | #### Syntax 198 | 199 | ``` 200 | SigFox.statusCode(protocol); 201 | ``` 202 | 203 | #### Parameters 204 | 205 | protocol: can be one of either: 206 | 207 | - SSM 208 | - ATMEL 209 | - SIGFOX 210 | 211 | #### Returns 212 | the status code of the chosen protocol: 213 | 214 | **SSM** 215 | 216 | TBD 217 | 218 | **Atmel** 219 | 220 | Bit0: PA on/off indication 221 | Bit6: System ready to operate (system ready event) 222 | Bit5: Frame sent (frame ready event) 223 | Bit4 to Bit1: Error code 224 | 225 | - 0000: no error 226 | - 0001: command error / not supported 227 | - 0010: generic error 228 | - 0011: frequency error 229 | - 0100: usage error 230 | - 0101: opening error 231 | - 0110: closing error 232 | - 0111: send error 233 | 234 | **SIGFOX** 235 | 236 | `0x00`: No error 237 | `0x01`: Manufacturer error 238 | `0x02`: ID or key error 239 | `0x03`: State machine error 240 | `0x04`: Frame size error 241 | `0x05`: Manufacturer send error 242 | `0x06`: Get voltage/temperature error 243 | `0x07`: Close issues encountered 244 | `0x08`: API error indication 245 | `0x09`: Error getting PN9 246 | `0x0A`: Error getting frequency 247 | `0x0B`: Error building frame 248 | `0x0C`: Error in delay routine 249 | `0x0D`: callback causes error 250 | `0x0E`: timing error 251 | `0x0F`: frequency error 252 | 253 | ### `SigFox.AtmVersion()` 254 | 255 | #### Description 256 | 257 | Returns the Atm version 258 | 259 | #### Syntax 260 | 261 | ``` 262 | SigFox.AtmVersion(); 263 | ``` 264 | 265 | #### Returns 266 | a String of 2 bytes containing the Atm version 267 | 268 | ### `SigFox.SigVersion()` 269 | 270 | #### Description 271 | 272 | Returns the module's firmware version 273 | 274 | #### Syntax 275 | 276 | ``` 277 | SigFox.SigVersion(); 278 | ``` 279 | 280 | #### Returns 281 | a String of 2 bytes containing the SigFox version 282 | 283 | ### `SigFox.ID()` 284 | 285 | #### Description 286 | 287 | Returns the module ID. When a module is manufactured, a unique SigFox ID is recorded in its permanent memory. It is very important to keep and store the ID tray carefully, as it will be useful to insure the tracability of these devices and to register them on a SigFox Network Operator (SNO). 288 | 289 | #### Syntax 290 | 291 | ``` 292 | SigFox.ID(); 293 | ``` 294 | 295 | #### Returns 296 | A String that contains the 4 bytes ID. 297 | 298 | ### `SigFox.PAC()` 299 | 300 | #### Description 301 | 302 | Returns the module PAC. For each module, a PAC key is a secret key corresponding to the Sigfox ID. The PAC key will be useful to register a device on a SigFox Network Operator (SNO). As opposed to the SigFox ID, a PAC key is not transferable and must be re-generated if the module's ownership is changed. 303 | 304 | #### Syntax 305 | 306 | ``` 307 | SigFox.PAC(); 308 | ``` 309 | 310 | #### Returns 311 | A String that contains the 16 bytes PAC. 312 | 313 | ### `SigFox.reset()` 314 | 315 | #### Description 316 | 317 | Resets the module 318 | 319 | #### Syntax 320 | 321 | ``` 322 | SigFox.reset(); 323 | ``` 324 | 325 | #### Returns 326 | None 327 | 328 | ### `SigFox.internalTemperature()` 329 | 330 | #### Description 331 | 332 | Returns the internal temperature sensor reading 333 | 334 | #### Syntax 335 | 336 | ``` 337 | SigFox.internalTemperature(); 338 | ``` 339 | 340 | #### Returns 341 | a float representing the reading 342 | 343 | ### `SigFox.debug()` 344 | 345 | #### Description 346 | 347 | Enable debugging. Enabling the debugging all the power saving features are disabled and the led indicated as signaling pin (LED_BUILTIN as default) is used during transmission and receive events. 348 | 349 | #### Syntax 350 | 351 | ``` 352 | SigFox.debug(); 353 | ``` 354 | 355 | #### Parameters 356 | None 357 | 358 | ### `SigFox.noDebug()` 359 | 360 | #### Description 361 | 362 | Disable debugging. Disabling the debugging all the power saving features are enabled and the led indicated as signaling pin (LED_BUILTIN as default) is not used during transmission and receive events. 363 | 364 | #### Syntax 365 | 366 | ``` 367 | SigFox.debug(); 368 | ``` 369 | 370 | #### Parameters 371 | None 372 | 373 | ### `SigFox.end()` 374 | 375 | #### Description 376 | 377 | De-initializes the Sigfox library and module 378 | 379 | #### Syntax 380 | 381 | ``` 382 | SigFox.end(); 383 | ``` 384 | 385 | #### Returns 386 | None 387 | 388 | #### Example 389 | 390 | ``` 391 | #include "SigFox.h" 392 | #include "ArduinoLowPower.h" 393 | 394 | void setup() { 395 | Serial.begin(115200); 396 | while (!Serial) {}; 397 | 398 | // Uncomment this line and comment begin() if you are working with a custom board 399 | //if (!SigFox.begin(SPI1, 30, 31, 33, 28, LED_BUILTIN)) { 400 | if (!SigFox.begin()) { 401 | Serial.println("Shield error or not present!"); 402 | return; 403 | else 404 | SigFox.end(); 405 | 406 | } 407 | 408 | void loop(){ 409 | } 410 | ``` 411 | 412 | ### `peek()` 413 | 414 | #### Description 415 | 416 | Returns the next byte (character) of incoming serial data without removing it from the internal buffer. That is, successive calls to peek() will return the same character, as will the next call to read(). peek() inherits from the Stream utility class. 417 | 418 | #### Syntax 419 | 420 | ``` 421 | SigFox.peek() 422 | ``` 423 | 424 | #### Parameters 425 | None 426 | 427 | 428 | #### Returns 429 | the first byte of incoming serial data available (or -1 if no data is available) - int 430 | 431 | ### `available()` 432 | 433 | #### Description 434 | 435 | Get the number of bytes (characters) available for reading. This is data that's already arrived and stored in a receive buffer (which holds 8 bytes). available() inherits from the Stream utility class. 436 | 437 | #### Syntax 438 | 439 | ``` 440 | SigFox.available() 441 | ``` 442 | 443 | #### Parameters 444 | none 445 | 446 | 447 | #### Returns 448 | the number of bytes available to read 449 | 450 | ### `read()` 451 | 452 | #### Description 453 | 454 | Reads incoming SigFox data. read() inherits from the Stream utility class. 455 | 456 | #### Syntax 457 | 458 | ``` 459 | SigFox.read() 460 | ``` 461 | 462 | #### Parameters 463 | None 464 | 465 | 466 | 467 | #### Returns 468 | the first byte of incoming SigFox data available (or -1 if no data is available) - int 469 | 470 | #### Example 471 | 472 | ``` 473 | /* 474 | SigFox First Configuration 475 | 476 | This sketch demonstrates the usage of MKRFox1200 SigFox module. 477 | Since the board is designed with low power in mind, it depends directly on ArduinoLowPower library 478 | 479 | This example code is in the public domain. 480 | */ 481 | 482 | #include 483 | #include 484 | 485 | void setup() { 486 | Serial.begin(9600); 487 | while (!Serial) {}; 488 | 489 | // Uncomment this line and comment begin() if you are working with a custom board 490 | //if (!SigFox.begin(SPI1, 30, 31, 33, 28, LED_BUILTIN)) { 491 | if (!SigFox.begin()) { 492 | Serial.println("Shield error or not present!"); 493 | return; 494 | } 495 | // Enable debug led and disable automatic deep sleep 496 | // Comment this line when shipping your project :) 497 | SigFox.debug(); 498 | 499 | String version = SigFox.SigVersion(); 500 | String ID = SigFox.ID(); 501 | String PAC = SigFox.PAC(); 502 | 503 | // Display module information 504 | Serial.println("MKRFox1200 Sigfox first configuration"); 505 | Serial.println("SigFox FW version " + version); 506 | Serial.println("ID = " + ID); 507 | Serial.println("PAC = " + PAC); 508 | 509 | Serial.println(""); 510 | 511 | Serial.print("Module temperature: "); 512 | Serial.println(SigFox.internalTemperature()); 513 | 514 | Serial.println("Register your board on https://backend.sigfox.com/activate with provided ID and PAC"); 515 | 516 | delay(100); 517 | 518 | // Send the module to the deepest sleep 519 | SigFox.end(); 520 | 521 | Serial.println("Type the message to be sent"); 522 | while (!Serial.available()); 523 | 524 | String message; 525 | while (Serial.available()) { 526 | message += (char)Serial.read(); 527 | } 528 | 529 | // Every SigFox packet cannot exceed 12 bytes 530 | // If the string is longer, only the first 12 bytes will be sent 531 | 532 | if (message.length() > 12) { 533 | Serial.println("Message too long, only first 12 bytes will be sent"); 534 | } 535 | 536 | Serial.println("Sending " + message); 537 | 538 | // Remove EOL 539 | message.trim(); 540 | 541 | // Example of message that can be sent 542 | // sendString(message); 543 | 544 | Serial.println("Getting the response will take up to 50 seconds"); 545 | Serial.println("The LED will blink while the operation is ongoing"); 546 | 547 | // Example of send and read response 548 | sendStringAndGetResponse(message); 549 | } 550 | 551 | void loop() 552 | { 553 | } 554 | 555 | void sendString(String str) { 556 | // Start the module 557 | SigFox.begin(); 558 | // Wait at least 30mS after first configuration (100mS before) 559 | delay(100); 560 | // Clears all pending interrupts 561 | SigFox.status(); 562 | delay(1); 563 | 564 | SigFox.beginPacket(); 565 | SigFox.print(str); 566 | 567 | int ret = SigFox.endPacket(); // send buffer to SIGFOX network 568 | if (ret > 0) { 569 | Serial.println("No transmission"); 570 | } else { 571 | Serial.println("Transmission ok"); 572 | } 573 | 574 | Serial.println(SigFox.status(SIGFOX)); 575 | Serial.println(SigFox.status(ATMEL)); 576 | SigFox.end(); 577 | } 578 | 579 | void sendStringAndGetResponse(String str) { 580 | // Start the module 581 | SigFox.begin(); 582 | // Wait at least 30mS after first configuration (100mS before) 583 | delay(100); 584 | // Clears all pending interrupts 585 | SigFox.status(); 586 | delay(1); 587 | 588 | SigFox.beginPacket(); 589 | SigFox.print(str); 590 | 591 | int ret = SigFox.endPacket(true); // send buffer to SIGFOX network and wait for a response 592 | if (ret > 0) { 593 | Serial.println("No transmission"); 594 | } else { 595 | Serial.println("Transmission ok"); 596 | } 597 | 598 | Serial.println(SigFox.status(SIGFOX)); 599 | Serial.println(SigFox.status(ATMEL)); 600 | 601 | if (SigFox.parsePacket()) { 602 | Serial.println("Response from server:"); 603 | while (SigFox.available()) { 604 | Serial.print("0x"); 605 | Serial.println(SigFox.read(), HEX); 606 | } 607 | } else { 608 | Serial.println("Could not get any response from the server"); 609 | Serial.println("Check the SigFox coverage in your area"); 610 | Serial.println("If you are indoor, check the 20dB coverage or move near a window"); 611 | } 612 | Serial.println(); 613 | 614 | SigFox.end(); 615 | } 616 | ``` -------------------------------------------------------------------------------- /docs/readme.md: -------------------------------------------------------------------------------- 1 | # SigFox library 2 | 3 | This library allows you to use the [ATMEL SigFox transceiver (ATAB8520E)](http://www.atmel.com/Images/Atmel-9415-ATA8520E-Production-and-EOL-Testing.pdf) on the [Arduino MKR FOX 1200](https://store.arduino.cc/products/arduino-mkr-fox-1200) board. You can find out more about this board through the following links: 4 | 5 | - [MKR FOX 1200 Store Page](https://store.arduino.cc/products/arduino-mkr-fox-1200). 6 | - [MKR FOX 1200 Documentation Page](). 7 | 8 | SigFox employs a cellular system that enables remote devices to connect using Ultra-Narrow Band (UNB) technology. It requires little energy, being termed Low-power Wide-area network (LPWAN). 9 | 10 | Check the SigFox [coverage](http://www.sigfox.com/coverage) in your area! 11 | 12 | To use this library: 13 | 14 | ``` 15 | #include 16 | ``` -------------------------------------------------------------------------------- /examples/EventTrigger/EventTrigger.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SigFox Event Trigger tutorial 3 | 4 | This sketch demonstrates the usage of a MKR Fox 1200 5 | to build a battery-powered alarm sensor with email notifications 6 | 7 | A couple of sensors (normally open) should be wired between pins 1 and 2 and GND. 8 | 9 | This example code is in the public domain. 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | // Set debug to false to enable continuous mode 16 | // and disable serial prints 17 | int debug = true; 18 | 19 | volatile int alarm_source = 0; 20 | 21 | void setup() { 22 | 23 | if (debug == true) { 24 | 25 | // We are using Serial1 instead of Serial because we are going into standby 26 | // and the USB port could get confused during wakeup. To read the debug prints, 27 | // connect pins 13-14 (TX-RX) to a 3.3 V USB-to-serial converter 28 | 29 | Serial1.begin(115200); 30 | while (!Serial1) {} 31 | } 32 | 33 | if (!SigFox.begin()) { 34 | //something is really wrong, try rebooting 35 | reboot(); 36 | } 37 | 38 | //Send module to standby until we need to send a message 39 | SigFox.end(); 40 | 41 | if (debug == true) { 42 | // Enable debug prints and LED indication if we are testing 43 | SigFox.debug(); 44 | } 45 | 46 | // attach pin 0 and 1 to a switch and enable the interrupt on voltage falling event 47 | pinMode(0, INPUT_PULLUP); 48 | LowPower.attachInterruptWakeup(0, alarmEvent1, FALLING); 49 | 50 | pinMode(1, INPUT_PULLUP); 51 | LowPower.attachInterruptWakeup(1, alarmEvent2, FALLING); 52 | } 53 | 54 | void loop() 55 | { 56 | // Sleep until an event is recognized 57 | LowPower.sleep(); 58 | 59 | // if we get here it means that an event was received 60 | 61 | SigFox.begin(); 62 | 63 | if (debug == true) { 64 | Serial1.println("Alarm event on sensor " + String(alarm_source)); 65 | } 66 | delay(100); 67 | 68 | // 3 bytes (ALM) + 8 bytes (ID as String) + 1 byte (source) < 12 bytes 69 | String to_be_sent = "ALM" + SigFox.ID() + String(alarm_source); 70 | 71 | SigFox.beginPacket(); 72 | SigFox.print(to_be_sent); 73 | int ret = SigFox.endPacket(); 74 | 75 | // shut down module, back to standby 76 | SigFox.end(); 77 | 78 | if (debug == true) { 79 | if (ret > 0) { 80 | Serial1.println("No transmission"); 81 | } else { 82 | Serial1.println("Transmission ok"); 83 | } 84 | 85 | Serial1.println(SigFox.status(SIGFOX)); 86 | Serial1.println(SigFox.status(ATMEL)); 87 | 88 | // Loop forever if we are testing for a single event 89 | while (1) {}; 90 | } 91 | } 92 | 93 | void alarmEvent1() { 94 | alarm_source = 1; 95 | } 96 | 97 | void alarmEvent2() { 98 | alarm_source = 2; 99 | } 100 | 101 | void reboot() { 102 | NVIC_SystemReset(); 103 | while (1); 104 | } 105 | -------------------------------------------------------------------------------- /examples/FirstConfiguration/FirstConfiguration.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SigFox First Configuration 3 | 4 | This sketch demonstrates the usage of MKR Fox 1200 Sigfox module. 5 | Since the board is designed with low power in mind, it depends directly on the ArduinoLowPower library 6 | 7 | This example code is in the public domain. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | void setup() { 14 | Serial.begin(9600); 15 | while (!Serial) {}; 16 | 17 | // Uncomment this line and comment begin() if you are working with a custom board 18 | //if (!SigFox.begin(SPI1, 30, 31, 33, 28, LED_BUILTIN)) { 19 | if (!SigFox.begin()) { 20 | Serial.println("Shield error or not present!"); 21 | return; 22 | } 23 | // Enable debug LED and disable automatic deep sleep 24 | // Comment this line when shipping your project :) 25 | SigFox.debug(); 26 | 27 | String version = SigFox.SigVersion(); 28 | String ID = SigFox.ID(); 29 | String PAC = SigFox.PAC(); 30 | 31 | // Display module information 32 | Serial.println("MKR Fox 1200 Sigfox first configuration"); 33 | Serial.println("SigFox FW version " + version); 34 | Serial.println("ID = " + ID); 35 | Serial.println("PAC = " + PAC); 36 | 37 | Serial.println(""); 38 | 39 | Serial.print("Module temperature: "); 40 | Serial.println(SigFox.internalTemperature()); 41 | 42 | Serial.println("Register your board on https://buy.sigfox.com/activate with provided ID and PAC"); 43 | Serial.println("The displayed PAC is the factory value. It is a throw-away value, which can only be used once for registration."); 44 | Serial.println("If this device has already been registered, you can retrieve the updated PAC value on https://backend.sigfox.com/device/list"); 45 | Serial.println("Join the Sigfox Builders Slack community to exchange with other developers, get help .. and find new ideas! https://builders.iotagency.sigfox.com/"); 46 | delay(100); 47 | 48 | // Send the module to the deepest sleep 49 | SigFox.end(); 50 | 51 | Serial.println("Type the message to be sent"); 52 | while (!Serial.available()); 53 | 54 | String message; 55 | while (Serial.available()) { 56 | message += (char)Serial.read(); 57 | } 58 | 59 | // Every SigFox packet cannot exceed 12 bytes 60 | // If the string is longer, only the first 12 bytes will be sent 61 | 62 | if (message.length() > 12) { 63 | Serial.println("Message too long, only first 12 bytes will be sent"); 64 | } 65 | 66 | Serial.println("Sending " + message); 67 | 68 | // Remove EOL 69 | message.trim(); 70 | 71 | // Example of message that can be sent 72 | // sendString(message); 73 | 74 | Serial.println("Getting the response will take up to 50 seconds"); 75 | Serial.println("The LED will blink while the operation is ongoing"); 76 | 77 | // Example of send and read response 78 | sendStringAndGetResponse(message); 79 | } 80 | 81 | void loop() 82 | { 83 | } 84 | 85 | void sendString(String str) { 86 | // Start the module 87 | SigFox.begin(); 88 | // Wait at least 30mS after first configuration (100mS before) 89 | delay(100); 90 | // Clears all pending interrupts 91 | SigFox.status(); 92 | delay(1); 93 | 94 | SigFox.beginPacket(); 95 | SigFox.print(str); 96 | 97 | int ret = SigFox.endPacket(); // send buffer to SIGFOX network 98 | if (ret > 0) { 99 | Serial.println("No transmission"); 100 | } else { 101 | Serial.println("Transmission ok"); 102 | } 103 | 104 | Serial.println(SigFox.status(SIGFOX)); 105 | Serial.println(SigFox.status(ATMEL)); 106 | SigFox.end(); 107 | } 108 | 109 | void sendStringAndGetResponse(String str) { 110 | // Start the module 111 | SigFox.begin(); 112 | // Wait at least 30mS after first configuration (100mS before) 113 | delay(100); 114 | // Clears all pending interrupts 115 | SigFox.status(); 116 | delay(1); 117 | 118 | SigFox.beginPacket(); 119 | SigFox.print(str); 120 | 121 | int ret = SigFox.endPacket(true); // send buffer to SIGFOX network and wait for a response 122 | if (ret > 0) { 123 | Serial.println("No transmission"); 124 | } else { 125 | Serial.println("Transmission ok"); 126 | } 127 | 128 | Serial.println(SigFox.status(SIGFOX)); 129 | Serial.println(SigFox.status(ATMEL)); 130 | 131 | if (SigFox.parsePacket()) { 132 | Serial.println("Response from server:"); 133 | while (SigFox.available()) { 134 | Serial.print("0x"); 135 | Serial.println(SigFox.read(), HEX); 136 | } 137 | } else { 138 | Serial.println("Could not get any response from the server"); 139 | Serial.println("Check the Sigfox coverage in your area"); 140 | Serial.println("If you are indoor, check the 20 dB coverage or move near a window"); 141 | } 142 | Serial.println(); 143 | 144 | SigFox.end(); 145 | } 146 | -------------------------------------------------------------------------------- /examples/SendBoolean/SendBoolean.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SigFox Send Boolean tutorial 3 | 4 | This sketch demonstrates how to send a simple binary data ( 0 or 1 ) using a MKR Fox 1200. 5 | If the application only needs to send one bit of information the transmission time 6 | (and thus power consumption) will be much lower than sending a full 12 bytes packet. 7 | 8 | This example code is in the public domain. 9 | */ 10 | 11 | #include 12 | 13 | // We want to send a Boolean value to signal a binary event 14 | // like open/close or on/off 15 | 16 | bool value_to_send = true; 17 | 18 | #define DEBUG 1 19 | 20 | void setup() { 21 | 22 | if (DEBUG){ 23 | Serial.begin(9600); 24 | while (!Serial) {}; 25 | } 26 | 27 | // Initialize the Sigfox module 28 | if (!SigFox.begin()) { 29 | if (DEBUG){ 30 | Serial.println("Sigfox module unavailable !"); 31 | } 32 | return; 33 | } 34 | 35 | // If we want to to debug the application, print the device ID to easily find it in the backend 36 | if (DEBUG){ 37 | SigFox.debug(); 38 | Serial.println("ID = " + SigFox.ID()); 39 | } 40 | 41 | delay(100); 42 | 43 | // Compose a message as usual; the single bit transmission will be performed transparently 44 | // if the data we want to send is suitable 45 | SigFox.beginPacket(); 46 | SigFox.write(value_to_send); 47 | int ret = SigFox.endPacket(); 48 | 49 | if (DEBUG){ 50 | Serial.print("Status : "); 51 | Serial.println(ret); 52 | } 53 | } 54 | 55 | void loop(){} 56 | -------------------------------------------------------------------------------- /examples/WeatherMonitor/WeatherMonitor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SigFox Simple Weather Station 3 | 4 | This sketch demonstrates the usage of MKR Fox 1200 as a simple weather station. 5 | It uses 6 | the onboard temperature sensor 7 | HTU21D I2C sensor to get humidity 8 | Bosch BMP280 to get the barometric pressure 9 | TSL2561 Light Sensor to get luminosity 10 | 11 | Download the needed libraries from the following links 12 | http://librarymanager/All#BMP280&Adafruit 13 | http://librarymanager/All#HTU21D&Adafruit 14 | http://librarymanager/All#TSL2561&Adafruit 15 | http://librarymanager/All#adafruit&sensor&abstraction 16 | 17 | Since the Sigfox network can send a maximum of 120 messages per day (depending on your plan) 18 | we'll optimize the readings and send data in compact binary format 19 | 20 | This example code is in the public domain. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "conversions.h" 30 | 31 | // Set oneshot to false to trigger continuous mode when you finished setting up the whole flow 32 | int oneshot = true; 33 | 34 | Adafruit_BMP280 bmp; 35 | Adafruit_HTU21DF htu = Adafruit_HTU21DF(); 36 | Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345); 37 | 38 | #define STATUS_OK 0 39 | #define STATUS_BMP_KO 1 40 | #define STATUS_HTU_KO 2 41 | #define STATUS_TSL_KO 4 42 | 43 | /* 44 | ATTENTION - the structure we are going to send MUST 45 | be declared "packed" otherwise we'll get padding mismatch 46 | on the sent data - see http://www.catb.org/esr/structure-packing/#_structure_alignment_and_padding 47 | for more details 48 | */ 49 | typedef struct __attribute__ ((packed)) sigfox_message { 50 | uint8_t status; 51 | int16_t moduleTemperature; 52 | int16_t bmpTemperature; 53 | uint16_t bmpPressure; 54 | uint16_t htuHumidity; 55 | uint16_t tlsLight; 56 | uint8_t lastMessageStatus; 57 | } SigfoxMessage; 58 | 59 | // stub for message which will be sent 60 | SigfoxMessage msg; 61 | 62 | void setup() { 63 | 64 | if (oneshot == true) { 65 | // Wait for the serial 66 | Serial.begin(115200); 67 | while (!Serial) {} 68 | } 69 | 70 | if (!SigFox.begin()) { 71 | // Something is really wrong, try rebooting 72 | // Reboot is useful if we are powering the board using an unreliable power source 73 | // (eg. solar panels or other energy harvesting methods) 74 | reboot(); 75 | } 76 | 77 | //Send module to standby until we need to send a message 78 | SigFox.end(); 79 | 80 | if (oneshot == true) { 81 | // Enable debug prints and LED indication if we are testing 82 | SigFox.debug(); 83 | } 84 | 85 | // Configure the sensors and populate the status field 86 | if (!bmp.begin()) { 87 | msg.status |= STATUS_BMP_KO; 88 | } else { 89 | Serial.println("BMP OK"); 90 | } 91 | 92 | if (!htu.begin()) { 93 | msg.status |= STATUS_HTU_KO; 94 | } else { 95 | Serial.println("HTU OK"); 96 | } 97 | 98 | if (!tsl.begin()) { 99 | msg.status |= STATUS_TSL_KO; 100 | } else { 101 | Serial.println("TLS OK"); 102 | tsl.enableAutoRange(true); 103 | tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); 104 | } 105 | } 106 | 107 | void loop() { 108 | // Every 15 minutes, read all the sensors and send them 109 | // Let's try to optimize the data format 110 | // Only use floats as intermediate representation, don't send them directly 111 | 112 | sensors_event_t event; 113 | 114 | float pressure = bmp.readPressure(); 115 | msg.bmpPressure = convertoFloatToUInt16(pressure, 200000); 116 | float temperature = bmp.readTemperature(); 117 | msg.bmpTemperature = convertoFloatToInt16(temperature, 60, -60); 118 | 119 | tsl.getEvent(&event); 120 | if (event.light) { 121 | msg.tlsLight = convertoFloatToUInt16(event.light, 100000); 122 | } 123 | 124 | float humidity = htu.readHumidity(); 125 | msg.htuHumidity = convertoFloatToUInt16(humidity, 110); 126 | 127 | // Start the module 128 | SigFox.begin(); 129 | // Wait at least 30 ms after first configuration (100 ms before) 130 | delay(100); 131 | 132 | // We can only read the module temperature before SigFox.end() 133 | temperature = SigFox.internalTemperature(); 134 | msg.moduleTemperature = convertoFloatToInt16(temperature, 60, -60); 135 | 136 | if (oneshot == true) { 137 | Serial.println("Pressure: " + String(pressure)); 138 | Serial.println("External temperature: " + String(temperature)); 139 | Serial.println("Internal temp: " + String(temperature)); 140 | Serial.println("Light: " + String(event.light)); 141 | Serial.println("Humidity: " + String(humidity)); 142 | } 143 | 144 | // Clears all pending interrupts 145 | SigFox.status(); 146 | delay(1); 147 | 148 | SigFox.beginPacket(); 149 | SigFox.write((uint8_t*)&msg, 12); 150 | 151 | msg.lastMessageStatus = SigFox.endPacket(); 152 | 153 | if (oneshot == true) { 154 | Serial.println("Status: " + String(msg.lastMessageStatus)); 155 | } 156 | 157 | SigFox.end(); 158 | 159 | if (oneshot == true) { 160 | // spin forever, so we can test that the backend is behaving correctly 161 | while (1) {} 162 | } 163 | 164 | //Sleep for 15 minutes 165 | LowPower.sleep(15 * 60 * 1000); 166 | } 167 | 168 | void reboot() { 169 | NVIC_SystemReset(); 170 | while (1); 171 | } 172 | -------------------------------------------------------------------------------- /examples/WeatherMonitor/conversions.h: -------------------------------------------------------------------------------- 1 | 2 | #define UINT16_t_MAX 65536 3 | #define INT16_t_MAX UINT16_t_MAX/2 4 | 5 | int16_t convertoFloatToInt16(float value, long max, long min) { 6 | float conversionFactor = (float) (INT16_t_MAX) / (float)(max - min); 7 | return (int16_t)(value * conversionFactor); 8 | } 9 | 10 | uint16_t convertoFloatToUInt16(float value, long max, long min = 0) { 11 | float conversionFactor = (float) (UINT16_t_MAX) / (float)(max - min); 12 | return (uint16_t)(value * conversionFactor); 13 | } 14 | -------------------------------------------------------------------------------- /examples/WeatherMonitorStream/WeatherMonitorStream.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SigFox Simple Weather Station 3 | 4 | This sketch demonstrates the usage of MKR Fox 1200 as a simple weather station. 5 | It uses 6 | the onboard temperature sensor 7 | HTU21D I2C sensor to get humidity 8 | Bosch BMP280 to get the barometric pressure 9 | TSL2561 Light Sensor to get luminosity 10 | 11 | Download the needed libraries from the following links 12 | http://librarymanager/All#BMP280&Adafruit 13 | http://librarymanager/All#HTU21D&Adafruit 14 | http://librarymanager/All#TSL2561&Adafruit 15 | http://librarymanager/All#adafruit&sensor&abstraction 16 | 17 | Since the Sigfox network can send a maximum of 120 messages per day (depending on your plan) 18 | we'll optimize the readings and send data in compact binary format 19 | 20 | This sketch shows how to use the Stream APIs of the library. 21 | Refer to the WeatherMonitor sketch for an example using data structures. 22 | 23 | This example code is in the public domain. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "conversions.h" 33 | 34 | // Set oneshot to false to trigger continuous mode when you finished setting up the whole flow 35 | int oneshot = true; 36 | 37 | Adafruit_BMP280 bmp; 38 | Adafruit_HTU21DF htu = Adafruit_HTU21DF(); 39 | Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345); 40 | 41 | #define STATUS_OK 0 42 | #define STATUS_BMP_KO 1 43 | #define STATUS_HTU_KO 2 44 | #define STATUS_TSL_KO 4 45 | 46 | byte status; 47 | 48 | void setup() { 49 | 50 | if (oneshot == true) { 51 | // Wait for the serial 52 | Serial.begin(115200); 53 | while (!Serial) {} 54 | } 55 | 56 | if (!SigFox.begin()) { 57 | // Something is really wrong, try rebooting 58 | // Reboot is useful if we are powering the board using an unreliable power source 59 | // (eg. solar panels or other energy harvesting methods) 60 | reboot(); 61 | } 62 | 63 | //Send module to standby until we need to send a message 64 | SigFox.end(); 65 | 66 | if (oneshot == true) { 67 | // Enable debug prints and LED indication if we are testing 68 | SigFox.debug(); 69 | } 70 | 71 | // Configure the sensors and populate the status field 72 | if (!bmp.begin()) { 73 | status |= STATUS_BMP_KO; 74 | } else { 75 | Serial.println("BMP OK"); 76 | } 77 | 78 | if (!htu.begin()) { 79 | status |= STATUS_HTU_KO; 80 | } else { 81 | Serial.println("HTU OK"); 82 | } 83 | 84 | if (!tsl.begin()) { 85 | status |= STATUS_TSL_KO; 86 | } else { 87 | Serial.println("TLS OK"); 88 | tsl.enableAutoRange(true); 89 | tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); 90 | } 91 | } 92 | 93 | void loop() { 94 | // Every 15 minutes, read all the sensors and send them 95 | // Let's try to optimize the data format 96 | // Only use floats as intermediate representation, don't send them directly 97 | 98 | sensors_event_t event; 99 | 100 | float pressure = bmp.readPressure(); 101 | float temperature = bmp.readTemperature(); 102 | float humidity = htu.readHumidity(); 103 | 104 | tsl.getEvent(&event); 105 | float light = event.light; 106 | 107 | // Start the module 108 | SigFox.begin(); 109 | // Wait at least 30 ms after first configuration (100 ms before) 110 | delay(100); 111 | 112 | // Prepare the packet using the Stream APIs 113 | SigFox.beginPacket(); 114 | SigFox.write((byte)status); 115 | SigFox.write((short)convertoFloatToInt16(temperature, 60, -60)); 116 | SigFox.write((unsigned short)convertoFloatToUInt16(pressure, 200000)); 117 | SigFox.write((unsigned short)convertoFloatToUInt16(humidity, 110)); 118 | SigFox.write((unsigned short)convertoFloatToUInt16(light, 100000)); 119 | 120 | int ret = SigFox.endPacket(); 121 | 122 | if (oneshot == true) { 123 | Serial.println("Pressure: " + String(pressure)); 124 | Serial.println("External temperature: " + String(temperature)); 125 | Serial.println("Light: " + String(event.light)); 126 | Serial.println("Humidity: " + String(humidity)); 127 | Serial.println("Status: " + String(ret)); 128 | } 129 | 130 | // Shut down the module 131 | SigFox.end(); 132 | 133 | if (oneshot == true) { 134 | // spin forever, so we can test that the backend is behaving correctly 135 | while (1) {} 136 | } 137 | 138 | //Sleep for 15 minutes 139 | LowPower.sleep(15 * 60 * 1000); 140 | } 141 | 142 | void reboot() { 143 | NVIC_SystemReset(); 144 | while (1); 145 | } 146 | -------------------------------------------------------------------------------- /examples/WeatherMonitorStream/conversions.h: -------------------------------------------------------------------------------- 1 | 2 | #define UINT16_t_MAX 65536 3 | #define INT16_t_MAX UINT16_t_MAX/2 4 | 5 | int16_t convertoFloatToInt16(float value, long max, long min) { 6 | float conversionFactor = (float) (INT16_t_MAX) / (float)(max - min); 7 | return (int16_t)(value * conversionFactor); 8 | } 9 | 10 | uint16_t convertoFloatToUInt16(float value, long max, long min = 0) { 11 | float conversionFactor = (float) (UINT16_t_MAX) / (float)(max - min); 12 | return (uint16_t)(value * conversionFactor); 13 | } 14 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For SigFox 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | SigFox KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | PAC KEYWORD2 16 | ID KEYWORD2 17 | send KEYWORD2 18 | receive KEYWORD2 19 | status KEYWORD2 20 | setMode KEYWORD2 21 | internalTemperature KEYWORD2 22 | reset KEYWORD2 23 | AtmVersion KEYWORD2 24 | SigVersion KEYWORD2 25 | statusCode KEYWORD2 26 | debug KEYWORD2 27 | noDebug KEYWORD2 28 | 29 | ####################################### 30 | # Constants (LITERAL1) 31 | ####################################### 32 | 33 | ATMEL LITERAL1 34 | SIGFOX LITERAL1 35 | SSM LITERAL1 36 | TX LITERAL1 37 | TXRX LITERAL1 38 | US LITERAL1 39 | EU LITERAL1 40 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Arduino SigFox for MKRFox1200 2 | version=1.0.5 3 | author=Arduino 4 | maintainer=Arduino 5 | sentence=Helper library for MKR Fox 1200 board and ATAB8520E Sigfox module 6 | paragraph=This library allows some high level operations on Sigfox modules, to ease integration with existing projects 7 | category=Device Control 8 | url=https://www.arduino.cc/en/Reference/SigFox 9 | architectures=samd 10 | depends=Arduino Low Power 11 | -------------------------------------------------------------------------------- /src/SigFox.cpp: -------------------------------------------------------------------------------- 1 | /*****************************************************************************/ 2 | /* 3 | Arduino library for Atmel SIGFOX module ATA8520. 4 | This library uses Arduino SPI library. 5 | */ 6 | /*****************************************************************************/ 7 | 8 | /* 9 | Copyright (c) 2016 Arduino LLC 10 | 11 | This software is open source software and is not owned by Atmel; 12 | you can redistribute it and/or modify it under the terms of the GNU 13 | Lesser General Public License as published by the Free Software Foundation; 14 | either version 2.1 of the License, or (at your option) any later version. 15 | 16 | You acknowledge that the ArduinoUNO software is distributed to you free of 17 | charge on an "as is" basis and that it has not been developed to meet your 18 | specific requirements. It is supplied in the hope that it will be useful but 19 | WITHOUT ANY WARRANTY that its use will be uninterrupted or error-free. 20 | All other conditions, warranties or other terms which might have effect 21 | between the parties or be implied or incorporated into this licence or any 22 | collateral contract whether by statute or otherwise are hereby excluded, 23 | including the implied conditions, warranties or other terms as to 24 | satisfactory quality, fitness for purpose, non-infringement or the use of 25 | reasonable skill and care. 26 | See the GNU Lesser General Public License for more details. 27 | */ 28 | 29 | 30 | #include "SigFox.h" 31 | #include 32 | 33 | #ifdef SIGFOX_SPI 34 | #include "ArduinoLowPower.h" 35 | #endif 36 | 37 | const char str0[] = "OK"; 38 | const char str1[] = "Manufacturer error"; 39 | const char str2[] = "ID or key error"; 40 | const char str3[] = "State machine error"; 41 | const char str4[] = "Frame size error"; 42 | const char str5[] = "Manufacturer send error"; 43 | const char str6[] = "Get voltage/temperature error"; 44 | const char str7[] = "Close issues encountered"; 45 | const char str8[] = "API error indication"; 46 | const char str9[] = "Error getting PN9"; 47 | const char str10[] = "Error getting frequency"; 48 | const char str11[] = "Error building frame"; 49 | const char str12[] = "Error in delay routine"; 50 | const char str13[] = "Callback causes error"; 51 | const char str14[] = "Timing error"; 52 | const char str15[] = "Frequency error"; 53 | 54 | const char * sigstr[16] = // SIGFOX message status 55 | {str0, str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11, str12, str13, str14, str15}; 56 | 57 | #define SPICONFIG SPISettings(100000UL, MSBFIRST, SPI_MODE0) 58 | 59 | void SIGFOXClass::debug(bool const ledOFF) { 60 | // Enables debug via LED and Serial prints 61 | // Also disables greedy sleep strategy 62 | debugging = true; 63 | no_led = ledOFF; 64 | pinMode(led_pin, OUTPUT); 65 | } 66 | 67 | void SIGFOXClass::noDebug() { 68 | debugging = false; 69 | } 70 | 71 | int SIGFOXClass::begin() 72 | { 73 | #ifdef SIGFOX_SPI 74 | spi_port = &SIGFOX_SPI; 75 | reset_pin = SIGFOX_RES_PIN; 76 | poweron_pin = SIGFOX_PWRON_PIN; 77 | interrupt_pin = SIGFOX_EVENT_PIN; 78 | chip_select_pin = SIGFOX_SS_PIN; 79 | led_pin = LED_BUILTIN; 80 | #else 81 | // begin() can only be used on boards with embedded Sigfox module 82 | if (_configured == false) { 83 | return false; 84 | } 85 | #endif 86 | 87 | pinMode(interrupt_pin, INPUT_PULLUP); 88 | pinMode(poweron_pin, OUTPUT); 89 | digitalWrite(poweron_pin, HIGH); 90 | pinMode(chip_select_pin, OUTPUT); 91 | digitalWrite(chip_select_pin, HIGH); 92 | pinMode(reset_pin, OUTPUT); 93 | // Power cycle the chip 94 | digitalWrite(reset_pin, HIGH); 95 | delay(10); 96 | digitalWrite(reset_pin, LOW); 97 | delay(10); 98 | digitalWrite(reset_pin, HIGH); 99 | spi_port->begin(); 100 | 101 | delay(100); 102 | 103 | String version = SigVersion(); 104 | if (version == "0.0") 105 | return false; 106 | return true; 107 | } 108 | 109 | int SIGFOXClass::begin(arduino::HardwareSPI & spi, int reset, int poweron, int interrupt, int chip_select, int led) 110 | { 111 | spi_port = &spi; 112 | reset_pin = reset; 113 | poweron_pin = poweron; 114 | interrupt_pin = interrupt; 115 | chip_select_pin = chip_select; 116 | led_pin = led; 117 | _configured = true; 118 | return begin(); 119 | } 120 | 121 | int SIGFOXClass::send(unsigned char mess[], int len, bool rx) 122 | { 123 | if (len == 0) return 98; 124 | 125 | if (rx == false && len == 1 && mess[0] < 2) { 126 | //we can use send_bit command 127 | return sendBit(mess[0]); 128 | } 129 | 130 | status(); 131 | 132 | digitalWrite(chip_select_pin, LOW); 133 | delay(1); 134 | spi_port->beginTransaction(SPICONFIG); 135 | if (len > 12) len = 12; 136 | int i = 0; 137 | 138 | spi_port->transfer(0x07); 139 | spi_port->transfer(len); 140 | spi_port->transfer(mess, len); 141 | spi_port->endTransaction(); 142 | delay(1); 143 | digitalWrite(chip_select_pin, HIGH); 144 | 145 | delay(5); 146 | calibrateCrystal(); 147 | delay(5); 148 | 149 | digitalWrite(chip_select_pin, LOW); 150 | delay(1); 151 | spi_port->beginTransaction(SPICONFIG); 152 | if (rx) { 153 | spi_port->transfer(0x0E); 154 | } else { 155 | spi_port->transfer(0x0D); 156 | } 157 | spi_port->endTransaction(); 158 | delay(1); 159 | digitalWrite(chip_select_pin, HIGH); 160 | int ret = 99; 161 | 162 | int timeout = 10000; //10 seconds 163 | if (rx) { 164 | timeout = 60000; //60 seconds 165 | } 166 | 167 | if (!debugging) { 168 | #ifdef SIGFOX_SPI 169 | spi_port->end(); 170 | LowPower.attachInterruptWakeup(interrupt_pin, NULL, FALLING); 171 | LowPower.sleep(timeout); 172 | spi_port->begin(); 173 | #endif 174 | if (digitalRead(interrupt_pin) == 0) { 175 | status(); 176 | ret = statusCode(SIGFOX); 177 | } 178 | goto exit; 179 | } 180 | 181 | for (i = 0; i < timeout/10; i++) 182 | { 183 | if (digitalRead(interrupt_pin) == 0) { 184 | status(); 185 | ret = statusCode(SIGFOX); 186 | break; 187 | } 188 | else { 189 | if(!no_led) digitalWrite(led_pin, HIGH); 190 | delay(50); 191 | if(!no_led) digitalWrite(led_pin, LOW); 192 | delay(50); 193 | } 194 | } 195 | 196 | exit: 197 | if (ret == 99) sig = 13; 198 | 199 | if (sig == 0 && rx) { 200 | digitalWrite(chip_select_pin, LOW); 201 | delay(1); 202 | spi_port->beginTransaction(SPICONFIG); 203 | spi_port->transfer(0x10); 204 | spi_port->transfer(MAX_RX_BUF_LEN); 205 | spi_port->transfer(rx_buffer, MAX_RX_BUF_LEN); 206 | spi_port->endTransaction(); 207 | delay(1); 208 | digitalWrite(chip_select_pin, HIGH); 209 | 210 | rx_buf_len = MAX_RX_BUF_LEN; 211 | } 212 | 213 | return sig; 214 | } 215 | 216 | int SIGFOXClass::sendBit(bool value){ 217 | int i = 0; 218 | status(); 219 | 220 | digitalWrite(chip_select_pin, LOW); 221 | delay(1); 222 | spi_port->beginTransaction(SPICONFIG); 223 | 224 | spi_port->transfer(0x0B); 225 | spi_port->transfer(value ? 1 : 0); 226 | spi_port->endTransaction(); 227 | delay(1); 228 | digitalWrite(chip_select_pin, HIGH); 229 | 230 | int timeout = 7000; //7 seconds 231 | 232 | if (!debugging) { 233 | #ifdef SIGFOX_SPI 234 | spi_port->end(); 235 | LowPower.attachInterruptWakeup(interrupt_pin, NULL, FALLING); 236 | LowPower.sleep(timeout); 237 | spi_port->begin(); 238 | #endif 239 | if (digitalRead(interrupt_pin) == 0) { 240 | status(); 241 | return statusCode(SIGFOX); 242 | } 243 | } 244 | 245 | for (i = 0; i < timeout/10; i++) 246 | { 247 | if (digitalRead(interrupt_pin) == 0) { 248 | status(); 249 | return statusCode(SIGFOX); 250 | break; 251 | } 252 | else { 253 | if(!no_led) digitalWrite(led_pin, HIGH); 254 | delay(50); 255 | if(!no_led) digitalWrite(led_pin, LOW); 256 | delay(50); 257 | } 258 | } 259 | return 99; //default 260 | } 261 | 262 | int SIGFOXClass::beginPacket() { 263 | bool ret = (tx_buffer_index == -1); 264 | tx_buffer_index = 0; 265 | return (ret ? 1 : 0); 266 | } 267 | 268 | int SIGFOXClass::endPacket(bool rx) { 269 | int ret = send(tx_buffer, tx_buffer_index, rx); 270 | // invalidate the buffer 271 | tx_buffer_index = -1; 272 | return ret; 273 | } 274 | 275 | size_t SIGFOXClass::write(uint8_t val) { 276 | if (tx_buffer_index >= 0 && tx_buffer_index < MAX_TX_BUF_LEN) { 277 | tx_buffer[tx_buffer_index++] = val; 278 | return 1; 279 | } 280 | return 0; 281 | }; 282 | 283 | size_t SIGFOXClass::write(const uint8_t *buffer, size_t size) { 284 | if (tx_buffer_index >= 0) { 285 | if (tx_buffer_index + size < MAX_TX_BUF_LEN) { 286 | memcpy(&tx_buffer[tx_buffer_index], buffer, size); 287 | tx_buffer_index += size; 288 | return size; 289 | } else { 290 | int len = MAX_TX_BUF_LEN - tx_buffer_index -1; 291 | memcpy(&tx_buffer[tx_buffer_index], buffer, len); 292 | tx_buffer_index += len; 293 | return len; 294 | } 295 | } 296 | return 0; 297 | } 298 | 299 | int SIGFOXClass::available() { 300 | return rx_buf_len; 301 | } 302 | 303 | int SIGFOXClass::read() { 304 | int ret = rx_buffer[0]; 305 | for (int i = 0; i < rx_buf_len - 1; i++) { 306 | rx_buffer[i] = rx_buffer[i+1]; 307 | } 308 | rx_buf_len --; 309 | return ret; 310 | } 311 | 312 | int SIGFOXClass::peek() { 313 | return rx_buffer[0]; 314 | } 315 | 316 | int SIGFOXClass::parsePacket() { 317 | if (rx_buf_len == MAX_RX_BUF_LEN) { 318 | return MAX_RX_BUF_LEN; 319 | } 320 | return 0; 321 | } 322 | 323 | int SIGFOXClass::calibrateCrystal() { 324 | digitalWrite(chip_select_pin, LOW); 325 | spi_port->beginTransaction(SPICONFIG); 326 | spi_port->transfer(0x14); 327 | spi_port->endTransaction(); 328 | delay(1); 329 | digitalWrite(chip_select_pin, HIGH); 330 | delay(1); 331 | int ret = 99; 332 | for (int i = 0; i < 6000; i++) 333 | { 334 | if (digitalRead(interrupt_pin) == 0) { 335 | status(); 336 | ret = statusCode(SIGFOX); 337 | break; 338 | } 339 | else { 340 | if(!no_led) digitalWrite(led_pin, HIGH); 341 | delay(50); 342 | if(!no_led) digitalWrite(led_pin, LOW); 343 | delay(50); 344 | } 345 | } 346 | if (ret == 99) sig = 13; 347 | return sig; 348 | } 349 | 350 | int SIGFOXClass::statusCode(Protocol type) 351 | { 352 | switch (type) 353 | { 354 | case SSM : return ssm; break; 355 | case ATMEL : return atm; break; 356 | case SIGFOX : return sig; break; 357 | } 358 | return -1; 359 | } 360 | 361 | char* SIGFOXClass::status(Protocol type) 362 | { 363 | status(); 364 | switch (type) 365 | { 366 | case SSM : 367 | break; 368 | case ATMEL : 369 | return getStatusAtm(); 370 | break; 371 | case SIGFOX : 372 | return getStatusSig(); 373 | break; 374 | } 375 | buffer[0] = '\0'; 376 | return (char*)buffer; 377 | } 378 | 379 | char* SIGFOXClass::getStatusAtm() 380 | { 381 | buffer[0] = '\0'; 382 | byte err = (atm & 0b0011110) >> 1; 383 | char pa[10]; pa[0] = '\0'; 384 | if (bitRead(atm, 0) == 1) strcpy(pa, "PA ON"); else strcpy(pa, "PA OFF"); 385 | if (err > 0) 386 | { 387 | snprintf((char*)buffer, BLEN, "Error code: %i", err); 388 | return (char*)buffer; 389 | } 390 | if (bitRead(atm, 5) == 1) 391 | { 392 | snprintf((char*)buffer, BLEN, "Frame sent"); 393 | return (char*)buffer; 394 | } 395 | if (bitRead(atm, 6) == 1) 396 | { 397 | snprintf((char*)buffer, BLEN, "%s . System ready", pa); 398 | return (char*)buffer; 399 | } 400 | snprintf((char*)buffer, BLEN, "%s", pa); 401 | return (char*)buffer; 402 | } 403 | 404 | char* SIGFOXClass::getStatusSig() 405 | { 406 | if (sig > 0xF) 407 | { 408 | snprintf((char*)buffer, BLEN, "Controller comm. error: %d", sig); 409 | return (char*)buffer; 410 | } 411 | strncpy((char*)buffer, sigstr[sig], BLEN); 412 | 413 | return (char*)buffer; 414 | } 415 | 416 | void SIGFOXClass::status() 417 | { 418 | digitalWrite(chip_select_pin, LOW); 419 | spi_port->beginTransaction(SPICONFIG); 420 | spi_port->transfer(0x0A); 421 | spi_port->transfer(0); 422 | ssm = spi_port->transfer(0); 423 | atm = spi_port->transfer(0); 424 | sig = spi_port->transfer(0); 425 | sig2 = spi_port->transfer(0); 426 | spi_port->endTransaction(); 427 | digitalWrite(chip_select_pin, HIGH); 428 | delay(1); 429 | } 430 | 431 | float SIGFOXClass::internalTemperature() 432 | { 433 | digitalWrite(chip_select_pin, LOW); 434 | delay(1); 435 | spi_port->beginTransaction(SPICONFIG); 436 | spi_port->transfer(0x14); 437 | spi_port->endTransaction(); 438 | delay(1); 439 | digitalWrite(chip_select_pin, HIGH); 440 | delay(1); 441 | 442 | for (int i = 0; i < 10; i++) 443 | { 444 | if (digitalRead(interrupt_pin) == 0) { 445 | status(); 446 | break; 447 | } 448 | else { 449 | delay(10); 450 | } 451 | } 452 | 453 | digitalWrite(chip_select_pin, LOW); 454 | delay(1); 455 | spi_port->beginTransaction(SPICONFIG); 456 | uint8_t buf[8]; 457 | buf[0] = 0x13; 458 | spi_port->transfer(buf, 8); 459 | temperatureL = buf[6]; 460 | temperatureH = buf[7]; 461 | delay(1); 462 | spi_port->endTransaction(); 463 | digitalWrite(chip_select_pin, HIGH); 464 | delay(1); 465 | 466 | return ((float)((int16_t)((uint16_t)temperatureH << 8 | temperatureL)) - 50.0f) / 10; 467 | } 468 | 469 | char* SIGFOXClass::readConfig(int* len) 470 | { 471 | 472 | digitalWrite(chip_select_pin, LOW); 473 | delay(1); 474 | spi_port->beginTransaction(SPICONFIG); 475 | spi_port->transfer(0x1F); 476 | spi_port->endTransaction(); 477 | digitalWrite(chip_select_pin, HIGH); 478 | 479 | delay(5); 480 | 481 | digitalWrite(chip_select_pin, LOW); 482 | spi_port->beginTransaction(SPICONFIG); 483 | spi_port->transfer(0x20); 484 | spi_port->transfer(0); 485 | tx_freq = SPI.transfer(0) | tx_freq << 8; 486 | tx_freq = SPI.transfer(0) | tx_freq << 8; 487 | tx_freq = SPI.transfer(0) | tx_freq << 8; 488 | tx_freq = SPI.transfer(0) | tx_freq << 8; 489 | rx_freq = SPI.transfer(0) | rx_freq << 8; 490 | rx_freq = SPI.transfer(0) | rx_freq << 8; 491 | rx_freq = SPI.transfer(0) | rx_freq << 8; 492 | rx_freq = SPI.transfer(0) | rx_freq << 8; 493 | repeat = spi_port->transfer(0); 494 | configuration = spi_port->transfer(0); 495 | spi_port->endTransaction(); 496 | delay(1); 497 | digitalWrite(chip_select_pin, HIGH); 498 | delay(1); 499 | 500 | buffer[0] = tx_freq; 501 | buffer[4] = rx_freq; 502 | buffer[8] = repeat; 503 | buffer[9] = configuration; 504 | buffer[10] = 0; 505 | *len = 10; 506 | return (char*)buffer; 507 | } 508 | 509 | String SIGFOXClass::AtmVersion() 510 | { 511 | digitalWrite(chip_select_pin, LOW); 512 | spi_port->beginTransaction(SPICONFIG); 513 | spi_port->transfer(0x06); 514 | spi_port->transfer(0); 515 | byte mv = spi_port->transfer(0); 516 | byte lv = spi_port->transfer(0); 517 | spi_port->endTransaction(); 518 | digitalWrite(chip_select_pin, HIGH); 519 | delay(1); 520 | snprintf(buffer, BLEN, "%d.%d", mv, lv); 521 | return String(buffer); 522 | } 523 | 524 | String SIGFOXClass::SigVersion() 525 | { 526 | digitalWrite(chip_select_pin, LOW); 527 | spi_port->beginTransaction(SPICONFIG); 528 | spi_port->transfer(0x06); 529 | spi_port->transfer(0); 530 | byte mv = spi_port->transfer(0); 531 | byte lv = spi_port->transfer(0); 532 | spi_port->endTransaction(); 533 | digitalWrite(chip_select_pin, HIGH); 534 | delay(1); 535 | snprintf(buffer, BLEN, "%d.%d", mv, lv); 536 | return String(buffer); 537 | } 538 | 539 | String SIGFOXClass::ID() 540 | { 541 | digitalWrite(chip_select_pin, LOW); 542 | spi_port->beginTransaction(SPICONFIG); 543 | spi_port->transfer(0x12); 544 | spi_port->transfer(0); 545 | byte ID3 = spi_port->transfer(0); 546 | byte ID2 = spi_port->transfer(0); 547 | byte ID1 = spi_port->transfer(0); 548 | byte ID0 = spi_port->transfer(0); 549 | spi_port->endTransaction(); 550 | digitalWrite(chip_select_pin, HIGH); 551 | delay(1); 552 | snprintf(buffer, BLEN, "%02X%02X%02X%02X", ID0, ID1, ID2, ID3); 553 | return String(buffer); 554 | } 555 | 556 | String SIGFOXClass::PAC() 557 | { 558 | uint8_t pac[16]; 559 | digitalWrite(chip_select_pin, LOW); 560 | spi_port->beginTransaction(SPICONFIG); 561 | spi_port->transfer(0x0F); 562 | spi_port->transfer(0); 563 | for (int i = 0; i < 16; i++) { 564 | pac[i] = spi_port->transfer(0); 565 | } 566 | spi_port->endTransaction(); 567 | digitalWrite(chip_select_pin, HIGH); 568 | delay(1); 569 | for (int i = 0; i < 8; i++) { 570 | snprintf(buffer + (i * 2), BLEN - (i*2), "%02X", pac[i]); 571 | } 572 | return String(buffer); 573 | } 574 | 575 | void SIGFOXClass::reset() 576 | { 577 | digitalWrite(chip_select_pin, LOW); 578 | spi_port->beginTransaction(SPICONFIG); 579 | spi_port->transfer(0x01); 580 | spi_port->endTransaction(); 581 | digitalWrite(chip_select_pin, HIGH); 582 | delay(1); 583 | } 584 | 585 | void SIGFOXClass::testMode(bool on) 586 | { 587 | digitalWrite(chip_select_pin, LOW); 588 | spi_port->beginTransaction(SPICONFIG); 589 | spi_port->transfer(0x17); 590 | if (on) { 591 | spi_port->transfer(0x11); 592 | } else { 593 | spi_port->transfer(0x00); 594 | } 595 | spi_port->endTransaction(); 596 | digitalWrite(chip_select_pin, HIGH); 597 | delay(1); 598 | } 599 | 600 | void SIGFOXClass::setMode(Country EUMode, TxRxMode tx_rx) 601 | { 602 | digitalWrite(chip_select_pin, LOW); 603 | spi_port->beginTransaction(SPICONFIG); 604 | spi_port->transfer(0x11); 605 | spi_port->transfer(0); 606 | spi_port->transfer(1); 607 | spi_port->transfer(0x2); 608 | uint8_t mode = (0x3 << 4) | (1 << 3) | (EUMode << 2) | (tx_rx << 1) | 1; 609 | spi_port->transfer(mode); 610 | spi_port->endTransaction(); 611 | digitalWrite(chip_select_pin, HIGH); 612 | delay(1); 613 | 614 | int ret = 99; 615 | for (int i = 0; i < 300; i++) 616 | { 617 | if (digitalRead(interrupt_pin) == 0) { 618 | status(); 619 | ret = statusCode(SIGFOX); 620 | break; 621 | } 622 | delay(10); 623 | } 624 | if (ret == 99) { 625 | Serial.println("Failed to set mode"); 626 | } 627 | 628 | digitalWrite(chip_select_pin, LOW); 629 | spi_port->beginTransaction(SPICONFIG); 630 | spi_port->transfer(0x05); 631 | spi_port->endTransaction(); 632 | digitalWrite(chip_select_pin, HIGH); 633 | delay(100); 634 | } 635 | 636 | void SIGFOXClass::end() 637 | { 638 | pinMode(poweron_pin, LOW); 639 | delay(1); 640 | digitalWrite(chip_select_pin, LOW); 641 | delay(1); 642 | spi_port->beginTransaction(SPICONFIG); 643 | spi_port->transfer(0x05); 644 | spi_port->endTransaction(); 645 | delay(1); 646 | digitalWrite(chip_select_pin, HIGH); 647 | delay(1); 648 | spi_port->end(); 649 | } 650 | 651 | SIGFOXClass SigFox; //singleton 652 | -------------------------------------------------------------------------------- /src/SigFox.h: -------------------------------------------------------------------------------- 1 | /*****************************************************************************/ 2 | /* 3 | Arduino library for Atmel SIGFOX module ATA8520. 4 | This library uses Arduino SPI library. 5 | */ 6 | /*****************************************************************************/ 7 | 8 | /* 9 | Copyright (c) 2016 Arduino LLC 10 | 11 | This software is open source software and is not owned by Atmel; 12 | you can redistribute it and/or modify it under the terms of the GNU 13 | Lesser General Public License as published by the Free Software Foundation; 14 | either version 2.1 of the License, or (at your option) any later version. 15 | 16 | You acknowledge that the ArduinoUNO software is distributed to you free of 17 | charge on an "as is" basis and that it has not been developed to meet your 18 | specific requirements. It is supplied in the hope that it will be useful but 19 | WITHOUT ANY WARRANTY that its use will be uninterrupted or error-free. 20 | All other conditions, warranties or other terms which might have effect 21 | between the parties or be implied or incorporated into this licence or any 22 | collateral contract whether by statute or otherwise are hereby excluded, 23 | including the implied conditions, warranties or other terms as to 24 | satisfactory quality, fitness for purpose, non-infringement or the use of 25 | reasonable skill and care. 26 | See the GNU Lesser General Public License for more details. 27 | */ 28 | 29 | #ifndef SIGFOX_h 30 | #define SIGFOX_h 31 | 32 | #include 33 | #include 34 | 35 | #define BLEN 64 // Communication buffer length 36 | #define MAX_RX_BUF_LEN 8 37 | #define MAX_TX_BUF_LEN 13 38 | 39 | 40 | typedef enum country { 41 | US = 0 , 42 | EU 43 | } Country; 44 | 45 | typedef enum communication { 46 | TXRX = 0 , 47 | TX 48 | } TxRxMode; 49 | 50 | typedef enum protocol { 51 | SSM = 0 , 52 | ATMEL, 53 | SIGFOX 54 | } Protocol; 55 | 56 | class SIGFOXClass : public Stream 57 | { 58 | public: 59 | 60 | /* 61 | * Enables debug LED and prints 62 | */ 63 | void debug(bool const ledOFF = false); 64 | /* 65 | * Disables debug LED and prints 66 | */ 67 | void noDebug(); 68 | /* 69 | * Initialize module (ready to transmit) 70 | */ 71 | int begin(); 72 | /* 73 | * Initialize module specifying SPI port and pins (ready to transmit) 74 | */ 75 | int begin(arduino::HardwareSPI & spi, int reset, int poweron, int interrupt, int chip_select, int led); 76 | 77 | // Stream compatibility (like UDP) 78 | int beginPacket(); 79 | int endPacket(bool rx = false); 80 | size_t write(uint8_t); 81 | size_t write(const uint8_t *buffer, size_t size); 82 | 83 | template inline size_t write(T val) {return write((uint8_t*)&val, sizeof(T));}; 84 | using Print::write; 85 | 86 | //makes no sense in Sigfox world 87 | void flush() {}; 88 | 89 | /* 90 | * Commodity functions for Arduino-style message parse 91 | */ 92 | int peek(); 93 | int available(); 94 | int read(); 95 | 96 | int parsePacket(); 97 | 98 | /* 99 | * Read status (fill ssm,atm,sig status variables) 100 | */ 101 | void status(); 102 | /* 103 | * Return status code. 104 | * Type: 0 -> ssm status ; 1 -> atm status ; 2 -> sigfox status 105 | */ 106 | int statusCode(Protocol type); 107 | /* 108 | * Return status code. 109 | * Type: 0 -> ssm status ; 1 -> atm status ; 2 -> sigfox status 110 | */ 111 | char* status(Protocol type); 112 | /* 113 | * Return ATM version (major ver,minor ver)(two bytes) 114 | */ 115 | String AtmVersion(); 116 | /* 117 | * Return SIGFOX version (major ver, minor ver) (two bytes) 118 | */ 119 | String SigVersion(); 120 | /* 121 | * Return ID (4 bytes) 122 | */ 123 | String ID(); 124 | /* 125 | * Return PAC (16 bytes) 126 | */ 127 | String PAC(); 128 | /* 129 | * Reset module 130 | */ 131 | void reset(); 132 | 133 | float internalTemperature(); 134 | 135 | /* 136 | * Disable module 137 | */ 138 | void end(); 139 | 140 | private: 141 | 142 | /* 143 | * Send an array of bytes (max 12 bytes long) as message to SIGFOX network 144 | * Return SIGFOX status code 145 | */ 146 | int send(unsigned char mess[], int len = 12, bool rx = false); 147 | 148 | /* 149 | * Send a single bit (0 | 1) over the Sigfox network 150 | * Returns the status code from the Atmel Sigfox chipset 151 | **/ 152 | int sendBit(bool value); 153 | 154 | /* 155 | * Return atm status message 156 | */ 157 | char* getStatusAtm(); 158 | /* 159 | * Return SIGFOX status message 160 | */ 161 | char* getStatusSig(); 162 | 163 | int calibrateCrystal(); 164 | 165 | /* 166 | * Test mode 167 | */ 168 | void testMode (bool); 169 | 170 | char* readConfig(int* len); 171 | 172 | void setMode(Country EUMode, TxRxMode tx_rx); 173 | 174 | byte ssm; 175 | byte atm; 176 | byte sig; 177 | byte sig2; 178 | byte vhidle; 179 | byte vlidle; 180 | byte vhactive; 181 | byte vlactive; 182 | byte temperatureL; 183 | byte temperatureH; 184 | uint32_t tx_freq, rx_freq; 185 | uint8_t configuration; 186 | uint8_t repeat; 187 | bool _configured = false; 188 | char buffer[BLEN]; 189 | unsigned char rx_buffer[MAX_RX_BUF_LEN]; 190 | unsigned char tx_buffer[MAX_TX_BUF_LEN]; 191 | int tx_buffer_index = -1; 192 | arduino::HardwareSPI *spi_port; 193 | int reset_pin; 194 | int poweron_pin; 195 | int interrupt_pin; 196 | int chip_select_pin; 197 | int led_pin; 198 | int rx_buf_len = 0; 199 | bool debugging = false; 200 | bool no_led = false; 201 | }; 202 | 203 | extern SIGFOXClass SigFox; 204 | 205 | #endif 206 | --------------------------------------------------------------------------------