diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 000000000..03b0e93f9
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,13 @@
+# See: https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#about-the-dependabotyml-file
+version: 2
+
+updates:
+ # Configure check for outdated GitHub Actions actions in workflows.
+ # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/dependabot/README.md
+ # See: https://docs.github.com/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
+ - package-ecosystem: github-actions
+ directory: /.github/workflows/
+ schedule:
+ interval: daily
+ labels:
+ - "topic: infrastructure"
diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml
index 15f7c2e73..1c6a3de27 100644
--- a/.github/workflows/check-arduino.yml
+++ b/.github/workflows/check-arduino.yml
@@ -16,10 +16,10 @@ jobs:
steps:
- name: Checkout repository
- uses: actions/checkout@v2
+ uses: actions/checkout@v6
- name: Arduino Lint
- uses: arduino/arduino-lint-action@v1
+ uses: arduino/arduino-lint-action@v2
with:
compliance: specification
library-manager: update
diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml
index 2477ab652..45a0f5ecf 100644
--- a/.github/workflows/compile-examples.yml
+++ b/.github/workflows/compile-examples.yml
@@ -22,12 +22,16 @@ jobs:
# Install the ArduinoIoTCloud library from the repository
- source-path: ./
- name: Arduino_ConnectionHandler
+ - name: ArduinoHttpClient
- name: Arduino_DebugUtils
- name: ArduinoMqttClient
+ - name: Arduino_SecureElement
+ - name: Arduino_CloudUtils
# sketch paths to compile (recursive) for all boards
UNIVERSAL_SKETCH_PATHS: |
- examples/ArduinoIoTCloud-Advanced
- examples/ArduinoIoTCloud-Basic
+ - examples/ArduinoIoTCloud-Callbacks
- examples/utility/ArduinoIoTCloud_Travis_CI
SKETCHES_REPORTS_PATH: sketches-reports
@@ -38,30 +42,58 @@ jobs:
board:
- fqbn: arduino:samd:mkr1000
type: mkr1000
+ artifact-name-suffix: arduino-samd-mkr1000
- fqbn: arduino:samd:mkrwifi1010
type: nina
+ artifact-name-suffix: arduino-samd-mkrwifi1010
- fqbn: arduino:samd:nano_33_iot
type: nina
+ artifact-name-suffix: arduino-samd-nano_33_iot
- fqbn: arduino:samd:mkrwan1300
type: wan
+ artifact-name-suffix: arduino-samd-mkrwan1300
- fqbn: arduino:samd:mkrgsm1400
type: gsm
+ artifact-name-suffix: arduino-samd-mkrgsm1400
- fqbn: arduino:samd:mkrnb1500
type: nb
+ artifact-name-suffix: arduino-samd-mkrnb1500
- fqbn: arduino:mbed_portenta:envie_m7
type: mbed_portenta
+ artifact-name-suffix: arduino-mbed_portenta-envie_m7
- fqbn: esp8266:esp8266:huzzah
type: esp8266
+ artifact-name-suffix: esp8266-esp8266-huzzah
- fqbn: esp32:esp32:esp32
type: esp32
+ artifact-name-suffix: esp32-esp32-esp32
- fqbn: arduino:mbed_nano:nanorp2040connect
type: nina
+ artifact-name-suffix: arduino-mbed_nano-nanorp2040connect
- fqbn: arduino:mbed_nicla:nicla_vision
type: mbed_nicla
+ artifact-name-suffix: arduino-mbed_nicla-nicla_vision
- fqbn: arduino:mbed_opta:opta
type: mbed_opta
+ artifact-name-suffix: arduino-mbed_opta-opta
- fqbn: arduino:mbed_giga:giga
type: mbed_giga
+ artifact-name-suffix: arduino-mbed_giga-giga
+ - fqbn: arduino:renesas_portenta:portenta_c33
+ type: renesas_portenta
+ artifact-name-suffix: arduino-renesas_portenta-portenta_c33
+ - fqbn: arduino:renesas_uno:unor4wifi
+ type: renesas_uno
+ artifact-name-suffix: arduino-renesas_uno-unor4wifi
+ - fqbn: arduino:esp32:nano_nora
+ type: arduino_esp32
+ artifact-name-suffix: arduino-esp32-nano_nora
+ - fqbn: arduino:mbed_edge:edge_control
+ type: mbed_edge
+ artifact-name-suffix: arduino-mbed_edge-edge_control
+ - fqbn: "rp2040:rp2040:rpipicow"
+ type: rp2040
+ artifact-name-suffix: rp2040-rp2040-rpipicow
# make board type-specific customizations to the matrix jobs
@@ -73,11 +105,15 @@ jobs:
# Install samd platform via Boards Manager
- name: arduino:samd
libraries: |
+ - name: ArduinoBearSSL
- name: ArduinoECCX08
+ - name: Blues Wireless Notecard
- name: RTCZero
- name: WiFi101
- source-url: https://github.com/adafruit/Adafruit_SleepyDog.git
sketch-paths: |
+ - examples/ArduinoIoTCloud-Notecard
+ - examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
# MKR WiFi 1010, Nano 33 IoT, Nano RP2040 Connect
- board:
@@ -87,12 +123,17 @@ jobs:
- name: arduino:samd
- name: arduino:mbed_nano
libraries: |
+ - name: ArduinoBearSSL
- name: ArduinoECCX08
+ - name: Blues Wireless Notecard
- name: RTCZero
- name: WiFiNINA
- name: Arduino_JSON
- source-url: https://github.com/adafruit/Adafruit_SleepyDog.git
sketch-paths: |
+ - examples/ArduinoIoTCloud-DeferredOTA
+ - examples/ArduinoIoTCloud-Notecard
+ - examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
- examples/utility/SelfProvisioning
- board:
@@ -102,10 +143,12 @@ jobs:
- name: arduino:samd
libraries: |
- name: ArduinoECCX08
+ - name: Blues Wireless Notecard
- name: RTCZero
- name: MKRWAN
- source-url: https://github.com/adafruit/Adafruit_SleepyDog.git
- sketch-paths:
+ sketch-paths: |
+ - examples/ArduinoIoTCloud-Notecard
# GSM boards
- board:
type: gsm
@@ -113,11 +156,15 @@ jobs:
# Install samd platform via Boards Manager
- name: arduino:samd
libraries: |
+ - name: ArduinoBearSSL
- name: ArduinoECCX08
+ - name: Blues Wireless Notecard
- name: RTCZero
- name: MKRGSM
- source-url: https://github.com/adafruit/Adafruit_SleepyDog.git
sketch-paths: |
+ - examples/ArduinoIoTCloud-Notecard
+ - examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
# NB boards
- board:
@@ -126,11 +173,15 @@ jobs:
# Install samd platform via Boards Manager
- name: arduino:samd
libraries: |
+ - name: ArduinoBearSSL
- name: ArduinoECCX08
+ - name: Blues Wireless Notecard
- name: RTCZero
- name: MKRNB
- source-url: https://github.com/adafruit/Adafruit_SleepyDog.git
sketch-paths: |
+ - examples/ArduinoIoTCloud-Notecard
+ - examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
# Portenta
- board:
@@ -139,9 +190,18 @@ jobs:
# Install mbed_portenta platform via Boards Manager
- name: arduino:mbed_portenta
libraries: |
+ - name: ArduinoBearSSL
- name: ArduinoECCX08
- - name: Arduino_Portenta_OTA
+ - name: Arduino_Cellular
+ - name: Blues Wireless Notecard
+ - name: ArduinoBLE
+ - name: Arduino_KVStore
+ - name: Arduino_NetworkConfigurator
sketch-paths: |
+ - examples/ArduinoIoTCloud-NetConfig
+ - examples/ArduinoIoTCloud-DeferredOTA
+ - examples/ArduinoIoTCloud-Notecard
+ - examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
# Nicla Vision
- board:
@@ -150,8 +210,15 @@ jobs:
# Install mbed_nicla platform via Boards Manager
- name: arduino:mbed_nicla
libraries: |
- - name: Arduino_Portenta_OTA
+ - name: Blues Wireless Notecard
+ - name: ArduinoBLE
+ - name: Arduino_KVStore
+ - name: Arduino_NetworkConfigurator
sketch-paths: |
+ - examples/ArduinoIoTCloud-NetConfig
+ - examples/ArduinoIoTCloud-DeferredOTA
+ - examples/ArduinoIoTCloud-Notecard
+ - examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
# Opta
- board:
@@ -160,9 +227,17 @@ jobs:
# Install mbed_opta platform via Boards Manager
- name: arduino:mbed_opta
libraries: |
+ - name: ArduinoBearSSL
- name: ArduinoECCX08
- - name: Arduino_Portenta_OTA
+ - name: Blues Wireless Notecard
+ - name: ArduinoBLE
+ - name: Arduino_KVStore
+ - name: Arduino_NetworkConfigurator
sketch-paths: |
+ - examples/ArduinoIoTCloud-NetConfig
+ - examples/ArduinoIoTCloud-DeferredOTA
+ - examples/ArduinoIoTCloud-Notecard
+ - examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
# GIGA
- board:
@@ -171,10 +246,73 @@ jobs:
# Install mbed_giga platform via Boards Manager
- name: arduino:mbed_giga
libraries: |
+ - name: ArduinoBearSSL
- name: ArduinoECCX08
- - name: Arduino_Portenta_OTA
+ - name: Blues Wireless Notecard
+ - name: ArduinoBLE
+ - name: Arduino_KVStore
+ - name: Arduino_NetworkConfigurator
+ sketch-paths: |
+ - examples/ArduinoIoTCloud-NetConfig
+ - examples/ArduinoIoTCloud-DeferredOTA
+ - examples/ArduinoIoTCloud-Notecard
+ - examples/ArduinoIoTCloud-Schedule
+ - examples/utility/Provisioning
+ # Portenta C33
+ - board:
+ type: renesas_portenta
+ platforms: |
+ # Install renesas_portenta platform via Boards Manager
+ - name: arduino:renesas_portenta
+ libraries: |
+ - name: Arduino_Cellular
+ - name: Blues Wireless Notecard
+ - name: ArduinoBLE
+ - name: Arduino_KVStore
+ - name: Arduino_NetworkConfigurator
sketch-paths: |
+ - examples/ArduinoIoTCloud-NetConfig
+ - examples/ArduinoIoTCloud-Notecard
+ - examples/ArduinoIoTCloud-Schedule
- examples/utility/Provisioning
+ # UNO R4 WiFi
+ - board:
+ type: renesas_uno
+ platforms: |
+ # Install renesas_uno platform via Boards Manager
+ - name: arduino:renesas_uno
+ libraries: |
+ - name: Blues Wireless Notecard
+ - name: ArduinoBLE
+ - name: Arduino_KVStore
+ - name: Arduino_NetworkConfigurator
+ sketch-paths: |
+ - examples/ArduinoIoTCloud-NetConfig
+ - examples/ArduinoIoTCloud-Notecard
+ - examples/ArduinoIoTCloud-Schedule
+ # Nano ESP32
+ - board:
+ type: arduino_esp32
+ platforms: |
+ # Install arduino_esp32 platform via Boards Manager
+ - name: arduino:esp32
+ libraries: |
+ - name: Blues Wireless Notecard
+ sketch-paths: |
+ - examples/ArduinoIoTCloud-DeferredOTA
+ - examples/ArduinoIoTCloud-Notecard
+ - examples/ArduinoIoTCloud-Schedule
+ # Edge Control
+ - board:
+ type: mbed_edge
+ platforms: |
+ # Install mbed_edge platform via Boards Manager
+ - name: arduino:mbed_edge
+ libraries: |
+ - name: Blues Wireless Notecard
+ sketch-paths: |
+ - examples/ArduinoIoTCloud-Notecard
+ - examples/ArduinoIoTCloud-Schedule
# ESP8266 boards
- board:
type: esp8266
@@ -185,7 +323,8 @@ jobs:
# Use the version currently installed in Arduino Cloud
version: 2.5.0
libraries:
- sketch-paths:
+ sketch-paths: |
+ - examples/ArduinoIoTCloud-Schedule
# ESP32 boards
- board:
type: esp32
@@ -194,12 +333,22 @@ jobs:
- name: esp32:esp32
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
libraries: |
- - name: Arduino_ESP32_OTA
- sketch-paths:
+ - name: Blues Wireless Notecard
+ sketch-paths: |
+ - examples/ArduinoIoTCloud-DeferredOTA
+ - examples/ArduinoIoTCloud-Notecard
+ - examples/ArduinoIoTCloud-Schedule
+ # PicoW
+ - board:
+ type: rp2040
+ platforms: |
+ # Install rp2040 platform via Boards Manager
+ - name: rp2040:rp2040
+ source-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
steps:
- name: Checkout
- uses: actions/checkout@v2
+ uses: actions/checkout@v6
- name: Install ESP32 platform dependencies
if: matrix.board.type == 'esp32'
@@ -231,7 +380,7 @@ jobs:
- name: Save memory usage change report as artifact
if: github.event_name == 'pull_request'
- uses: actions/upload-artifact@v2
+ uses: actions/upload-artifact@v5
with:
- name: ${{ env.SKETCHES_REPORTS_PATH }}
+ name: sketches-report-${{ matrix.board.artifact-name-suffix }}
path: ${{ env.SKETCHES_REPORTS_PATH }}
diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml
index 9b0f2cdb5..39e2a0ad2 100644
--- a/.github/workflows/report-size-deltas.yml
+++ b/.github/workflows/report-size-deltas.yml
@@ -1,14 +1,24 @@
+name: Report Size Deltas
+
+# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
on:
+ push:
+ paths:
+ - ".github/workflows/report-size-deltas.yml"
schedule:
- - cron: '*/5 * * * *'
+ # Run at the minimum interval allowed by GitHub Actions.
+ # Note: GitHub Actions periodically has outages which result in workflow failures.
+ # In this event, the workflows will start passing again once the service recovers.
+ - cron: "*/5 * * * *"
+ workflow_dispatch:
+ repository_dispatch:
jobs:
report:
runs-on: ubuntu-latest
-
steps:
- name: Comment size deltas reports to PRs
uses: arduino/report-size-deltas@v1
with:
- # The name of the workflow artifact created by the "Compile Examples" workflow
- sketches-reports-source: sketches-reports
+ # Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow
+ sketches-reports-source: ^sketches-report-.+
diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml
index b96e8e9d8..22c0d8524 100644
--- a/.github/workflows/spell-check.yml
+++ b/.github/workflows/spell-check.yml
@@ -10,7 +10,7 @@ jobs:
steps:
- name: Checkout
- uses: actions/checkout@v2
+ uses: actions/checkout@v6
- name: Spell check
uses: codespell-project/actions-codespell@master
diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml
index 3ee6febdc..d49c1cb65 100644
--- a/.github/workflows/sync-labels.yml
+++ b/.github/workflows/sync-labels.yml
@@ -27,11 +27,11 @@ jobs:
steps:
- name: Checkout repository
- uses: actions/checkout@v2
+ uses: actions/checkout@v6
- name: Download JSON schema for labels configuration file
id: download-schema
- uses: carlosperate/download-file-action@v1
+ uses: carlosperate/download-file-action@v2
with:
file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json
location: ${{ runner.temp }}/label-configuration-schema
@@ -65,12 +65,12 @@ jobs:
steps:
- name: Download
- uses: carlosperate/download-file-action@v1
+ uses: carlosperate/download-file-action@v2
with:
file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }}
- name: Pass configuration files to next job via workflow artifact
- uses: actions/upload-artifact@v2
+ uses: actions/upload-artifact@v5
with:
path: |
*.yaml
@@ -105,16 +105,16 @@ jobs:
echo "::set-output name=flag::--dry-run"
- name: Checkout repository
- uses: actions/checkout@v2
+ uses: actions/checkout@v6
- name: Download configuration files artifact
- uses: actions/download-artifact@v2
+ uses: actions/download-artifact@v6
with:
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
path: ${{ env.CONFIGURATIONS_FOLDER }}
- name: Remove unneeded artifact
- uses: geekyeggo/delete-artifact@v1
+ uses: geekyeggo/delete-artifact@v5
with:
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml
index f3b66c2c8..de40363fa 100644
--- a/.github/workflows/unit-tests.yml
+++ b/.github/workflows/unit-tests.yml
@@ -23,7 +23,7 @@ jobs:
steps:
- name: Checkout
- uses: actions/checkout@v2
+ uses: actions/checkout@v6
- uses: arduino/cpp-test-action@main
with:
@@ -32,11 +32,25 @@ jobs:
coverage-exclude-paths: |
- '*/extras/test/*'
- '/usr/*'
- - '*/src/cbor/lib/*'
coverage-data-path: ${{ env.COVERAGE_DATA_PATH }}
+ # A token is used to avoid intermittent spurious job failures caused by rate limiting.
+ - name: Set up Codecov upload token
+ run: |
+ if [[ "${{ github.repository }}" == "arduino-libraries/ArduinoIoTCloud" ]]; then
+ # In order to avoid uploads of data from forks, only use the token for runs in the parent repo.
+ # Token is intentionally exposed.
+ # See: https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954
+ CODECOV_TOKEN="47827969-3fda-4ba1-9506-e8d0834ed88c"
+ else
+ # codecov/codecov-action does unauthenticated upload if empty string is passed via the `token` input.
+ CODECOV_TOKEN=""
+ fi
+ echo "CODECOV_TOKEN=$CODECOV_TOKEN" >> "$GITHUB_ENV"
+
- name: Upload coverage report to Codecov
- uses: codecov/codecov-action@v1
+ uses: codecov/codecov-action@v3
with:
file: "${{ env.COVERAGE_DATA_PATH }}"
fail_ci_if_error: true
+ token: ${{ env.CODECOV_TOKEN }}
diff --git a/.gitignore b/.gitignore
index 16e30d984..c71e1ae86 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,22 @@
*.orig
.vs
build
+.idea/
+### CMake ###
+CMakeLists.txt.user
+CMakeCache.txt
+CMakeFiles
+CMakeScripts
+Testing
+Makefile
+cmake_install.cmake
+install_manifest.txt
+compile_commands.json
+CTestTestfile.cmake
+_deps
+
+### CMake Patch ###
+CMakeUserPresets.json
+
+# External projects
+*-prefix/
diff --git a/LICENSE b/LICENSE
index 4a1b324fd..dbdb0fa8e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,688 +1,373 @@
-This file includes licensing information for ArduinoIoTCloud
-
-Copyright (c) 2019 ARDUINO SA (www.arduino.cc)
-
-The software is released under the GNU General Public License, which covers the main body
-of the ArduinoIoTCloud code. The terms of this license can be found at:
-https://www.gnu.org/licenses/gpl-3.0.en.html
-
-You can be released from the requirements of the above licenses by purchasing
-a commercial license. Buying such a license is mandatory if you want to modify or
-otherwise use the software for commercial activities involving the Arduino
-software without disclosing the source code of your own applications. To purchase
-a commercial license, send an email to license@arduino.cc
-
- GNU GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc.
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
-
- The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works. By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users. We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors. You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
-
- To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights. Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received. You must make sure that they, too, receive
-or can get the source code. And you must show them these terms so they
-know their rights.
-
- Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
-
- For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software. For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
-
- Some devices are designed to deny users access to install or run
-modified versions of the software inside them, although the manufacturer
-can do so. This is fundamentally incompatible with the aim of
-protecting users' freedom to change the software. The systematic
-pattern of such abuse occurs in the area of products for individuals to
-use, which is precisely where it is most unacceptable. Therefore, we
-have designed this version of the GPL to prohibit the practice for those
-products. If such problems arise substantially in other domains, we
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
-
- Finally, every program is threatened constantly by software patents.
-States should not allow patents to restrict development and use of
-software on general-purpose computers, but in those that do, we wish to
-avoid the special danger that patents applied to a free program could
-make it effectively proprietary. To prevent this, the GPL assures that
-patents cannot be used to render the program non-free.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- TERMS AND CONDITIONS
-
- 0. Definitions.
-
- "This License" refers to version 3 of the GNU General Public License.
-
- "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
- "The Program" refers to any copyrightable work licensed under this
-License. Each licensee is addressed as "you". "Licensees" and
-"recipients" may be individuals or organizations.
-
- To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy. The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
- A "covered work" means either the unmodified Program or a work based
-on the Program.
-
- To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy. Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
- To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies. Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
- An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License. If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
- 1. Source Code.
-
- The "source code" for a work means the preferred form of the work
-for making modifications to it. "Object code" means any non-source
-form of a work.
-
- A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
- The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form. A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
- The "Corresponding Source" for a work in object code form means all
-the source code needed to generate, install, and (for an executable
-work) run the object code and to modify the work, including scripts to
-control those activities. However, it does not include the work's
-System Libraries, or general-purpose tools or generally available free
-programs which are used unmodified in performing those activities but
-which are not part of the work. For example, Corresponding Source
-includes interface definition files associated with source files for
-the work, and the source code for shared libraries and dynamically
-linked subprograms that the work is specifically designed to require,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
- The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
- The Corresponding Source for a work in source code form is that
-same work.
-
- 2. Basic Permissions.
-
- All rights granted under this License are granted for the term of
-copyright on the Program, and are irrevocable provided the stated
-conditions are met. This License explicitly affirms your unlimited
-permission to run the unmodified Program. The output from running a
-covered work is covered by this License only if the output, given its
-content, constitutes a covered work. This License acknowledges your
-rights of fair use or other equivalent, as provided by copyright law.
-
- You may make, run and propagate covered works that you do not
-convey, without conditions so long as your license otherwise remains
-in force. You may convey covered works to others for the sole purpose
-of having them make modifications exclusively for you, or provide you
-with facilities for running those works, provided that you comply with
-the terms of this License in conveying all material for which you do
-not control copyright. Those thus making or running the covered works
-for you must do so exclusively on your behalf, under your direction
-and control, on terms that prohibit them from making any copies of
-your copyrighted material outside their relationship with you.
-
- Conveying under any other circumstances is permitted solely under
-the conditions stated below. Sublicensing is not allowed; section 10
-makes it unnecessary.
-
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
- No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
- When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
- 4. Conveying Verbatim Copies.
-
- You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
- You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
- 5. Conveying Modified Source Versions.
-
- You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
- a) The work must carry prominent notices stating that you modified
- it, and giving a relevant date.
-
- b) The work must carry prominent notices stating that it is
- released under this License and any conditions added under section
- 7. This requirement modifies the requirement in section 4 to
- "keep intact all notices".
-
- c) You must license the entire work, as a whole, under this
- License to anyone who comes into possession of a copy. This
- License will therefore apply, along with any applicable section 7
- additional terms, to the whole of the work, and all its parts,
- regardless of how they are packaged. This License gives no
- permission to license the work in any other way, but it does not
- invalidate such permission if you have separately received it.
-
- d) If the work has interactive user interfaces, each must display
- Appropriate Legal Notices; however, if the Program has interactive
- interfaces that do not display Appropriate Legal Notices, your
- work need not make them do so.
-
- A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-and which are not combined with it such as to form a larger program,
-in or on a volume of a storage or distribution medium, is called an
-"aggregate" if the compilation and its resulting copyright are not
-used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit. Inclusion of a covered work
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
- 6. Conveying Non-Source Forms.
-
- You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
- a) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by the
- Corresponding Source fixed on a durable physical medium
- customarily used for software interchange.
-
- b) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by a
- written offer, valid for at least three years and valid for as
- long as you offer spare parts or customer support for that product
- model, to give anyone who possesses the object code either (1) a
- copy of the Corresponding Source for all the software in the
- product that is covered by this License, on a durable physical
- medium customarily used for software interchange, for a price no
- more than your reasonable cost of physically performing this
- conveying of source, or (2) access to copy the
- Corresponding Source from a network server at no charge.
-
- c) Convey individual copies of the object code with a copy of the
- written offer to provide the Corresponding Source. This
- alternative is allowed only occasionally and noncommercially, and
- only if you received the object code with such an offer, in accord
- with subsection 6b.
-
- d) Convey the object code by offering access from a designated
- place (gratis or for a charge), and offer equivalent access to the
- Corresponding Source in the same way through the same place at no
- further charge. You need not require recipients to copy the
- Corresponding Source along with the object code. If the place to
- copy the object code is a network server, the Corresponding Source
- may be on a different server (operated by you or a third party)
- that supports equivalent copying facilities, provided you maintain
- clear directions next to the object code saying where to find the
- Corresponding Source. Regardless of what server hosts the
- Corresponding Source, you remain obligated to ensure that it is
- available for as long as needed to satisfy these requirements.
-
- e) Convey the object code using peer-to-peer transmission, provided
- you inform other peers where the object code and Corresponding
- Source of the work are being offered to the general public at no
- charge under subsection 6d.
-
- A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-included in conveying the object code work.
-
- A "User Product" is either (1) a "consumer product", which means any
-tangible personal property which is normally used for personal, family,
-or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling. In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage. For a particular
-product received by a particular user, "normally used" refers to a
-typical or common use of that class of product, regardless of the status
-of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product. A product
-is a consumer product regardless of whether the product has substantial
-commercial, industrial or non-consumer uses, unless such uses represent
-the only significant mode of use of the product.
-
- "Installation Information" for a User Product means any methods,
-procedures, authorization keys, or other information required to install
-and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source. The information must
-suffice to ensure that the continued functioning of the modified object
-code is in no case prevented or interfered with solely because
-modification has been made.
-
- If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-part of a transaction in which the right of possession and use of the
-User Product is transferred to the recipient in perpetuity or for a
-fixed term (regardless of how the transaction is characterized), the
-Corresponding Source conveyed under this section must be accompanied
-by the Installation Information. But this requirement does not apply
-if neither you nor any third party retains the ability to install
-modified object code on the User Product (for example, the work has
-been installed in ROM).
-
- The requirement to provide Installation Information does not include a
-requirement to continue to provide support service, warranty, or updates
-for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed. Access to a
-network may be denied when the modification itself materially and
-adversely affects the operation of the network or violates the rules and
-protocols for communication across the network.
-
- Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
- 7. Additional Terms.
-
- "Additional permissions" are terms that supplement the terms of this
-License by making exceptions from one or more of its conditions.
-Additional permissions that are applicable to the entire Program shall
-be treated as though they were included in this License, to the extent
-that they are valid under applicable law. If additional permissions
-apply only to part of the Program, that part may be used separately
-under those permissions, but the entire Program remains governed by
-this License without regard to the additional permissions.
-
- When you convey a copy of a covered work, you may at your option
-remove any additional permissions from that copy, or from any part of
-it. (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.) You may place
-additional permissions on material, added by you to a covered work,
-for which you have or can give appropriate copyright permission.
-
- Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
- a) Disclaiming warranty or limiting liability differently from the
- terms of sections 15 and 16 of this License; or
-
- b) Requiring preservation of specified reasonable legal notices or
- author attributions in that material or in the Appropriate Legal
- Notices displayed by works containing it; or
-
- c) Prohibiting misrepresentation of the origin of that material, or
- requiring that modified versions of such material be marked in
- reasonable ways as different from the original version; or
-
- d) Limiting the use for publicity purposes of names of licensors or
- authors of the material; or
-
- e) Declining to grant rights under trademark law for use of some
- trade names, trademarks, or service marks; or
-
- f) Requiring indemnification of licensors and authors of that
- material by anyone who conveys the material (or modified versions of
- it) with contractual assumptions of liability to the recipient, for
- any liability that these contractual assumptions directly impose on
- those licensors and authors.
-
- All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10. If the Program as you
-received it, or any part of it, contains a notice stating that it is
-governed by this License along with a term that is a further
-restriction, you may remove that term. If a license document contains
-a further restriction but permits relicensing or conveying under this
-License, you may add to a covered work material governed by the terms
-of that license document, provided that the further restriction does
-not survive such relicensing or conveying.
-
- If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
- Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-the above requirements apply either way.
-
- 8. Termination.
-
- You may not propagate or modify a covered work except as expressly
-provided under this License. Any attempt otherwise to propagate or
-modify it is void, and will automatically terminate your rights under
-this License (including any patent licenses granted under the third
-paragraph of section 11).
-
- However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
- Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-your receipt of the notice.
-
- Termination of your rights under this section does not terminate the
-licenses of parties who have received copies or rights from you under
-this License. If your rights have been terminated and not permanently
-reinstated, you do not qualify to receive new licenses for the same
-material under section 10.
-
- 9. Acceptance Not Required for Having Copies.
-
- You are not required to accept this License in order to receive or
-run a copy of the Program. Ancillary propagation of a covered work
-occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance. However,
-nothing other than this License grants you permission to propagate or
-modify any covered work. These actions infringe copyright if you do
-not accept this License. Therefore, by modifying or propagating a
-covered work, you indicate your acceptance of this License to do so.
-
- 10. Automatic Licensing of Downstream Recipients.
-
- Each time you convey a covered work, the recipient automatically
-receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License. You are not responsible
-for enforcing compliance by third parties with this License.
-
- An "entity transaction" is a transaction transferring control of an
-organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations. If propagation of a covered
-work results from an entity transaction, each party to that
-transaction who receives a copy of the work also receives whatever
-licenses to the work the party's predecessor in interest had or could
-give under the previous paragraph, plus a right to possession of the
-Corresponding Source of the work from the predecessor in interest, if
-the predecessor has it or can get it with reasonable efforts.
-
- You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License. For example, you may
-not impose a license fee, royalty, or other charge for exercise of
-rights granted under this License, and you may not initiate litigation
-(including a cross-claim or counterclaim in a lawsuit) alleging that
-any patent claim is infringed by making, using, selling, offering for
-sale, or importing the Program or any portion of it.
-
- 11. Patents.
-
- A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based. The
-work thus licensed is called the contributor's "contributor version".
-
- A contributor's "essential patent claims" are all patent claims
-owned or controlled by the contributor, whether already acquired or
-hereafter acquired, that would be infringed by some manner, permitted
-by this License, of making, using, or selling its contributor version,
-but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version. For
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
-this License.
-
- Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-propagate the contents of its contributor version.
-
- In the following three paragraphs, a "patent license" is any express
-agreement or commitment, however denominated, not to enforce a patent
-(such as an express permission to practice a patent or covenant not to
-sue for patent infringement). To "grant" such a patent license to a
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
- If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-then you must either (1) cause the Corresponding Source to be so
-available, or (2) arrange to deprive yourself of the benefit of the
-patent license for this particular work, or (3) arrange, in a manner
-consistent with the requirements of this License, to extend the patent
-license to downstream recipients. "Knowingly relying" means you have
-actual knowledge that, but for the patent license, your conveying the
-covered work in a country, or your recipient's use of the covered work
-in a country, would infringe one or more identifiable patents in that
-country that you have reason to believe are valid.
-
- If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-work and works based on it.
-
- A patent license is "discriminatory" if it does not include within
-the scope of its coverage, prohibits the exercise of, or is
-conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License. You may not convey a covered
-work if you are a party to an arrangement with a third party that is
-in the business of distributing software, under which you make payment
-to the third party based on the extent of your activity of conveying
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
- Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
- 12. No Surrender of Others' Freedom.
-
- If conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot convey a
-covered work so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you may
-not convey it at all. For example, if you agree to terms that obligate you
-to collect a royalty for further conveying from those to whom you convey
-the Program, the only way you could satisfy both those terms and this
-License would be to refrain entirely from conveying the Program.
-
- 13. Use with the GNU Affero General Public License.
-
- Notwithstanding any other provision of this License, you have
-permission to link or combine any covered work with a work licensed
-under version 3 of the GNU Affero General Public License into a single
-combined work, and to convey the resulting work. The terms of this
-License will continue to apply to the part which is the covered work,
-but the special requirements of the GNU Affero General Public License,
-section 13, concerning interaction through a network will apply to the
-combination as such.
-
- 14. Revised Versions of this License.
-
- The Free Software Foundation may publish revised and/or new versions of
-the GNU General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
- Each version is given a distinguishing version number. If the
-Program specifies that a certain numbered version of the GNU General
-Public License "or any later version" applies to it, you have the
-option of following the terms and conditions either of that numbered
-version or of any later version published by the Free Software
-Foundation. If the Program does not specify a version number of the
-GNU General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
- If the Program specifies that a proxy can decide which future
-versions of the GNU General Public License can be used, that proxy's
-public statement of acceptance of a version permanently authorizes you
-to choose that version for the Program.
-
- Later license versions may give you additional or different
-permissions. However, no additional obligations are imposed on any
-author or copyright holder as a result of your choosing to follow a
-later version.
-
- 15. Disclaimer of Warranty.
-
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
-HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
-OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. Limitation of Liability.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
- 17. Interpretation of Sections 15 and 16.
-
- If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-state the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-
- Copyright (C)
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-
-Also add information on how to contact you by electronic and paper mail.
-
- If the program does terminal interaction, make it output a short
-notice like this when it starts in an interactive mode:
-
- Copyright (C)
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, your program's commands
-might be different; for a GUI interface, you would use an "about box".
-
- You should also get your employer (if you work as a programmer) or school,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU GPL, see
-.
-
- The GNU General Public License does not permit incorporating your program
-into proprietary programs. If your program is a subroutine library, you
-may consider it more useful to permit linking proprietary applications with
-the library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License. But first, please read
-.
+Mozilla Public License Version 2.0
+==================================
+
+1. Definitions
+--------------
+
+1.1. "Contributor"
+ means each individual or legal entity that creates, contributes to
+ the creation of, or owns Covered Software.
+
+1.2. "Contributor Version"
+ means the combination of the Contributions of others (if any) used
+ by a Contributor and that particular Contributor's Contribution.
+
+1.3. "Contribution"
+ means Covered Software of a particular Contributor.
+
+1.4. "Covered Software"
+ means Source Code Form to which the initial Contributor has attached
+ the notice in Exhibit A, the Executable Form of such Source Code
+ Form, and Modifications of such Source Code Form, in each case
+ including portions thereof.
+
+1.5. "Incompatible With Secondary Licenses"
+ means
+
+ (a) that the initial Contributor has attached the notice described
+ in Exhibit B to the Covered Software; or
+
+ (b) that the Covered Software was made available under the terms of
+ version 1.1 or earlier of the License, but not also under the
+ terms of a Secondary License.
+
+1.6. "Executable Form"
+ means any form of the work other than Source Code Form.
+
+1.7. "Larger Work"
+ means a work that combines Covered Software with other material, in
+ a separate file or files, that is not Covered Software.
+
+1.8. "License"
+ means this document.
+
+1.9. "Licensable"
+ means having the right to grant, to the maximum extent possible,
+ whether at the time of the initial grant or subsequently, any and
+ all of the rights conveyed by this License.
+
+1.10. "Modifications"
+ means any of the following:
+
+ (a) any file in Source Code Form that results from an addition to,
+ deletion from, or modification of the contents of Covered
+ Software; or
+
+ (b) any new file in Source Code Form that contains any Covered
+ Software.
+
+1.11. "Patent Claims" of a Contributor
+ means any patent claim(s), including without limitation, method,
+ process, and apparatus claims, in any patent Licensable by such
+ Contributor that would be infringed, but for the grant of the
+ License, by the making, using, selling, offering for sale, having
+ made, import, or transfer of either its Contributions or its
+ Contributor Version.
+
+1.12. "Secondary License"
+ means either the GNU General Public License, Version 2.0, the GNU
+ Lesser General Public License, Version 2.1, the GNU Affero General
+ Public License, Version 3.0, or any later versions of those
+ licenses.
+
+1.13. "Source Code Form"
+ means the form of the work preferred for making modifications.
+
+1.14. "You" (or "Your")
+ means an individual or a legal entity exercising rights under this
+ License. For legal entities, "You" includes any entity that
+ controls, is controlled by, or is under common control with You. For
+ purposes of this definition, "control" means (a) the power, direct
+ or indirect, to cause the direction or management of such entity,
+ whether by contract or otherwise, or (b) ownership of more than
+ fifty percent (50%) of the outstanding shares or beneficial
+ ownership of such entity.
+
+2. License Grants and Conditions
+--------------------------------
+
+2.1. Grants
+
+Each Contributor hereby grants You a world-wide, royalty-free,
+non-exclusive license:
+
+(a) under intellectual property rights (other than patent or trademark)
+ Licensable by such Contributor to use, reproduce, make available,
+ modify, display, perform, distribute, and otherwise exploit its
+ Contributions, either on an unmodified basis, with Modifications, or
+ as part of a Larger Work; and
+
+(b) under Patent Claims of such Contributor to make, use, sell, offer
+ for sale, have made, import, and otherwise transfer either its
+ Contributions or its Contributor Version.
+
+2.2. Effective Date
+
+The licenses granted in Section 2.1 with respect to any Contribution
+become effective for each Contribution on the date the Contributor first
+distributes such Contribution.
+
+2.3. Limitations on Grant Scope
+
+The licenses granted in this Section 2 are the only rights granted under
+this License. No additional rights or licenses will be implied from the
+distribution or licensing of Covered Software under this License.
+Notwithstanding Section 2.1(b) above, no patent license is granted by a
+Contributor:
+
+(a) for any code that a Contributor has removed from Covered Software;
+ or
+
+(b) for infringements caused by: (i) Your and any other third party's
+ modifications of Covered Software, or (ii) the combination of its
+ Contributions with other software (except as part of its Contributor
+ Version); or
+
+(c) under Patent Claims infringed by Covered Software in the absence of
+ its Contributions.
+
+This License does not grant any rights in the trademarks, service marks,
+or logos of any Contributor (except as may be necessary to comply with
+the notice requirements in Section 3.4).
+
+2.4. Subsequent Licenses
+
+No Contributor makes additional grants as a result of Your choice to
+distribute the Covered Software under a subsequent version of this
+License (see Section 10.2) or under the terms of a Secondary License (if
+permitted under the terms of Section 3.3).
+
+2.5. Representation
+
+Each Contributor represents that the Contributor believes its
+Contributions are its original creation(s) or it has sufficient rights
+to grant the rights to its Contributions conveyed by this License.
+
+2.6. Fair Use
+
+This License is not intended to limit any rights You have under
+applicable copyright doctrines of fair use, fair dealing, or other
+equivalents.
+
+2.7. Conditions
+
+Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
+in Section 2.1.
+
+3. Responsibilities
+-------------------
+
+3.1. Distribution of Source Form
+
+All distribution of Covered Software in Source Code Form, including any
+Modifications that You create or to which You contribute, must be under
+the terms of this License. You must inform recipients that the Source
+Code Form of the Covered Software is governed by the terms of this
+License, and how they can obtain a copy of this License. You may not
+attempt to alter or restrict the recipients' rights in the Source Code
+Form.
+
+3.2. Distribution of Executable Form
+
+If You distribute Covered Software in Executable Form then:
+
+(a) such Covered Software must also be made available in Source Code
+ Form, as described in Section 3.1, and You must inform recipients of
+ the Executable Form how they can obtain a copy of such Source Code
+ Form by reasonable means in a timely manner, at a charge no more
+ than the cost of distribution to the recipient; and
+
+(b) You may distribute such Executable Form under the terms of this
+ License, or sublicense it under different terms, provided that the
+ license for the Executable Form does not attempt to limit or alter
+ the recipients' rights in the Source Code Form under this License.
+
+3.3. Distribution of a Larger Work
+
+You may create and distribute a Larger Work under terms of Your choice,
+provided that You also comply with the requirements of this License for
+the Covered Software. If the Larger Work is a combination of Covered
+Software with a work governed by one or more Secondary Licenses, and the
+Covered Software is not Incompatible With Secondary Licenses, this
+License permits You to additionally distribute such Covered Software
+under the terms of such Secondary License(s), so that the recipient of
+the Larger Work may, at their option, further distribute the Covered
+Software under the terms of either this License or such Secondary
+License(s).
+
+3.4. Notices
+
+You may not remove or alter the substance of any license notices
+(including copyright notices, patent notices, disclaimers of warranty,
+or limitations of liability) contained within the Source Code Form of
+the Covered Software, except that You may alter any license notices to
+the extent required to remedy known factual inaccuracies.
+
+3.5. Application of Additional Terms
+
+You may choose to offer, and to charge a fee for, warranty, support,
+indemnity or liability obligations to one or more recipients of Covered
+Software. However, You may do so only on Your own behalf, and not on
+behalf of any Contributor. You must make it absolutely clear that any
+such warranty, support, indemnity, or liability obligation is offered by
+You alone, and You hereby agree to indemnify every Contributor for any
+liability incurred by such Contributor as a result of warranty, support,
+indemnity or liability terms You offer. You may include additional
+disclaimers of warranty and limitations of liability specific to any
+jurisdiction.
+
+4. Inability to Comply Due to Statute or Regulation
+---------------------------------------------------
+
+If it is impossible for You to comply with any of the terms of this
+License with respect to some or all of the Covered Software due to
+statute, judicial order, or regulation then You must: (a) comply with
+the terms of this License to the maximum extent possible; and (b)
+describe the limitations and the code they affect. Such description must
+be placed in a text file included with all distributions of the Covered
+Software under this License. Except to the extent prohibited by statute
+or regulation, such description must be sufficiently detailed for a
+recipient of ordinary skill to be able to understand it.
+
+5. Termination
+--------------
+
+5.1. The rights granted under this License will terminate automatically
+if You fail to comply with any of its terms. However, if You become
+compliant, then the rights granted under this License from a particular
+Contributor are reinstated (a) provisionally, unless and until such
+Contributor explicitly and finally terminates Your grants, and (b) on an
+ongoing basis, if such Contributor fails to notify You of the
+non-compliance by some reasonable means prior to 60 days after You have
+come back into compliance. Moreover, Your grants from a particular
+Contributor are reinstated on an ongoing basis if such Contributor
+notifies You of the non-compliance by some reasonable means, this is the
+first time You have received notice of non-compliance with this License
+from such Contributor, and You become compliant prior to 30 days after
+Your receipt of the notice.
+
+5.2. If You initiate litigation against any entity by asserting a patent
+infringement claim (excluding declaratory judgment actions,
+counter-claims, and cross-claims) alleging that a Contributor Version
+directly or indirectly infringes any patent, then the rights granted to
+You by any and all Contributors for the Covered Software under Section
+2.1 of this License shall terminate.
+
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all
+end user license agreements (excluding distributors and resellers) which
+have been validly granted by You or Your distributors under this License
+prior to termination shall survive termination.
+
+************************************************************************
+* *
+* 6. Disclaimer of Warranty *
+* ------------------------- *
+* *
+* Covered Software is provided under this License on an "as is" *
+* basis, without warranty of any kind, either expressed, implied, or *
+* statutory, including, without limitation, warranties that the *
+* Covered Software is free of defects, merchantable, fit for a *
+* particular purpose or non-infringing. The entire risk as to the *
+* quality and performance of the Covered Software is with You. *
+* Should any Covered Software prove defective in any respect, You *
+* (not any Contributor) assume the cost of any necessary servicing, *
+* repair, or correction. This disclaimer of warranty constitutes an *
+* essential part of this License. No use of any Covered Software is *
+* authorized under this License except under this disclaimer. *
+* *
+************************************************************************
+
+************************************************************************
+* *
+* 7. Limitation of Liability *
+* -------------------------- *
+* *
+* Under no circumstances and under no legal theory, whether tort *
+* (including negligence), contract, or otherwise, shall any *
+* Contributor, or anyone who distributes Covered Software as *
+* permitted above, be liable to You for any direct, indirect, *
+* special, incidental, or consequential damages of any character *
+* including, without limitation, damages for lost profits, loss of *
+* goodwill, work stoppage, computer failure or malfunction, or any *
+* and all other commercial damages or losses, even if such party *
+* shall have been informed of the possibility of such damages. This *
+* limitation of liability shall not apply to liability for death or *
+* personal injury resulting from such party's negligence to the *
+* extent applicable law prohibits such limitation. Some *
+* jurisdictions do not allow the exclusion or limitation of *
+* incidental or consequential damages, so this exclusion and *
+* limitation may not apply to You. *
+* *
+************************************************************************
+
+8. Litigation
+-------------
+
+Any litigation relating to this License may be brought only in the
+courts of a jurisdiction where the defendant maintains its principal
+place of business and such litigation shall be governed by laws of that
+jurisdiction, without reference to its conflict-of-law provisions.
+Nothing in this Section shall prevent a party's ability to bring
+cross-claims or counter-claims.
+
+9. Miscellaneous
+----------------
+
+This License represents the complete agreement concerning the subject
+matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent
+necessary to make it enforceable. Any law or regulation which provides
+that the language of a contract shall be construed against the drafter
+shall not be used to construe this License against a Contributor.
+
+10. Versions of the License
+---------------------------
+
+10.1. New Versions
+
+Mozilla Foundation is the license steward. Except as provided in Section
+10.3, no one other than the license steward has the right to modify or
+publish new versions of this License. Each version will be given a
+distinguishing version number.
+
+10.2. Effect of New Versions
+
+You may distribute the Covered Software under the terms of the version
+of the License under which You originally received the Covered Software,
+or under the terms of any subsequent version published by the license
+steward.
+
+10.3. Modified Versions
+
+If you create software not governed by this License, and you want to
+create a new license for such software, you may create and use a
+modified version of this License if you rename the license and remove
+any references to the name of the license steward (except to note that
+such modified license differs from this License).
+
+10.4. Distributing Source Code Form that is Incompatible With Secondary
+Licenses
+
+If You choose to distribute Source Code Form that is Incompatible With
+Secondary Licenses under the terms of this version of the License, the
+notice described in Exhibit B of this License must be attached.
+
+Exhibit A - Source Code Form License Notice
+-------------------------------------------
+
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
+If it is not possible or desirable to put the notice in a particular
+file, then You may include the notice in a location (such as a LICENSE
+file in a relevant directory) where a recipient would be likely to look
+for such a notice.
+
+You may add additional accurate notices of copyright ownership.
+
+Exhibit B - "Incompatible With Secondary Licenses" Notice
+---------------------------------------------------------
+
+ This Source Code Form is "Incompatible With Secondary Licenses", as
+ defined by the Mozilla Public License, v. 2.0.
\ No newline at end of file
diff --git a/README.md b/README.md
index 07151347c..26e108995 100644
--- a/README.md
+++ b/README.md
@@ -10,11 +10,12 @@
### What?
The `ArduinoIoTCloud` library is the central element of the firmware enabling certain Arduino boards to connect to the [Arduino IoT Cloud](https://www.arduino.cc/en/IoT/HomePage). The following boards are supported:
-* **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32/releases/tag/1.0.6)
+* **WiFi**: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`GIGA R1 WiFi`](https://store.arduino.cc/products/giga-r1-wifi), [`Portenta C33`](https://store.arduino.cc/products/portenta-c33), [`UNO R4 WiFi`](https://store.arduino.cc/products/uno-r4-wifi), [`Nano ESP32`](https://store.arduino.cc/products/nano-esp32), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32/releases/tag/2.0.5)
* **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415)
* **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413)
* **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310)
-* **Ethernet**: [`Portenta H7`](https://store.arduino.cc/products/portenta-h7) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet), [`Max Carrier`](https://store.arduino.cc/products/portenta-max-carrier), [`Breakout`](https://store.arduino.cc/products/arduino-portenta-breakout), [`Portenta Machine Control`](https://store.arduino.cc/products/arduino-portenta-machine-control)
+* **Ethernet**: [`Portenta H7`](https://store.arduino.cc/products/portenta-h7) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet), [`Portenta Max Carrier`](https://store.arduino.cc/products/portenta-max-carrier), [`Portenta Breakout`](https://store.arduino.cc/collections/portenta-family/products/portenta-breakout), [`Portenta Machine Control`](https://store.arduino.cc/collections/portenta-family/products/portenta-machine-control), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`OPTA RS485`](https://store.arduino.cc/products/opta-rs485), [`OPTA Lite`](https://store.arduino.cc/products/opta-lite), [`Portenta C33`](https://store.arduino.cc/products/portenta-c33) + [`Vision Shield Ethernet`](https://store.arduino.cc/products/arduino-portenta-vision-shield-ethernet)
+* **Notecard**: [Provides Cellular/LoRa/Satellite/Wi-Fi to any modern board/architecture](examples/ArduinoIoTCloud-Notecard/README.md)
### How?
1) Register your Arduino IoT Cloud capable board via [Arduino IoT Cloud](https://create.arduino.cc/iot) (Devices Section).
@@ -70,11 +71,13 @@ void onLedChange() {
### FAQ
#### Watchdog
-The [1.0.0](https://github.com/arduino-libraries/ArduinoIoTCloud/releases/tag/1.0.0) release of this library adds watchdog functionality to all ATSAMD21G18 based cloud connected boards. A watchdog is simply an electronic timer counting down from a preset start value which, upon reaching zero, triggers a reset of the microcontroller. It can be used to automatically recover from temporary hardware faults or unrecoverable software errors. In order to avoid the watchdog from reaching zero the countdown timer needs to be regularly re-set to its start value. This is happening within `ArduinoCloud.update()` which is periodically called at the start of the `loop()` function. Although the watchdog is automatically enabled it can be disabled by setting the second parameter of `ArduinoCloud.begin(...)` to `false`:
+The [1.0.0](https://github.com/arduino-libraries/ArduinoIoTCloud/releases/tag/1.0.0) release of this library adds watchdog functionality to all ATSAMD21G18 based cloud connected boards. A watchdog is simply an electronic timer counting down from a preset start value which, upon reaching zero, triggers a reset of the microcontroller. It can be used to automatically recover from temporary hardware faults or unrecoverable software errors. In order to avoid the watchdog from reaching zero the countdown timer needs to be regularly re-set to its start value. This is happening within `ArduinoCloud.update()` which is periodically called at the start of the `loop()` function. Although the watchdog is automatically enabled it can be disabled by setting the second parameter of `ArduinoCloud.begin(...)` to `false`:
```C++
ArduinoCloud.begin(ArduinoIoTPreferredConnection, false).
```
+Whatchdog is enabled by default using the following boards: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415), [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413), [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`OPTA RS485`](https://store.arduino.cc/products/opta-rs485), [`OPTA Lite`](https://store.arduino.cc/products/opta-lite), [`GIGA R1 WiFi`](https://store.arduino.cc/products/giga-r1-wifi)
+
#### Device can not subscribe to `THING_ID`
```
ArduinoIoTCloudTCP::handle_SubscribeMqttTopics could not subscribe to /a/t/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/e/i
@@ -83,11 +86,13 @@ In this case either the device has not been associated with the thing within the
#### OTA
OTA is supported by the following boards:
-[`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision)
+[`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`OPTA RS485`](https://store.arduino.cc/products/opta-rs485), [`OPTA Lite`](https://store.arduino.cc/products/opta-lite), [`GIGA R1 WiFi`](https://store.arduino.cc/products/giga-r1-wifi), [`Nano ESP32`](https://store.arduino.cc/products/nano-esp32), [`ESP32`](https://github.com/espressif/arduino-esp32/releases/tag/2.0.5)
+
+#### Authentication
+Boards can authenticate to the ArduinoIoTCloud servers using 3 methods:
+
+ * `DEVICE_LOGIN_NAME` and `DEVICE_KEY`. This values are defined in the `thingProperties.h` file and included in the Sketch. Boards that are using this method are: [`UNO R4 WiFi`](https://store.arduino.cc/products/uno-r4-wifi), [`Nano ESP32`](https://store.arduino.cc/products/nano-esp32), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32/releases/tag/2.0.5)
-#### ESP Boards
-Support for ESP boards is obtained through a third-party core with some differences and limitations compared to Arduino boards.
+ * `DEVICE_CERTIFICATE` and `PRIVATE_KEY`. This values are stored inside the board secure element during the device provisioning phase. Boards that are using this method are: [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415), [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`Portenta H7`](https://store.arduino.cc/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), [`OPTA WiFi`](https://store.arduino.cc/products/opta-wifi), [`OPTA RS485`](https://store.arduino.cc/products/opta-rs485), [`OPTA Lite`](https://store.arduino.cc/products/opta-lite), [`GIGA R1 WiFi`](https://store.arduino.cc/products/giga-r1-wifi), [`Portenta C33`](https://store.arduino.cc/products/portenta-c33)
-- **Authentication scheme**: Board authentication is done through `DEVICE_LOGIN_NAME` and `DEVICE_KEY`, both values are included in the `thingProperties.h` file.
-- **Watchdog**: Watchdog support is not included.
-- **OTA**: OTA support is not included
+ * `APP_EUI` and `APP_KEY`. This values are defined in the `thingProperties.h` file and included in the Sketch. Boards that are using this method are: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310)
diff --git a/docs/api.md b/docs/api.md
new file mode 100644
index 000000000..e4825e2d6
--- /dev/null
+++ b/docs/api.md
@@ -0,0 +1,504 @@
+## ArduinoCloud Class (Base)
+
+### `ArduinoCloud (Class)`
+
+#### Description
+
+`ArduinoIoTCloud` is a class for interfacing with the Arduino IoT Cloud. It provides an interface for managing IoT Cloud connectivity, updating data, and handling events.
+
+Depending on what type of connection is used (TCP/LPWAN), either the `ArduinoIoTCloudTCP` or `ArduinoIoTCloudLPWAN` base classes are initialized. This specification is done in the Arduino IoT Cloud's "Thing" interface, and is reflected in the automatically generated `thingProperties.h` file.
+
+The above classes are inherited from the `ArduinoIoTCloudClass` base class, with methods used depending on what connection is used.
+
+#### Syntax
+
+```
+ArduinoCloud.method()
+```
+
+### `push()`
+
+#### Description
+
+Pushes data to the IoT Cloud.
+
+#### Syntax
+
+```
+ArduinoCloud.push()
+```
+
+#### Parameters
+
+None.
+
+#### Returns
+
+Nothing.
+
+### `setTimestamp()`
+
+Sets a timestamp for a cloud variable.
+
+#### Syntax
+
+```
+ArduinoCloud.setTimestamp(cloudVariable, timestamp)
+```
+
+#### Parameters
+
+- `String` - property name
+- `unsigned long const` - timestamp
+
+
+### `getThingId()`
+
+Gets the Thing ID.
+
+#### Syntax
+
+```
+ArduinoCloud.getThingId()
+```
+
+#### Parameters
+None.
+
+#### Returns
+- `String` - Thing ID.
+
+### `setDeviceId()`
+
+Sets the Device ID.
+
+#### Syntax
+
+```
+ArduinoCloud.setDeviceId(deviceId)
+```
+
+#### Parameters
+
+- `String` - Device ID.
+
+### `getDeviceId()`
+
+Gets the Device ID.
+
+#### Syntax
+
+```
+ArduinoCloud.getDeviceId()
+```
+
+#### Parameters
+
+None
+
+#### Returns
+
+- `String` - Device ID.
+
+### `getConnection()`
+
+Gets the connection handler used.
+
+#### Syntax
+
+```
+ArduinoCloud.getConnection()
+```
+
+#### Parameters
+
+### `getInternalTime()`
+
+Gets the internal time.
+
+#### Syntax
+
+```
+ArduinoCloud.getInternalTime()
+```
+
+#### Parameters
+None.
+
+#### Returns
+- `unsigned long` - internal time
+
+### `getLocalTime()`
+
+Gets the local time (based on your time zone).
+
+#### Syntax
+
+```
+ArduinoCloud.getLocalTime()
+```
+
+#### Parameters
+None
+
+#### Returns
+- `unsigned long` - local time
+
+
+### `addCallback()`
+
+Adds a callback function for IoT Cloud events.
+
+#### Syntax
+
+```
+ArduinoCloud.addCallback(ArduinoIoTCloudEvent::CONNECT, doThisOnConnect);
+ArduinoCloud.addCallback(ArduinoIoTCloudEvent::SYNC, doThisOnSync);
+ArduinoCloud.addCallback(ArduinoIoTCloudEvent::DISCONNECT, doThisOnDisconnect);
+```
+
+#### Parameters
+- Event (CONNECT, SYNC, DISCONNECT)
+- Callback function
+
+#### Example
+
+See the [ArduinoIoTCloud-Callbacks](https://github.com/arduino-libraries/ArduinoIoTCloud/blob/master/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino) example.
+
+
+
+## ArduinoCloud Class (TCP)
+
+### `begin()` (TCP)
+
+#### Description
+
+Initialises the library with the connection handler specified in `thingProperties.h`. This is automatically generated based on the type of device.
+
+#### Syntax
+
+```
+ArduinoCloud.begin()
+```
+
+#### Parameters
+
+The `ArduinoIoTPreferredConnection` object is created automatically inside a `thingProperties.h` file when configuring a Thing and depends on what type of device you use. The connection handler classes are not part of the Arduino IoT Cloud, but exists inside the [Arduino_ConnectionHandler](https://github.com/arduino-libraries/Arduino_ConnectionHandler) library (listed as a dependency).
+
+For example, using the `WiFiConnectionHandler`, we use the `SSID`, `PASS` parameters which are defined in the `arduino_secrets.h` file, also generated based on what you input in the Arduino IoT Cloud interface.
+
+```
+WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
+```
+
+#### Returns
+Nothing.
+
+### `update()` (TCP)
+
+#### Description
+
+**Note:** for LoRa devices, the `update()` function is implemented differently. See
+
+Responsible for updating the IoT Cloud connection.
+- First it feeds a watchdog timer, making sure it is not stuck anywhere,
+- then sends variable updates to the IoT Cloud (via MQTT client)
+- finally, it checks for new data from the IoT Cloud (via the MQTT client)
+
+Any IoT Cloud sketch needs to continuously call the `update()` function, as it will otherwise time out and reset. The `update()` is by default placed inside of the `loop()`.
+
+**Note:** do not use the `delay()` function in the sketch, as the watchdog timer will cause the board to reset and attempt to reconnect.
+
+#### Syntax
+
+```
+ArduinoCloud.update()
+```
+
+#### Parameters
+None.
+
+#### Returns
+Nothing.
+
+
+### `connected()` (TCP)
+
+#### Description
+
+Checks the connection status and returns an integer the connection status (int).
+
+#### Syntax
+
+```
+ArduinoCloud.connected()
+```
+
+#### Parameters
+None.
+
+#### Returns
+- `int` - status of connection
+
+### `printDebugInfo()` (TCP)
+
+#### Description
+
+Print any available debug information.
+
+#### Parameters
+None
+
+#### Returns
+Nothing.
+
+### `addProperty()` (TCP)
+
+#### Description
+
+Adds a variable/property with a set of parameters.
+
+#### Syntax
+```
+ArduinoCloud.addProperty(cloudVariable, tag, permission, policy, callbackFunction)
+```
+
+#### Parameters
+- `cloudVariable` - name of the variable/property.
+- `permission` - can either be `READ` / `WRITE` or `READWRITE`
+- `policy` - `ON_CHANGE` (whenever variable data changes) or ` * SECONDS`. `` is specified in the Thing configuration.
+- `callBackFunction` - by default, a callback function is added to a variable with **WRITE** permissions. A variable called `test` will automatically be added as `onTestChange` which also is added to your sketch.
+
+#### Returns
+Nothing.
+
+### `setBoardId()`
+
+#### Description
+
+This method is only enabled if you are using an ESP32/ESP8266 board, and sets the board/device id.
+
+Currently, the following official Arduino boards uses this method:
+- [Arduino UNO R4 WiFi](https://store.arduino.cc/products/uno-r4-wifi)
+- [Arduino Nano ESP32](https://store.arduino.cc/products/nano-esp32)
+
+#### Syntax
+
+```
+ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
+```
+
+### `setSecretDeviceKey()`
+
+#### Description
+
+This method is only enabled if you are using an ESP32/ESP8266 based board, and sets the secret device key for the device. The secret key is only obtainable from the Arduino IoT Cloud during device configuration.
+
+#### Syntax
+
+```
+ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
+```
+
+### `getBrokerAddress()`
+
+#### Description
+
+Get the MQTT broker address used.
+
+#### Syntax
+
+```
+ArduinoCloud.getBrokerAddress()
+```
+
+#### Parameters
+None.
+
+#### Return
+- `String` - the MQTT broker address.
+
+### `getBrokerPort()`
+
+#### Description
+
+Get the MQTT broker port used.
+
+#### Syntax
+
+```
+ArduinoCloud.getBrokerPort()
+```
+
+#### Parameters
+None.
+
+#### Return
+- `int` - the MQTT broker port.
+
+
+
+## ArduinoCloud Class (LPWAN)
+
+### `begin()` (LPWAN)
+
+### Description
+This function initializes the ArduinoIoTCloudLPWAN library with the specified connection handler and retry settings.
+
+#### Parameters
+- `ConnectionHandler` - object containing `APPEUI`, `APPKEY` and frequency band (e.g. `_lora_band::EU868`)
+- `bool` - a boolean value that decides whether retry functionality is enabled (`true`) or disabled (`false`)
+
+#### Returns
+
+- `int` - returns `1` on successful initialization.
+
+### `update()` (LPWAN)
+
+#### Description
+
+This method handles the update between the board and the IoT Cloud.
+
+#### Syntax
+
+```
+ArduinoCloud.update()
+```
+
+#### Parameters
+None.
+
+#### Returns
+Nothing.
+
+
+### `connected()` (LPWAN)
+
+#### Description
+
+Checks the connection status and returns an integer the connection status (int).
+
+#### Syntax
+
+```
+ArduinoCloud.connected()
+```
+
+#### Parameters
+None.
+
+#### Returns
+- `int` - status of connection
+
+### `printDebugInfo()` (LPWAN)
+
+#### Description
+
+Print any available debug information.
+
+#### Parameters
+None.
+
+#### Returns
+Nothing.
+
+### `addProperty()` (LPWAN)
+
+#### Description
+
+Adds a variable/property with a set of parameters.
+
+#### Syntax
+```
+ArduinoCloud.addProperty(cloudVariable, tag, permission, policy, callbackFunction)
+```
+
+#### Parameters
+- `cloudVariable` - name of the variable/property.
+- `permission` - can either be `READ` / `WRITE` or `READWRITE`
+- `tag` - matches the cloud and local variables with a number. E.g. adding a second variable will have the tag `2`.
+- `policy` - `ON_CHANGE` (whenever variable data changes) or ` * SECONDS`. `` is specified in the Thing configuration.
+- `callBackFunction` - by default, a callback function is added to a variable with **WRITE** permissions. A variable called `test` will automatically be added as `onTestChange` which also is added to your sketch.
+
+#### Returns
+Nothing.
+
+### `setThingId()`
+
+Sets the Thing ID.
+
+#### Syntax
+
+```
+ArduinoCloud.setThingId(thingId)
+```
+
+#### Parameters
+- `String` - your Thing's ID. Obtainable in the IoT Cloud interface.
+
+
+### `isRetryEnabled()`
+
+#### Description
+This method is used to check whether retry functionality is enabled.
+
+#### Parameters
+None.
+
+#### Returns
+- `bool` - returns `true` if retry functionality is enabled, otherwise returns `false`.
+
+
+### `getMaxRetry()`
+
+#### Description
+This method is used to retrieve the maximum number of retry attempts.
+
+#### Parameters
+None.
+
+#### Returns
+- `int` - returns the maximum number of retry attempts as an integer.
+
+### `getIntervalRetry()`
+
+#### Description
+This method is used to retrieve the interval in milliseconds between the retry attempts.
+
+#### Parameters
+None.
+
+#### Returns
+- `long` - returns the interval between retry attempts in milliseconds.
+
+### `enableRetry()`
+
+#### Description
+This method is used to enable or disable retry functionality.
+
+#### Parameters
+- `bool` - if `true`, retry functionality is enabled; if `false`, retry functionality is disabled.
+
+#### Returns
+Nothing.
+
+### `setMaxRetry()`
+
+Used to set the maximum number of retry attempts.
+
+#### Parameters
+- `int` - the maximum number of retry attempts to set.
+
+#### Returns
+Nothing.
+
+### `setIntervalRetry()`
+
+#### Description
+Sets the interval in milliseconds between retry attempts.
+
+#### Parameters
+- `long` - the interval between retry attempts in milliseconds to set.
+
+#### Returns
+Nothing.
\ No newline at end of file
diff --git a/docs/readme.md b/docs/readme.md
new file mode 100644
index 000000000..16c3cea7b
--- /dev/null
+++ b/docs/readme.md
@@ -0,0 +1,36 @@
+# ArduinoIoTCloud
+
+The ArduinoIoTCloud library is the central element of the firmware enabling certain Arduino boards to connect to the [Arduino IoT Cloud](https://create.arduino.cc/iot/).
+
+- To get started, check out the [official documentation](https://docs.arduino.cc/arduino-cloud/)
+- For source code, check out the [GitHub repository](https://github.com/arduino-libraries/ArduinoIoTCloud)
+
+## thingProperties.h
+
+When you are create and configure a Thing in the [Arduino IoT Cloud interface](https://create.arduino.cc/iot/), the `thingProperties.h` file is generated automatically.
+
+This file adds all the variable/properties along with its specifications (e.g. update policy, read/write permissions), and the type of connection handler depending on what device you have attached.
+
+Methods such as `addProperty()` and `setThingId()` are implemented here, so there's no need for manually entering anything.
+
+We recommend that **you do not edit this file** as it is automatically updating whenever you make changes in the Arduino IoT Cloud.
+
+### Offline Editing
+
+If you have set up your sketch in an offline environment, make sure that whatever changes you make are reflected in this file, as it will be updated in the online environment.
+
+## TCP / LPWAN
+
+Depending on what type of connection is used (TCP/LPWAN), either the `ArduinoIoTCloudTCP` or `ArduinoIoTCloudLPWAN` base classes are initialized. This specification is done in the Arduino IoT Cloud's "Thing" interface, and is reflected in the automatically generated `thingProperties.h` file.
+
+- If a board is configured as a **TCP** device, it will automatically include the `ArduinoIoTCloudTCP.h` file, and methods of the `ArduinoIoTCloudTCP` class will be made available. This is the most common option.
+- If a board is configured as an **LPWAN** device, it will instead include the `ArduinoIoTCloudLPWAN.h` file, and methods of the `ArduinoIoTCloudLPWAN` class will be made available.
+
+As a result, functions such as `begin()`, `update()`, `connected()` and `printDebugInfo()` are documented under each corresponding class.
+
+## Connection Handler Library
+
+When the library is initialized via the `begin()` function, it will choose the specified **connection handler**, which is automatically added to your `thingProperties.h` file when configuring a Thing.
+
+The connection handler is done via another library, [Arduino_ConnectionHandler](https://github.com/arduino-libraries/Arduino_ConnectionHandler), which supports Wi-Fi®, GSM, NB-IoT, LoRa® & Ethernet.
+
diff --git a/examples/ArduinoIoTCloud-AWS-Basic/ArduinoIoTCloud-AWS-Basic.ino b/examples/ArduinoIoTCloud-AWS-Basic/ArduinoIoTCloud-AWS-Basic.ino
new file mode 100644
index 000000000..3213a3bf8
--- /dev/null
+++ b/examples/ArduinoIoTCloud-AWS-Basic/ArduinoIoTCloud-AWS-Basic.ino
@@ -0,0 +1,151 @@
+#include "arduino_secrets.h"
+/*
+ This sketch demonstrates how to connect to ArduinoIoTCloud and AWS IoT core.
+
+ The full list of compatible boards can be found here:
+ - https://github.com/arduino-libraries/ArduinoIoTCloud#what
+*/
+
+#include "thingProperties.h"
+#include "aws_secrets.h"
+
+Client& getDefaultClient() {
+ switch(ArduinoIoTPreferredConnection.getInterface()) {
+
+#ifdef BOARD_HAS_WIFI
+ case NetworkAdapter::WIFI:
+ static WiFiClient wclient;
+ return wclient;
+#endif
+
+#ifdef BOARD_HAS_ETHERNET
+ case NetworkAdapter::ETHERNET:
+ static EthernetClient eclient;
+ return eclient;
+#endif
+
+ default:
+ Serial.println("Error: could not create default AWS client");
+ break;
+ }
+}
+
+unsigned long publishMillis = 0;
+unsigned long connectMillis = 0;
+
+BearSSLClient sslClientAWS(getDefaultClient());
+MqttClient mqttClientAWS(sslClientAWS);
+
+void setup() {
+ /* Initialize serial and wait up to 5 seconds for port to open */
+ Serial.begin(9600);
+
+ /* Configure LED pin as an output */
+ pinMode(LED_BUILTIN, OUTPUT);
+
+ /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
+ initProperties();
+
+ /* Initialize Arduino IoT Cloud library */
+ ArduinoCloud.begin(ArduinoIoTPreferredConnection, true, "iot.arduino.cc");
+
+ setDebugMessageLevel(5);
+ ArduinoCloud.printDebugInfo();
+
+ /* Initialize AWS Client */
+ ArduinoBearSSL.onGetTime(getTime);
+ sslClientAWS.setEccSlot(AWS_SLOT, AWS_CERTIFICATE);
+
+ mqttClientAWS.setId("ArduinoAWSClient");
+ mqttClientAWS.onMessage(onMessageReceived);
+ mqttClientAWS.setConnectionTimeout(10 * 1000);
+ mqttClientAWS.setKeepAliveInterval(30 * 1000);
+ mqttClientAWS.setCleanSession(false);
+}
+
+void loop() {
+ ArduinoCloud.update();
+ potentiometer = analogRead(A0);
+ seconds = millis() / 1000;
+
+ if (!ArduinoCloud.connected()) {
+ return;
+ }
+
+ if (!mqttClientAWS.connected()) {
+ if (millis() - connectMillis > 5000) {
+ connectMillis = millis();
+ // MQTT client is disconnected, connect
+ if (!connectMQTT()) {
+ return;
+ }
+ } else {
+ return;
+ }
+ }
+
+ // poll for new MQTT messages and send keep alive
+ mqttClientAWS.poll();
+
+ // publish a message roughly every 5 seconds.
+ if (millis() - publishMillis > 5000) {
+ publishMillis = millis();
+
+ publishMessage();
+ }
+}
+
+/*
+ * 'onLedChange' is called when the "led" property of your Thing changes
+ */
+void onLedChange() {
+ Serial.print("LED set to ");
+ Serial.println(led);
+ digitalWrite(LED_BUILTIN, led);
+}
+
+void onMessageReceived(int messageSize)
+{
+ // we received a message, print out the topic and contents
+ Serial.print("Received a message with topic '");
+ Serial.print(mqttClientAWS.messageTopic());
+ Serial.print("', length ");
+ Serial.print(messageSize);
+ Serial.println(" bytes:");
+
+ for (int i = 0; i < messageSize; i++) {
+ const char c = mqttClientAWS.read();
+ Serial.print(c);
+ }
+ Serial.println();
+}
+
+int connectMQTT() {
+ Serial.print("Attempting to connect to MQTT broker: ");
+ Serial.print(AWS_BROKER);
+ Serial.println(" ");
+
+ if (!mqttClientAWS.connect(AWS_BROKER, 8883)) {
+ // failed, retry
+ Serial.print(".");
+ return 0;
+ }
+ Serial.println();
+
+ Serial.println("You're connected to the MQTT broker");
+ Serial.println();
+
+ // subscribe to a topic
+ mqttClientAWS.subscribe("arduino/incoming");
+ return 1;
+}
+
+void publishMessage() {
+ Serial.println("Publishing message");
+
+ // send message, the Print interface can be used to set the message contents
+ mqttClientAWS.beginMessage("arduino/outgoing");
+ mqttClientAWS.print("hello ");
+ mqttClientAWS.print(millis());
+ mqttClientAWS.endMessage();
+}
diff --git a/examples/ArduinoIoTCloud-AWS-Basic/arduino_secrets.h b/examples/ArduinoIoTCloud-AWS-Basic/arduino_secrets.h
new file mode 100644
index 000000000..dee3e7210
--- /dev/null
+++ b/examples/ArduinoIoTCloud-AWS-Basic/arduino_secrets.h
@@ -0,0 +1,2 @@
+#define SECRET_SSID ""
+#define SECRET_OPTIONAL_PASS ""
diff --git a/examples/ArduinoIoTCloud-AWS-Basic/aws_secrets.h b/examples/ArduinoIoTCloud-AWS-Basic/aws_secrets.h
new file mode 100644
index 000000000..07131d1da
--- /dev/null
+++ b/examples/ArduinoIoTCloud-AWS-Basic/aws_secrets.h
@@ -0,0 +1,10 @@
+/* Fill in the hostname of your AWS IoT broker */
+#define AWS_BROKER ""
+
+#define AWS_SLOT 4
+
+/* Fill in the boards public certificate */
+const char AWS_CERTIFICATE[] = R"(
+-----BEGIN CERTIFICATE-----
+-----END CERTIFICATE-----
+)";
diff --git a/examples/ArduinoIoTCloud-AWS-Basic/thingProperties.h b/examples/ArduinoIoTCloud-AWS-Basic/thingProperties.h
new file mode 100644
index 000000000..6717ea377
--- /dev/null
+++ b/examples/ArduinoIoTCloud-AWS-Basic/thingProperties.h
@@ -0,0 +1,21 @@
+// Code generated by Arduino IoT Cloud, DO NOT EDIT.
+
+#include
+#include
+
+const char SSID[] = SECRET_SSID; // Network SSID (name)
+const char PASS[] = SECRET_OPTIONAL_PASS; // Network password (use for WPA, or use as key for WEP)
+
+void onLedChange();
+
+bool led;
+int potentiometer;
+int seconds;
+
+void initProperties() {
+ ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
+ ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
+ ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1);
+}
+
+WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_OPTIONAL_PASS);
diff --git a/examples/ArduinoIoTCloud-Advanced/ArduinoIoTCloud-Advanced.ino b/examples/ArduinoIoTCloud-Advanced/ArduinoIoTCloud-Advanced.ino
index a026d6297..f5f9b03b9 100644
--- a/examples/ArduinoIoTCloud-Advanced/ArduinoIoTCloud-Advanced.ino
+++ b/examples/ArduinoIoTCloud-Advanced/ArduinoIoTCloud-Advanced.ino
@@ -3,20 +3,28 @@
IMPORTANT:
This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
- On a LoRa board, if it is configured as a class A device (default and preferred option), values from Cloud dashboard are received
- only after a value is sent to Cloud.
+ On a LoRa board, if it is configured as a class A device (default and preferred option),
+ values from Cloud dashboard are received only after a value is sent to Cloud.
The full list of compatible boards can be found here:
- https://github.com/arduino-libraries/ArduinoIoTCloud#what
*/
-#include "arduino_secrets.h"
#include "thingProperties.h"
void setup() {
/* Initialize serial and wait up to 5 seconds for port to open */
Serial.begin(9600);
- for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
+ for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
+
+ /* Set the debug message level:
+ * - DBG_ERROR: Only show error messages
+ * - DBG_WARNING: Show warning and error messages
+ * - DBG_INFO: Show info, warning, and error messages
+ * - DBG_DEBUG: Show debug, info, warning, and error messages
+ * - DBG_VERBOSE: Show all messages
+ */
+ setDebugMessageLevel(DBG_INFO);
/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
initProperties();
@@ -24,7 +32,6 @@ void setup() {
/* Initialize Arduino IoT Cloud library */
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
- setDebugMessageLevel(DBG_INFO);
ArduinoCloud.printDebugInfo();
}
diff --git a/examples/ArduinoIoTCloud-Advanced/arduino_secrets.h b/examples/ArduinoIoTCloud-Advanced/arduino_secrets.h
index d1615135f..4134e9377 100644
--- a/examples/ArduinoIoTCloud-Advanced/arduino_secrets.h
+++ b/examples/ArduinoIoTCloud-Advanced/arduino_secrets.h
@@ -1,21 +1,22 @@
-#include
#include
/* A complete list of supported boards with WiFi is available here:
* https://github.com/arduino-libraries/ArduinoIoTCloud/#what
*/
#if defined(BOARD_HAS_WIFI)
- #define SECRET_SSID "YOUR_WIFI_NETWORK_NAME"
- #define SECRET_PASS "YOUR_WIFI_PASSWORD"
+ #define SECRET_WIFI_SSID "YOUR_WIFI_NETWORK_NAME"
+ #define SECRET_WIFI_PASS "YOUR_WIFI_PASSWORD"
#endif
-/* ESP8266 ESP32*/
-#if defined(BOARD_ESP)
+/* ESP8266 ESP32 */
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
#define SECRET_DEVICE_KEY "my-device-password"
#endif
-/* MKR GSM 1400 */
-#if defined(BOARD_HAS_GSM)
+/* MKR GSM 1400 */ /* MKR NB 1500 */ /* Portenta CAT.M1/NB IoT GNSS Shield */
+/* Portenta H7 and C33 + Portenta Mid Carrier + 4G Module */
+#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || \
+ defined(BOARD_HAS_CATM1_NBIOT) || defined(BOARD_HAS_CELLULAR)
#define SECRET_PIN ""
#define SECRET_APN ""
#define SECRET_LOGIN ""
@@ -28,14 +29,6 @@
#define SECRET_APP_KEY ""
#endif
-/* MKR NB 1500 */
-#if defined(BOARD_HAS_NB)
- #define SECRET_PIN ""
- #define SECRET_APN ""
- #define SECRET_LOGIN ""
- #define SECRET_PASS ""
-#endif
-
/* Portenta H7 + Ethernet shield */
#if defined(BOARD_HAS_ETHERNET)
#define SECRET_OPTIONAL_IP ""
diff --git a/examples/ArduinoIoTCloud-Advanced/thingProperties.h b/examples/ArduinoIoTCloud-Advanced/thingProperties.h
index f8d7bb506..482b2991e 100644
--- a/examples/ArduinoIoTCloud-Advanced/thingProperties.h
+++ b/examples/ArduinoIoTCloud-Advanced/thingProperties.h
@@ -1,16 +1,19 @@
-#if defined(BOARD_HAS_WIFI)
-#elif defined(BOARD_HAS_GSM)
-#elif defined(BOARD_HAS_LORA)
-#elif defined(BOARD_HAS_NB)
-#elif defined(BOARD_HAS_ETHERNET)
-#else
- #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
+#include
+#include
+#include "arduino_secrets.h"
+
+#if !(defined(HAS_TCP) || defined(HAS_LORA))
+ #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
#endif
-#if defined(BOARD_ESP)
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
#endif
+#if defined(HAS_LORA)
+ #define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
+#endif
+
void onSwitchButtonChange();
void onColorChange();
@@ -19,32 +22,39 @@ CloudLocation location;
CloudColor color;
void initProperties() {
-#if defined(BOARD_ESP)
+#if defined(HAS_TCP)
+ ArduinoCloud.addProperty(switchButton, Permission::Write).onUpdate(onSwitchButtonChange);
+ ArduinoCloud.addProperty(location, Permission::Read).publishOnChange(0.0f);
+ ArduinoCloud.addProperty(color, Permission::ReadWrite).onUpdate(onColorChange);
+
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
ArduinoCloud.setBoardId(BOARD_ID);
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
#endif
-#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB)
- ArduinoCloud.addProperty(switchButton, WRITE, ON_CHANGE, onSwitchButtonChange);
- ArduinoCloud.addProperty(location, READ, ON_CHANGE);
- ArduinoCloud.addProperty(color, READWRITE, ON_CHANGE, onColorChange);
-#elif defined(BOARD_HAS_LORA)
- ArduinoCloud.addProperty(switchButton, 1, WRITE, ON_CHANGE, onSwitchButtonChange);
- ArduinoCloud.addProperty(location, 2, READ, ON_CHANGE);
- ArduinoCloud.addProperty(color, 3, READWRITE, ON_CHANGE, onColorChange);
+#elif defined(HAS_LORA)
+ ArduinoCloud.addProperty(switchButton, 1, Permission::Write).onUpdate(onSwitchButtonChange);
+ ArduinoCloud.addProperty(location, 2, Permission::Read).publishOnChange(0.0f);
+ ArduinoCloud.addProperty(color, 3, Permission::ReadWrite).onUpdate(onColorChange);
+
+ ArduinoCloud.setThingId(THING_ID);
#endif
}
#if defined(BOARD_HAS_WIFI)
- WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS);
+ WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
#elif defined(BOARD_HAS_GSM)
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#elif defined(BOARD_HAS_LORA)
LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A);
#elif defined(BOARD_HAS_NB)
NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
+#elif defined(BOARD_HAS_CATM1_NBIOT)
+ CatM1ConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#elif defined(BOARD_HAS_ETHERNET)
/* DHCP mode */
//EthernetConnectionHandler ArduinoIoTPreferredConnection;
/* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */
EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK);
+#elif defined(BOARD_HAS_CELLULAR)
+ CellularConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#endif
diff --git a/examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino b/examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino
index a32644941..238b59f55 100644
--- a/examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino
+++ b/examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino
@@ -7,24 +7,32 @@
IMPORTANT:
This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
- On a LoRa board, if it is configured as a class A device (default and preferred option), values from Cloud dashboard are received
- only after a value is sent to Cloud.
+ On a LoRa board, if it is configured as a class A device (default and preferred option),
+ values from Cloud dashboard are received only after a value is sent to Cloud.
The full list of compatible boards can be found here:
- https://github.com/arduino-libraries/ArduinoIoTCloud#what
*/
-#include "arduino_secrets.h"
#include "thingProperties.h"
-#if !defined(LED_BUILTIN)
+#if !defined(LED_BUILTIN) && !defined(ARDUINO_NANO_ESP32)
static int const LED_BUILTIN = 2;
#endif
void setup() {
/* Initialize serial and wait up to 5 seconds for port to open */
Serial.begin(9600);
- for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
+ for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
+
+ /* Set the debug message level:
+ * - DBG_ERROR: Only show error messages
+ * - DBG_WARNING: Show warning and error messages
+ * - DBG_INFO: Show info, warning, and error messages
+ * - DBG_DEBUG: Show debug, info, warning, and error messages
+ * - DBG_VERBOSE: Show all messages
+ */
+ setDebugMessageLevel(DBG_INFO);
/* Configure LED pin as an output */
pinMode(LED_BUILTIN, OUTPUT);
@@ -35,7 +43,6 @@ void setup() {
/* Initialize Arduino IoT Cloud library */
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
- setDebugMessageLevel(DBG_INFO);
ArduinoCloud.printDebugInfo();
}
diff --git a/examples/ArduinoIoTCloud-Basic/arduino_secrets.h b/examples/ArduinoIoTCloud-Basic/arduino_secrets.h
index d1615135f..4134e9377 100644
--- a/examples/ArduinoIoTCloud-Basic/arduino_secrets.h
+++ b/examples/ArduinoIoTCloud-Basic/arduino_secrets.h
@@ -1,21 +1,22 @@
-#include
#include
/* A complete list of supported boards with WiFi is available here:
* https://github.com/arduino-libraries/ArduinoIoTCloud/#what
*/
#if defined(BOARD_HAS_WIFI)
- #define SECRET_SSID "YOUR_WIFI_NETWORK_NAME"
- #define SECRET_PASS "YOUR_WIFI_PASSWORD"
+ #define SECRET_WIFI_SSID "YOUR_WIFI_NETWORK_NAME"
+ #define SECRET_WIFI_PASS "YOUR_WIFI_PASSWORD"
#endif
-/* ESP8266 ESP32*/
-#if defined(BOARD_ESP)
+/* ESP8266 ESP32 */
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
#define SECRET_DEVICE_KEY "my-device-password"
#endif
-/* MKR GSM 1400 */
-#if defined(BOARD_HAS_GSM)
+/* MKR GSM 1400 */ /* MKR NB 1500 */ /* Portenta CAT.M1/NB IoT GNSS Shield */
+/* Portenta H7 and C33 + Portenta Mid Carrier + 4G Module */
+#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || \
+ defined(BOARD_HAS_CATM1_NBIOT) || defined(BOARD_HAS_CELLULAR)
#define SECRET_PIN ""
#define SECRET_APN ""
#define SECRET_LOGIN ""
@@ -28,14 +29,6 @@
#define SECRET_APP_KEY ""
#endif
-/* MKR NB 1500 */
-#if defined(BOARD_HAS_NB)
- #define SECRET_PIN ""
- #define SECRET_APN ""
- #define SECRET_LOGIN ""
- #define SECRET_PASS ""
-#endif
-
/* Portenta H7 + Ethernet shield */
#if defined(BOARD_HAS_ETHERNET)
#define SECRET_OPTIONAL_IP ""
diff --git a/examples/ArduinoIoTCloud-Basic/thingProperties.h b/examples/ArduinoIoTCloud-Basic/thingProperties.h
index e11eaf81f..8ad84c419 100644
--- a/examples/ArduinoIoTCloud-Basic/thingProperties.h
+++ b/examples/ArduinoIoTCloud-Basic/thingProperties.h
@@ -1,16 +1,19 @@
-#if defined(BOARD_HAS_WIFI)
-#elif defined(BOARD_HAS_GSM)
-#elif defined(BOARD_HAS_LORA)
-#elif defined(BOARD_HAS_NB)
-#elif defined(BOARD_HAS_ETHERNET)
-#else
- #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
+#include
+#include
+#include "arduino_secrets.h"
+
+#if !(defined(HAS_TCP) || defined(HAS_LORA))
+ #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
#endif
-#if defined(BOARD_ESP)
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
#endif
+#if defined(HAS_LORA)
+ #define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
+#endif
+
void onLedChange();
bool led;
@@ -18,18 +21,21 @@ int potentiometer;
int seconds;
void initProperties() {
-#if defined(BOARD_ESP)
- ArduinoCloud.setBoardId(BOARD_ID);
- ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
-#endif
-#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET)
+#if defined(HAS_TCP)
ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1);
-#elif defined(BOARD_HAS_LORA)
- ArduinoCloud.addProperty(led, 1, READWRITE, ON_CHANGE, onLedChange);
- ArduinoCloud.addProperty(potentiometer, 2, READ, ON_CHANGE);
- ArduinoCloud.addProperty(seconds, 3, READ, 5 * MINUTES);
+
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
+ ArduinoCloud.setBoardId(BOARD_ID);
+ ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
+#endif
+#elif defined(HAS_LORA)
+ ArduinoCloud.addProperty(led, 1, Permission::ReadWrite).onUpdate(onLedChange);
+ ArduinoCloud.addProperty(potentiometer, 2, Permission::Read).publishOnChange(10);
+ ArduinoCloud.addProperty(seconds, 3, Permission::Read).publishEvery(5 * MINUTES);
+
+ ArduinoCloud.setThingId(THING_ID);
#endif
}
@@ -39,11 +45,15 @@ void initProperties() {
/* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */
EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK);
#elif defined(BOARD_HAS_WIFI)
- WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS);
+ WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
#elif defined(BOARD_HAS_GSM)
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#elif defined(BOARD_HAS_LORA)
LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A);
#elif defined(BOARD_HAS_NB)
NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
+#elif defined(BOARD_HAS_CATM1_NBIOT)
+ CatM1ConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
+#elif defined(BOARD_HAS_CELLULAR)
+ CellularConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#endif
diff --git a/examples/ArduinoIoTCloud-BlockForOTA/ArduinoIoTCloud-BlockForOTA.ino b/examples/ArduinoIoTCloud-BlockForOTA/ArduinoIoTCloud-BlockForOTA.ino
new file mode 100644
index 000000000..d682ff2b3
--- /dev/null
+++ b/examples/ArduinoIoTCloud-BlockForOTA/ArduinoIoTCloud-BlockForOTA.ino
@@ -0,0 +1,97 @@
+/*
+ This sketch demonstrates how to optimize OTA in case of complex loop().
+
+ * Connect a potentiometer (or other analog sensor) to A0.
+ * When the potentiometer (or sensor) value changes the data is sent to the Cloud.
+ * When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF.
+
+ IMPORTANT:
+ This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
+ On a LoRa board, if it is configured as a class A device (default and preferred option),
+ values from Cloud dashboard are received only after a value is sent to Cloud.
+
+ The full list of compatible boards can be found here:
+ - https://github.com/arduino-libraries/ArduinoIoTCloud#what
+*/
+
+#include "thingProperties.h"
+
+#if !defined(LED_BUILTIN) && !defined(ARDUINO_NANO_ESP32)
+static int const LED_BUILTIN = 2;
+#endif
+
+bool block_for_ota { false };
+bool ota_started { false };
+
+bool onOTARequestCallback() {
+ block_for_ota = true;
+ ota_started = true;
+ return true;
+}
+
+constexpr unsigned long printInterval { 1000 };
+unsigned long printNow { printInterval };
+
+void setup() {
+ /* Initialize serial and wait up to 5 seconds for port to open */
+ Serial.begin(9600);
+ for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
+
+ /* Set the debug message level:
+ * - DBG_ERROR: Only show error messages
+ * - DBG_WARNING: Show warning and error messages
+ * - DBG_INFO: Show info, warning, and error messages
+ * - DBG_DEBUG: Show debug, info, warning, and error messages
+ * - DBG_VERBOSE: Show all messages
+ */
+ setDebugMessageLevel(DBG_VERBOSE);
+
+ /* Configure LED pin as an output */
+ pinMode(LED_BUILTIN, OUTPUT);
+
+ /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
+ initProperties();
+
+ /* Initialize Arduino IoT Cloud library */
+ ArduinoCloud.begin(ArduinoIoTPreferredConnection);
+
+ /* Setup OTA callback */
+ ArduinoCloud.onOTARequestCb(onOTARequestCallback);
+
+ ArduinoCloud.printDebugInfo();
+}
+
+void loop() {
+ // When OTA is available, stay there until it completes.
+ // The rest of the loop() does not run and the sketch
+ // restarts automatically at the end of the OTA process.
+ while (block_for_ota) {
+ ArduinoCloud.update();
+ if (ota_started) {
+ Serial.print("Waiting for OTA to finish...");
+ ota_started = false;
+ }
+ if (millis() > printNow) {
+ Serial.print(".");
+ printNow = millis() + printInterval;
+ }
+ }
+
+ ArduinoCloud.update();
+ potentiometer = analogRead(A0);
+ seconds = millis() / 1000;
+
+ if (millis() > printNow) {
+ Serial.println(millis());
+ printNow = millis() + printInterval;
+ }
+}
+
+/*
+ * 'onLedChange' is called when the "led" property of your Thing changes
+ */
+void onLedChange() {
+ Serial.print("LED set to ");
+ Serial.println(led);
+ digitalWrite(LED_BUILTIN, led);
+}
diff --git a/examples/ArduinoIoTCloud-BlockForOTA/arduino_secrets.h b/examples/ArduinoIoTCloud-BlockForOTA/arduino_secrets.h
new file mode 100644
index 000000000..4134e9377
--- /dev/null
+++ b/examples/ArduinoIoTCloud-BlockForOTA/arduino_secrets.h
@@ -0,0 +1,38 @@
+#include
+
+/* A complete list of supported boards with WiFi is available here:
+ * https://github.com/arduino-libraries/ArduinoIoTCloud/#what
+ */
+#if defined(BOARD_HAS_WIFI)
+ #define SECRET_WIFI_SSID "YOUR_WIFI_NETWORK_NAME"
+ #define SECRET_WIFI_PASS "YOUR_WIFI_PASSWORD"
+#endif
+
+/* ESP8266 ESP32 */
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
+ #define SECRET_DEVICE_KEY "my-device-password"
+#endif
+
+/* MKR GSM 1400 */ /* MKR NB 1500 */ /* Portenta CAT.M1/NB IoT GNSS Shield */
+/* Portenta H7 and C33 + Portenta Mid Carrier + 4G Module */
+#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || \
+ defined(BOARD_HAS_CATM1_NBIOT) || defined(BOARD_HAS_CELLULAR)
+ #define SECRET_PIN ""
+ #define SECRET_APN ""
+ #define SECRET_LOGIN ""
+ #define SECRET_PASS ""
+#endif
+
+/* MKR WAN 1300/1310 */
+#if defined(BOARD_HAS_LORA)
+ #define SECRET_APP_EUI ""
+ #define SECRET_APP_KEY ""
+#endif
+
+/* Portenta H7 + Ethernet shield */
+#if defined(BOARD_HAS_ETHERNET)
+ #define SECRET_OPTIONAL_IP ""
+ #define SECRET_OPTIONAL_DNS ""
+ #define SECRET_OPTIONAL_GATEWAY ""
+ #define SECRET_OPTIONAL_NETMASK ""
+#endif
diff --git a/examples/ArduinoIoTCloud-BlockForOTA/thingProperties.h b/examples/ArduinoIoTCloud-BlockForOTA/thingProperties.h
new file mode 100644
index 000000000..8ad84c419
--- /dev/null
+++ b/examples/ArduinoIoTCloud-BlockForOTA/thingProperties.h
@@ -0,0 +1,59 @@
+#include
+#include
+#include "arduino_secrets.h"
+
+#if !(defined(HAS_TCP) || defined(HAS_LORA))
+ #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
+#endif
+
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
+ #define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
+#endif
+
+#if defined(HAS_LORA)
+ #define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
+#endif
+
+void onLedChange();
+
+bool led;
+int potentiometer;
+int seconds;
+
+void initProperties() {
+#if defined(HAS_TCP)
+ ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
+ ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
+ ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1);
+
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
+ ArduinoCloud.setBoardId(BOARD_ID);
+ ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
+#endif
+#elif defined(HAS_LORA)
+ ArduinoCloud.addProperty(led, 1, Permission::ReadWrite).onUpdate(onLedChange);
+ ArduinoCloud.addProperty(potentiometer, 2, Permission::Read).publishOnChange(10);
+ ArduinoCloud.addProperty(seconds, 3, Permission::Read).publishEvery(5 * MINUTES);
+
+ ArduinoCloud.setThingId(THING_ID);
+#endif
+}
+
+#if defined(BOARD_HAS_ETHERNET)
+ /* DHCP mode */
+ //EthernetConnectionHandler ArduinoIoTPreferredConnection;
+ /* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */
+ EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK);
+#elif defined(BOARD_HAS_WIFI)
+ WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
+#elif defined(BOARD_HAS_GSM)
+ GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
+#elif defined(BOARD_HAS_LORA)
+ LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A);
+#elif defined(BOARD_HAS_NB)
+ NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
+#elif defined(BOARD_HAS_CATM1_NBIOT)
+ CatM1ConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
+#elif defined(BOARD_HAS_CELLULAR)
+ CellularConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
+#endif
diff --git a/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino b/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino
index 634464716..3234def46 100644
--- a/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino
+++ b/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino
@@ -8,7 +8,7 @@
You don't need any specific Properties to be created in order to demonstrate these functionalities.
Simply create a new Thing and give it 1 arbitrary Property.
- Remember that the Thing ID needs to be configured in thingProperties.h
+ Remember that the Thing ID needs to be configured in thingProperties.h
These events can be very useful in particular cases, for instance to disable a peripheral
or a connected sensor/actuator when no data connection is available, as well as to perform
specific operations on connection or right after properties values are synchronised.
@@ -19,20 +19,28 @@
IMPORTANT:
This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
- On a LoRa board, if it is configured as a class A device (default and preferred option), values from Cloud dashboard are received
- only after a value is sent to Cloud.
+ On a LoRa board, if it is configured as a class A device (default and preferred option),
+ values from Cloud dashboard are received only after a value is sent to Cloud.
The full list of compatible boards can be found here:
- https://github.com/arduino-libraries/ArduinoIoTCloud#what
*/
-#include "arduino_secrets.h"
#include "thingProperties.h"
void setup() {
/* Initialize serial and wait up to 5 seconds for port to open */
Serial.begin(9600);
- for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
+ for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
+
+ /* Set the debug message level:
+ * - DBG_ERROR: Only show error messages
+ * - DBG_WARNING: Show warning and error messages
+ * - DBG_INFO: Show info, warning, and error messages
+ * - DBG_DEBUG: Show debug, info, warning, and error messages
+ * - DBG_VERBOSE: Show all messages
+ */
+ setDebugMessageLevel(DBG_INFO);
/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
initProperties();
@@ -52,7 +60,6 @@ void setup() {
ArduinoCloud.addCallback(ArduinoIoTCloudEvent::SYNC, doThisOnSync);
ArduinoCloud.addCallback(ArduinoIoTCloudEvent::DISCONNECT, doThisOnDisconnect);
- setDebugMessageLevel(DBG_INFO);
ArduinoCloud.printDebugInfo();
}
diff --git a/examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h b/examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h
index d1615135f..4134e9377 100644
--- a/examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h
+++ b/examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h
@@ -1,21 +1,22 @@
-#include
#include
/* A complete list of supported boards with WiFi is available here:
* https://github.com/arduino-libraries/ArduinoIoTCloud/#what
*/
#if defined(BOARD_HAS_WIFI)
- #define SECRET_SSID "YOUR_WIFI_NETWORK_NAME"
- #define SECRET_PASS "YOUR_WIFI_PASSWORD"
+ #define SECRET_WIFI_SSID "YOUR_WIFI_NETWORK_NAME"
+ #define SECRET_WIFI_PASS "YOUR_WIFI_PASSWORD"
#endif
-/* ESP8266 ESP32*/
-#if defined(BOARD_ESP)
+/* ESP8266 ESP32 */
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
#define SECRET_DEVICE_KEY "my-device-password"
#endif
-/* MKR GSM 1400 */
-#if defined(BOARD_HAS_GSM)
+/* MKR GSM 1400 */ /* MKR NB 1500 */ /* Portenta CAT.M1/NB IoT GNSS Shield */
+/* Portenta H7 and C33 + Portenta Mid Carrier + 4G Module */
+#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || \
+ defined(BOARD_HAS_CATM1_NBIOT) || defined(BOARD_HAS_CELLULAR)
#define SECRET_PIN ""
#define SECRET_APN ""
#define SECRET_LOGIN ""
@@ -28,14 +29,6 @@
#define SECRET_APP_KEY ""
#endif
-/* MKR NB 1500 */
-#if defined(BOARD_HAS_NB)
- #define SECRET_PIN ""
- #define SECRET_APN ""
- #define SECRET_LOGIN ""
- #define SECRET_PASS ""
-#endif
-
/* Portenta H7 + Ethernet shield */
#if defined(BOARD_HAS_ETHERNET)
#define SECRET_OPTIONAL_IP ""
diff --git a/examples/ArduinoIoTCloud-Callbacks/thingProperties.h b/examples/ArduinoIoTCloud-Callbacks/thingProperties.h
index d92788f98..e5e89e2ee 100644
--- a/examples/ArduinoIoTCloud-Callbacks/thingProperties.h
+++ b/examples/ArduinoIoTCloud-Callbacks/thingProperties.h
@@ -1,34 +1,45 @@
-#if defined(BOARD_HAS_WIFI)
-#elif defined(BOARD_HAS_GSM)
-#elif defined(BOARD_HAS_LORA)
-#elif defined(BOARD_HAS_NB)
-#elif defined(BOARD_HAS_ETHERNET)
-#else
- #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
+#include
+#include
+#include "arduino_secrets.h"
+
+#if !(defined(HAS_TCP) || defined(HAS_LORA))
+ #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
#endif
-#if defined(BOARD_ESP)
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
#endif
+#if defined(BOARD_HAS_LORA)
+ #define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
+#endif
+
void initProperties() {
-#if defined(BOARD_ESP)
+#if defined(HAS_TCP)
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
ArduinoCloud.setBoardId(BOARD_ID);
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
#endif
+#elif defined(HAS_LORA)
+ ArduinoCloud.setThingId(THING_ID);
+#endif
}
#if defined(BOARD_HAS_WIFI)
- WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS);
+ WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
#elif defined(BOARD_HAS_GSM)
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#elif defined(BOARD_HAS_LORA)
LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A);
#elif defined(BOARD_HAS_NB)
NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
+#elif defined(BOARD_HAS_CATM1_NBIOT)
+ CatM1ConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#elif defined(BOARD_HAS_ETHERNET)
/* DHCP mode */
//EthernetConnectionHandler ArduinoIoTPreferredConnection;
/* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */
EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK);
+#elif defined(BOARD_HAS_CELLULAR)
+ CellularConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#endif
diff --git a/examples/ArduinoIoTCloud-DeferredOTA/ArduinoIoTCloud-DeferredOTA.ino b/examples/ArduinoIoTCloud-DeferredOTA/ArduinoIoTCloud-DeferredOTA.ino
index fd5ab7977..84eed2436 100644
--- a/examples/ArduinoIoTCloud-DeferredOTA/ArduinoIoTCloud-DeferredOTA.ino
+++ b/examples/ArduinoIoTCloud-DeferredOTA/ArduinoIoTCloud-DeferredOTA.ino
@@ -16,10 +16,9 @@
- https://github.com/arduino-libraries/ArduinoIoTCloud/#ota
*/
-#include "arduino_secrets.h"
#include "thingProperties.h"
-#if defined(ESP32)
+#if !defined(LED_BUILTIN) && !defined(ARDUINO_NANO_ESP32)
static int const LED_BUILTIN = 2;
#endif
@@ -40,7 +39,7 @@ bool ask_user_via_serial() {
if (Serial.available()) {
char c = Serial.read();
if (c == 'y' || c == 'Y') {
- return true;
+ return true;
}
}
return false;
@@ -57,7 +56,16 @@ bool onOTARequestCallback()
void setup() {
/* Initialize serial and wait up to 5 seconds for port to open */
Serial.begin(9600);
- for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
+ for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
+
+ /* Set the debug message level:
+ * - DBG_ERROR: Only show error messages
+ * - DBG_WARNING: Show warning and error messages
+ * - DBG_INFO: Show info, warning, and error messages
+ * - DBG_DEBUG: Show debug, info, warning, and error messages
+ * - DBG_VERBOSE: Show all messages
+ */
+ setDebugMessageLevel(DBG_INFO);
/* Configure LED pin as an output */
pinMode(LED_BUILTIN, OUTPUT);
@@ -71,7 +79,6 @@ void setup() {
/* Setup OTA callback */
ArduinoCloud.onOTARequestCb(onOTARequestCallback);
- setDebugMessageLevel(DBG_INFO);
ArduinoCloud.printDebugInfo();
}
diff --git a/examples/ArduinoIoTCloud-DeferredOTA/arduino_secrets.h b/examples/ArduinoIoTCloud-DeferredOTA/arduino_secrets.h
index d1615135f..d0762b4c8 100644
--- a/examples/ArduinoIoTCloud-DeferredOTA/arduino_secrets.h
+++ b/examples/ArduinoIoTCloud-DeferredOTA/arduino_secrets.h
@@ -1,41 +1,18 @@
-#include
#include
/* A complete list of supported boards with WiFi is available here:
* https://github.com/arduino-libraries/ArduinoIoTCloud/#what
*/
#if defined(BOARD_HAS_WIFI)
- #define SECRET_SSID "YOUR_WIFI_NETWORK_NAME"
- #define SECRET_PASS "YOUR_WIFI_PASSWORD"
+ #define SECRET_WIFI_SSID "YOUR_WIFI_NETWORK_NAME"
+ #define SECRET_WIFI_PASS "YOUR_WIFI_PASSWORD"
#endif
-/* ESP8266 ESP32*/
-#if defined(BOARD_ESP)
+/* ESP8266 ESP32 */
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
#define SECRET_DEVICE_KEY "my-device-password"
#endif
-/* MKR GSM 1400 */
-#if defined(BOARD_HAS_GSM)
- #define SECRET_PIN ""
- #define SECRET_APN ""
- #define SECRET_LOGIN ""
- #define SECRET_PASS ""
-#endif
-
-/* MKR WAN 1300/1310 */
-#if defined(BOARD_HAS_LORA)
- #define SECRET_APP_EUI ""
- #define SECRET_APP_KEY ""
-#endif
-
-/* MKR NB 1500 */
-#if defined(BOARD_HAS_NB)
- #define SECRET_PIN ""
- #define SECRET_APN ""
- #define SECRET_LOGIN ""
- #define SECRET_PASS ""
-#endif
-
/* Portenta H7 + Ethernet shield */
#if defined(BOARD_HAS_ETHERNET)
#define SECRET_OPTIONAL_IP ""
diff --git a/examples/ArduinoIoTCloud-DeferredOTA/thingProperties.h b/examples/ArduinoIoTCloud-DeferredOTA/thingProperties.h
index 94b3b0ece..1feeee877 100644
--- a/examples/ArduinoIoTCloud-DeferredOTA/thingProperties.h
+++ b/examples/ArduinoIoTCloud-DeferredOTA/thingProperties.h
@@ -1,13 +1,12 @@
-#if defined(BOARD_HAS_WIFI)
-#elif defined(BOARD_HAS_GSM)
-#elif defined(BOARD_HAS_LORA)
-#elif defined(BOARD_HAS_NB)
-#elif defined(BOARD_HAS_ETHERNET)
-#else
+#include
+#include
+#include "arduino_secrets.h"
+
+#if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_ETHERNET))
#error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
#endif
-#if defined(BOARD_ESP)
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
#endif
@@ -16,25 +15,17 @@ void onLedChange();
bool led;
void initProperties() {
-#if defined(BOARD_ESP)
+#if defined(HAS_TCP)
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
ArduinoCloud.setBoardId(BOARD_ID);
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
#endif
-#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET)
- ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
-#elif defined(BOARD_HAS_LORA)
- ArduinoCloud.addProperty(led, 1, READWRITE, ON_CHANGE, onLedChange);
#endif
+ ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
}
#if defined(BOARD_HAS_WIFI)
- WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS);
-#elif defined(BOARD_HAS_GSM)
- GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
-#elif defined(BOARD_HAS_LORA)
- LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A);
-#elif defined(BOARD_HAS_NB)
- NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
+ WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
#elif defined(BOARD_HAS_ETHERNET)
/* DHCP mode */
//EthernetConnectionHandler ArduinoIoTPreferredConnection;
diff --git a/examples/ArduinoIoTCloud-NetConfig/ArduinoIoTCloud-NetConfig.ino b/examples/ArduinoIoTCloud-NetConfig/ArduinoIoTCloud-NetConfig.ino
new file mode 100644
index 000000000..238b59f55
--- /dev/null
+++ b/examples/ArduinoIoTCloud-NetConfig/ArduinoIoTCloud-NetConfig.ino
@@ -0,0 +1,62 @@
+/*
+ This sketch demonstrates how to exchange data between your board and the Arduino IoT Cloud.
+
+ * Connect a potentiometer (or other analog sensor) to A0.
+ * When the potentiometer (or sensor) value changes the data is sent to the Cloud.
+ * When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF.
+
+ IMPORTANT:
+ This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
+ On a LoRa board, if it is configured as a class A device (default and preferred option),
+ values from Cloud dashboard are received only after a value is sent to Cloud.
+
+ The full list of compatible boards can be found here:
+ - https://github.com/arduino-libraries/ArduinoIoTCloud#what
+*/
+
+#include "thingProperties.h"
+
+#if !defined(LED_BUILTIN) && !defined(ARDUINO_NANO_ESP32)
+static int const LED_BUILTIN = 2;
+#endif
+
+void setup() {
+ /* Initialize serial and wait up to 5 seconds for port to open */
+ Serial.begin(9600);
+ for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
+
+ /* Set the debug message level:
+ * - DBG_ERROR: Only show error messages
+ * - DBG_WARNING: Show warning and error messages
+ * - DBG_INFO: Show info, warning, and error messages
+ * - DBG_DEBUG: Show debug, info, warning, and error messages
+ * - DBG_VERBOSE: Show all messages
+ */
+ setDebugMessageLevel(DBG_INFO);
+
+ /* Configure LED pin as an output */
+ pinMode(LED_BUILTIN, OUTPUT);
+
+ /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
+ initProperties();
+
+ /* Initialize Arduino IoT Cloud library */
+ ArduinoCloud.begin(ArduinoIoTPreferredConnection);
+
+ ArduinoCloud.printDebugInfo();
+}
+
+void loop() {
+ ArduinoCloud.update();
+ potentiometer = analogRead(A0);
+ seconds = millis() / 1000;
+}
+
+/*
+ * 'onLedChange' is called when the "led" property of your Thing changes
+ */
+void onLedChange() {
+ Serial.print("LED set to ");
+ Serial.println(led);
+ digitalWrite(LED_BUILTIN, led);
+}
diff --git a/examples/ArduinoIoTCloud-NetConfig/thingProperties.h b/examples/ArduinoIoTCloud-NetConfig/thingProperties.h
new file mode 100644
index 000000000..4eba7e49c
--- /dev/null
+++ b/examples/ArduinoIoTCloud-NetConfig/thingProperties.h
@@ -0,0 +1,49 @@
+#if !defined(ARDUINO_SAMD_MKRWIFI1010) && !defined(ARDUINO_SAMD_NANO_33_IOT) && !defined(ARDUINO_NANO_RP2040_CONNECT) \
+ && !defined(ARDUINO_PORTENTA_H7_M7) && !defined(ARDUINO_NICLA_VISION) && !defined(ARDUINO_OPTA) && !defined(ARDUINO_GIGA) \
+ && !defined(ARDUINO_UNOR4_WIFI) && !defined(ARDUINO_PORTENTA_C33)
+#error "This example is not compatible with this board."
+#endif
+#include
+#include
+#include
+#include
+#include
+#include
+
+void onLedChange();
+
+bool led;
+int potentiometer;
+int seconds;
+
+GenericConnectionHandler ArduinoIoTPreferredConnection;
+KVStore kvStore;
+NetworkConfiguratorClass NetworkConfigurator(ArduinoIoTPreferredConnection);
+BLEAgentClass BLEAgent;
+SerialAgentClass SerialAgent;
+
+void initProperties() {
+ NetworkConfigurator.addAgent(BLEAgent);
+ NetworkConfigurator.addAgent(SerialAgent);
+ NetworkConfigurator.setStorage(kvStore);
+
+ /* For changing the default reset pin uncomment and set your preferred pin.
+ * Use DISABLE_PIN for disabling the reset procedure.
+ * The pin must be in the list of digital pins usable for interrupts.
+ * Please refer to the Arduino documentation for more details:
+ * https://docs.arduino.cc/language-reference/en/functions/external-interrupts/attachInterrupt/
+ */
+ //NetworkConfigurator.setReconfigurePin(your_pin);
+
+ /* Otherwise if you need to monitor the pin status changes
+ * you can set a custom callback function that is fired on every change
+ */
+ //NetworkConfigurator.setPinChangedCallback(your_callback);
+
+ ArduinoCloud.setConfigurator(NetworkConfigurator);
+
+ ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
+ ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
+ ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1);
+
+}
diff --git a/examples/ArduinoIoTCloud-Notecard/ArduinoIoTCloud-Notecard.ino b/examples/ArduinoIoTCloud-Notecard/ArduinoIoTCloud-Notecard.ino
new file mode 100644
index 000000000..a31c404b7
--- /dev/null
+++ b/examples/ArduinoIoTCloud-Notecard/ArduinoIoTCloud-Notecard.ino
@@ -0,0 +1,73 @@
+/*
+ This sketch demonstrates how to exchange data between your board and the
+ Arduino IoT Cloud, while using the Notecard for wireless communication.
+
+ * Connect a potentiometer (or other analog sensor) to A0.
+ * When the potentiometer (or sensor) value changes the data is sent to the Cloud.
+ * When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF.
+
+ IMPORTANT:
+ This sketch works with any Wi-Fi, Cellular, LoRa or Satellite enabled Notecard.
+
+ The full list of compatible boards can be found here:
+ - https://github.com/arduino-libraries/ArduinoIoTCloud#what
+*/
+
+#include
+#include "thingProperties.h"
+
+#if !defined(LED_BUILTIN) && !defined(ARDUINO_NANO_ESP32)
+static int const LED_BUILTIN = 2;
+#endif
+
+/*
+ * Choose an interrupt capable pin to reduce polling and improve
+ * the overall responsiveness of the ArduinoIoTCloud library
+ */
+// #define ATTN_PIN 9
+
+void setup() {
+ /* Initialize serial and wait up to 5 seconds for port to open */
+ Serial.begin(9600);
+ for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
+
+ /* Set the debug message level:
+ * - DBG_ERROR: Only show error messages
+ * - DBG_WARNING: Show warning and error messages
+ * - DBG_INFO: Show info, warning, and error messages
+ * - DBG_DEBUG: Show debug, info, warning, and error messages
+ * - DBG_VERBOSE: Show all messages
+ */
+ setDebugMessageLevel(DBG_INFO);
+
+ /* Configure LED pin as an output */
+ pinMode(LED_BUILTIN, OUTPUT);
+
+ /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
+ initProperties();
+
+ /* Initialize Arduino IoT Cloud library */
+#ifndef ATTN_PIN
+ ArduinoCloud.begin(ArduinoIoTPreferredConnection);
+ ArduinoCloud.setNotecardPollingInterval(3000); // default: 1000ms, min: 250ms
+#else
+ ArduinoCloud.begin(ArduinoIoTPreferredConnection, ATTN_PIN);
+#endif
+
+ ArduinoCloud.printDebugInfo();
+}
+
+void loop() {
+ ArduinoCloud.update();
+ potentiometer = analogRead(A0);
+ seconds = millis() / 1000;
+}
+
+/*
+ * 'onLedChange' is called when the "led" property of your Thing changes
+ */
+void onLedChange() {
+ Serial.print("LED set to ");
+ Serial.println(led);
+ digitalWrite(LED_BUILTIN, led);
+}
diff --git a/examples/ArduinoIoTCloud-Notecard/README.md b/examples/ArduinoIoTCloud-Notecard/README.md
new file mode 100644
index 000000000..a17d954c1
--- /dev/null
+++ b/examples/ArduinoIoTCloud-Notecard/README.md
@@ -0,0 +1,78 @@
+Notecard Connectivity
+=====================
+
+The Notecard is a wireless, secure abstraction for device connectivity, that can
+be used to enable _ANY*_ device with I2C, or UART, to connect to the Arduino IoT
+Cloud via cellular, LoRa, satellite or Wi-Fi!
+
+As a result, your existing device architecture can now have first class support
+in the Arduino IoT Cloud, by using a Notecard as a secure communication channel.
+
+> \*_While any device with I2C/UART may use the Notecard, the Arduino IoT Cloud
+> library is not supported by the AVR toolchain. Therefore, devices based on the
+> AVR architecture cannot access the Arduino IoT Cloud via the Notecard._
+>
+> _However, any device (including AVR), may use the Notecard library to send data
+> to Notehub, then that data may be routed to any endpoint of your choosing. See the
+> [Notecard Routing Guide](https://dev.blues.io/guides-and-tutorials/routing-data-to-cloud)
+> for more information..._
+
+Wireless Connectivity Options
+-----------------------------
+
+- [Cellular](https://shop.blues.com/collections/notecard/products/notecard-cellular)
+- [Cellular + Wi-Fi](https://shop.blues.com/collections/notecard/products/notecard-cell-wifi)
+- [Wi-Fi](https://shop.blues.com/collections/notecard/products/wifi-notecard)
+- [LoRa](https://shop.blues.com/collections/notecard/products/notecard-lora)
+- [Satellite](https://shop.blues.com/products/starnote)
+
+How it Works
+------------
+
+**Architecture Diagram:**
+
+```
+-------- ------------ ----------- -----------
+| | | | | | | |
+| Host | | | Secure | | | Arduino |
+| MCU |------| Notecard | ( ( Wireless ) ) | Notehub |------| IoT |
+| | | | Protocol | | | Cloud |
+|______| |__________| |_________| |_________|
+```
+
+Getting Started
+---------------
+
+### Setup a Notehub Account
+
+Using the Notecard only requires a couple of easy steps:
+
+1. [Purchase a Notecard](https://shop.blues.com/collections/notecard) (and
+[Notecarrier](https://shop.blues.com/collections/notecarrier)) that fits the
+needs of your device.
+ > _**NOTE:** We recommend starting with our [Dev Kit](https://shop.blues.com/products/blues-global-starter-kit)
+ > if you are unsure._
+1. [Setup a Notehub account](https://dev.blues.io/quickstart/notecard-quickstart/notecard-and-notecarrier-f/#set-up-notehub).
+ > _**NOTE:** Notehub accounts are free (no credit card required)._
+1. [Create a project on your Notehub account](https://dev.blues.io/quickstart/notecard-quickstart/notecard-and-notecarrier-f/#create-a-notehub-project).
+1. In `thingProperties.h`, replace "com.domain.you:product" (from
+`NOTECARD_PRODUCT_UID`) with the ProductUID of your new Notehub project.
+
+### Power-up the Device
+
+1. [Connect the Notecard to your Host MCU](https://dev.blues.io/quickstart/notecard-quickstart/notecard-and-notecarrier-f/#connect-your-notecard-and-notecarrier)
+1. Flash the `ArduinoIoTCloud-Notecard` example sketch to your device. You
+should see the device reporting itself as online in your [Notehub Project](https://notehub.io).
+
+### Associate Notecard to Arduino IoT Cloud
+
+1. Create a "MANUAL Device" in the Arduino IoT Cloud, then [add environment
+variables for the "Device ID" and "Secret Key" to your Notecard in Notehub](https://dev.blues.io/guides-and-tutorials/notecard-guides/understanding-environment-variables/#setting-a-notehub-device-variable).
+ - `_sn`: \
+ - `_secret_key`: \
+
+### More Information
+
+For more information about the Notecard and Notehub in general, please see our
+[Quickstart Guide](https://dev.blues.io/quickstart/) for a general overview of
+how the Notecard and Notehub are designed to work.
diff --git a/examples/ArduinoIoTCloud-Notecard/arduino_secrets.h b/examples/ArduinoIoTCloud-Notecard/arduino_secrets.h
new file mode 100644
index 000000000..43e3b76e1
--- /dev/null
+++ b/examples/ArduinoIoTCloud-Notecard/arduino_secrets.h
@@ -0,0 +1,7 @@
+#include
+
+/* If provided, the Wi-Fi Credentials will be passed along to the Notecard. If
+ * the Notecard supports Wi-Fi, it will attempt to connect to the network using
+ * these credentials, if not, the Notecard will safely ignore these values. */
+#define SECRET_WIFI_SSID "YOUR_WIFI_NETWORK_NAME"
+#define SECRET_WIFI_PASS "YOUR_WIFI_PASSWORD"
diff --git a/examples/ArduinoIoTCloud-Notecard/thingProperties.h b/examples/ArduinoIoTCloud-Notecard/thingProperties.h
new file mode 100644
index 000000000..cbcaf4da3
--- /dev/null
+++ b/examples/ArduinoIoTCloud-Notecard/thingProperties.h
@@ -0,0 +1,36 @@
+#include
+
+#include
+#include
+#include "arduino_secrets.h"
+
+/* The Notecard can provide connectivity to almost any board via ESLOV (I2C)
+ * or UART. An empty string (or the default value provided below) will not
+ * override the Notecard's existing configuration.
+ * Learn more at: https://dev.blues.io */
+#define NOTECARD_PRODUCT_UID "com.domain.you:product"
+
+/* Uncomment the following line to use the Notecard over UART */
+// #define UART_INTERFACE Serial1
+
+void onLedChange();
+
+bool led;
+int potentiometer;
+int seconds;
+
+#ifndef UART_INTERFACE
+NotecardConnectionHandler ArduinoIoTPreferredConnection(NOTECARD_PRODUCT_UID);
+#else
+NotecardConnectionHandler ArduinoIoTPreferredConnection(NOTECARD_PRODUCT_UID, UART_INTERFACE);
+#endif
+
+void initProperties() {
+ ArduinoCloud.addProperty(led, Permission::ReadWrite).onUpdate(onLedChange);
+ ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
+ ArduinoCloud.addProperty(seconds, Permission::Read).publishEvery(5 * MINUTES);
+
+ if (::strncmp(SECRET_WIFI_SSID, "YOUR_WIFI_NETWORK_NAME", sizeof(SECRET_WIFI_SSID))) {
+ ArduinoIoTPreferredConnection.setWiFiCredentials(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
+ }
+}
diff --git a/examples/ArduinoIoTCloud-Schedule/ArduinoIoTCloud-Schedule.ino b/examples/ArduinoIoTCloud-Schedule/ArduinoIoTCloud-Schedule.ino
index 7b82394ac..8529e9ec9 100644
--- a/examples/ArduinoIoTCloud-Schedule/ArduinoIoTCloud-Schedule.ino
+++ b/examples/ArduinoIoTCloud-Schedule/ArduinoIoTCloud-Schedule.ino
@@ -6,17 +6,25 @@
*/
-#include "arduino_secrets.h"
#include "thingProperties.h"
-#if defined(ESP32)
+#if !defined(LED_BUILTIN) && !defined(ARDUINO_NANO_ESP32)
static int const LED_BUILTIN = 2;
#endif
void setup() {
/* Initialize the serial port and wait up to 5 seconds for a connection */
Serial.begin(9600);
- for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { }
+ for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
+
+ /* Set the debug message level:
+ * - DBG_ERROR: Only show error messages
+ * - DBG_WARNING: Show warning and error messages
+ * - DBG_INFO: Show info, warning, and error messages
+ * - DBG_DEBUG: Show debug, info, warning, and error messages
+ * - DBG_VERBOSE: Show all messages
+ */
+ setDebugMessageLevel(DBG_INFO);
/* Configure LED pin as an output */
pinMode(LED_BUILTIN, OUTPUT);
@@ -27,7 +35,6 @@ void setup() {
/* Initialize Arduino IoT Cloud library */
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
- setDebugMessageLevel(DBG_INFO);
ArduinoCloud.printDebugInfo();
/* Setup one shot schedule example */
@@ -58,7 +65,7 @@ void setup() {
*/
void setupOneShotSchedule() {
- ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00");
+ ScheduleTimeType startingFrom = TimeServiceClass::getTimeFromString("2021 Nov 01 17:00:00");
ScheduleTimeType until = startingFrom + ( DAYS * 1 );
ScheduleTimeType activePeriod = MINUTES * 5;
@@ -74,7 +81,7 @@ void setupOneShotSchedule() {
*/
void setupMinuteSchedule() {
- ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00");
+ ScheduleTimeType startingFrom = TimeServiceClass::getTimeFromString("2021 Nov 01 17:00:00");
ScheduleTimeType until = startingFrom + ( DAYS * 1 );
ScheduleTimeType activePeriod = SECONDS * 15;
unsigned int repetitionPeriod = 1;
@@ -91,8 +98,8 @@ void setupMinuteSchedule() {
*/
void setupHourlySchedule() {
- ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00");
- ScheduleTimeType until = TimeService::getTimeFromString("2021 Nov 15 13:00:00");
+ ScheduleTimeType startingFrom = TimeServiceClass::getTimeFromString("2021 Nov 01 17:00:00");
+ ScheduleTimeType until = TimeServiceClass::getTimeFromString("2021 Nov 15 13:00:00");
ScheduleTimeType activePeriod = MINUTES * 20;
unsigned int repetitionPeriod = 1;
@@ -108,8 +115,8 @@ void setupHourlySchedule() {
*/
void setupDailySchedule() {
- ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00");
- ScheduleTimeType until = TimeService::getTimeFromString("2021 Nov 15 13:00:00");
+ ScheduleTimeType startingFrom = TimeServiceClass::getTimeFromString("2021 Nov 01 17:00:00");
+ ScheduleTimeType until = TimeServiceClass::getTimeFromString("2021 Nov 15 13:00:00");
ScheduleTimeType activePeriod = HOURS * 2;
unsigned int repetitionPeriod = 1;
@@ -133,7 +140,7 @@ void setupDailySchedule() {
*/
void setupWeeklySchedule() {
- unsigned int startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00");
+ unsigned int startingFrom = TimeServiceClass::getTimeFromString("2021 Nov 01 17:00:00");
unsigned int until = startingFrom + ( DAYS * 30 );
unsigned int executionPeriod = MINUTES * 3;
@@ -158,8 +165,8 @@ void setupWeeklySchedule() {
*/
void setupMonthlySchedule() {
- ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00");
- ScheduleTimeType until = TimeService::getTimeFromString("2021 Nov 15 13:00:00");
+ ScheduleTimeType startingFrom = TimeServiceClass::getTimeFromString("2021 Nov 01 17:00:00");
+ ScheduleTimeType until = TimeServiceClass::getTimeFromString("2021 Nov 15 13:00:00");
ScheduleTimeType activePeriod = DAYS * 1;
int dayOfMonth = 3;
@@ -175,8 +182,8 @@ void setupMonthlySchedule() {
*/
void setupYearlySchedule() {
- ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 06 17:00:00");
- ScheduleTimeType until = TimeService::getTimeFromString("2041 Nov 06 13:00:00");
+ ScheduleTimeType startingFrom = TimeServiceClass::getTimeFromString("2021 Nov 06 17:00:00");
+ ScheduleTimeType until = TimeServiceClass::getTimeFromString("2041 Nov 06 13:00:00");
ScheduleTimeType activePeriod = DAYS * 2;
int dayOfMonth = 6;
@@ -207,7 +214,7 @@ void loop() {
if(daily.isActive()) {
Serial.println("Daily schedule is active");
}
-
+
/* Activate LED when the weekly schedule is active */
digitalWrite(LED_BUILTIN, weekly.isActive());
@@ -220,6 +227,4 @@ void loop() {
if(yearly.isActive()) {
Serial.println("Yearly schedule is active");
}
-
}
-
diff --git a/examples/ArduinoIoTCloud-Schedule/arduino_secrets.h b/examples/ArduinoIoTCloud-Schedule/arduino_secrets.h
index d1615135f..7a9190b5d 100644
--- a/examples/ArduinoIoTCloud-Schedule/arduino_secrets.h
+++ b/examples/ArduinoIoTCloud-Schedule/arduino_secrets.h
@@ -1,35 +1,22 @@
-#include
#include
/* A complete list of supported boards with WiFi is available here:
* https://github.com/arduino-libraries/ArduinoIoTCloud/#what
*/
#if defined(BOARD_HAS_WIFI)
- #define SECRET_SSID "YOUR_WIFI_NETWORK_NAME"
- #define SECRET_PASS "YOUR_WIFI_PASSWORD"
+ #define SECRET_WIFI_SSID "YOUR_WIFI_NETWORK_NAME"
+ #define SECRET_WIFI_PASS "YOUR_WIFI_PASSWORD"
#endif
-/* ESP8266 ESP32*/
-#if defined(BOARD_ESP)
+/* ESP8266 ESP32 */
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
#define SECRET_DEVICE_KEY "my-device-password"
#endif
-/* MKR GSM 1400 */
-#if defined(BOARD_HAS_GSM)
- #define SECRET_PIN ""
- #define SECRET_APN ""
- #define SECRET_LOGIN ""
- #define SECRET_PASS ""
-#endif
-
-/* MKR WAN 1300/1310 */
-#if defined(BOARD_HAS_LORA)
- #define SECRET_APP_EUI ""
- #define SECRET_APP_KEY ""
-#endif
-
-/* MKR NB 1500 */
-#if defined(BOARD_HAS_NB)
+/* MKR GSM 1400 */ /* MKR NB 1500 */ /* Portenta CAT.M1/NB IoT GNSS Shield */
+/* Portenta H7 and C33 + Portenta Mid Carrier + 4G Module */
+#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || \
+ defined(BOARD_HAS_CATM1_NBIOT) || defined(BOARD_HAS_CELLULAR)
#define SECRET_PIN ""
#define SECRET_APN ""
#define SECRET_LOGIN ""
diff --git a/examples/ArduinoIoTCloud-Schedule/thingProperties.h b/examples/ArduinoIoTCloud-Schedule/thingProperties.h
index 940cb5c26..290feb8bd 100644
--- a/examples/ArduinoIoTCloud-Schedule/thingProperties.h
+++ b/examples/ArduinoIoTCloud-Schedule/thingProperties.h
@@ -1,13 +1,12 @@
-#if defined(BOARD_HAS_WIFI)
-#elif defined(BOARD_HAS_GSM)
-#elif defined(BOARD_HAS_LORA)
-#elif defined(BOARD_HAS_NB)
-#elif defined(BOARD_HAS_ETHERNET)
-#else
- #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
+#include
+#include
+#include "arduino_secrets.h"
+
+#if !defined(HAS_TCP)
+ #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
#endif
-#if defined(BOARD_ESP)
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
#endif
@@ -23,35 +22,36 @@ CloudSchedule monthly;
CloudSchedule yearly;
void initProperties() {
-#if defined(BOARD_ESP)
+#if defined(HAS_TCP)
+ ArduinoCloud.addProperty(switchButton, Permission::Write);
+ ArduinoCloud.addProperty(oneShot, Permission::ReadWrite);
+ ArduinoCloud.addProperty(minute, Permission::ReadWrite);
+ ArduinoCloud.addProperty(hourly, Permission::ReadWrite);
+ ArduinoCloud.addProperty(daily, Permission::ReadWrite);
+ ArduinoCloud.addProperty(weekly, Permission::ReadWrite);
+ ArduinoCloud.addProperty(monthly, Permission::ReadWrite);
+ ArduinoCloud.addProperty(yearly, Permission::ReadWrite);
+
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
ArduinoCloud.setBoardId(BOARD_ID);
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
#endif
-#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET)
- ArduinoCloud.addProperty(switchButton, WRITE, ON_CHANGE);
- ArduinoCloud.addProperty(oneShot, READWRITE, ON_CHANGE);
- ArduinoCloud.addProperty(minute, READWRITE, ON_CHANGE);
- ArduinoCloud.addProperty(hourly, READWRITE, ON_CHANGE);
- ArduinoCloud.addProperty(daily, READWRITE, ON_CHANGE);
- ArduinoCloud.addProperty(weekly, READWRITE, ON_CHANGE);
- ArduinoCloud.addProperty(monthly, READWRITE, ON_CHANGE);
- ArduinoCloud.addProperty(yearly, READWRITE, ON_CHANGE);
-#elif defined(BOARD_HAS_LORA)
- ArduinoCloud.addProperty(switchButton, 1, WRITE, ON_CHANGE;
#endif
}
#if defined(BOARD_HAS_WIFI)
- WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS);
+ WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
#elif defined(BOARD_HAS_GSM)
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
-#elif defined(BOARD_HAS_LORA)
- LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A);
#elif defined(BOARD_HAS_NB)
NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
+#elif defined(BOARD_HAS_CATM1_NBIOT)
+ CatM1ConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#elif defined(BOARD_HAS_ETHERNET)
/* DHCP mode */
//EthernetConnectionHandler ArduinoIoTPreferredConnection;
/* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */
EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK);
+#elif defined(BOARD_HAS_CELLULAR)
+ CellularConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#endif
diff --git a/examples/utility/ArduinoIoTCloud_Travis_CI/ArduinoIoTCloud_Travis_CI.ino b/examples/utility/ArduinoIoTCloud_Travis_CI/ArduinoIoTCloud_Travis_CI.ino
index 6a971f629..4d478e065 100644
--- a/examples/utility/ArduinoIoTCloud_Travis_CI/ArduinoIoTCloud_Travis_CI.ino
+++ b/examples/utility/ArduinoIoTCloud_Travis_CI/ArduinoIoTCloud_Travis_CI.ino
@@ -5,21 +5,20 @@
IMPORTANT:
This sketch works with WiFi, GSM, NB, Ethernet and Lora enabled boards supported by Arduino IoT Cloud.
- On a LoRa board, if it is configured as a class A device (default and preferred option), values from Cloud dashboard are received
- only after a value is sent to Cloud.
+ On a LoRa board, if it is configured as a class A device (default and preferred option),
+ values from Cloud dashboard are received only after a value is sent to Cloud.
The full list of compatible boards can be found here:
- https://github.com/arduino-libraries/ArduinoIoTCloud#what
*/
-#include "arduino_secrets.h"
#include "thingProperties.h"
void setup() {
Serial.begin(9600);
unsigned long serialBeginTime = millis();
- while (!Serial && (millis() - serialBeginTime > 5000));
+ while (!Serial && (millis() - serialBeginTime <= 5000));
Serial.println("Starting Arduino IoT Cloud Example");
diff --git a/examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h b/examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h
index d1615135f..f4bceabb6 100644
--- a/examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h
+++ b/examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h
@@ -1,21 +1,22 @@
-#include
#include
/* A complete list of supported boards with WiFi is available here:
* https://github.com/arduino-libraries/ArduinoIoTCloud/#what
*/
#if defined(BOARD_HAS_WIFI)
- #define SECRET_SSID "YOUR_WIFI_NETWORK_NAME"
- #define SECRET_PASS "YOUR_WIFI_PASSWORD"
+ #define SECRET_WIFI_SSID "YOUR_WIFI_NETWORK_NAME"
+ #define SECRET_WIFI_PASS "YOUR_WIFI_PASSWORD"
#endif
/* ESP8266 ESP32*/
-#if defined(BOARD_ESP)
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
#define SECRET_DEVICE_KEY "my-device-password"
#endif
-/* MKR GSM 1400 */
-#if defined(BOARD_HAS_GSM)
+/* MKR GSM 1400 */ /* MKR NB 1500 */ /* Portenta CAT.M1/NB IoT GNSS Shield */
+/* Portenta H7 and C33 + Portenta Mid Carrier + 4G Module */
+#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || \
+ defined(BOARD_HAS_CATM1_NBIOT) || defined(BOARD_HAS_CELLULAR)
#define SECRET_PIN ""
#define SECRET_APN ""
#define SECRET_LOGIN ""
@@ -28,14 +29,6 @@
#define SECRET_APP_KEY ""
#endif
-/* MKR NB 1500 */
-#if defined(BOARD_HAS_NB)
- #define SECRET_PIN ""
- #define SECRET_APN ""
- #define SECRET_LOGIN ""
- #define SECRET_PASS ""
-#endif
-
/* Portenta H7 + Ethernet shield */
#if defined(BOARD_HAS_ETHERNET)
#define SECRET_OPTIONAL_IP ""
diff --git a/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h b/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h
index eff3035bd..eb3c29258 100644
--- a/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h
+++ b/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h
@@ -1,20 +1,23 @@
-#if defined(BOARD_HAS_WIFI)
-#elif defined(BOARD_HAS_GSM)
-#elif defined(BOARD_HAS_LORA)
-#elif defined(BOARD_HAS_NB)
-#elif defined(BOARD_HAS_ETHERNET)
-#else
- #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
+#include
+#include
+#include "arduino_secrets.h"
+
+#if !(defined(HAS_TCP) || defined(HAS_LORA))
+ #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
#endif
/******************************************************************************
DEFINES
******************************************************************************/
-#if defined(BOARD_ESP)
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
#endif
+#if defined(HAS_LORA)
+ #define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
+#endif
+
/******************************************************************************
GLOBAL CONSTANTS
******************************************************************************/
@@ -51,18 +54,22 @@ String str_property_7;
String str_property_8;
#if defined(BOARD_HAS_WIFI)
- WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS);
+ WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
#elif defined(BOARD_HAS_GSM)
GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#elif defined(BOARD_HAS_LORA)
LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, EU868);
#elif defined(BOARD_HAS_NB)
NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
+#elif defined(BOARD_HAS_CATM1_NBIOT)
+ CatM1ConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#elif defined(BOARD_HAS_ETHERNET)
/* DHCP mode */
//EthernetConnectionHandler ArduinoIoTPreferredConnection;
/* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */
EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK);
+#elif defined(BOARD_HAS_CELLULAR)
+ CellularConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#endif
/******************************************************************************
@@ -77,9 +84,9 @@ void onStringPropertyChange();
/******************************************************************************
FUNCTIONS
******************************************************************************/
-#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined (BOARD_HAS_NB)
+#if defined(HAS_TCP)
void initProperties() {
-#if defined(BOARD_ESP)
+#if !defined(BOARD_HAS_SECURE_ELEMENT)
ArduinoCloud.setBoardId(BOARD_ID);
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
#endif
@@ -110,8 +117,9 @@ void initProperties() {
ArduinoCloud.addProperty(str_property_8, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(DEVICE_WINS);
}
-#elif defined(BOARD_HAS_LORA)
+#elif defined(HAS_LORA)
void initProperties() {
+ ArduinoCloud.setThingId(THING_ID);
ArduinoCloud.addProperty(bool_property_1, 1, READWRITE, 1 * SECONDS);
ArduinoCloud.addProperty(int_property_1, 2, READ, 2 * MINUTES);
diff --git a/examples/utility/Provisioning/ECCX08TLSConfig.h b/examples/utility/Provisioning/ECCX08TLSConfig.h
deleted file mode 100644
index 9126b3666..000000000
--- a/examples/utility/Provisioning/ECCX08TLSConfig.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- This file is part of ArduinoIoTCloud.
-
- Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
-
- This software is released under the GNU General Public License version 3,
- which covers the main part of arduino-cli.
- The terms of this license can be found at:
- https://www.gnu.org/licenses/gpl-3.0.en.html
-
- You can be released from the requirements of the above licenses by purchasing
- a commercial license. Buying such a license is mandatory if you want to modify or
- otherwise use the software for commercial activities involving the Arduino
- software without disclosing the source code of your own applications. To purchase
- a commercial license, send an email to license@arduino.cc.
-*/
-
-#ifndef _ECCX08_TLS_CONFIG_H_
-#define _ECCX08_TLS_CONFIG_H_
-
-const byte DEFAULT_ECCX08_TLS_CONFIG[128] = {
- // Read only - start
- // SN[0:3]
- 0x01, 0x23, 0x00, 0x00,
- // RevNum
- 0x00, 0x00, 0x50, 0x00,
- // SN[4:8]
- 0x00, 0x00, 0x00, 0x00, 0x00,
- // Reserved
- 0xC0,
- // I2C_Enable
- 0x71,
- // Reserved
- 0x00,
- // Read only - end
- // I2C_Address
- 0xC0,
- // Reserved
- 0x00,
- // OTPmode
- 0x55,
- // ChipMode
- 0x00,
- // SlotConfig
- 0x83, 0x20, // External Signatures | Internal Signatures | IsSecret | Write Configure Never, Default: 0x83, 0x20,
- 0x87, 0x20, // External Signatures | Internal Signatures | ECDH | IsSecret | Write Configure Never, Default: 0x87, 0x20,
- 0x87, 0x20, // External Signatures | Internal Signatures | ECDH | IsSecret | Write Configure Never, Default: 0x8F, 0x20,
- 0x87, 0x2F, // External Signatures | Internal Signatures | ECDH | IsSecret | WriteKey all slots | Write Configure Never, Default: 0xC4, 0x8F,
- 0x87, 0x2F, // External Signatures | Internal Signatures | ECDH | IsSecret | WriteKey all slots | Write Configure Never, Default: 0x8F, 0x8F,
- 0x8F, 0x8F,
- 0x9F, 0x8F,
- 0xAF, 0x8F,
- 0x00, 0x00,
- 0x00, 0x00,
- 0x00, 0x00,
- 0x00, 0x00,
- 0x00, 0x00,
- 0x00, 0x00,
- 0x00, 0x00,
- 0xAF, 0x8F,
- // Counter[0]
- 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
- // Counter[1]
- 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
- // LastKeyUse
- 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF,
- // Write via commands only - start
- // UserExtra
- 0x00,
- // Selector
- 0x00,
- // LockValue
- 0x55,
- // LockConfig
- 0x55,
- // SlotLocked
- 0xFF, 0xFF,
- // Write via commands only - end
- // RFU
- 0x00, 0x00,
- // X509format
- 0x00, 0x00, 0x00, 0x00,
- // KeyConfig
- 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00,
- 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00,
- 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00,
- 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x1C, 0x00,
- 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x1C, 0x00,
- 0x1C, 0x00,
- 0x1C, 0x00,
- 0x1C, 0x00,
- 0x3C, 0x00,
- 0x3C, 0x00,
- 0x3C, 0x00,
- 0x3C, 0x00,
- 0x3C, 0x00,
- 0x3C, 0x00,
- 0x3C, 0x00,
- 0x1C, 0x00
-};
-
-#endif /* _ECCX08_TLS_CONFIG_H_ */
diff --git a/examples/utility/Provisioning/Provisioning.ino b/examples/utility/Provisioning/Provisioning.ino
index 97394fc2c..ebde2218b 100644
--- a/examples/utility/Provisioning/Provisioning.ino
+++ b/examples/utility/Provisioning/Provisioning.ino
@@ -1,21 +1,37 @@
-#include
-#include "ECCX08TLSConfig.h"
-
-const bool DEBUG = true;
-
-ArduinoIoTCloudCertClass Certificate;
-CryptoUtil Crypto;
+#include
+#include
+#include
+#include
+#include
+
+#ifdef ARDUINO_SAMD_MKR1000
+#include
+#define LATEST_WIFI_FIRMWARE_VERSION WIFI_FIRMWARE_LATEST_MODEL_B
+#endif
+#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_NANO_RP2040_CONNECT)
+#include
+#define LATEST_WIFI_FIRMWARE_VERSION WIFI_FIRMWARE_LATEST_VERSION
+#endif
+#if defined(ARDUINO_UNOR4_WIFI)
+#include
+#define LATEST_WIFI_FIRMWARE_VERSION WIFI_FIRMWARE_LATEST_VERSION
+#endif
+
+String promptAndReadLine(const char* prompt, const unsigned int timeout = 0);
void setup() {
Serial.begin(9600);
while (!Serial);
- if (!Crypto.begin()) {
+ SecureElement secureElement;
+
+ if (!secureElement.begin()) {
Serial.println("No crypto present!");
while (1);
}
- if (!Crypto.locked()) {
+ if (!secureElement.locked()) {
+ /* WARNING: This string is parsed from IoTCloud frontend */
String lockConfirm = promptAndReadLine("Your crypto is unlocked, would you like to lock it (y/N): ");
lockConfirm.toLowerCase();
@@ -24,12 +40,14 @@ void setup() {
while (1);
}
- if (!Crypto.writeConfiguration(DEFAULT_ECCX08_TLS_CONFIG)) {
+ if (!secureElement.writeConfiguration()) {
+ /* WARNING: This string is parsed from IoTCloud frontend */
Serial.println("Writing crypto configuration failed!");
while (1);
}
- if (!Crypto.lock()) {
+ if (!secureElement.lock()) {
+ /* WARNING: This string is parsed from IoTCloud frontend */
Serial.println("Locking crypto configuration failed!");
while (1);
}
@@ -38,7 +56,8 @@ void setup() {
Serial.println();
}
- String csrConfirm = promptAndReadLine("Would you like to generate a new private key and CSR (y/N): ");
+ /* WARNING: This string is parsed from IoTCloud frontend */
+ String csrConfirm = promptAndReadLine("Would you like to generate a new private key and CSR (y/N): ", 5000);
csrConfirm.toLowerCase();
if (csrConfirm != "y") {
@@ -46,15 +65,19 @@ void setup() {
while (1);
}
+ ECP256Certificate Certificate;
+
if (!Certificate.begin()) {
Serial.println("Error starting CSR generation!");
while (1);
}
- String deviceId = promptAndReadLine("Please enter the device ID: ");
+ /* WARNING: This string is parsed from IoTCloud frontend */
+ String deviceId = promptAndReadLine("Please enter the device id: ");
Certificate.setSubjectCommonName(deviceId);
- if (!Crypto.buildCSR(Certificate, CryptoSlot::Key, true)) {
+ if (!SElementCSR::build(secureElement, Certificate, (int)SElementArduinoCloudSlot::Key, true)) {
+ /* WARNING: This string is parsed from IoTCloud frontend */
Serial.println("Error generating CSR!");
while (1);
}
@@ -62,12 +85,14 @@ void setup() {
String csr = Certificate.getCSRPEM();
if (!csr) {
+ /* WARNING: This string is parsed from IoTCloud frontend */
Serial.println("Error generating CSR!");
while (1);
}
Serial.println("Generated CSR is:");
Serial.println();
+ /* WARNING: This string is parsed from IoTCloud frontend */
Serial.println(csr);
String issueYear = promptAndReadLine("Please enter the issue year of the certificate (2000 - 2031): ");
@@ -79,20 +104,21 @@ void setup() {
String authorityKeyIdentifier = promptAndReadLine("Please enter the certificates authority key identifier: ");
String signature = promptAndReadLine("Please enter the certificates signature: ");
- byte serialNumberBytes[CERT_SERIAL_NUMBER_LENGTH];
- byte authorityKeyIdentifierBytes[CERT_AUTHORITY_KEY_ID_LENGTH];
- byte signatureBytes[CERT_SIGNATURE_LENGTH];
+ byte serialNumberBytes[ECP256_CERT_SERIAL_NUMBER_LENGTH];
+ byte authorityKeyIdentifierBytes[ECP256_CERT_AUTHORITY_KEY_ID_LENGTH];
+ byte signatureBytes[ECP256_CERT_SIGNATURE_LENGTH];
hexStringToBytes(serialNumber, serialNumberBytes, sizeof(serialNumberBytes));
hexStringToBytes(authorityKeyIdentifier, authorityKeyIdentifierBytes, sizeof(authorityKeyIdentifierBytes));
hexStringToBytes(signature, signatureBytes, sizeof(signatureBytes));
- if (!Crypto.writeDeviceId(deviceId, CryptoSlot::DeviceId)) {
+ if (!SElementArduinoCloudDeviceId::write(secureElement, deviceId, SElementArduinoCloudSlot::DeviceId)) {
Serial.println("Error storing device ID!");
while (1);
}
if (!Certificate.begin()) {
+ /* WARNING: This string is parsed from IoTCloud frontend */
Serial.println("Error starting crypto storage!");
while (1);
}
@@ -111,20 +137,17 @@ void setup() {
Certificate.setIssueHour(issueHour.toInt());
Certificate.setExpireYears(expireYears.toInt());
- if (!Crypto.buildCert(Certificate, CryptoSlot::Key)) {
+ if (!SElementArduinoCloudCertificate::build(secureElement, Certificate, static_cast(SElementArduinoCloudSlot::Key))) {
Serial.println("Error building cert!");
while (1);
}
-
- if (!Crypto.writeCert(Certificate, CryptoSlot::CompressedCertificate)) {
+
+ if (!SElementArduinoCloudCertificate::write(secureElement, Certificate, SElementArduinoCloudSlot::CompressedCertificate)) {
Serial.println("Error storing cert!");
while (1);
}
- if (!DEBUG) {
- return;
- }
-
+ /* WARNING: This string is parsed from IoTCloud frontend */
Serial.println("Compressed cert = ");
const byte* certData = Certificate.bytes();
@@ -139,23 +162,72 @@ void setup() {
Serial.print(b, HEX);
}
Serial.println();
+
+
+ String cert = Certificate.getCertPEM();
+ if (!cert) {
+ Serial.println("Error generating cert!");
+ while (1);
+ }
+ Serial.println("Cert PEM = ");
+ Serial.println();
+ Serial.println(cert);
+
+
+#ifdef LATEST_WIFI_FIRMWARE_VERSION
+ Serial.println("Checking firmware of WiFi module...");
+ Serial.println();
+ String fv = WiFi.firmwareVersion();
+ /* WARNING: This string is parsed from IoTCloud frontend */
+ Serial.print("Current firmware version: ");
+ /* WARNING: This string is parsed from IoTCloud frontend */
+ Serial.println(fv);
+
+ String latestFv = LATEST_WIFI_FIRMWARE_VERSION;
+ if (fv >= latestFv) {
+ /* WARNING: This string is parsed from IoTCloud frontend */
+ Serial.println("Latest firmware version correctly installed.");
+ } else {
+ /* WARNING: This string is parsed from IoTCloud frontend */
+ String latestFvStr = "The firmware is not up to date. Latest version available: " + latestFv;
+ Serial.println(latestFvStr);
+ }
+#else
+ Serial.println();
+ /* WARNING: This string is parsed from IoTCloud frontend */
+ Serial.println("Program finished.");
+#endif
}
void loop() {
}
-String promptAndReadLine(const char* prompt) {
- Serial.print(prompt);
- String s = readLine();
+String promptAndReadLine(const char* prompt, const unsigned int timeout) {
+ String s = "";
+ while(1) {
+ Serial.print(prompt);
+ s = readLine(timeout);
+ if (s.length() > 0) {
+ break;
+ }
+ }
Serial.println(s);
return s;
}
-String readLine() {
- String line;
+bool isExpired(const unsigned int start, const unsigned int timeout) {
+ if (timeout) {
+ return (millis() - start) > timeout;
+ } else {
+ return false;
+ }
+}
- while (1) {
+String readLine(const unsigned int timeout) {
+ String line;
+ const unsigned int start = millis();
+ while (!isExpired(start, timeout)) {
if (Serial.available()) {
char c = Serial.read();
diff --git a/examples/utility/Provisioning_2.0/CSRHandler.cpp b/examples/utility/Provisioning_2.0/CSRHandler.cpp
new file mode 100644
index 000000000..1a6101e4b
--- /dev/null
+++ b/examples/utility/Provisioning_2.0/CSRHandler.cpp
@@ -0,0 +1,428 @@
+/*
+ Copyright (c) 2024 Arduino SA
+
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+
+#include "CSRHandler.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "Arduino_DebugUtils.h"
+#include
+
+#define RESPONSE_TIMEOUT 5000
+#define CONNECTION_RETRY_TIMEOUT_MS 2000
+#define BACKEND_INTERVAL_s 12
+#define MAX_CSR_REQUEST_INTERVAL 180000
+#define MAX_CSR_REQUEST_INTERVAL_ATTEMPTS 15
+
+#ifdef COMPILE_TEST
+constexpr char *server = "boards-v2.oniudra.cc";
+#else
+constexpr char *server = "boards-v2.arduino.cc";
+#endif
+
+CSRHandlerClass::CSRHandlerClass() :
+ _ledFeedback{LEDFeedbackClass::getInstance()},
+ _state{CSRHandlerStates::END},
+ _nextRequestAt{0},
+ _requestAttempt{0},
+ _startWaitingResponse{0},
+ _uhwid{nullptr},
+ _certForCSR{nullptr},
+ _connectionHandler{nullptr},
+ _secureElement{nullptr},
+ _tlsClient{nullptr},
+ _client{nullptr},
+ _fw_version{""},
+ _deviceId{""},
+ _issueYear{0},
+ _issueMonth{0},
+ _issueDay{0},
+ _issueHour{0} {
+ memset(_serialNumber, 0, sizeof(_serialNumber));
+ memset(_authorityKeyIdentifier, 0, sizeof(_authorityKeyIdentifier));
+ memset(_signature, 0, sizeof(_signature));
+}
+
+CSRHandlerClass::~CSRHandlerClass() {
+ if (_certForCSR) {
+ delete _certForCSR;
+ _certForCSR = nullptr;
+ }
+ if (_client) {
+ delete _client;
+ _client = nullptr;
+ }
+
+ if(_tlsClient){
+ delete _tlsClient;
+ _tlsClient = nullptr;
+ }
+}
+
+bool CSRHandlerClass::begin(ConnectionHandler &connectionHandler, SecureElement &secureElement, String &uhwid) {
+ if(_state != CSRHandlerStates::END) {
+ return true;
+ }
+
+ if(uhwid == "") {
+ return false;
+ }
+
+ _connectionHandler = &connectionHandler;
+ _secureElement = &secureElement;
+ _uhwid = &uhwid;
+
+#ifdef BOARD_HAS_WIFI
+ _fw_version = WiFi.firmwareVersion();
+#endif
+ if(!_tlsClient){
+ _tlsClient = new TLSClientMqtt();
+ }
+ _tlsClient->begin(*_connectionHandler);
+ _tlsClient->setTimeout(RESPONSE_TIMEOUT);
+ _client = new HttpClient(*_tlsClient, server, 443);
+ TimeService.begin(_connectionHandler);
+ _requestAttempt = 0;
+ _nextRequestAt = 0;
+ _startWaitingResponse = 0;
+ _state = CSRHandlerStates::BUILD_CSR;
+}
+
+void CSRHandlerClass::end() {
+ if (_client) {
+ _client->stop();
+ delete _client;
+ _client = nullptr;
+ }
+
+ if (_certForCSR) {
+ delete _certForCSR;
+ _certForCSR = nullptr;
+ }
+
+ if(_tlsClient){
+ delete _tlsClient;
+ _tlsClient = nullptr;
+ }
+ _fw_version = "";
+ _deviceId = "";
+ _state = CSRHandlerStates::END;
+}
+
+CSRHandlerClass::CSRHandlerStates CSRHandlerClass::poll() {
+ switch (_state) {
+ case CSRHandlerStates::BUILD_CSR: _state = handleBuildCSR (); break;
+ case CSRHandlerStates::REQUEST_SIGNATURE: _state = handleRequestSignature (); break;
+ case CSRHandlerStates::WAITING_RESPONSE: _state = handleWaitingResponse (); break;
+ case CSRHandlerStates::PARSE_RESPONSE: _state = handleParseResponse (); break;
+ case CSRHandlerStates::BUILD_CERTIFICATE: _state = handleBuildCertificate (); break;
+ case CSRHandlerStates::CERT_CREATED: _state = handleCertCreated (); break;
+ case CSRHandlerStates::WAITING_COMPLETE_RES: _state = handleWaitingCompleteRes(); break;
+ case CSRHandlerStates::COMPLETED: break;
+ case CSRHandlerStates::ERROR: handleError (); break;
+ case CSRHandlerStates::END: break;
+ }
+
+ return _state;
+}
+
+void CSRHandlerClass::updateNextRequestAt() {
+ uint32_t delay;
+ if(_requestAttempt <= MAX_CSR_REQUEST_INTERVAL_ATTEMPTS) {
+ delay = BACKEND_INTERVAL_s * _requestAttempt * 1000; // use linear backoff since backend has a rate limit
+ }else {
+ delay = MAX_CSR_REQUEST_INTERVAL;
+ }
+
+ _nextRequestAt = millis() + delay + jitter();
+}
+
+uint32_t CSRHandlerClass::jitter(uint32_t base, uint32_t max) {
+ srand(millis());
+ return base + rand() % (max - base);
+}
+
+bool CSRHandlerClass::postRequest(const char *url, String &postData) {
+ if(!_client){
+ _client = new HttpClient(*_tlsClient, server, 443);
+ }
+
+ uint32_t ts = getTimestamp();
+ if(ts == 0){
+ DEBUG_WARNING("CSRH::%s Failed getting timestamp", __FUNCTION__);
+ return false;
+ }
+
+ String token = getAIoTCloudJWT(*_secureElement, *_uhwid, ts, 1);
+
+ _requestAttempt++;
+ _client->beginRequest();
+
+ if(_client->post(url) == 0){
+ _client->sendHeader("Host", server);
+ _client->sendHeader("Connection", "close");
+ _client->sendHeader("Content-Type", "application/json;charset=UTF-8");
+ _client->sendHeader("Authorization", "Bearer " + token);
+ _client->sendHeader("Content-Length", postData.length());
+ _client->beginBody();
+ _client->print(postData);
+ _startWaitingResponse = millis();
+ return true;
+ }
+ return false;
+}
+
+uint32_t CSRHandlerClass::getTimestamp() {
+ uint8_t getTsAttempt = 0;
+ uint32_t ts = 0;
+ do{
+ TimeService.sync();
+ ts = TimeService.getTime();
+ getTsAttempt++;
+ }while(ts == 0 && getTsAttempt < 3);
+
+ return ts;
+}
+
+CSRHandlerClass::CSRHandlerStates CSRHandlerClass::handleBuildCSR() {
+ if (!_certForCSR) {
+ _certForCSR = new ECP256Certificate();
+ }
+ _certForCSR->begin();
+
+ _certForCSR->setSubjectCommonName(*_uhwid);
+
+ if (!SElementCSR::build(*_secureElement, *_certForCSR, static_cast(SElementArduinoCloudSlot::Key), true)) {
+ DEBUG_ERROR("CSRH::%s Error generating CSR!", __FUNCTION__);
+ _ledFeedback.setMode(LEDFeedbackClass::LEDFeedbackMode::ERROR);
+ return CSRHandlerStates::ERROR;
+ }
+ return CSRHandlerStates::REQUEST_SIGNATURE;
+}
+
+CSRHandlerClass::CSRHandlerStates CSRHandlerClass::handleRequestSignature() {
+ CSRHandlerStates nextState = _state;
+
+ if(millis() < _nextRequestAt) {
+ return nextState;
+ }
+
+ NetworkConnectionState connectionRes = _connectionHandler->check();
+ if (connectionRes != NetworkConnectionState::CONNECTED) {
+ nextNetworkRetry();
+ return nextState;
+ }
+
+ if(!_certForCSR){
+ return CSRHandlerStates::BUILD_CSR;
+ }
+
+ String csr = _certForCSR->getCSRPEM();
+ csr.replace("\n", "\\n");
+
+ String PostData = "{\"csr\":\"";
+ PostData += csr;
+ PostData += "\"}";
+ DEBUG_INFO("CSRH Downloading certificate...");
+
+ if(postRequest("/provisioning/v1/onboarding/provision/csr", PostData)){
+ nextState = CSRHandlerStates::WAITING_RESPONSE;
+ } else {
+ updateNextRequestAt();
+ DEBUG_WARNING("CSRH::%s Failed sending request, retrying in %d ms", __FUNCTION__, _nextRequestAt - millis());
+ }
+
+ return nextState;
+}
+
+CSRHandlerClass::CSRHandlerStates CSRHandlerClass::handleWaitingResponse() {
+ CSRHandlerStates nextState = _state;
+ NetworkConnectionState connectionRes = _connectionHandler->check();
+ if (connectionRes != NetworkConnectionState::CONNECTED) {
+ nextNetworkRetry();
+ _client->stop();
+ return CSRHandlerStates::REQUEST_SIGNATURE;
+ }
+
+ if (millis() - _startWaitingResponse > RESPONSE_TIMEOUT) {
+ _client->stop();
+ updateNextRequestAt();
+ DEBUG_WARNING("CSRH::%s CSR request timeout, retrying in %d ms", __FUNCTION__, _nextRequestAt - millis());
+ nextState = CSRHandlerStates::REQUEST_SIGNATURE;
+ }
+
+
+ int statusCode = _client->responseStatusCode();
+ if(statusCode == 200){
+ nextState = CSRHandlerStates::PARSE_RESPONSE;
+ } else {
+ _client->stop();
+ updateNextRequestAt();
+ DEBUG_WARNING("CSRH::%s CSR request error code %d, retrying in %d ms", __FUNCTION__, statusCode ,_nextRequestAt - millis());
+ nextState = CSRHandlerStates::REQUEST_SIGNATURE;
+ }
+
+ return nextState;
+}
+
+CSRHandlerClass::CSRHandlerStates CSRHandlerClass::handleParseResponse() {
+ String certResponse = _client->responseBody();
+ _client->stop();
+
+ /* Parse the response in format:
+ * device_id|authority_key_identifier|not_before|serial|signature_asn1_x|signature_asn1_y
+ */
+ char *response = (char *)certResponse.c_str();
+ char *token[6];
+ int i = 1;
+ token[0] = strtok(response, "|");
+ for (; i < 6; i++) {
+ char *tok = strtok(NULL, "|");
+ if(tok == NULL){
+ break;
+ }
+ token[i] = tok;
+ }
+
+ if(i < 6 || strlen(token[0]) != 36 || strlen(token[1]) != 40
+ || strlen(token[2]) < 10 || strlen(token[3]) != 32
+ || strlen(token[4]) != 64 || strlen(token[5]) != 64
+ || sscanf(token[2], "%4d-%2d-%2dT%2d", &_issueYear, &_issueMonth, &_issueDay, &_issueHour) != 4){
+ updateNextRequestAt();
+ DEBUG_ERROR("CSRH::%s Error parsing response, retrying in %d ms", __FUNCTION__, _nextRequestAt - millis());
+ return CSRHandlerStates::REQUEST_SIGNATURE;
+ }
+
+ _deviceId = token[0];
+ hex::decode(token[1], _authorityKeyIdentifier, sizeof(_authorityKeyIdentifier));
+ hex::decode(token[3], _serialNumber, sizeof(_serialNumber));
+ hex::decode(token[4], _signature, sizeof(_signature));
+ hex::decode(token[5], &_signature[32], sizeof(_signature) - 32);
+
+ return CSRHandlerStates::BUILD_CERTIFICATE;
+}
+
+CSRHandlerClass::CSRHandlerStates CSRHandlerClass::handleBuildCertificate() {
+ int expireYears = 31;
+
+ if (!SElementArduinoCloudDeviceId::write(*_secureElement, _deviceId, SElementArduinoCloudSlot::DeviceId)) {
+ DEBUG_ERROR("CSRH::%s Error storing device id!", __FUNCTION__);
+ _ledFeedback.setMode(LEDFeedbackClass::LEDFeedbackMode::ERROR);
+ return CSRHandlerStates::ERROR;
+ }
+
+ ECP256Certificate cert;
+ cert.begin();
+
+ cert.setSubjectCommonName(_deviceId);
+ cert.setIssuerCountryName("US");
+ cert.setIssuerOrganizationName("Arduino LLC US");
+ cert.setIssuerOrganizationalUnitName("IT");
+ cert.setIssuerCommonName("Arduino");
+ cert.setSignature(_signature, sizeof(_signature));
+ cert.setAuthorityKeyId(_authorityKeyIdentifier, sizeof(_authorityKeyIdentifier));
+ cert.setSerialNumber(_serialNumber, sizeof(_serialNumber));
+ cert.setIssueYear(_issueYear);
+ cert.setIssueMonth(_issueMonth);
+ cert.setIssueDay(_issueDay);
+ cert.setIssueHour(_issueHour);
+ cert.setExpireYears(expireYears);
+
+ if (!SElementArduinoCloudCertificate::build(*_secureElement, cert, static_cast(SElementArduinoCloudSlot::Key))) {
+ DEBUG_ERROR("CSRH::%s Error building secureElement compressed cert!", __FUNCTION__);
+ _ledFeedback.setMode(LEDFeedbackClass::LEDFeedbackMode::ERROR);
+ return CSRHandlerStates::ERROR;
+ }
+
+ if (!SElementArduinoCloudCertificate::write(*_secureElement, cert, SElementArduinoCloudSlot::CompressedCertificate)) {
+ DEBUG_ERROR("CSRH::%s Error storing cert!" , __FUNCTION__);
+ _ledFeedback.setMode(LEDFeedbackClass::LEDFeedbackMode::ERROR);
+ return CSRHandlerStates::ERROR;
+ }
+
+ DEBUG_INFO("CSRH Certificate created!");
+ _nextRequestAt = 0;
+ _requestAttempt = 0;
+ return CSRHandlerStates::CERT_CREATED;
+}
+
+CSRHandlerClass::CSRHandlerStates CSRHandlerClass::handleCertCreated() {
+ CSRHandlerStates nextState = _state;
+
+ if(millis() < _nextRequestAt) {
+ return nextState;
+ }
+
+ NetworkConnectionState connectionRes = _connectionHandler->check();
+ if (connectionRes != NetworkConnectionState::CONNECTED) {
+ nextNetworkRetry();
+ return nextState;
+ }
+
+ String PostData = "{\"wifi_fw_version\":\"";
+ PostData += _fw_version;
+ PostData += "\"}";
+ if(postRequest("/provisioning/v1/onboarding/provision/complete", PostData)){
+ nextState = CSRHandlerStates::WAITING_COMPLETE_RES;
+ } else {
+ updateNextRequestAt();
+ DEBUG_WARNING("CSRH::%s Error sending complete request, retrying in %d ms", __FUNCTION__, _nextRequestAt - millis());
+ }
+
+ return nextState;
+}
+
+CSRHandlerClass::CSRHandlerStates CSRHandlerClass::handleWaitingCompleteRes() {
+ CSRHandlerStates nextState = _state;
+ NetworkConnectionState connectionRes = _connectionHandler->check();
+ if (connectionRes != NetworkConnectionState::CONNECTED) {
+ nextNetworkRetry();
+ _client->stop();
+ return CSRHandlerStates::CERT_CREATED;
+ }
+
+ if (millis() - _startWaitingResponse > RESPONSE_TIMEOUT) {
+ _client->stop();
+ updateNextRequestAt();
+ DEBUG_WARNING("CSRH::%s Complete request timeout, retrying in %d ms", __FUNCTION__, _nextRequestAt - millis());
+ nextState = CSRHandlerStates::CERT_CREATED;
+ }
+
+ int statusCode = _client->responseStatusCode();
+ if(statusCode == 200){
+ if (_certForCSR) {
+ delete _certForCSR;
+ _certForCSR = nullptr;
+ }
+ DEBUG_INFO("CSRH Provisioning completed!");
+ nextState = CSRHandlerStates::COMPLETED;
+ } else if (statusCode == 429 || statusCode == 503) {
+ updateNextRequestAt();
+ nextState = CSRHandlerStates::CERT_CREATED;
+ } else {
+ DEBUG_WARNING("CSRH::%s Complete request error code %d, retrying in %d ms", __FUNCTION__, statusCode ,_nextRequestAt - millis());
+ _requestAttempt = 0;
+ _nextRequestAt = 0;
+ nextState = CSRHandlerStates::REQUEST_SIGNATURE;
+ }
+ _client->stop();
+
+ return nextState;
+}
+
+void CSRHandlerClass::nextNetworkRetry() {
+ _nextRequestAt = millis() + CONNECTION_RETRY_TIMEOUT_MS;
+}
+
+void CSRHandlerClass::handleError() {
+ _ledFeedback.update();
+}
diff --git a/examples/utility/Provisioning_2.0/CSRHandler.h b/examples/utility/Provisioning_2.0/CSRHandler.h
new file mode 100644
index 000000000..ae5956b7e
--- /dev/null
+++ b/examples/utility/Provisioning_2.0/CSRHandler.h
@@ -0,0 +1,74 @@
+/*
+ Copyright (c) 2024 Arduino SA
+
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+
+#pragma once
+#include
+#include
+#include
+#include
+#include
+#include "utility/LEDFeedback.h"
+#define JITTER_BASE 0
+#define JITTER_MAX 1000
+
+class CSRHandlerClass {
+public:
+ CSRHandlerClass();
+ ~CSRHandlerClass();
+ enum class CSRHandlerStates {
+ BUILD_CSR,
+ REQUEST_SIGNATURE,
+ WAITING_RESPONSE,
+ PARSE_RESPONSE,
+ BUILD_CERTIFICATE,
+ CERT_CREATED,
+ WAITING_COMPLETE_RES,
+ COMPLETED,
+ ERROR,
+ END
+ };
+ bool begin(ConnectionHandler &connectionHandler, SecureElement &secureElement, String &uhwid);
+ void end();
+ CSRHandlerStates poll();
+private:
+ CSRHandlerStates _state;
+ unsigned long _nextRequestAt;
+ uint32_t _requestAttempt;
+ uint32_t _startWaitingResponse;
+ String *_uhwid;
+ String _fw_version;
+
+ int _issueYear;
+ uint8_t _issueMonth;
+ uint8_t _issueDay;
+ uint8_t _issueHour;
+ byte _serialNumber[16];
+ byte _authorityKeyIdentifier[20];
+ byte _signature[64];
+ String _deviceId;
+
+ ECP256Certificate *_certForCSR;
+ ConnectionHandler *_connectionHandler;
+ SecureElement *_secureElement;
+ TLSClientMqtt *_tlsClient;
+ HttpClient *_client;
+ LEDFeedbackClass &_ledFeedback;
+ void updateNextRequestAt();
+ void nextNetworkRetry();
+ uint32_t jitter(uint32_t base = JITTER_BASE, uint32_t max = JITTER_MAX);
+ bool postRequest(const char *url, String &postData);
+ uint32_t getTimestamp();
+ CSRHandlerStates handleBuildCSR();
+ CSRHandlerStates handleRequestSignature();
+ CSRHandlerStates handleWaitingResponse();
+ CSRHandlerStates handleParseResponse();
+ CSRHandlerStates handleBuildCertificate();
+ CSRHandlerStates handleCertCreated();
+ CSRHandlerStates handleWaitingCompleteRes();
+ void handleError();
+};
diff --git a/examples/utility/Provisioning_2.0/ClaimingHandler.cpp b/examples/utility/Provisioning_2.0/ClaimingHandler.cpp
new file mode 100644
index 000000000..e2567e084
--- /dev/null
+++ b/examples/utility/Provisioning_2.0/ClaimingHandler.cpp
@@ -0,0 +1,235 @@
+/*
+ Copyright (c) 2024 Arduino SA
+
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+
+#include "ClaimingHandler.h"
+#include
+#include "Arduino_DebugUtils.h"
+#include
+#include "utility/HCI.h"
+#include
+#include "ANetworkConfigurator_Config.h"
+
+#define SLOT_BOARD_PRIVATE_KEY 1
+
+extern const char *SKETCH_VERSION;
+
+ClaimingHandlerClass::ClaimingHandlerClass():
+ _uhwid {nullptr},
+ _state {ClaimingHandlerStates::END},
+ _secureElement {nullptr},
+ _clearStoredCredentials {nullptr},
+ _agentManager { AgentsManagerClass::getInstance()},
+ _ledFeedback {LEDFeedbackClass::getInstance()} {
+ _receivedEvent = ClaimingReqEvents::NONE;
+ _ts = 0;
+}
+
+bool ClaimingHandlerClass::begin(SecureElement &secureElement, String &uhwid, ClearStoredCredentialsHandler clearStoredCredentials) {
+ if(_state != ClaimingHandlerStates::END) {
+ return true;
+ }
+
+ if(uhwid == "" || clearStoredCredentials == nullptr) {
+ return false;
+ }
+
+ if (!_agentManager.addRequestHandler(RequestType::GET_ID, getIdRequestCb)) {
+ return false;
+ }
+
+ if (!_agentManager.addRequestHandler(RequestType::RESET, resetStoredCredRequestCb)) {
+ return false;
+ }
+
+ if(!_agentManager.addRequestHandler(RequestType::GET_BLE_MAC_ADDRESS, getBLEMacAddressRequestCb)) {
+ return false;
+ }
+
+ if(!_agentManager.addRequestHandler(RequestType::GET_PROVISIONING_SKETCH_VERSION, getProvSketchVersionRequestCb)) {
+ return false;
+ }
+
+ if (!_agentManager.addReturnTimestampCallback(setTimestamp)) {
+ return false;
+ }
+
+ _agentManager.begin();
+ _uhwid = &uhwid;
+ _secureElement = &secureElement;
+ _clearStoredCredentials = clearStoredCredentials;
+ _state = ClaimingHandlerStates::INIT;
+}
+
+void ClaimingHandlerClass::end() {
+ if(_state == ClaimingHandlerStates::END) {
+ return;
+ }
+
+ _agentManager.removeReturnTimestampCallback();
+ _agentManager.removeRequestHandler(RequestType::GET_ID);
+ _agentManager.removeRequestHandler(RequestType::RESET);
+ _agentManager.end();
+ _state = ClaimingHandlerStates::END;
+}
+
+void ClaimingHandlerClass::poll() {
+ if(_state == ClaimingHandlerStates::END) {
+ return;
+ }
+ _ledFeedback.update();
+ _agentManager.update();
+
+ switch (_receivedEvent) {
+ case ClaimingReqEvents::GET_ID: getIdReqHandler (); break;
+ case ClaimingReqEvents::RESET: resetStoredCredReqHandler (); break;
+ case ClaimingReqEvents::GET_BLE_MAC_ADDRESS: getBLEMacAddressReqHandler (); break;
+ case ClaimingReqEvents::GET_PROV_SKETCH_VERSION: getProvSketchVersionReqHandler(); break;
+ }
+ _receivedEvent = ClaimingReqEvents::NONE;
+ return;
+}
+
+void ClaimingHandlerClass::getIdReqHandler() {
+ if (_ts == 0) {
+ DEBUG_ERROR("CH::%s Error: timestamp not provided" , __FUNCTION__);
+ sendStatus(StatusMessage::PARAMS_NOT_FOUND);
+ return;
+ }
+
+ byte _uhwidBytes[32];
+ hex::decode(_uhwid->c_str(), _uhwidBytes, _uhwid->length());
+
+ String token = generateToken();
+ if (token == "") {
+ DEBUG_ERROR("CH::%s Error: token not created", __FUNCTION__);
+ sendStatus(StatusMessage::ERROR);
+ return;
+ }
+
+ SElementJWS sejws;
+ String publicKey = sejws.publicKey(*_secureElement, SLOT_BOARD_PRIVATE_KEY, false);
+ if (publicKey == "") {
+ DEBUG_ERROR("CH::%s Error: public key not created", __FUNCTION__);
+ sendStatus(StatusMessage::ERROR);
+ return;
+ }
+
+ //Send public key
+ ProvisioningOutputMessage publicKeyMsg = {MessageOutputType::PROV_PUBLIC_KEY};
+ publicKeyMsg.m.provPublicKey = publicKey.c_str();
+ _agentManager.sendMsg(publicKeyMsg);
+
+
+ //Send UHWID
+ ProvisioningOutputMessage idMsg = {MessageOutputType::UHWID};
+ idMsg.m.uhwid = _uhwidBytes;
+ _agentManager.sendMsg(idMsg);
+
+ //Send JWT
+ ProvisioningOutputMessage jwtMsg = {MessageOutputType::JWT};
+ jwtMsg.m.jwt = token.c_str();
+ _agentManager.sendMsg(jwtMsg);
+ _ts = 0;
+
+}
+
+void ClaimingHandlerClass::resetStoredCredReqHandler() {
+ if( !_clearStoredCredentials()){
+ DEBUG_ERROR("CH::%s Error: reset stored credentials failed", __FUNCTION__);
+ sendStatus(StatusMessage::ERROR);
+ } else {
+ sendStatus(StatusMessage::RESET_COMPLETED);
+ }
+
+}
+
+void ClaimingHandlerClass::getBLEMacAddressReqHandler() {
+ /* Set the default MAC address as ff:ff:ff:ff:ff:ff for compatibility
+ * with the Arduino IoT Cloud WebUI
+ */
+ uint8_t mac[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+
+#ifdef ARDUINO_OPTA
+ if(_getPid_() == OPTA_WIFI_PID) {
+#endif
+ bool activated = false;
+ ConfiguratorAgent * connectedAgent = _agentManager.getConnectedAgent();
+ if(!_agentManager.isAgentEnabled(ConfiguratorAgent::AgentTypes::BLE) || (connectedAgent != nullptr &&
+ connectedAgent->getAgentType() != ConfiguratorAgent::AgentTypes::BLE)) {
+ activated = true;
+ BLE.begin();
+ }
+
+ HCI.readBdAddr(mac);
+
+ for(int i = 0; i < 3; i++){
+ uint8_t byte = mac[i];
+ mac[i] = mac[5-i];
+ mac[5-i] = byte;
+ }
+ if (activated) {
+ BLE.end();
+ }
+#ifdef ARDUINO_OPTA
+ }
+#endif
+ ProvisioningOutputMessage outputMsg;
+ outputMsg.type = MessageOutputType::BLE_MAC_ADDRESS;
+ outputMsg.m.BLEMacAddress = mac;
+ _agentManager.sendMsg(outputMsg);
+}
+
+void ClaimingHandlerClass::getProvSketchVersionReqHandler() {
+ ProvisioningOutputMessage outputMsg;
+ outputMsg.type = MessageOutputType::PROV_SKETCH_VERSION;
+ outputMsg.m.provSketchVersion = SKETCH_VERSION;
+ _agentManager.sendMsg(outputMsg);
+}
+
+void ClaimingHandlerClass::getIdRequestCb() {
+ DEBUG_VERBOSE("CH Get ID request received");
+ _receivedEvent = ClaimingReqEvents::GET_ID;
+}
+void ClaimingHandlerClass::setTimestamp(uint64_t ts) {
+ _ts = ts;
+}
+
+void ClaimingHandlerClass::resetStoredCredRequestCb() {
+ DEBUG_VERBOSE("CH Reset stored credentials request received");
+ _receivedEvent = ClaimingReqEvents::RESET;
+}
+
+void ClaimingHandlerClass::getBLEMacAddressRequestCb() {
+ DEBUG_VERBOSE("CH Get BLE MAC address request received");
+ _receivedEvent = ClaimingReqEvents::GET_BLE_MAC_ADDRESS;
+}
+
+void ClaimingHandlerClass::getProvSketchVersionRequestCb() {
+ DEBUG_VERBOSE("CH Get provisioning sketch version request received");
+ _receivedEvent = ClaimingReqEvents::GET_PROV_SKETCH_VERSION;
+}
+
+String ClaimingHandlerClass::generateToken() {
+ String token = getAIoTCloudJWT(*_secureElement, *_uhwid, _ts, SLOT_BOARD_PRIVATE_KEY);
+ if(token == "") {
+ byte publicKey[64];
+ DEBUG_INFO("Generating private key");
+ if(!_secureElement->generatePrivateKey(SLOT_BOARD_PRIVATE_KEY, publicKey)){
+ DEBUG_ERROR("CH::%s Error: private key generation failed", __FUNCTION__);
+ return "";
+ }
+ token = getAIoTCloudJWT(*_secureElement, *_uhwid, _ts, SLOT_BOARD_PRIVATE_KEY);
+ }
+
+ return token;
+}
+
+bool ClaimingHandlerClass::sendStatus(StatusMessage msg) {
+ ProvisioningOutputMessage statusMsg = {MessageOutputType::STATUS, {msg}};
+ return _agentManager.sendMsg(statusMsg);
+}
diff --git a/examples/utility/Provisioning_2.0/ClaimingHandler.h b/examples/utility/Provisioning_2.0/ClaimingHandler.h
new file mode 100644
index 000000000..7b8693b36
--- /dev/null
+++ b/examples/utility/Provisioning_2.0/ClaimingHandler.h
@@ -0,0 +1,54 @@
+/*
+ Copyright (c) 2024 Arduino SA
+
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+
+#pragma once
+#include "Arduino.h"
+#include "configuratorAgents/AgentsManager.h"
+#include
+#include "utility/LEDFeedback.h"
+
+typedef bool (*ClearStoredCredentialsHandler)();
+class ClaimingHandlerClass {
+public:
+ ClaimingHandlerClass();
+ bool begin(SecureElement &secureElement, String &uhwid, ClearStoredCredentialsHandler clearStoredCredentials);
+ void end();
+ void poll();
+private:
+ String *_uhwid;
+ enum class ClaimingHandlerStates {
+ INIT,
+ END
+ };
+ enum class ClaimingReqEvents { NONE,
+ GET_ID,
+ RESET,
+ GET_BLE_MAC_ADDRESS,
+ GET_PROV_SKETCH_VERSION};
+ static inline ClaimingReqEvents _receivedEvent;
+ ClaimingHandlerStates _state;
+ AgentsManagerClass &_agentManager;
+ LEDFeedbackClass &_ledFeedback;
+ static inline uint64_t _ts;
+ SecureElement *_secureElement;
+ String generateToken();
+
+ bool sendStatus(StatusMessage msg);
+ /* Commands handlers */
+ void getIdReqHandler();
+ void resetStoredCredReqHandler();
+ void getBLEMacAddressReqHandler();
+ void getProvSketchVersionReqHandler();
+ ClearStoredCredentialsHandler _clearStoredCredentials;
+ /* Callbacks for receiving commands */
+ static void getIdRequestCb();
+ static void setTimestamp(uint64_t ts);
+ static void resetStoredCredRequestCb();
+ static void getBLEMacAddressRequestCb();
+ static void getProvSketchVersionRequestCb();
+};
diff --git a/examples/utility/Provisioning_2.0/Provisioning_2.0.ino b/examples/utility/Provisioning_2.0/Provisioning_2.0.ino
new file mode 100644
index 000000000..7f8f44ceb
--- /dev/null
+++ b/examples/utility/Provisioning_2.0/Provisioning_2.0.ino
@@ -0,0 +1,228 @@
+/*
+ Copyright (c) 2024 Arduino SA
+
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+#include "thingProperties.h"
+#include "CSRHandler.h"
+#include "ClaimingHandler.h"
+#include "SecretsHelper.h"
+#include
+#include
+#include
+#include
+#include "utility/LEDFeedback.h"
+
+const char *SKETCH_VERSION = "0.3.3";
+
+enum class DeviceState {
+ HARDWARE_CHECK,
+ BEGIN,
+ NETWORK_CONFIG,
+ CSR,
+ BEGIN_CLOUD,
+ RUN,
+ ERROR
+ };
+
+DeviceState _state = DeviceState::HARDWARE_CHECK;
+SecureElement secureElement;
+
+String uhwid = "";
+bool resetEvent = false;
+
+CSRHandlerClass CSRHandler;
+ClaimingHandlerClass ClaimingHandler;
+
+bool clearStoredCredentials() {
+ const uint8_t empty[4] = {0x00,0x00,0x00,0x00};
+ if(!NetworkConfigurator.resetStoredConfiguration() || \
+ !secureElement.writeSlot(static_cast(SElementArduinoCloudSlot::DeviceId), (byte*)empty, sizeof(empty)) || \
+ !secureElement.writeSlot(static_cast(SElementArduinoCloudSlot::CompressedCertificate), (byte*)empty, sizeof(empty))) {
+ return false;
+ }
+
+ ArduinoCloud.disconnect();
+ resetEvent = true;
+ return true;
+ }
+
+void setup() {
+ Serial.begin(9600);
+
+ delay(1500);
+
+ setDebugMessageLevel(4);
+
+ initProperties();
+ AgentsManagerClass::getInstance().begin();
+ LEDFeedbackClass::getInstance().begin();
+ DEBUG_INFO("Starting Provisioning version %s", SKETCH_VERSION);
+}
+
+void sendStatus(StatusMessage msg) {
+ ProvisioningOutputMessage outMsg = { MessageOutputType::STATUS, { msg } };
+ AgentsManagerClass::getInstance().sendMsg(outMsg);
+}
+
+DeviceState handleHardwareCheck() {
+ // Init the secure element
+ if(!secureElement.begin()) {
+ DEBUG_ERROR("Sketch: Error during secureElement begin!");
+ LEDFeedbackClass::getInstance().setMode(LEDFeedbackClass::LEDFeedbackMode::ERROR);
+ sendStatus(StatusMessage::HW_ERROR_SE_BEGIN);
+ return DeviceState::ERROR;
+ }
+
+ if (!secureElement.locked()) {
+ if (!secureElement.writeConfiguration()) {
+ DEBUG_ERROR("Sketch: Writing secureElement configuration failed!");
+ LEDFeedbackClass::getInstance().setMode(LEDFeedbackClass::LEDFeedbackMode::ERROR);
+ sendStatus(StatusMessage::HW_ERROR_SE_CONFIG);
+ return DeviceState::ERROR;
+ }
+
+ if (!secureElement.lock()) {
+ DEBUG_ERROR("Sketch: Locking secureElement configuration failed!");
+ LEDFeedbackClass::getInstance().setMode(LEDFeedbackClass::LEDFeedbackMode::ERROR);
+ sendStatus(StatusMessage::HW_ERROR_SE_LOCK);
+ return DeviceState::ERROR;
+ }
+ DEBUG_INFO("secureElement locked successfully");
+ }
+
+ FlashFormatter flashFormatter;
+ // Check if the board storage is properly formatted
+ if(!flashFormatter.checkAndFormatPartition()) {
+ DEBUG_ERROR("Sketch: Error partitioning storage");
+ LEDFeedbackClass::getInstance().setMode(LEDFeedbackClass::LEDFeedbackMode::ERROR);
+ sendStatus(StatusMessage::FAIL_TO_PARTITION_STORAGE);
+ return DeviceState::ERROR;
+ }
+
+ return DeviceState::BEGIN;
+}
+
+DeviceState handleBegin() {
+ uhwid = GetUHWID();
+ if(uhwid == ""){
+ DEBUG_ERROR("Sketch: Error getting UHWID");
+ LEDFeedbackClass::getInstance().setMode(LEDFeedbackClass::LEDFeedbackMode::ERROR);
+ sendStatus(StatusMessage::ERROR_GENERATING_UHWID);
+ return DeviceState::ERROR;
+ }
+ // Scan the network options
+ NetworkConfigurator.scanNetworkOptions();
+ NetworkConfigurator.begin();
+ ClaimingHandler.begin(secureElement, uhwid, clearStoredCredentials);
+ DEBUG_INFO("BLE Available");
+ return DeviceState::NETWORK_CONFIG;
+}
+
+DeviceState handleNetworkConfig() {
+ ClaimingHandler.poll();
+ if(resetEvent){
+ resetEvent = false;
+ }
+ NetworkConfiguratorStates s = NetworkConfigurator.update();
+
+ DeviceState nextState = _state;
+ if (s == NetworkConfiguratorStates::CONFIGURED) {
+ String deviceId = "";
+ SElementArduinoCloudDeviceId::read(secureElement, deviceId, SElementArduinoCloudSlot::DeviceId);
+
+ if (deviceId == "") {
+ CSRHandler.begin(ArduinoIoTPreferredConnection, secureElement, uhwid);
+ nextState = DeviceState::CSR;
+ } else {
+ nextState = DeviceState::BEGIN_CLOUD;
+ }
+ }
+ return nextState;
+}
+
+DeviceState handleCSR() {
+ NetworkConfigurator.update();
+ ClaimingHandler.poll();
+ if(resetEvent) {
+ resetEvent = false;
+ CSRHandler.end();
+ return DeviceState::NETWORK_CONFIG;
+ }
+
+ DeviceState nextState = _state;
+
+ CSRHandlerClass::CSRHandlerStates res = CSRHandler.poll();
+ if (res == CSRHandlerClass::CSRHandlerStates::COMPLETED) {
+ CSRHandler.end();
+ nextState = DeviceState::BEGIN_CLOUD;
+ }
+
+ return nextState;
+}
+
+DeviceState handleBeginCloud() {
+ // Close the connection to the peer (App mobile, FE, etc)
+ NetworkConfigurator.disconnectAgent();
+ // Close the BLE connectivity
+ if (NetworkConfigurator.isAgentEnabled(ConfiguratorAgent::AgentTypes::BLE)) {
+ NetworkConfigurator.enableAgent(ConfiguratorAgent::AgentTypes::BLE, false);
+ }
+ // Connect to Arduino IoT Cloud
+#ifdef COMPILE_TEST
+ ArduinoCloud.begin(ArduinoIoTPreferredConnection, false, "mqtts-sa.iot.oniudra.cc");
+#else
+ ArduinoCloud.begin(ArduinoIoTPreferredConnection);
+#endif
+ ArduinoCloud.printDebugInfo();
+
+ return DeviceState::RUN;
+}
+
+void cloudConnectedHandler(bool connected) {
+ static bool _status = false;
+ if(connected != _status){
+ _status = connected;
+ if(connected){
+ LEDFeedbackClass::getInstance().setMode(LEDFeedbackClass::LEDFeedbackMode::CONNECTED_TO_CLOUD);
+ } else {
+ LEDFeedbackClass::getInstance().setMode(LEDFeedbackClass::LEDFeedbackMode::NONE);
+ }
+ }
+}
+
+DeviceState handleRun() {
+ ClaimingHandler.poll();
+ if(resetEvent) {
+ resetEvent = false;
+ return DeviceState::NETWORK_CONFIG;
+ }
+
+ DeviceState nextState = _state;
+ ArduinoCloud.update();
+
+ cloudConnectedHandler(ArduinoCloud.connected());
+
+ return nextState;
+}
+
+DeviceState handleError() {
+ LEDFeedbackClass::getInstance().update();
+ AgentsManagerClass::getInstance().update();
+ return DeviceState::ERROR;
+}
+
+void loop() {
+ switch (_state) {
+ case DeviceState::HARDWARE_CHECK: _state = handleHardwareCheck(); break;
+ case DeviceState::BEGIN: _state = handleBegin (); break;
+ case DeviceState::NETWORK_CONFIG : _state = handleNetworkConfig(); break;
+ case DeviceState::CSR: _state = handleCSR (); break;
+ case DeviceState::BEGIN_CLOUD: _state = handleBeginCloud (); break;
+ case DeviceState::RUN: _state = handleRun (); break;
+ case DeviceState::ERROR: _state = handleError (); break;
+ default: break;
+ }
+}
diff --git a/examples/utility/Provisioning_2.0/SecretsHelper.h b/examples/utility/Provisioning_2.0/SecretsHelper.h
new file mode 100644
index 000000000..bdb6354d1
--- /dev/null
+++ b/examples/utility/Provisioning_2.0/SecretsHelper.h
@@ -0,0 +1,20 @@
+/*
+ Copyright (c) 2024 Arduino SA
+
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+
+#pragma once
+
+#include
+#include
+
+inline String GetUHWID() {
+ UniqueHWId Id;
+ if (Id.begin()) {
+ return Id.get();
+ }
+ return "";
+}
diff --git a/examples/utility/Provisioning_2.0/thingProperties.h b/examples/utility/Provisioning_2.0/thingProperties.h
new file mode 100644
index 000000000..7f51fa6ca
--- /dev/null
+++ b/examples/utility/Provisioning_2.0/thingProperties.h
@@ -0,0 +1,32 @@
+/*
+ Copyright (c) 2024 Arduino SA
+
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+#if defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310)
+#error "Board not supported for Provisioning 2.0"
+#endif
+
+#include
+#include
+#include
+#include "configuratorAgents/agents/BLEAgent.h"
+#include "configuratorAgents/agents/SerialAgent.h"
+
+GenericConnectionHandler ArduinoIoTPreferredConnection;
+KVStore kvStore;
+BLEAgentClass BLEAgent;
+SerialAgentClass SerialAgent;
+NetworkConfiguratorClass NetworkConfigurator(ArduinoIoTPreferredConnection);
+
+void initProperties() {
+
+ NetworkConfigurator.addAgent(BLEAgent);
+ NetworkConfigurator.addAgent(SerialAgent);
+ NetworkConfigurator.setStorage(kvStore);
+ ArduinoCloud.setConfigurator(NetworkConfigurator);
+}
+
+
diff --git a/examples/utility/SelfProvisioning/ECCX08Cert.cpp b/examples/utility/SelfProvisioning/ECCX08Cert.cpp
deleted file mode 100644
index db037d4e0..000000000
--- a/examples/utility/SelfProvisioning/ECCX08Cert.cpp
+++ /dev/null
@@ -1,939 +0,0 @@
-/*
- This file is part of ArduinoIoTCloud.
-
- Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
-
- This software is released under the GNU General Public License version 3,
- which covers the main part of arduino-cli.
- The terms of this license can be found at:
- https://www.gnu.org/licenses/gpl-3.0.en.html
-
- You can be released from the requirements of the above licenses by purchasing
- a commercial license. Buying such a license is mandatory if you want to modify or
- otherwise use the software for commercial activities involving the Arduino
- software without disclosing the source code of your own applications. To purchase
- a commercial license, send an email to license@arduino.cc.
-*/
-
-/******************************************************************************
- * INCLUDE
- ******************************************************************************/
-
-#include
-#include
-#include "ECCX08Cert.h"
-#include "tls/utility/SHA256.h"
-
-/******************************************************************************
- * DEFINE
- ******************************************************************************/
-
-#define ASN1_INTEGER 0x02
-#define ASN1_BIT_STRING 0x03
-#define ASN1_NULL 0x05
-#define ASN1_OBJECT_IDENTIFIER 0x06
-#define ASN1_PRINTABLE_STRING 0x13
-#define ASN1_SEQUENCE 0x30
-#define ASN1_SET 0x31
-
-struct __attribute__((__packed__)) CompressedCert {
- byte signature[64];
- byte dates[3];
- byte unused[5];
-};
-
-#define SERIAL_NUMBER_LENGTH 16
-#define AUTHORITY_KEY_IDENTIFIER_LENGTH 20
-
-struct __attribute__((__packed__)) SerialNumberAndAuthorityKeyIdentifier {
- byte serialNumber[SERIAL_NUMBER_LENGTH];
- byte authorityKeyIdentifier[AUTHORITY_KEY_IDENTIFIER_LENGTH];
-};
-
-/******************************************************************************
- * LOCAL MODULE FUNCTIONS
- ******************************************************************************/
-
-static String base64Encode(const byte in[], unsigned int length, const char* prefix, const char* suffix) {
- static const char* CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
-
- int b;
- String out;
-
- int reserveLength = 4 * ((length + 2) / 3) + ((length / 3 * 4) / 76) + strlen(prefix) + strlen(suffix);
- out.reserve(reserveLength);
-
- if (prefix) {
- out += prefix;
- }
-
- for (unsigned int i = 0; i < length; i += 3) {
- if (i > 0 && (i / 3 * 4) % 76 == 0) {
- out += '\n';
- }
-
- b = (in[i] & 0xFC) >> 2;
- out += CODES[b];
-
- b = (in[i] & 0x03) << 4;
- if (i + 1 < length) {
- b |= (in[i + 1] & 0xF0) >> 4;
- out += CODES[b];
- b = (in[i + 1] & 0x0F) << 2;
- if (i + 2 < length) {
- b |= (in[i + 2] & 0xC0) >> 6;
- out += CODES[b];
- b = in[i + 2] & 0x3F;
- out += CODES[b];
- } else {
- out += CODES[b];
- out += '=';
- }
- } else {
- out += CODES[b];
- out += "==";
- }
- }
-
- if (suffix) {
- out += suffix;
- }
-
- return out;
-}
-
-/******************************************************************************
- * CTOR/DTOR
- ******************************************************************************/
-
-ECCX08CertClass::ECCX08CertClass() :
- _keySlot(-1),
- _compressedCertSlot(-1),
- _serialNumberAndAuthorityKeyIdentifierSlot(-1),
- _bytes(NULL),
- _length(0) {
-}
-
-ECCX08CertClass::~ECCX08CertClass() {
- if (_bytes) {
- free(_bytes);
- _bytes = NULL;
- }
-}
-
-/******************************************************************************
- * PUBLIC MEMBER FUNCTIONS
- ******************************************************************************/
-
-int ECCX08CertClass::beginCSR(int keySlot, bool newPrivateKey) {
- if (keySlot < 0 || keySlot > 8) {
- return 0;
- }
-
- _keySlot = keySlot;
-
- if (newPrivateKey) {
- if (!ECCX08.generatePrivateKey(_keySlot, _temp)) {
- return 0;
- }
- } else {
- if (!ECCX08.generatePublicKey(_keySlot, _temp)) {
- return 0;
- }
- }
-
- return 1;
-}
-
-String ECCX08CertClass::endCSR() {
- int versionLen = versionLength();
- int subjectLen = issuerOrSubjectLength(_subjectCountryName,
- _subjectStateProvinceName,
- _subjectLocalityName,
- _subjectOrganizationName,
- _subjectOrganizationalUnitName,
- _subjectCommonName);
- int subjectHeaderLen = sequenceHeaderLength(subjectLen);
- int publicKeyLen = publicKeyLength();
-
- int csrInfoLen = versionLen + subjectHeaderLen + subjectLen + publicKeyLen + 2;
- int csrInfoHeaderLen = sequenceHeaderLength(csrInfoLen);
-
- byte csrInfo[csrInfoHeaderLen + csrInfoLen];
- byte* out = csrInfo;
-
- appendSequenceHeader(csrInfoLen, out);
- out += csrInfoHeaderLen;
-
- // version
- appendVersion(0x00, out);
- out += versionLen;
-
- // subject
- appendSequenceHeader(subjectLen, out);
- out += subjectHeaderLen;
- appendIssuerOrSubject(_subjectCountryName,
- _subjectStateProvinceName,
- _subjectLocalityName,
- _subjectOrganizationName,
- _subjectOrganizationalUnitName,
- _subjectCommonName, out);
- out += subjectLen;
-
- // public key
- appendPublicKey(_temp, out);
- out += publicKeyLen;
-
- // terminator
- *out++ = 0xa0;
- *out++ = 0x00;
-
- SHA256 sha256;
- byte csrInfoSha256[64];
- byte signature[64];
-
- sha256.begin();
- sha256.update(csrInfo, csrInfoHeaderLen + csrInfoLen);
- sha256.finalize(csrInfoSha256);
-
- if (!ECCX08.ecSign(_keySlot, csrInfoSha256, signature)) {
- return "";
- }
-
- int signatureLen = signatureLength(signature);
- int csrLen = csrInfoHeaderLen + csrInfoLen + signatureLen;
- int csrHeaderLen = sequenceHeaderLength(csrLen);
-
- byte csr[csrLen + csrHeaderLen];
- out = csr;
-
- appendSequenceHeader(csrLen, out);
- out += csrHeaderLen;
-
- // info
- memcpy(out, csrInfo, csrInfoHeaderLen + csrInfoLen);
- out += (csrInfoHeaderLen + csrInfoLen);
-
- // signature
- appendSignature(signature, out);
- out += signatureLen;
-
- return base64Encode(csr, csrLen + csrHeaderLen, "-----BEGIN CERTIFICATE REQUEST-----\n", "\n-----END CERTIFICATE REQUEST-----\n");
-}
-
-int ECCX08CertClass::beginStorage(int compressedCertSlot, int serialNumberAndAuthorityKeyIdentifierSlot) {
- if (compressedCertSlot < 8 || compressedCertSlot > 15) {
- return 0;
- }
-
- if (serialNumberAndAuthorityKeyIdentifierSlot < 8 || serialNumberAndAuthorityKeyIdentifierSlot > 15) {
- return 0;
- }
-
- _compressedCertSlot = compressedCertSlot;
- _serialNumberAndAuthorityKeyIdentifierSlot = serialNumberAndAuthorityKeyIdentifierSlot;
-
- memset(_temp, 0x00, sizeof(_temp));
-
- return 1;
-}
-
-void ECCX08CertClass::setSignature(byte signature[]) {
- struct CompressedCert* compressedCert = (struct CompressedCert*)_temp;
-
- memcpy(compressedCert->signature, signature, 64);
-}
-
-void ECCX08CertClass::setIssueYear(int issueYear) {
- struct CompressedCert* compressedCert = (struct CompressedCert*)_temp;
-
- compressedCert->dates[0] &= 0x07;
- compressedCert->dates[0] |= (issueYear - 2000) << 3;
-}
-
-void ECCX08CertClass::setIssueMonth(int issueMonth) {
- struct CompressedCert* compressedCert = (struct CompressedCert*)_temp;
-
- compressedCert->dates[0] &= 0xf8;
- compressedCert->dates[0] |= issueMonth >> 1;
-
- compressedCert->dates[1] &= 0x7f;
- compressedCert->dates[1] |= issueMonth << 7;
-}
-
-void ECCX08CertClass::setIssueDay(int issueDay) {
- struct CompressedCert* compressedCert = (struct CompressedCert*)_temp;
-
- compressedCert->dates[1] &= 0x83;
- compressedCert->dates[1] |= issueDay << 2;
-}
-
-void ECCX08CertClass::setIssueHour(int issueHour) {
- struct CompressedCert* compressedCert = (struct CompressedCert*)_temp;
-
- compressedCert->dates[2] &= 0x1f;
- compressedCert->dates[2] |= issueHour << 5;
-
- compressedCert->dates[1] &= 0xfc;
- compressedCert->dates[1] |= issueHour >> 3;
-}
-
-void ECCX08CertClass::setExpireYears(int expireYears) {
- struct CompressedCert* compressedCert = (struct CompressedCert*)_temp;
-
- compressedCert->dates[2] &= 0xe0;
- compressedCert->dates[2] |= expireYears;
-}
-
-void ECCX08CertClass::setSerialNumber(const byte serialNumber[]) {
- memcpy(&_temp[72], serialNumber, SERIAL_NUMBER_LENGTH);
-}
-
-void ECCX08CertClass::setAuthorityKeyIdentifier(const byte authorityKeyIdentifier[]) {
- memcpy(&_temp[88], authorityKeyIdentifier, AUTHORITY_KEY_IDENTIFIER_LENGTH);
-}
-
-int ECCX08CertClass::endStorage() {
- if (!ECCX08.writeSlot(_compressedCertSlot, &_temp[0], 72)) {
- return 0;
- }
-
- if (!ECCX08.writeSlot(_serialNumberAndAuthorityKeyIdentifierSlot, &_temp[72], SERIAL_NUMBER_LENGTH + AUTHORITY_KEY_IDENTIFIER_LENGTH)) {
- return 0;
- }
-
- return 1;
-}
-
-int ECCX08CertClass::beginReconstruction(int keySlot, int compressedCertSlot, int serialNumberAndAuthorityKeyIdentifierSlot) {
- if (keySlot < 0 || keySlot > 8) {
- return 0;
- }
-
- if (compressedCertSlot < 8 || compressedCertSlot > 15) {
- return 0;
- }
-
- if (serialNumberAndAuthorityKeyIdentifierSlot < 8 || serialNumberAndAuthorityKeyIdentifierSlot > 15) {
- return 0;
- }
-
- _keySlot = keySlot;
- _compressedCertSlot = compressedCertSlot;
- _serialNumberAndAuthorityKeyIdentifierSlot = serialNumberAndAuthorityKeyIdentifierSlot;
-
- return 1;
-}
-
-int ECCX08CertClass::endReconstruction() {
- byte publicKey[64];
- struct CompressedCert compressedCert;
- struct SerialNumberAndAuthorityKeyIdentifier serialNumberAndAuthorityKeyIdentifier;
-
- if (!ECCX08.generatePublicKey(_keySlot, publicKey)) {
- return 0;
- }
-
- if (!ECCX08.readSlot(_compressedCertSlot, (byte*)&compressedCert, sizeof(compressedCert))) {
- return 0;
- }
-
- if (!ECCX08.readSlot(_serialNumberAndAuthorityKeyIdentifierSlot, (byte*)&serialNumberAndAuthorityKeyIdentifier, sizeof(serialNumberAndAuthorityKeyIdentifier))) {
- return 0;
- }
-
- // dates
- int year = (compressedCert.dates[0] >> 3) + 2000;
- int month = ((compressedCert.dates[0] & 0x07) << 1) | (compressedCert.dates[1] >> 7);
- int day = (compressedCert.dates[1] & 0x7c) >> 2;
- int hour = ((compressedCert.dates[1] & 0x03) << 3) | (compressedCert.dates[2] >> 5);
- int expireYears = (compressedCert.dates[2] & 0x1f);
-
- int datesSize = 30;
-
- if (year > 2049) {
- // two more bytes for GeneralizedTime
- datesSize += 2;
- }
-
- if ((year + expireYears) > 2049) {
- // two more bytes for GeneralizedTime
- datesSize += 2;
- }
-
- int serialNumberLen = serialNumberLength(serialNumberAndAuthorityKeyIdentifier.serialNumber);
-
- int issuerLen = issuerOrSubjectLength(_issuerCountryName,
- _issuerStateProvinceName,
- _issuerLocalityName,
- _issuerOrganizationName,
- _issuerOrganizationalUnitName,
- _issuerCommonName);
-
- int issuerHeaderLen = sequenceHeaderLength(issuerLen);
-
- int subjectLen = issuerOrSubjectLength(_subjectCountryName,
- _subjectStateProvinceName,
- _subjectLocalityName,
- _subjectOrganizationName,
- _subjectOrganizationalUnitName,
- _subjectCommonName);
-
- int subjectHeaderLen = sequenceHeaderLength(subjectLen);
-
- int publicKeyLen = publicKeyLength();
-
- int authorityKeyIdentifierLen = authorityKeyIdentifierLength(serialNumberAndAuthorityKeyIdentifier.authorityKeyIdentifier);
-
- int signatureLen = signatureLength(compressedCert.signature);
-
- int certInfoLen = 5 + serialNumberLen + 12 + issuerHeaderLen + issuerLen + (datesSize + 2) +
- subjectHeaderLen + subjectLen + publicKeyLen;
-
- if (authorityKeyIdentifierLen) {
- certInfoLen += authorityKeyIdentifierLen;
- } else {
- certInfoLen += 4;
- }
-
- int certInfoHeaderLen = sequenceHeaderLength(certInfoLen);
-
- int certDataLen = certInfoLen + certInfoHeaderLen + signatureLen;
- int certDataHeaderLen = sequenceHeaderLength(certDataLen);
-
- _length = certDataLen + certDataHeaderLen;
- _bytes = (byte*)realloc(_bytes, _length);
-
- if (!_bytes) {
- _length = 0;
- return 0;
- }
-
- byte* out = _bytes;
-
- appendSequenceHeader(certDataLen, out);
- out += certDataHeaderLen;
-
- appendSequenceHeader(certInfoLen, out);
- out += certInfoHeaderLen;
-
- // version
- *out++ = 0xA0;
- *out++ = 0x03;
- *out++ = 0x02;
- *out++ = 0x01;
- *out++ = 0x02;
-
- // serial number
- appendSerialNumber(serialNumberAndAuthorityKeyIdentifier.serialNumber, out);
- out += serialNumberLen;
-
- // ecdsaWithSHA256
- out += appendEcdsaWithSHA256(out);
-
- // issuer
- appendSequenceHeader(issuerLen, out);
- out += issuerHeaderLen;
- appendIssuerOrSubject(_issuerCountryName,
- _issuerStateProvinceName,
- _issuerLocalityName,
- _issuerOrganizationName,
- _issuerOrganizationalUnitName,
- _issuerCommonName, out);
- out += issuerLen;
-
- *out++ = ASN1_SEQUENCE;
- *out++ = datesSize;
- out += appendDate(year, month, day, hour, 0, 0, out);
- out += appendDate(year + expireYears, month, day, hour, 0, 0, out);
-
- // subject
- appendSequenceHeader(subjectLen, out);
- out += subjectHeaderLen;
- appendIssuerOrSubject(_subjectCountryName,
- _subjectStateProvinceName,
- _subjectLocalityName,
- _subjectOrganizationName,
- _subjectOrganizationalUnitName,
- _subjectCommonName, out);
- out += subjectLen;
-
- // public key
- appendPublicKey(publicKey, out);
- out += publicKeyLen;
-
- if (authorityKeyIdentifierLen) {
- appendAuthorityKeyIdentifier(serialNumberAndAuthorityKeyIdentifier.authorityKeyIdentifier, out);
- out += authorityKeyIdentifierLen;
- } else {
- // null sequence
- *out++ = 0xA3;
- *out++ = 0x02;
- *out++ = 0x30;
- *out++ = 0x00;
- }
-
- // signature
- appendSignature(compressedCert.signature, out);
- out += signatureLen;
-
- return 1;
-}
-
-byte* ECCX08CertClass::bytes() {
- return _bytes;
-}
-
-int ECCX08CertClass::length() {
- return _length;
-}
-
-void ECCX08CertClass::setIssuerCountryName(const String& countryName) {
- _issuerCountryName = countryName;
-}
-
-void ECCX08CertClass::setIssuerStateProvinceName(const String& stateProvinceName) {
- _issuerStateProvinceName = stateProvinceName;
-}
-
-void ECCX08CertClass::setIssuerLocalityName(const String& localityName) {
- _issuerLocalityName = localityName;
-}
-
-void ECCX08CertClass::setIssuerOrganizationName(const String& organizationName) {
- _issuerOrganizationName = organizationName;
-}
-
-void ECCX08CertClass::setIssuerOrganizationalUnitName(const String& organizationalUnitName) {
- _issuerOrganizationalUnitName = organizationalUnitName;
-}
-
-void ECCX08CertClass::setIssuerCommonName(const String& commonName) {
- _issuerCommonName = commonName;
-}
-
-void ECCX08CertClass::setSubjectCountryName(const String& countryName) {
- _subjectCountryName = countryName;
-}
-
-void ECCX08CertClass::setSubjectStateProvinceName(const String& stateProvinceName) {
- _subjectStateProvinceName = stateProvinceName;
-}
-
-void ECCX08CertClass::setSubjectLocalityName(const String& localityName) {
- _subjectLocalityName = localityName;
-}
-
-void ECCX08CertClass::setSubjectOrganizationName(const String& organizationName) {
- _subjectOrganizationName = organizationName;
-}
-
-void ECCX08CertClass::setSubjectOrganizationalUnitName(const String& organizationalUnitName) {
- _subjectOrganizationName = organizationalUnitName;
-}
-
-void ECCX08CertClass::setSubjectCommonName(const String& commonName) {
- _subjectCommonName = commonName;
-}
-
-int ECCX08CertClass::versionLength() {
- return 3;
-}
-
-int ECCX08CertClass::issuerOrSubjectLength(const String& countryName,
- const String& stateProvinceName,
- const String& localityName,
- const String& organizationName,
- const String& organizationalUnitName,
- const String& commonName) {
- int length = 0;
- int countryNameLength = countryName.length();
- int stateProvinceNameLength = stateProvinceName.length();
- int localityNameLength = localityName.length();
- int organizationNameLength = organizationName.length();
- int organizationalUnitNameLength = organizationalUnitName.length();
- int commonNameLength = commonName.length();
-
- if (countryNameLength) {
- length += (11 + countryNameLength);
- }
-
- if (stateProvinceNameLength) {
- length += (11 + stateProvinceNameLength);
- }
-
- if (localityNameLength) {
- length += (11 + localityNameLength);
- }
-
- if (organizationNameLength) {
- length += (11 + organizationNameLength);
- }
-
- if (organizationalUnitNameLength) {
- length += (11 + organizationalUnitNameLength);
- }
-
- if (commonNameLength) {
- length += (11 + commonNameLength);
- }
-
- return length;
-}
-
-int ECCX08CertClass::publicKeyLength() {
- return (2 + 2 + 9 + 10 + 4 + 64);
-}
-
-int ECCX08CertClass::authorityKeyIdentifierLength(const byte authorityKeyIdentifier[]) {
- bool set = false;
-
- // check if the authority key identifier is non-zero
- for (int i = 0; i < AUTHORITY_KEY_IDENTIFIER_LENGTH; i++) {
- if (authorityKeyIdentifier[i] != 0) {
- set = true;
- break;
- }
- }
-
- return (set ? 37 : 0);
-}
-
-int ECCX08CertClass::signatureLength(const byte signature[]) {
- const byte* r = &signature[0];
- const byte* s = &signature[32];
-
- int rLength = 32;
- int sLength = 32;
-
- while (*r == 0x00 && rLength) {
- r++;
- rLength--;
- }
-
- if (*r & 0x80) {
- rLength++;
- }
-
- while (*s == 0x00 && sLength) {
- s++;
- sLength--;
- }
-
- if (*s & 0x80) {
- sLength++;
- }
-
- return (21 + rLength + sLength);
-}
-
-int ECCX08CertClass::serialNumberLength(const byte serialNumber[]) {
- int length = SERIAL_NUMBER_LENGTH;
-
- while (*serialNumber == 0 && length) {
- serialNumber++;
- length--;
- }
-
- if (*serialNumber & 0x80) {
- length++;
- }
-
- return (2 + length);
-}
-
-int ECCX08CertClass::sequenceHeaderLength(int length) {
- if (length > 255) {
- return 4;
- } else if (length > 127) {
- return 3;
- } else {
- return 2;
- }
-}
-
-void ECCX08CertClass::appendVersion(int version, byte out[]) {
- out[0] = ASN1_INTEGER;
- out[1] = 0x01;
- out[2] = version;
-}
-
-void ECCX08CertClass::appendIssuerOrSubject(const String& countryName,
- const String& stateProvinceName,
- const String& localityName,
- const String& organizationName,
- const String& organizationalUnitName,
- const String& commonName,
- byte out[]) {
- if (countryName.length() > 0) {
- out += appendName(countryName, 0x06, out);
- }
-
- if (stateProvinceName.length() > 0) {
- out += appendName(stateProvinceName, 0x08, out);
- }
-
- if (localityName.length() > 0) {
- out += appendName(localityName, 0x07, out);
- }
-
- if (organizationName.length() > 0) {
- out += appendName(organizationName, 0x0a, out);
- }
-
- if (organizationalUnitName.length() > 0) {
- out += appendName(organizationalUnitName, 0x0b, out);
- }
-
- if (commonName.length() > 0) {
- out += appendName(commonName, 0x03, out);
- }
-}
-
-void ECCX08CertClass::appendPublicKey(const byte publicKey[], byte out[]) {
- int subjectPublicKeyDataLength = 2 + 9 + 10 + 4 + 64;
-
- // subject public key
- *out++ = ASN1_SEQUENCE;
- *out++ = (subjectPublicKeyDataLength) & 0xff;
-
- *out++ = ASN1_SEQUENCE;
- *out++ = 0x13;
-
- // EC public key
- *out++ = ASN1_OBJECT_IDENTIFIER;
- *out++ = 0x07;
- *out++ = 0x2a;
- *out++ = 0x86;
- *out++ = 0x48;
- *out++ = 0xce;
- *out++ = 0x3d;
- *out++ = 0x02;
- *out++ = 0x01;
-
- // PRIME 256 v1
- *out++ = ASN1_OBJECT_IDENTIFIER;
- *out++ = 0x08;
- *out++ = 0x2a;
- *out++ = 0x86;
- *out++ = 0x48;
- *out++ = 0xce;
- *out++ = 0x3d;
- *out++ = 0x03;
- *out++ = 0x01;
- *out++ = 0x07;
-
- *out++ = 0x03;
- *out++ = 0x42;
- *out++ = 0x00;
- *out++ = 0x04;
-
- memcpy(out, publicKey, 64);
-}
-
-void ECCX08CertClass::appendAuthorityKeyIdentifier(const byte authorityKeyIdentifier[], byte out[]) {
- // [3]
- *out++ = 0xa3;
- *out++ = 0x23;
-
- // sequence
- *out++ = ASN1_SEQUENCE;
- *out++ = 0x21;
-
- // sequence
- *out++ = ASN1_SEQUENCE;
- *out++ = 0x1f;
-
- // 2.5.29.35 authorityKeyIdentifier(X.509 extension)
- *out++ = 0x06;
- *out++ = 0x03;
- *out++ = 0x55;
- *out++ = 0x1d;
- *out++ = 0x23;
-
- // octet string
- *out++ = 0x04;
- *out++ = 0x18;
-
- // sequence
- *out++ = ASN1_SEQUENCE;
- *out++ = 0x16;
-
- *out++ = 0x80;
- *out++ = 0x14;
-
- memcpy(out, authorityKeyIdentifier, 20);
-}
-
-void ECCX08CertClass::appendSignature(const byte signature[], byte out[]) {
- // signature algorithm
- *out++ = ASN1_SEQUENCE;
- *out++ = 0x0a;
- *out++ = ASN1_OBJECT_IDENTIFIER;
- *out++ = 0x08;
-
- // ECDSA with SHA256
- *out++ = 0x2a;
- *out++ = 0x86;
- *out++ = 0x48;
- *out++ = 0xce;
- *out++ = 0x3d;
- *out++ = 0x04;
- *out++ = 0x03;
- *out++ = 0x02;
-
- const byte* r = &signature[0];
- const byte* s = &signature[32];
-
- int rLength = 32;
- int sLength = 32;
-
- while (*r == 0 && rLength) {
- r++;
- rLength--;
- }
-
- while (*s == 0 && sLength) {
- s++;
- sLength--;
- }
-
- if (*r & 0x80) {
- rLength++;
- }
-
- if (*s & 0x80) {
- sLength++;
- }
-
- *out++ = ASN1_BIT_STRING;
- *out++ = (rLength + sLength + 7);
- *out++ = 0;
-
- *out++ = ASN1_SEQUENCE;
- *out++ = (rLength + sLength + 4);
-
- *out++ = ASN1_INTEGER;
- *out++ = rLength;
- if ((*r & 0x80) && rLength) {
- *out++ = 0;
- rLength--;
- }
- memcpy(out, r, rLength);
- out += rLength;
-
- *out++ = ASN1_INTEGER;
- *out++ = sLength;
- if ((*s & 0x80) && sLength) {
- *out++ = 0;
- sLength--;
- }
- memcpy(out, s, sLength);
- out += rLength;
-}
-
-void ECCX08CertClass::appendSerialNumber(const byte serialNumber[], byte out[]) {
- int length = SERIAL_NUMBER_LENGTH;
-
- while (*serialNumber == 0 && length) {
- serialNumber++;
- length--;
- }
-
- if (*serialNumber & 0x80) {
- length++;
- }
-
- *out++ = ASN1_INTEGER;
- *out++ = length;
-
- if (*serialNumber & 0x80) {
- *out++ = 0x00;
- length--;
- }
-
- memcpy(out, serialNumber, length);
-}
-
-int ECCX08CertClass::appendName(const String& name, int type, byte out[]) {
- int nameLength = name.length();
-
- *out++ = ASN1_SET;
- *out++ = nameLength + 9;
-
- *out++ = ASN1_SEQUENCE;
- *out++ = nameLength + 7;
-
- *out++ = ASN1_OBJECT_IDENTIFIER;
- *out++ = 0x03;
- *out++ = 0x55;
- *out++ = 0x04;
- *out++ = type;
-
- *out++ = ASN1_PRINTABLE_STRING;
- *out++ = nameLength;
- memcpy(out, name.c_str(), nameLength);
-
- return (nameLength + 11);
-}
-
-void ECCX08CertClass::appendSequenceHeader(int length, byte out[]) {
- *out++ = ASN1_SEQUENCE;
- if (length > 255) {
- *out++ = 0x82;
- *out++ = (length >> 8) & 0xff;
- } else if (length > 127) {
- *out++ = 0x81;
- }
- *out++ = (length) & 0xff;
-}
-
-int ECCX08CertClass::appendDate(int year, int month, int day, int hour, int minute, int second, byte out[]) {
- bool useGeneralizedTime = (year > 2049);
-
- if (useGeneralizedTime) {
- *out++ = 0x18;
- *out++ = 0x0f;
- *out++ = '0' + (year / 1000);
- *out++ = '0' + ((year % 1000) / 100);
- *out++ = '0' + ((year % 100) / 10);
- *out++ = '0' + (year % 10);
- } else {
- year -= 2000;
-
- *out++ = 0x17;
- *out++ = 0x0d;
- *out++ = '0' + (year / 10);
- *out++ = '0' + (year % 10);
- }
- *out++ = '0' + (month / 10);
- *out++ = '0' + (month % 10);
- *out++ = '0' + (day / 10);
- *out++ = '0' + (day % 10);
- *out++ = '0' + (hour / 10);
- *out++ = '0' + (hour % 10);
- *out++ = '0' + (minute / 10);
- *out++ = '0' + (minute % 10);
- *out++ = '0' + (second / 10);
- *out++ = '0' + (second % 10);
- *out++ = 0x5a; // UTC
-
- return (useGeneralizedTime ? 17 : 15);
-}
-
-int ECCX08CertClass::appendEcdsaWithSHA256(byte out[]) {
- *out++ = ASN1_SEQUENCE;
- *out++ = 0x0A;
- *out++ = ASN1_OBJECT_IDENTIFIER;
- *out++ = 0x08;
- *out++ = 0x2A;
- *out++ = 0x86;
- *out++ = 0x48;
- *out++ = 0xCE;
- *out++ = 0x3D;
- *out++ = 0x04;
- *out++ = 0x03;
- *out++ = 0x02;
-
- return 12;
-}
diff --git a/examples/utility/SelfProvisioning/ECCX08Cert.h b/examples/utility/SelfProvisioning/ECCX08Cert.h
deleted file mode 100644
index d40d4cd02..000000000
--- a/examples/utility/SelfProvisioning/ECCX08Cert.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- This file is part of ArduinoIoTCloud.
-
- Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
-
- This software is released under the GNU General Public License version 3,
- which covers the main part of arduino-cli.
- The terms of this license can be found at:
- https://www.gnu.org/licenses/gpl-3.0.en.html
-
- You can be released from the requirements of the above licenses by purchasing
- a commercial license. Buying such a license is mandatory if you want to modify or
- otherwise use the software for commercial activities involving the Arduino
- software without disclosing the source code of your own applications. To purchase
- a commercial license, send an email to license@arduino.cc.
-*/
-
-#ifndef _ECCX08_CERT_H_
-#define _ECCX08_CERT_H_
-
-/******************************************************************************
- * INCLUDE
- ******************************************************************************/
-
-#include
-
-/******************************************************************************
- * CLASS DECLARATION
- ******************************************************************************/
-
-class ECCX08CertClass {
-
- public:
- ECCX08CertClass();
- virtual ~ECCX08CertClass();
-
- int beginCSR(int keySlot, bool newPrivateKey = true);
- String endCSR();
-
- int beginStorage(int compressedCertSlot, int serialNumberAndAuthorityKeyIdentifierSlot);
- void setSignature(byte signature[]);
- void setIssueYear(int issueYear);
- void setIssueMonth(int issueMonth);
- void setIssueDay(int issueDay);
- void setIssueHour(int issueHour);
- void setExpireYears(int expireYears);
- void setSerialNumber(const byte serialNumber[]);
- void setAuthorityKeyIdentifier(const byte authorityKeyIdentifier[]);
- int endStorage();
-
- int beginReconstruction(int keySlot, int compressedCertSlot, int serialNumberAndAuthorityKeyIdentifierSlot);
- int endReconstruction();
-
- byte* bytes();
- int length();
-
- void setIssuerCountryName(const String& countryName);
- void setIssuerStateProvinceName(const String& stateProvinceName);
- void setIssuerLocalityName(const String& localityName);
- void setIssuerOrganizationName(const String& organizationName);
- void setIssuerOrganizationalUnitName(const String& organizationalUnitName);
- void setIssuerCommonName(const String& commonName);
-
- void setSubjectCountryName(const String& countryName);
- void setSubjectStateProvinceName(const String& stateProvinceName);
- void setSubjectLocalityName(const String& localityName);
- void setSubjectOrganizationName(const String& organizationName);
- void setSubjectOrganizationalUnitName(const String& organizationalUnitName);
- void setSubjectCommonName(const String& commonName);
-
- private:
- int versionLength();
-
- int issuerOrSubjectLength(const String& countryName,
- const String& stateProvinceName,
- const String& localityName,
- const String& organizationName,
- const String& organizationalUnitName,
- const String& commonName);
-
- int publicKeyLength();
-
- int authorityKeyIdentifierLength(const byte authorityKeyIdentifier[]);
-
- int signatureLength(const byte signature[]);
-
- int serialNumberLength(const byte serialNumber[]);
-
- int sequenceHeaderLength(int length);
-
- void appendVersion(int version, byte out[]);
-
- void appendIssuerOrSubject(const String& countryName,
- const String& stateProvinceName,
- const String& localityName,
- const String& organizationName,
- const String& organizationalUnitName,
- const String& commonName,
- byte out[]);
-
- void appendPublicKey(const byte publicKey[], byte out[]);
-
- void appendAuthorityKeyIdentifier(const byte authorityKeyIdentifier[], byte out[]);
-
- void appendSignature(const byte signature[], byte out[]);
-
- void appendSerialNumber(const byte serialNumber[], byte out[]);
-
- int appendName(const String& name, int type, byte out[]);
-
- void appendSequenceHeader(int length, byte out[]);
-
- int appendDate(int year, int month, int day, int hour, int minute, int second, byte out[]);
-
- int appendEcdsaWithSHA256(byte out[]);
-
- private:
- int _keySlot;
- int _compressedCertSlot;
- int _serialNumberAndAuthorityKeyIdentifierSlot;
-
- String _issuerCountryName;
- String _issuerStateProvinceName;
- String _issuerLocalityName;
- String _issuerOrganizationName;
- String _issuerOrganizationalUnitName;
- String _issuerCommonName;
-
- String _subjectCountryName;
- String _subjectStateProvinceName;
- String _subjectLocalityName;
- String _subjectOrganizationName;
- String _subjectOrganizationalUnitName;
- String _subjectCommonName;
-
- byte _temp[108];
- byte* _bytes;
- int _length;
-};
-
-#endif /* _ECCX08_CERT_H_ */
diff --git a/examples/utility/SelfProvisioning/ECCX08TLSConfig.h b/examples/utility/SelfProvisioning/ECCX08TLSConfig.h
deleted file mode 100644
index 9126b3666..000000000
--- a/examples/utility/SelfProvisioning/ECCX08TLSConfig.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- This file is part of ArduinoIoTCloud.
-
- Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
-
- This software is released under the GNU General Public License version 3,
- which covers the main part of arduino-cli.
- The terms of this license can be found at:
- https://www.gnu.org/licenses/gpl-3.0.en.html
-
- You can be released from the requirements of the above licenses by purchasing
- a commercial license. Buying such a license is mandatory if you want to modify or
- otherwise use the software for commercial activities involving the Arduino
- software without disclosing the source code of your own applications. To purchase
- a commercial license, send an email to license@arduino.cc.
-*/
-
-#ifndef _ECCX08_TLS_CONFIG_H_
-#define _ECCX08_TLS_CONFIG_H_
-
-const byte DEFAULT_ECCX08_TLS_CONFIG[128] = {
- // Read only - start
- // SN[0:3]
- 0x01, 0x23, 0x00, 0x00,
- // RevNum
- 0x00, 0x00, 0x50, 0x00,
- // SN[4:8]
- 0x00, 0x00, 0x00, 0x00, 0x00,
- // Reserved
- 0xC0,
- // I2C_Enable
- 0x71,
- // Reserved
- 0x00,
- // Read only - end
- // I2C_Address
- 0xC0,
- // Reserved
- 0x00,
- // OTPmode
- 0x55,
- // ChipMode
- 0x00,
- // SlotConfig
- 0x83, 0x20, // External Signatures | Internal Signatures | IsSecret | Write Configure Never, Default: 0x83, 0x20,
- 0x87, 0x20, // External Signatures | Internal Signatures | ECDH | IsSecret | Write Configure Never, Default: 0x87, 0x20,
- 0x87, 0x20, // External Signatures | Internal Signatures | ECDH | IsSecret | Write Configure Never, Default: 0x8F, 0x20,
- 0x87, 0x2F, // External Signatures | Internal Signatures | ECDH | IsSecret | WriteKey all slots | Write Configure Never, Default: 0xC4, 0x8F,
- 0x87, 0x2F, // External Signatures | Internal Signatures | ECDH | IsSecret | WriteKey all slots | Write Configure Never, Default: 0x8F, 0x8F,
- 0x8F, 0x8F,
- 0x9F, 0x8F,
- 0xAF, 0x8F,
- 0x00, 0x00,
- 0x00, 0x00,
- 0x00, 0x00,
- 0x00, 0x00,
- 0x00, 0x00,
- 0x00, 0x00,
- 0x00, 0x00,
- 0xAF, 0x8F,
- // Counter[0]
- 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
- // Counter[1]
- 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
- // LastKeyUse
- 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF,
- // Write via commands only - start
- // UserExtra
- 0x00,
- // Selector
- 0x00,
- // LockValue
- 0x55,
- // LockConfig
- 0x55,
- // SlotLocked
- 0xFF, 0xFF,
- // Write via commands only - end
- // RFU
- 0x00, 0x00,
- // X509format
- 0x00, 0x00, 0x00, 0x00,
- // KeyConfig
- 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00,
- 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00,
- 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00,
- 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x1C, 0x00,
- 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x1C, 0x00,
- 0x1C, 0x00,
- 0x1C, 0x00,
- 0x1C, 0x00,
- 0x3C, 0x00,
- 0x3C, 0x00,
- 0x3C, 0x00,
- 0x3C, 0x00,
- 0x3C, 0x00,
- 0x3C, 0x00,
- 0x3C, 0x00,
- 0x1C, 0x00
-};
-
-#endif /* _ECCX08_TLS_CONFIG_H_ */
diff --git a/examples/utility/SelfProvisioning/SelfProvisioning.ino b/examples/utility/SelfProvisioning/SelfProvisioning.ino
index a0c13724b..46bfcafef 100644
--- a/examples/utility/SelfProvisioning/SelfProvisioning.ino
+++ b/examples/utility/SelfProvisioning/SelfProvisioning.ino
@@ -16,23 +16,13 @@
*/
#include "arduino_secrets.h"
-#include "ECCX08TLSConfig.h"
-#include "ECCX08Cert.h"
-#include
+#include
+#include
+#include
+#include
#include
-#include
-
-// from section 10.3.3 of the SAMD datasheet
-#define SERIAL_NUMBER_WORD_0 *(volatile uint32_t*)(0x0080A00C)
-#define SERIAL_NUMBER_WORD_1 *(volatile uint32_t*)(0x0080A040)
-#define SERIAL_NUMBER_WORD_2 *(volatile uint32_t*)(0x0080A044)
-#define SERIAL_NUMBER_WORD_3 *(volatile uint32_t*)(0x0080A048)
const bool DEBUG = true;
-const int keySlot = 0;
-const int compressedCertSlot = 10;
-const int serialNumberAndAuthorityKeyIdentifierSlot = 11;
-const int deviceIdSlot = 12;
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
@@ -40,13 +30,44 @@ char client_id[] = SECRET_CLIENT_ID;
char secret_id[] = SECRET_SECRET_ID;
#if defined(ARDUINO_SAMD_NANO_33_IOT)
+ #include
char board_type[] = "nano_33_iot"; // Nano 33 IoT
char board_fqbn[] = "arduino:samd:nano_33_iot"; // Nano 33 IoT
#elif defined(ARDUINO_SAMD_MKRWIFI1010)
+ #include
char board_type[] = "mkrwifi1010"; // MKR WiFi 1010
char board_fqbn[] = "arduino:samd:mkrwifi1010"; // MKR WiFi 1010
+#elif defined(ARDUINO_NANO_RP2040_CONNECT)
+ #include
+ char board_type[] = "nanorp2040connect"; // Nano RP2040 Connect
+ char board_fqbn[] = "arduino:mbed_nano:nanorp2040connect"; // Nano RP2040 Connect
+#elif defined(ARDUINO_PORTENTA_H7_M7)
+ #include
+ char board_type[] = "envie_m7"; // Portenta H7
+ char board_fqbn[] = "arduino:mbed_portenta:envie_m7"; // Portenta H7
+#elif defined(ARDUINO_NICLA_VISION)
+ #include
+ char board_type[] = "nicla_vision"; // Nicla Vision
+ char board_fqbn[] = "arduino:mbed_nicla:nicla_vision"; // Nicla Vision
+#elif defined(ARDUINO_GIGA)
+ #include
+ char board_type[] = "giga"; // Giga R1 WiFi
+ char board_fqbn[] = "arduino:mbed_giga:giga"; // Giga R1 WiFi
+#elif defined(ARDUINO_OPTA)
+ #include
+ char board_type[] = "opta"; // Opta
+ char board_fqbn[] = "arduino:mbed_opta:opta"; // Opta
+#elif defined(ARDUINO_PORTENTA_C33)
+ #include
+ #include
+ char board_type[] = "portenta_c33"; // Portenta C33
+ char board_fqbn[] = "arduino:renesas_portenta:portenta_c33"; // Portenta C33
+#elif defined(ARDUINO_UNOR4_WIFI)
+ #include
+ char board_type[] = "unor4wifi"; // UNO R4 WiFi
+ char board_fqbn[] = "arduino:renesas_uno:unor4wifi"; // UNO R4 WiFI
#else
- char board_type[] = "nonina"; // Not supported boards
+ char board_type[] = "unsupported"; // Not supported boards
char board_fqbn[] = "";
#endif
@@ -67,13 +88,13 @@ char server[] = "api2.arduino.cc"; // server address
WiFiSSLClient client;
int status = WL_IDLE_STATUS;
-ECCX08CertClass ECCX08Cert;
+SecureElement secureElement;
void setup() {
Serial.begin(9600);
while (!Serial);
- if (board_type == "nonina") {
+ if (board_type == "unsupported") {
Serial.println("Sorry, this sketch only works on Nano 33 IoT and MKR 1010 WiFi");
while (1) { ; }
}
@@ -84,7 +105,7 @@ void setup() {
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
- delay(10000);
+ delay(3000);
}
Serial.print("SSID: ");
@@ -94,56 +115,37 @@ void setup() {
Serial.print("IP Address: ");
Serial.println(ip);
- while (!ECCX08.begin()) {
- Serial.println("No ECCX08 present!");
+ while (!secureElement.begin()) {
+ Serial.println("No secureElement present!");
delay(100);
}
- if (!ECCX08.locked()) {
+ if (!secureElement.locked()) {
- if (!ECCX08.writeConfiguration(DEFAULT_ECCX08_TLS_CONFIG)) {
- Serial.println("Writing ECCX08 configuration failed!");
+ if (!secureElement.writeConfiguration()) {
+ Serial.println("Writing secureElement configuration failed!");
Serial.println("Stopping Provisioning");
while (1);
}
- if (!ECCX08.lock()) {
- Serial.println("Locking ECCX08 configuration failed!");
+ if (!secureElement.lock()) {
+ Serial.println("Locking secureElement configuration failed!");
Serial.println("Stopping Provisioning");
while (1);
}
- Serial.println("ECCX08 locked successfully");
+ Serial.println("secureElement locked successfully");
Serial.println();
}
//Random number for device name
- board_name += String(ECCX08.random(65535));
-
- uint32_t BoardUniqueID[4];
- BoardUniqueID[0] = SERIAL_NUMBER_WORD_0;
- BoardUniqueID[1] = SERIAL_NUMBER_WORD_1;
- BoardUniqueID[2] = SERIAL_NUMBER_WORD_2;
- BoardUniqueID[3] = SERIAL_NUMBER_WORD_3;
- uint8_t bid[32];
- for (int i = 0; i < 4; i++)
- {
- bid[i*4+0] = (uint8_t)(BoardUniqueID[i] >> 24);
- bid[i*4+1] = (uint8_t)(BoardUniqueID[i] >> 16);
- bid[i*4+2] = (uint8_t)(BoardUniqueID[i] >> 8);
- bid[i*4+3] = (uint8_t)(BoardUniqueID[i] >> 0);
- }
-
- for (size_t i = 0; i < 16; i++) {
- if (bid[i] < 16) {
- ArduinoID += String(0, HEX);
- }
- ArduinoID += String(bid[i], HEX);
- }
- ArduinoID.toUpperCase();
-
+ board_name += String(secureElement.random(65535));
Serial.print("Device Name: ");
Serial.println(board_name);
+ //Board Serial Number
+ ArduinoID = ArduinoSerialNumber();
+ Serial.print("SN: ");
+ Serial.println(ArduinoID);
// Create Arduino Token
ArduinoToken(client_id, secret_id);
Serial.print("Bearer Token: ");
@@ -155,18 +157,32 @@ void setup() {
delay(2000);
- while (!ECCX08Cert.beginCSR(keySlot, true)) {
+ // Configure WiFi firmware version
+ String fv = WiFi.firmwareVersion();
+ WiFiFirmwareVersion(fv, deviceId, Arduino_Token);
+ Serial.print("WiFi Firmware Version: ");
+ Serial.println(fv);
+
+ ECP256Certificate Certificate;
+
+ while (!Certificate.begin()) {
Serial.println("Error starting CSR generation!");
- delay(2000);
+ while (1);
}
- ECCX08Cert.setSubjectCommonName(deviceId);
+ Certificate.setSubjectCommonName(deviceId);
- String csr = ECCX08Cert.endCSR();
+ if (!SElementCSR::build(secureElement, Certificate, static_cast(SElementArduinoCloudSlot::Key), true)) {
+ Serial.println("Error generating CSR!");
+ while (1);
+ }
+
+ String csr = Certificate.getCSRPEM();
- while (!csr) {
+ if (!csr) {
+ /* WARNING: This string is parsed from IoTCloud frontend */
Serial.println("Error generating CSR!");
- delay(2000);
+ while (1);
}
Serial.println("Generated CSR is:");
@@ -206,42 +222,37 @@ void setup() {
hexStringToBytes(authorityKeyIdentifier, authorityKeyIdentifierBytes, sizeof(authorityKeyIdentifierBytes));
hexStringToBytes(signature, signatureBytes, sizeof(signatureBytes));
- if (!ECCX08.writeSlot(deviceIdSlot, deviceIdBytes, sizeof(deviceIdBytes))) {
+ if (!secureElement.writeSlot(static_cast(SElementArduinoCloudSlot::DeviceId), deviceIdBytes, sizeof(deviceIdBytes))) {
Serial.println("Error storing device id!");
while (1);
}
- if (!ECCX08Cert.beginStorage(compressedCertSlot, serialNumberAndAuthorityKeyIdentifierSlot)) {
- Serial.println("Error starting ECCX08 storage!");
- while (1);
- }
-
- ECCX08Cert.setSignature(signatureBytes);
- ECCX08Cert.setAuthorityKeyIdentifier(authorityKeyIdentifierBytes);
- ECCX08Cert.setSerialNumber(serialNumberBytes);
- ECCX08Cert.setIssueYear(issueYear.toInt());
- ECCX08Cert.setIssueMonth(issueMonth.toInt());
- ECCX08Cert.setIssueDay(issueDay.toInt());
- ECCX08Cert.setIssueHour(issueHour.toInt());
- ECCX08Cert.setExpireYears(expireYears.toInt());
-
- if (!ECCX08Cert.endStorage()) {
- Serial.println("Error storing ECCX08 compressed cert!");
+ if (!Certificate.begin()) {
+ Serial.println("Error starting secureElement storage!");
while (1);
}
- if (!ECCX08Cert.beginReconstruction(keySlot, compressedCertSlot, serialNumberAndAuthorityKeyIdentifierSlot)) {
- Serial.println("Error starting ECCX08 cert reconstruction!");
+ Certificate.setSubjectCommonName(deviceId);
+ Certificate.setIssuerCountryName("US");
+ Certificate.setIssuerOrganizationName("Arduino LLC US");
+ Certificate.setIssuerOrganizationalUnitName("IT");
+ Certificate.setIssuerCommonName("Arduino");
+ Certificate.setSignature(signatureBytes, sizeof(signatureBytes));
+ Certificate.setAuthorityKeyId(authorityKeyIdentifierBytes, sizeof(authorityKeyIdentifierBytes));
+ Certificate.setSerialNumber(serialNumberBytes, sizeof(serialNumberBytes));
+ Certificate.setIssueYear(issueYear.toInt());
+ Certificate.setIssueMonth(issueMonth.toInt());
+ Certificate.setIssueDay(issueDay.toInt());
+ Certificate.setIssueHour(issueHour.toInt());
+ Certificate.setExpireYears(expireYears.toInt());
+
+ if (!SElementArduinoCloudCertificate::build(secureElement, Certificate, static_cast(SElementArduinoCloudSlot::Key))) {
+ Serial.println("Error building secureElement compressed cert!");
while (1);
}
- ECCX08Cert.setIssuerCountryName("US");
- ECCX08Cert.setIssuerOrganizationName("Arduino LLC US");
- ECCX08Cert.setIssuerOrganizationalUnitName("IT");
- ECCX08Cert.setIssuerCommonName("Arduino");
-
- if (!ECCX08Cert.endReconstruction()) {
- Serial.println("Error reconstructing ECCX08 compressed cert!");
+ if (!SElementArduinoCloudCertificate::write(secureElement, Certificate, SElementArduinoCloudSlot::CompressedCertificate)) {
+ Serial.println("Error storing cert!");
while (1);
}
@@ -251,8 +262,8 @@ void setup() {
Serial.println("Compressed cert = ");
- const byte* certData = ECCX08Cert.bytes();
- int certLength = ECCX08Cert.length();
+ const byte* certData = Certificate.bytes();
+ int certLength = Certificate.length();
for (int i = 0; i < certLength; i++) {
byte b = certData[i];
@@ -314,6 +325,81 @@ void hexStringToBytes(String& in, byte out[], int length) {
}
}
+#if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_RENESAS)
+
+static void utox8(uint32_t val, uint8_t* s) {
+ for (int i = 0; i < 16; i=i+2) {
+ int d = val & 0XF;
+ val = (val >> 4);
+
+ s[15 - i -1] = d > 9 ? 'A' + d - 10 : '0' + d;
+ s[15 - i] = '\0';
+ }
+}
+#endif
+
+#ifdef ARDUINO_ARCH_SAMD
+
+uint8_t getUniqueSerialNumber(uint8_t* name) {
+ utox8(*(volatile uint32_t*)(0x0080A00C), &name[0]);
+ utox8(*(volatile uint32_t*)(0x0080A040), &name[16]);
+ utox8(*(volatile uint32_t*)(0x0080A044), &name[32]);
+ utox8(*(volatile uint32_t*)(0x0080A048), &name[48]);
+ return 64;
+}
+
+#endif
+
+#ifdef ARDUINO_ARCH_RENESAS
+uint8_t getUniqueSerialNumber(uint8_t* name) {
+ const bsp_unique_id_t* t = R_BSP_UniqueIdGet();
+ utox8(t->unique_id_words[0], &name[0]);
+ utox8(t->unique_id_words[1], &name[16]);
+ utox8(t->unique_id_words[2], &name[32]);
+ utox8(t->unique_id_words[3], &name[48]);
+ return 64;
+}
+#endif
+
+String ArduinoSerialNumber() {
+
+ uint8_t uniqueSerialNumber[64 + 1] = {0};
+ char BoardUniqueID[32 + 1] = {0};
+
+ int uniqueSerialNumberLength = getUniqueSerialNumber(uniqueSerialNumber);
+ for(int i = 0, k = 0; i < uniqueSerialNumberLength; i = i+2, k++) {
+ BoardUniqueID[k] = uniqueSerialNumber[i];
+ }
+
+ String serialNumber = String(BoardUniqueID);
+ serialNumber.toUpperCase();
+ return serialNumber;
+
+}
+
+void WiFiFirmwareVersion(String fv, String deviceId, String token) {
+ Serial.println("Configuring WiFi firmware version...");
+ String PostData = "{\"wifi_fw_version\":\"";
+ PostData += fv;
+ PostData += "\"}";
+
+ if (client.connect(server, 443)) {
+ client.print("POST /iot/v2/devices/");
+ client.print(deviceId);
+ client.println(" HTTP/1.1");
+ client.println("Host: api2.arduino.cc");
+ client.println("Connection: close");
+ client.println("Content-Type: application/json;charset=UTF-8");
+ client.print("Authorization: Bearer ");
+ client.println(token);
+ client.print("Content-Length: ");
+ client.println(PostData.length());
+ client.println();
+ client.println(PostData);
+ }
+ client.stop();
+}
+
void ArduinoToken(String client_id, String client_secret) {
Serial.println("Creating Bearer Token...");
String PostData = "grant_type=client_credentials&client_id=";
@@ -354,12 +440,14 @@ void ArduinoToken(String client_id, String client_secret) {
if (tokenResponse[intIndex] == -1) {
break;
}
+ delay(1);
intIndex++;
}
JSONVar myObject = JSON.parse(tokenResponse);
if (myObject.hasOwnProperty("access_token")) {
Arduino_Token += (const char*) myObject["access_token"];
}
+ client.stop();
}
void BoardUuid(String board_name, String board_type, String board_fqbn, String board_serial, String user_token) {
@@ -388,7 +476,8 @@ void BoardUuid(String board_name, String board_type, String board_fqbn, String b
}
while (!client.available()) {
- ;
+ Serial.println("No client");
+ delay(2000);
}
char endOfHeaders[] = "\r\n\r\n";
@@ -407,12 +496,14 @@ void BoardUuid(String board_name, String board_type, String board_fqbn, String b
if (deviceResponse[intIndex] == -1) {
break;
}
+ delay(1);
intIndex++;
}
JSONVar myObject = JSON.parse(deviceResponse);
if (myObject.hasOwnProperty("id")) {
deviceId += (const char*) myObject["id"];
}
+ client.stop();
}
void ArduinoCertificate(String user_token, String DeviceUuid, String csr) {
@@ -461,24 +552,27 @@ void ArduinoCertificate(String user_token, String DeviceUuid, String csr) {
if (certResponse[intIndex] == -1) {
break;
}
+ delay(1);
intIndex++;
}
- JSONVar myObject = JSON.parse(certResponse);
+ char* p = strstr(certResponse, "{");
+ JSONVar myObject = JSON.parse(p);
String certZip = JSON.stringify(myObject["compressed"]);
JSONVar myCert = JSON.parse(certZip);
- if (myCert.hasOwnProperty("not_before")) {
+ if (myCert.hasOwnProperty("not_before") &&
+ myCert.hasOwnProperty("serial") &&
+ myCert.hasOwnProperty("authority_key_identifier") &&
+ myCert.hasOwnProperty("signature_asn1_x") &&
+ myCert.hasOwnProperty("signature_asn1_x")) {
not_before += (const char*) myCert["not_before"];
- }
- if (myCert.hasOwnProperty("serial")) {
serialNumber += (const char*) myCert["serial"];
- }
- if (myCert.hasOwnProperty("authority_key_identifier")) {
authorityKeyIdentifier += (const char*) myCert["authority_key_identifier"];
- }
- if (myCert.hasOwnProperty("signature_asn1_x")) {
signature += (const char*) myCert["signature_asn1_x"];
- }
- if (myCert.hasOwnProperty("signature_asn1_y")) {
signature += (const char*) myCert["signature_asn1_y"];
+ } else {
+ Serial.println("Error parsing cloud certificate");
+ while (1) {
+ ;
+ }
}
-}
\ No newline at end of file
+}
diff --git a/extras/test/CMakeLists.txt b/extras/test/CMakeLists.txt
index 8e5148905..f9c13c8c0 100644
--- a/extras/test/CMakeLists.txt
+++ b/extras/test/CMakeLists.txt
@@ -1,20 +1,79 @@
##########################################################################
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 3.5)
##########################################################################
project(testArduinoIoTCloud)
+Include(FetchContent)
+
+FetchContent_Declare(
+ Catch2
+ GIT_REPOSITORY https://github.com/catchorg/Catch2.git
+ GIT_TAG v3.4.0
+)
+
+FetchContent_Declare(
+ cloudutils
+ GIT_REPOSITORY https://github.com/arduino-libraries/Arduino_CloudUtils.git
+ GIT_TAG main
+)
+
+FetchContent_Declare(
+ connectionhandler
+ GIT_REPOSITORY https://github.com/arduino-libraries/Arduino_ConnectionHandler.git
+ GIT_TAG master
+)
+
+FetchContent_MakeAvailable(Catch2)
+
+FetchContent_MakeAvailable(cloudutils)
+
+FetchContent_MakeAvailable(connectionhandler)
##########################################################################
include_directories(include)
include_directories(../../src)
+include_directories(../../src/message)
include_directories(../../src/cbor)
include_directories(../../src/property)
include_directories(../../src/utility/time)
-include_directories(external/catch/v2.13.10/include)
-include_directories(external/fakeit/v2.0.5/include)
+
+# add_library(cloudutils STATIC IMPORTED GLOBAL)
+add_library(cloudutils INTERFACE)
+
+target_include_directories(
+ cloudutils INTERFACE
+ ${cloudutils_SOURCE_DIR}/src/
+)
+
+target_include_directories(
+ cloudutils INTERFACE
+ ${cloudutils_SOURCE_DIR}/src/cbor
+)
+
+target_include_directories(
+ cloudutils INTERFACE
+ ${cloudutils_SOURCE_DIR}/src/cbor/utils
+)
+
+target_include_directories(
+ cloudutils INTERFACE
+ ${cloudutils_SOURCE_DIR}/src/interfaces
+)
+
+add_library(connectionhandler INTERFACE)
+
+target_include_directories(
+ connectionhandler INTERFACE
+ ${connectionhandler_SOURCE_DIR}/src/
+)
+
+target_include_directories(
+ connectionhandler INTERFACE
+ ${connectionhandler_SOURCE_DIR}/src/connectionHandlerModels
+)
##########################################################################
@@ -32,15 +91,21 @@ set(TEST_SRCS
src/test_addPropertyReal.cpp
src/test_callback.cpp
src/test_CloudColor.cpp
+ src/test_CloudFloat.cpp
+ src/test_CloudWrapperFloat.cpp
src/test_CloudLocation.cpp
src/test_CloudSchedule.cpp
src/test_decode.cpp
src/test_encode.cpp
+ src/test_command_decode.cpp
+ src/test_command_encode.cpp
src/test_publishEvery.cpp
src/test_publishOnChange.cpp
src/test_publishOnChangeRateLimit.cpp
src/test_readOnly.cpp
src/test_writeOnly.cpp
+ src/test_writeOnDemand.cpp
+ src/test_writeOnChange.cpp
)
set(TEST_UTIL_SRCS
@@ -53,18 +118,22 @@ set(TEST_DUT_SRCS
../../src/property/PropertyContainer.cpp
../../src/cbor/CBORDecoder.cpp
../../src/cbor/CBOREncoder.cpp
- ../../src/cbor/lib/tinycbor/src/cborencoder.c
- ../../src/cbor/lib/tinycbor/src/cborencoder_close_container_checked.c
- ../../src/cbor/lib/tinycbor/src/cborerrorstrings.c
- ../../src/cbor/lib/tinycbor/src/cborparser.c
- ../../src/cbor/lib/tinycbor/src/cborparser_dup_string.c
- ../../src/cbor/lib/tinycbor/src/cborpretty.c
- ../../src/cbor/lib/tinycbor/src/cborpretty_stdio.c
- ../../src/cbor/lib/tinycbor/src/cbortojson.c
- ../../src/cbor/lib/tinycbor/src/cborvalidation.c
- ../../src/cbor/lib/tinycbor/src/open_memstream.c
+ ../../src/cbor/IoTCloudMessageDecoder.cpp
+ ../../src/cbor/IoTCloudMessageEncoder.cpp
+
+ ${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborencoder.c
+ ${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborencoder_close_container_checked.c
+ ${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborerrorstrings.c
+ ${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborparser.c
+ ${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborparser_dup_string.c
+ ${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborpretty.c
+ ${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborpretty_stdio.c
+ ${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cbortojson.c
+ ${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/cborvalidation.c
+ ${cloudutils_SOURCE_DIR}/src/cbor/tinycbor/src/open_memstream.c
+ ${cloudutils_SOURCE_DIR}/src/cbor/MessageDecoder.cpp
+ ${cloudutils_SOURCE_DIR}/src/cbor/MessageEncoder.cpp
)
-
##########################################################################
set(TEST_TARGET_SRCS
@@ -77,12 +146,13 @@ set(TEST_TARGET_SRCS
##########################################################################
-add_compile_definitions(HOST)
+add_compile_definitions(BOARD_HAS_LORA BOARD_HAS_CATM1_NBIOT BOARD_HAS_WIFI BOARD_HAS_ETHERNET BOARD_HAS_CELLULAR BOARD_HAS_NB BOARD_HAS_GSM)
+add_compile_definitions(HOST HAS_TCP)
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
add_compile_options(-Wno-cast-function-type)
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "--coverage")
-set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "--coverage -Wno-deprecated-copy")
+set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "--coverage -Wno-deprecated-copy -Wno-missing-field-initializers")
##########################################################################
@@ -91,5 +161,9 @@ add_executable(
${TEST_TARGET_SRCS}
)
+target_link_libraries( ${TEST_TARGET} connectionhandler)
+target_link_libraries( ${TEST_TARGET} cloudutils)
+target_link_libraries( ${TEST_TARGET} Catch2WithMain )
+
##########################################################################
diff --git a/extras/test/external/catch/v2.13.10/include/catch.hpp b/extras/test/external/catch/v2.13.10/include/catch.hpp
deleted file mode 100644
index 9b309bddc..000000000
--- a/extras/test/external/catch/v2.13.10/include/catch.hpp
+++ /dev/null
@@ -1,17976 +0,0 @@
-/*
- * Catch v2.13.10
- * Generated: 2022-10-16 11:01:23.452308
- * ----------------------------------------------------------
- * This file has been merged from multiple headers. Please don't edit it directly
- * Copyright (c) 2022 Two Blue Cubes Ltd. All rights reserved.
- *
- * Distributed under the Boost Software License, Version 1.0. (See accompanying
- * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- */
-#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
-#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
-// start catch.hpp
-
-
-#define CATCH_VERSION_MAJOR 2
-#define CATCH_VERSION_MINOR 13
-#define CATCH_VERSION_PATCH 10
-
-#ifdef __clang__
-# pragma clang system_header
-#elif defined __GNUC__
-# pragma GCC system_header
-#endif
-
-// start catch_suppress_warnings.h
-
-#ifdef __clang__
-# ifdef __ICC // icpc defines the __clang__ macro
-# pragma warning(push)
-# pragma warning(disable: 161 1682)
-# else // __ICC
-# pragma clang diagnostic push
-# pragma clang diagnostic ignored "-Wpadded"
-# pragma clang diagnostic ignored "-Wswitch-enum"
-# pragma clang diagnostic ignored "-Wcovered-switch-default"
-# endif
-#elif defined __GNUC__
- // Because REQUIREs trigger GCC's -Wparentheses, and because still
- // supported version of g++ have only buggy support for _Pragmas,
- // Wparentheses have to be suppressed globally.
-# pragma GCC diagnostic ignored "-Wparentheses" // See #674 for details
-
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wunused-variable"
-# pragma GCC diagnostic ignored "-Wpadded"
-#endif
-// end catch_suppress_warnings.h
-#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER)
-# define CATCH_IMPL
-# define CATCH_CONFIG_ALL_PARTS
-#endif
-
-// In the impl file, we want to have access to all parts of the headers
-// Can also be used to sanely support PCHs
-#if defined(CATCH_CONFIG_ALL_PARTS)
-# define CATCH_CONFIG_EXTERNAL_INTERFACES
-# if defined(CATCH_CONFIG_DISABLE_MATCHERS)
-# undef CATCH_CONFIG_DISABLE_MATCHERS
-# endif
-# if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER)
-# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
-# endif
-#endif
-
-#if !defined(CATCH_CONFIG_IMPL_ONLY)
-// start catch_platform.h
-
-// See e.g.:
-// https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/TargetConditionals.h.auto.html
-#ifdef __APPLE__
-# include
-# if (defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1) || \
- (defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1)
-# define CATCH_PLATFORM_MAC
-# elif (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1)
-# define CATCH_PLATFORM_IPHONE
-# endif
-
-#elif defined(linux) || defined(__linux) || defined(__linux__)
-# define CATCH_PLATFORM_LINUX
-
-#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__)
-# define CATCH_PLATFORM_WINDOWS
-#endif
-
-// end catch_platform.h
-
-#ifdef CATCH_IMPL
-# ifndef CLARA_CONFIG_MAIN
-# define CLARA_CONFIG_MAIN_NOT_DEFINED
-# define CLARA_CONFIG_MAIN
-# endif
-#endif
-
-// start catch_user_interfaces.h
-
-namespace Catch {
- unsigned int rngSeed();
-}
-
-// end catch_user_interfaces.h
-// start catch_tag_alias_autoregistrar.h
-
-// start catch_common.h
-
-// start catch_compiler_capabilities.h
-
-// Detect a number of compiler features - by compiler
-// The following features are defined:
-//
-// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported?
-// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported?
-// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported?
-// CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled?
-// ****************
-// Note to maintainers: if new toggles are added please document them
-// in configuration.md, too
-// ****************
-
-// In general each macro has a _NO_ form
-// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature.
-// Many features, at point of detection, define an _INTERNAL_ macro, so they
-// can be combined, en-mass, with the _NO_ forms later.
-
-#ifdef __cplusplus
-
-# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
-# define CATCH_CPP14_OR_GREATER
-# endif
-
-# if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
-# define CATCH_CPP17_OR_GREATER
-# endif
-
-#endif
-
-// Only GCC compiler should be used in this block, so other compilers trying to
-// mask themselves as GCC should be ignored.
-#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) && !defined(__LCC__)
-# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" )
-# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" )
-
-# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__)
-
-#endif
-
-#if defined(__clang__)
-
-# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" )
-# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" )
-
-// As of this writing, IBM XL's implementation of __builtin_constant_p has a bug
-// which results in calls to destructors being emitted for each temporary,
-// without a matching initialization. In practice, this can result in something
-// like `std::string::~string` being called on an uninitialized value.
-//
-// For example, this code will likely segfault under IBM XL:
-// ```
-// REQUIRE(std::string("12") + "34" == "1234")
-// ```
-//
-// Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented.
-# if !defined(__ibmxl__) && !defined(__CUDACC__)
-# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg) */
-# endif
-
-# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
- _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \
- _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"")
-
-# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
- _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
-
-# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \
- _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" )
-
-# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
- _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" )
-
-# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
- _Pragma( "clang diagnostic ignored \"-Wunused-template\"" )
-
-#endif // __clang__
-
-////////////////////////////////////////////////////////////////////////////////
-// Assume that non-Windows platforms support posix signals by default
-#if !defined(CATCH_PLATFORM_WINDOWS)
- #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// We know some environments not to support full POSIX signals
-#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__)
- #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
-#endif
-
-#ifdef __OS400__
-# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
-# define CATCH_CONFIG_COLOUR_NONE
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// Android somehow still does not support std::to_string
-#if defined(__ANDROID__)
-# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
-# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// Not all Windows environments support SEH properly
-#if defined(__MINGW32__)
-# define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// PS4
-#if defined(__ORBIS__)
-# define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// Cygwin
-#ifdef __CYGWIN__
-
-// Required for some versions of Cygwin to declare gettimeofday
-// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin
-# define _BSD_SOURCE
-// some versions of cygwin (most) do not support std::to_string. Use the libstd check.
-// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813
-# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
- && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
-
-# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
-
-# endif
-#endif // __CYGWIN__
-
-////////////////////////////////////////////////////////////////////////////////
-// Visual C++
-#if defined(_MSC_VER)
-
-// Universal Windows platform does not support SEH
-// Or console colours (or console at all...)
-# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
-# define CATCH_CONFIG_COLOUR_NONE
-# else
-# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
-# endif
-
-# if !defined(__clang__) // Handle Clang masquerading for msvc
-
-// MSVC traditional preprocessor needs some workaround for __VA_ARGS__
-// _MSVC_TRADITIONAL == 0 means new conformant preprocessor
-// _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor
-# if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL)
-# define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
-# endif // MSVC_TRADITIONAL
-
-// Only do this if we're not using clang on Windows, which uses `diagnostic push` & `diagnostic pop`
-# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) )
-# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) )
-# endif // __clang__
-
-#endif // _MSC_VER
-
-#if defined(_REENTRANT) || defined(_MSC_VER)
-// Enable async processing, as -pthread is specified or no additional linking is required
-# define CATCH_INTERNAL_CONFIG_USE_ASYNC
-#endif // _MSC_VER
-
-////////////////////////////////////////////////////////////////////////////////
-// Check if we are compiled with -fno-exceptions or equivalent
-#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND)
-# define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-// DJGPP
-#ifdef __DJGPP__
-# define CATCH_INTERNAL_CONFIG_NO_WCHAR
-#endif // __DJGPP__
-
-////////////////////////////////////////////////////////////////////////////////
-// Embarcadero C++Build
-#if defined(__BORLANDC__)
- #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-
-// Use of __COUNTER__ is suppressed during code analysis in
-// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly
-// handled by it.
-// Otherwise all supported compilers support COUNTER macro,
-// but user still might want to turn it off
-#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L )
- #define CATCH_INTERNAL_CONFIG_COUNTER
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-
-// RTX is a special version of Windows that is real time.
-// This means that it is detected as Windows, but does not provide
-// the same set of capabilities as real Windows does.
-#if defined(UNDER_RTSS) || defined(RTX64_BUILD)
- #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
- #define CATCH_INTERNAL_CONFIG_NO_ASYNC
- #define CATCH_CONFIG_COLOUR_NONE
-#endif
-
-#if !defined(_GLIBCXX_USE_C99_MATH_TR1)
-#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER
-#endif
-
-// Various stdlib support checks that require __has_include
-#if defined(__has_include)
- // Check if string_view is available and usable
- #if __has_include() && defined(CATCH_CPP17_OR_GREATER)
- # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW
- #endif
-
- // Check if optional is available and usable
- # if __has_include() && defined(CATCH_CPP17_OR_GREATER)
- # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL
- # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER)
-
- // Check if byte is available and usable
- # if __has_include() && defined(CATCH_CPP17_OR_GREATER)
- # include
- # if defined(__cpp_lib_byte) && (__cpp_lib_byte > 0)
- # define CATCH_INTERNAL_CONFIG_CPP17_BYTE
- # endif
- # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER)
-
- // Check if variant is available and usable
- # if __has_include() && defined(CATCH_CPP17_OR_GREATER)
- # if defined(__clang__) && (__clang_major__ < 8)
- // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852
- // fix should be in clang 8, workaround in libstdc++ 8.2
- # include
- # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
- # define CATCH_CONFIG_NO_CPP17_VARIANT
- # else
- # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
- # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
- # else
- # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
- # endif // defined(__clang__) && (__clang_major__ < 8)
- # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER)
-#endif // defined(__has_include)
-
-#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
-# define CATCH_CONFIG_COUNTER
-#endif
-#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH)
-# define CATCH_CONFIG_WINDOWS_SEH
-#endif
-// This is set by default, because we assume that unix compilers are posix-signal-compatible by default.
-#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS)
-# define CATCH_CONFIG_POSIX_SIGNALS
-#endif
-// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions.
-#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR)
-# define CATCH_CONFIG_WCHAR
-#endif
-
-#if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING)
-# define CATCH_CONFIG_CPP11_TO_STRING
-#endif
-
-#if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL)
-# define CATCH_CONFIG_CPP17_OPTIONAL
-#endif
-
-#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW)
-# define CATCH_CONFIG_CPP17_STRING_VIEW
-#endif
-
-#if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT)
-# define CATCH_CONFIG_CPP17_VARIANT
-#endif
-
-#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE)
-# define CATCH_CONFIG_CPP17_BYTE
-#endif
-
-#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
-# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE
-#endif
-
-#if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE)
-# define CATCH_CONFIG_NEW_CAPTURE
-#endif
-
-#if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
-# define CATCH_CONFIG_DISABLE_EXCEPTIONS
-#endif
-
-#if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN)
-# define CATCH_CONFIG_POLYFILL_ISNAN
-#endif
-
-#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC)
-# define CATCH_CONFIG_USE_ASYNC
-#endif
-
-#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE)
-# define CATCH_CONFIG_ANDROID_LOGWRITE
-#endif
-
-#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
-# define CATCH_CONFIG_GLOBAL_NEXTAFTER
-#endif
-
-// Even if we do not think the compiler has that warning, we still have
-// to provide a macro that can be used by the code.
-#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION)
-# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
-#endif
-#if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION)
-# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
-#endif
-#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
-# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
-#endif
-#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS)
-# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
-#endif
-#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS)
-# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS
-#endif
-#if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS)
-# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS
-#endif
-
-// The goal of this macro is to avoid evaluation of the arguments, but
-// still have the compiler warn on problems inside...
-#if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN)
-# define CATCH_INTERNAL_IGNORE_BUT_WARN(...)
-#endif
-
-#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10)
-# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
-#elif defined(__clang__) && (__clang_major__ < 5)
-# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
-#endif
-
-#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS)
-# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
-#endif
-
-#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
-#define CATCH_TRY if ((true))
-#define CATCH_CATCH_ALL if ((false))
-#define CATCH_CATCH_ANON(type) if ((false))
-#else
-#define CATCH_TRY try
-#define CATCH_CATCH_ALL catch (...)
-#define CATCH_CATCH_ANON(type) catch (type)
-#endif
-
-#if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR)
-#define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
-#endif
-
-// end catch_compiler_capabilities.h
-#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
-#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
-#ifdef CATCH_CONFIG_COUNTER
-# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
-#else
-# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
-#endif
-
-#include
-#include
-#include
-
-// We need a dummy global operator<< so we can bring it into Catch namespace later
-struct Catch_global_namespace_dummy {};
-std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy);
-
-namespace Catch {
-
- struct CaseSensitive { enum Choice {
- Yes,
- No
- }; };
-
- class NonCopyable {
- NonCopyable( NonCopyable const& ) = delete;
- NonCopyable( NonCopyable && ) = delete;
- NonCopyable& operator = ( NonCopyable const& ) = delete;
- NonCopyable& operator = ( NonCopyable && ) = delete;
-
- protected:
- NonCopyable();
- virtual ~NonCopyable();
- };
-
- struct SourceLineInfo {
-
- SourceLineInfo() = delete;
- SourceLineInfo( char const* _file, std::size_t _line ) noexcept
- : file( _file ),
- line( _line )
- {}
-
- SourceLineInfo( SourceLineInfo const& other ) = default;
- SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
- SourceLineInfo( SourceLineInfo&& ) noexcept = default;
- SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default;
-
- bool empty() const noexcept { return file[0] == '\0'; }
- bool operator == ( SourceLineInfo const& other ) const noexcept;
- bool operator < ( SourceLineInfo const& other ) const noexcept;
-
- char const* file;
- std::size_t line;
- };
-
- std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
-
- // Bring in operator<< from global namespace into Catch namespace
- // This is necessary because the overload of operator<< above makes
- // lookup stop at namespace Catch
- using ::operator<<;
-
- // Use this in variadic streaming macros to allow
- // >> +StreamEndStop
- // as well as
- // >> stuff +StreamEndStop
- struct StreamEndStop {
- std::string operator+() const;
- };
- template
- T const& operator + ( T const& value, StreamEndStop ) {
- return value;
- }
-}
-
-#define CATCH_INTERNAL_LINEINFO \
- ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) )
-
-// end catch_common.h
-namespace Catch {
-
- struct RegistrarForTagAliases {
- RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo );
- };
-
-} // end namespace Catch
-
-#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \
- CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
- CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
- namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \
- CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
-
-// end catch_tag_alias_autoregistrar.h
-// start catch_test_registry.h
-
-// start catch_interfaces_testcase.h
-
-#include
-
-namespace Catch {
-
- class TestSpec;
-
- struct ITestInvoker {
- virtual void invoke () const = 0;
- virtual ~ITestInvoker();
- };
-
- class TestCase;
- struct IConfig;
-
- struct ITestCaseRegistry {
- virtual ~ITestCaseRegistry();
- virtual std::vector const& getAllTests() const = 0;
- virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0;
- };
-
- bool isThrowSafe( TestCase const& testCase, IConfig const& config );
- bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
- std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config );
- std::vector const& getAllTestCasesSorted( IConfig const& config );
-
-}
-
-// end catch_interfaces_testcase.h
-// start catch_stringref.h
-
-#include
-#include
-#include
-#include
-
-namespace Catch {
-
- /// A non-owning string class (similar to the forthcoming std::string_view)
- /// Note that, because a StringRef may be a substring of another string,
- /// it may not be null terminated.
- class StringRef {
- public:
- using size_type = std::size_t;
- using const_iterator = const char*;
-
- private:
- static constexpr char const* const s_empty = "";
-
- char const* m_start = s_empty;
- size_type m_size = 0;
-
- public: // construction
- constexpr StringRef() noexcept = default;
-
- StringRef( char const* rawChars ) noexcept;
-
- constexpr StringRef( char const* rawChars, size_type size ) noexcept
- : m_start( rawChars ),
- m_size( size )
- {}
-
- StringRef( std::string const& stdString ) noexcept
- : m_start( stdString.c_str() ),
- m_size( stdString.size() )
- {}
-
- explicit operator std::string() const {
- return std::string(m_start, m_size);
- }
-
- public: // operators
- auto operator == ( StringRef const& other ) const noexcept -> bool;
- auto operator != (StringRef const& other) const noexcept -> bool {
- return !(*this == other);
- }
-
- auto operator[] ( size_type index ) const noexcept -> char {
- assert(index < m_size);
- return m_start[index];
- }
-
- public: // named queries
- constexpr auto empty() const noexcept -> bool {
- return m_size == 0;
- }
- constexpr auto size() const noexcept -> size_type {
- return m_size;
- }
-
- // Returns the current start pointer. If the StringRef is not
- // null-terminated, throws std::domain_exception
- auto c_str() const -> char const*;
-
- public: // substrings and searches
- // Returns a substring of [start, start + length).
- // If start + length > size(), then the substring is [start, size()).
- // If start > size(), then the substring is empty.
- auto substr( size_type start, size_type length ) const noexcept -> StringRef;
-
- // Returns the current start pointer. May not be null-terminated.
- auto data() const noexcept -> char const*;
-
- constexpr auto isNullTerminated() const noexcept -> bool {
- return m_start[m_size] == '\0';
- }
-
- public: // iterators
- constexpr const_iterator begin() const { return m_start; }
- constexpr const_iterator end() const { return m_start + m_size; }
- };
-
- auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&;
- auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&;
-
- constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
- return StringRef( rawChars, size );
- }
-} // namespace Catch
-
-constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef {
- return Catch::StringRef( rawChars, size );
-}
-
-// end catch_stringref.h
-// start catch_preprocessor.hpp
-
-
-#define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__
-#define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__)))
-#define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__)))
-#define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__)))
-#define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__)))
-#define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__)))
-
-#ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
-#define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__
-// MSVC needs more evaluations
-#define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__)))
-#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__))
-#else
-#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__)
-#endif
-
-#define CATCH_REC_END(...)
-#define CATCH_REC_OUT
-
-#define CATCH_EMPTY()
-#define CATCH_DEFER(id) id CATCH_EMPTY()
-
-#define CATCH_REC_GET_END2() 0, CATCH_REC_END
-#define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2
-#define CATCH_REC_GET_END(...) CATCH_REC_GET_END1
-#define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT
-#define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0)
-#define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next)
-
-#define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ )
-#define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ )
-#define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ )
-
-#define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ )
-#define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ )
-#define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ )
-
-// Applies the function macro `f` to each of the remaining parameters, inserts commas between the results,
-// and passes userdata as the first parameter to each invocation,
-// e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c)
-#define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
-
-#define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
-
-#define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param)
-#define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__
-#define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__
-#define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF
-#define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__)
-#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
-#define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__
-#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param))
-#else
-// MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF
-#define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__)
-#define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__
-#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1)
-#endif
-
-#define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__
-#define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name)
-
-#define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__)
-
-#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
-#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper())
-#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))
-#else
-#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper()))
-#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)))
-#endif
-
-#define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\
- CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__)
-
-#define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0)
-#define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1)
-#define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2)
-#define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3)
-#define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4)
-#define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5)
-#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _3, _4, _5, _6)
-#define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7)
-#define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8)
-#define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9)
-#define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10)
-
-#define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
-
-#define INTERNAL_CATCH_TYPE_GEN\
- template struct TypeList {};\
- template\
- constexpr auto get_wrapper() noexcept -> TypeList { return {}; }\
- template class...> struct TemplateTypeList{};\
- template class...Cs>\
- constexpr auto get_wrapper() noexcept -> TemplateTypeList { return {}; }\
- template\
- struct append;\
- template\
- struct rewrap;\
- template class, typename...>\
- struct create;\
- template class, typename>\
- struct convert;\
- \
- template \
- struct append { using type = T; };\
- template< template class L1, typename...E1, template class L2, typename...E2, typename...Rest>\
- struct append, L2, Rest...> { using type = typename append, Rest...>::type; };\
- template< template class L1, typename...E1, typename...Rest>\
- struct append, TypeList, Rest...> { using type = L1; };\
- \
- template< template class Container, template class List, typename...elems>\
- struct rewrap, List> { using type = TypeList>; };\
- template< template class Container, template class List, class...Elems, typename...Elements>\
- struct rewrap, List, Elements...> { using type = typename append>, typename rewrap, Elements...>::type>::type; };\
- \
- template class Final, template< typename...> class...Containers, typename...Types>\
- struct create, TypeList> { using type = typename append, typename rewrap, Types...>::type...>::type; };\
- template class Final, template class List, typename...Ts>\
- struct convert> { using type = typename append,TypeList...>::type; };
-
-#define INTERNAL_CATCH_NTTP_1(signature, ...)\
- template struct Nttp{};\
- template\
- constexpr auto get_wrapper() noexcept -> Nttp<__VA_ARGS__> { return {}; } \
- template class...> struct NttpTemplateTypeList{};\
- template class...Cs>\
- constexpr auto get_wrapper() noexcept -> NttpTemplateTypeList { return {}; } \
- \
- template< template class Container, template class List, INTERNAL_CATCH_REMOVE_PARENS(signature)>\
- struct rewrap, List<__VA_ARGS__>> { using type = TypeList>; };\
- template< template class Container, template class List, INTERNAL_CATCH_REMOVE_PARENS(signature), typename...Elements>\
- struct rewrap, List<__VA_ARGS__>, Elements...> { using type = typename append>, typename rewrap, Elements...>::type>::type; };\
- template class Final, template class...Containers, typename...Types>\
- struct create, TypeList> { using type = typename append, typename rewrap, Types...>::type...>::type; };
-
-#define INTERNAL_CATCH_DECLARE_SIG_TEST0(TestName)
-#define INTERNAL_CATCH_DECLARE_SIG_TEST1(TestName, signature)\
- template\
- static void TestName()
-#define INTERNAL_CATCH_DECLARE_SIG_TEST_X(TestName, signature, ...)\
- template\
- static void TestName()
-
-#define INTERNAL_CATCH_DEFINE_SIG_TEST0(TestName)
-#define INTERNAL_CATCH_DEFINE_SIG_TEST1(TestName, signature)\
- template\
- static void TestName()
-#define INTERNAL_CATCH_DEFINE_SIG_TEST_X(TestName, signature,...)\
- template\
- static void TestName()
-
-#define INTERNAL_CATCH_NTTP_REGISTER0(TestFunc, signature)\
- template\
- void reg_test(TypeList, Catch::NameAndTags nameAndTags)\
- {\
- Catch::AutoReg( Catch::makeTestInvoker(&TestFunc), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\
- }
-
-#define INTERNAL_CATCH_NTTP_REGISTER(TestFunc, signature, ...)\
- template\
- void reg_test(Nttp<__VA_ARGS__>, Catch::NameAndTags nameAndTags)\
- {\
- Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<__VA_ARGS__>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\
- }
-
-#define INTERNAL_CATCH_NTTP_REGISTER_METHOD0(TestName, signature, ...)\
- template\
- void reg_test(TypeList, Catch::StringRef className, Catch::NameAndTags nameAndTags)\
- {\
- Catch::AutoReg( Catch::makeTestInvoker(&TestName::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\
- }
-
-#define INTERNAL_CATCH_NTTP_REGISTER_METHOD(TestName, signature, ...)\
- template\
- void reg_test(Nttp<__VA_ARGS__>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\
- {\
- Catch::AutoReg( Catch::makeTestInvoker(&TestName<__VA_ARGS__>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\
- }
-
-#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0(TestName, ClassName)
-#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1(TestName, ClassName, signature)\
- template \
- struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \
- void test();\
- }
-
-#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X(TestName, ClassName, signature, ...)\
- template \
- struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName)<__VA_ARGS__> { \
- void test();\
- }
-
-#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0(TestName)
-#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1(TestName, signature)\
- template \
- void INTERNAL_CATCH_MAKE_NAMESPACE(TestName)::TestName::test()
-#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X(TestName, signature, ...)\
- template \
- void INTERNAL_CATCH_MAKE_NAMESPACE(TestName)::TestName<__VA_ARGS__>::test()
-
-#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
-#define INTERNAL_CATCH_NTTP_0
-#define INTERNAL_CATCH_NTTP_GEN(...) INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__),INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_0)
-#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0)(TestName, __VA_ARGS__)
-#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0)(TestName, ClassName, __VA_ARGS__)
-#define INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD0, INTERNAL_CATCH_NTTP_REGISTER_METHOD0)(TestName, __VA_ARGS__)
-#define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__)
-#define INTERNAL_CATCH_DEFINE_SIG_TEST(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST1, INTERNAL_CATCH_DEFINE_SIG_TEST0)(TestName, __VA_ARGS__)
-#define INTERNAL_CATCH_DECLARE_SIG_TEST(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST1, INTERNAL_CATCH_DECLARE_SIG_TEST0)(TestName, __VA_ARGS__)
-#define INTERNAL_CATCH_REMOVE_PARENS_GEN(...) INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_REMOVE_PARENS_11_ARG,INTERNAL_CATCH_REMOVE_PARENS_10_ARG,INTERNAL_CATCH_REMOVE_PARENS_9_ARG,INTERNAL_CATCH_REMOVE_PARENS_8_ARG,INTERNAL_CATCH_REMOVE_PARENS_7_ARG,INTERNAL_CATCH_REMOVE_PARENS_6_ARG,INTERNAL_CATCH_REMOVE_PARENS_5_ARG,INTERNAL_CATCH_REMOVE_PARENS_4_ARG,INTERNAL_CATCH_REMOVE_PARENS_3_ARG,INTERNAL_CATCH_REMOVE_PARENS_2_ARG,INTERNAL_CATCH_REMOVE_PARENS_1_ARG)(__VA_ARGS__)
-#else
-#define INTERNAL_CATCH_NTTP_0(signature)
-#define INTERNAL_CATCH_NTTP_GEN(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1,INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_0)( __VA_ARGS__))
-#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0)(TestName, __VA_ARGS__))
-#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0)(TestName, ClassName, __VA_ARGS__))
-#define INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD0, INTERNAL_CATCH_NTTP_REGISTER_METHOD0)(TestName, __VA_ARGS__))
-#define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__))
-#define INTERNAL_CATCH_DEFINE_SIG_TEST(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST1, INTERNAL_CATCH_DEFINE_SIG_TEST0)(TestName, __VA_ARGS__))
-#define INTERNAL_CATCH_DECLARE_SIG_TEST(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST1, INTERNAL_CATCH_DECLARE_SIG_TEST0)(TestName, __VA_ARGS__))
-#define INTERNAL_CATCH_REMOVE_PARENS_GEN(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_REMOVE_PARENS_11_ARG,INTERNAL_CATCH_REMOVE_PARENS_10_ARG,INTERNAL_CATCH_REMOVE_PARENS_9_ARG,INTERNAL_CATCH_REMOVE_PARENS_8_ARG,INTERNAL_CATCH_REMOVE_PARENS_7_ARG,INTERNAL_CATCH_REMOVE_PARENS_6_ARG,INTERNAL_CATCH_REMOVE_PARENS_5_ARG,INTERNAL_CATCH_REMOVE_PARENS_4_ARG,INTERNAL_CATCH_REMOVE_PARENS_3_ARG,INTERNAL_CATCH_REMOVE_PARENS_2_ARG,INTERNAL_CATCH_REMOVE_PARENS_1_ARG)(__VA_ARGS__))
-#endif
-
-// end catch_preprocessor.hpp
-// start catch_meta.hpp
-
-
-#include
-
-namespace Catch {
- template
- struct always_false : std::false_type {};
-
- template struct true_given : std::true_type {};
- struct is_callable_tester {
- template
- true_given()(std::declval()...))> static test(int);
- template
- std::false_type static test(...);
- };
-
- template
- struct is_callable;
-
- template
- struct is_callable : decltype(is_callable_tester::test(0)) {};
-
-#if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703
- // std::result_of is deprecated in C++17 and removed in C++20. Hence, it is
- // replaced with std::invoke_result here.
- template
- using FunctionReturnType = std::remove_reference_t>>;
-#else
- // Keep ::type here because we still support C++11
- template
- using FunctionReturnType = typename std::remove_reference::type>::type>::type;
-#endif
-
-} // namespace Catch
-
-namespace mpl_{
- struct na;
-}
-
-// end catch_meta.hpp
-namespace Catch {
-
-template
-class TestInvokerAsMethod : public ITestInvoker {
- void (C::*m_testAsMethod)();
-public:
- TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {}
-
- void invoke() const override {
- C obj;
- (obj.*m_testAsMethod)();
- }
-};
-
-auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker*;
-
-template
-auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* {
- return new(std::nothrow) TestInvokerAsMethod( testAsMethod );
-}
-
-struct NameAndTags {
- NameAndTags( StringRef const& name_ = StringRef(), StringRef const& tags_ = StringRef() ) noexcept;
- StringRef name;
- StringRef tags;
-};
-
-struct AutoReg : NonCopyable {
- AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept;
- ~AutoReg();
-};
-
-} // end namespace Catch
-
-#if defined(CATCH_CONFIG_DISABLE)
- #define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \
- static void TestName()
- #define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \
- namespace{ \
- struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \
- void test(); \
- }; \
- } \
- void TestName::test()
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( TestName, TestFunc, Name, Tags, Signature, ... ) \
- INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature))
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \
- namespace{ \
- namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \
- INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
- } \
- } \
- INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))
-
- #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(Name, Tags, ...) \
- INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename TestType, __VA_ARGS__ )
- #else
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(Name, Tags, ...) \
- INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename TestType, __VA_ARGS__ ) )
- #endif
-
- #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(Name, Tags, Signature, ...) \
- INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ )
- #else
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(Name, Tags, Signature, ...) \
- INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ ) )
- #endif
-
- #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION( ClassName, Name, Tags,... ) \
- INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ )
- #else
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION( ClassName, Name, Tags,... ) \
- INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) )
- #endif
-
- #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION( ClassName, Name, Tags, Signature, ... ) \
- INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ )
- #else
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION( ClassName, Name, Tags, Signature, ... ) \
- INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_C_L_A_S_S_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) )
- #endif
-#endif
-
- ///////////////////////////////////////////////////////////////////////////////
- #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
- static void TestName(); \
- CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
- CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
- namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
- CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
- static void TestName()
- #define INTERNAL_CATCH_TESTCASE( ... ) \
- INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ), __VA_ARGS__ )
-
- ///////////////////////////////////////////////////////////////////////////////
- #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
- CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
- CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
- namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
- CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
-
- ///////////////////////////////////////////////////////////////////////////////
- #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
- CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
- CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
- namespace{ \
- struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \
- void test(); \
- }; \
- Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
- } \
- CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
- void TestName::test()
- #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
- INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_S_T_ ), ClassName, __VA_ARGS__ )
-
- ///////////////////////////////////////////////////////////////////////////////
- #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
- CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
- CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
- Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
- CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
-
- ///////////////////////////////////////////////////////////////////////////////
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_2(TestName, TestFunc, Name, Tags, Signature, ... )\
- CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
- CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
- CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
- CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
- INTERNAL_CATCH_DECLARE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
- namespace {\
- namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\
- INTERNAL_CATCH_TYPE_GEN\
- INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\
- INTERNAL_CATCH_NTTP_REG_GEN(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))\
- template \
- struct TestName{\
- TestName(){\
- int index = 0; \
- constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\
- using expander = int[];\
- (void)expander{(reg_test(Types{}, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \
- }\
- };\
- static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
- TestName();\
- return 0;\
- }();\
- }\
- }\
- CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
- INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))
-
-#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE(Name, Tags, ...) \
- INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename TestType, __VA_ARGS__ )
-#else
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE(Name, Tags, ...) \
- INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename TestType, __VA_ARGS__ ) )
-#endif
-
-#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG(Name, Tags, Signature, ...) \
- INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ )
-#else
- #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG(Name, Tags, Signature, ...) \
- INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ ) )
-#endif
-
- #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(TestName, TestFuncName, Name, Tags, Signature, TmplTypes, TypesList) \
- CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
- CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
- CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
- CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
- template static void TestFuncName(); \
- namespace {\
- namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \
- INTERNAL_CATCH_TYPE_GEN \
- INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature)) \
- template \
- struct TestName { \
- void reg_tests() { \
- int index = 0; \
- using expander = int[]; \
- constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\
- constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\
- constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
- (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFuncName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + "<" + std::string(types_list[index % num_types]) + ">", Tags } ), index++)... };/* NOLINT */\
- } \
- }; \
- static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
- using TestInit = typename create()), TypeList>::type; \
- TestInit t; \
- t.reg_tests(); \
- return 0; \
- }(); \
- } \
- } \
- CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
- template \
- static void TestFuncName()
-
-#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
- #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE(Name, Tags, ...)\
- INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename T,__VA_ARGS__)
-#else
- #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE(Name, Tags, ...)\
- INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, typename T, __VA_ARGS__ ) )
-#endif
-
-#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
- #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG(Name, Tags, Signature, ...)\
- INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__)
-#else
- #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG(Name, Tags, Signature, ...)\
- INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2( INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_ ), INTERNAL_CATCH_UNIQUE_NAME( C_A_T_C_H_T_E_M_P_L_A_T_E_T_E_S_T_F_U_N_C_ ), Name, Tags, Signature, __VA_ARGS__ ) )
-#endif
-
- #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2(TestName, TestFunc, Name, Tags, TmplList)\
- CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
- CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
- CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
- template static void TestFunc(); \
- namespace {\
- namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\
- INTERNAL_CATCH_TYPE_GEN\
- template \
- struct TestName { \
- void reg_tests() { \
- int index = 0; \
- using expander = int[]; \
- (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc