From 43e80b30a9c9f91cc96166f2ac46369d0f1a310f Mon Sep 17 00:00:00 2001 From: fabik111 Date: Wed, 3 Sep 2025 09:49:17 +0200 Subject: [PATCH 1/8] add parse date function instead of sscanf --- .../utility/Provisioning_2.0/CSRHandler.cpp | 38 ++++++++++++++++++- .../utility/Provisioning_2.0/CSRHandler.h | 1 + 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/examples/utility/Provisioning_2.0/CSRHandler.cpp b/examples/utility/Provisioning_2.0/CSRHandler.cpp index 1a6101e4b..8235db14a 100644 --- a/examples/utility/Provisioning_2.0/CSRHandler.cpp +++ b/examples/utility/Provisioning_2.0/CSRHandler.cpp @@ -193,6 +193,42 @@ uint32_t CSRHandlerClass::getTimestamp() { return ts; } +bool CSRHandlerClass::parseDateFromStr(char *str) { + char *tok[3]; + int i = 1; + tok[0] = strtok(str, "-"); + for (; i < 3; i++) { + char *t = strtok(NULL, "-"); + if(t == NULL){ + break; + } + tok[i] = t; + } + if (i < 3) { + return false; + } + + char *day = strtok(tok[2], "T"); + char *time = strtok(NULL, "T"); + + if(time == NULL){ + return false; + } + + char *hour = strtok(time, ":"); + + if(strlen(tok[0]) != 4 || strlen(tok[1]) != 2 || strlen(day) != 2 || strlen(hour) != 2){ + return false; + } + + _issueYear = atoi(tok[0]); + _issueMonth = atoi(tok[1]); + _issueDay = atoi(day); + _issueHour = atoi(hour); + + return true; +} + CSRHandlerClass::CSRHandlerStates CSRHandlerClass::handleBuildCSR() { if (!_certForCSR) { _certForCSR = new ECP256Certificate(); @@ -296,7 +332,7 @@ CSRHandlerClass::CSRHandlerStates CSRHandlerClass::handleParseResponse() { 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){ + || !parseDateFromStr(token[2])){ updateNextRequestAt(); DEBUG_ERROR("CSRH::%s Error parsing response, retrying in %d ms", __FUNCTION__, _nextRequestAt - millis()); return CSRHandlerStates::REQUEST_SIGNATURE; diff --git a/examples/utility/Provisioning_2.0/CSRHandler.h b/examples/utility/Provisioning_2.0/CSRHandler.h index ae5956b7e..dcc2bc479 100644 --- a/examples/utility/Provisioning_2.0/CSRHandler.h +++ b/examples/utility/Provisioning_2.0/CSRHandler.h @@ -63,6 +63,7 @@ class CSRHandlerClass { uint32_t jitter(uint32_t base = JITTER_BASE, uint32_t max = JITTER_MAX); bool postRequest(const char *url, String &postData); uint32_t getTimestamp(); + bool parseDateFromStr(char *str); CSRHandlerStates handleBuildCSR(); CSRHandlerStates handleRequestSignature(); CSRHandlerStates handleWaitingResponse(); From e3337590ba3cea4eddd862e78bbdcc7a698a70bf Mon Sep 17 00:00:00 2001 From: fabik111 Date: Wed, 3 Sep 2025 09:49:45 +0200 Subject: [PATCH 2/8] add networkconfigurator include --- examples/utility/Provisioning_2.0/thingProperties.h | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/utility/Provisioning_2.0/thingProperties.h b/examples/utility/Provisioning_2.0/thingProperties.h index 7f51fa6ca..9d2a6cdd7 100644 --- a/examples/utility/Provisioning_2.0/thingProperties.h +++ b/examples/utility/Provisioning_2.0/thingProperties.h @@ -12,6 +12,7 @@ #include #include #include +#include "Arduino_NetworkConfigurator.h" #include "configuratorAgents/agents/BLEAgent.h" #include "configuratorAgents/agents/SerialAgent.h" From 201101b1574425e4cfbcb15f9096b0c3105bf0f0 Mon Sep 17 00:00:00 2001 From: fabik111 Date: Wed, 3 Sep 2025 09:50:45 +0200 Subject: [PATCH 3/8] enable NetworkConfigurator for nina boards --- src/AIoTC_Config.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AIoTC_Config.h b/src/AIoTC_Config.h index b0fba96a3..bd1187765 100644 --- a/src/AIoTC_Config.h +++ b/src/AIoTC_Config.h @@ -155,7 +155,8 @@ #endif #if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_OPTA) || defined(ARDUINO_GIGA) \ - || defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_PORTENTA_C33) + || defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_PORTENTA_C33) || defined(ARDUINO_NANO_RP2040_CONNECT) \ + || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) #define NETWORK_CONFIGURATOR_ENABLED (1) #else #define NETWORK_CONFIGURATOR_ENABLED (0) From 440f9efe502cae469d6a2ef366460d1768344e06 Mon Sep 17 00:00:00 2001 From: fabik111 Date: Wed, 3 Sep 2025 09:51:36 +0200 Subject: [PATCH 4/8] Provisioning sketch version 0.4.0 --- examples/utility/Provisioning_2.0/Provisioning_2.0.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/utility/Provisioning_2.0/Provisioning_2.0.ino b/examples/utility/Provisioning_2.0/Provisioning_2.0.ino index 7f8f44ceb..eb87b4b99 100644 --- a/examples/utility/Provisioning_2.0/Provisioning_2.0.ino +++ b/examples/utility/Provisioning_2.0/Provisioning_2.0.ino @@ -15,7 +15,7 @@ #include #include "utility/LEDFeedback.h" -const char *SKETCH_VERSION = "0.3.3"; +const char *SKETCH_VERSION = "0.4.0"; enum class DeviceState { HARDWARE_CHECK, From dab268e6022c1a45540663238b987fb02ebb3149 Mon Sep 17 00:00:00 2001 From: fabik111 Date: Mon, 8 Sep 2025 14:25:56 +0200 Subject: [PATCH 5/8] add compile provisioning sketch flow --- .github/workflows/compile-provisioning.yml | 248 +++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 .github/workflows/compile-provisioning.yml diff --git a/.github/workflows/compile-provisioning.yml b/.github/workflows/compile-provisioning.yml new file mode 100644 index 000000000..391376c87 --- /dev/null +++ b/.github/workflows/compile-provisioning.yml @@ -0,0 +1,248 @@ +name: Compile Provisioning + +on: + pull_request: + paths: + - ".github/workflows/compile-provisioning.yml" + - "examples/**" + - "src/**" + push: + paths: + - ".github/workflows/compile-provisioning.yml" + - "examples/**" + - "src/**" + +jobs: + build: + runs-on: ubuntu-latest + + env: + # libraries to install for all boards + UNIVERSAL_LIBRARIES: | + # Install the ArduinoIoTCloud library from the repository + - source-path: ./ + - source-url: https://github.com/pennam/ArduinoBLE.git + version: 5915fa2df776e6eb7e9e5afd896ed3d1c048c9c0 + - name: ArduinoHttpClient + version: 0.6.1 + - name: Arduino_DebugUtils + version: 1.4.0 + - name: ArduinoMqttClient + version: 0.1.8 + - name: Arduino_KVStore + version: 1.0.0 + - source-url: https://github.com/pennam/Arduino_ConnectionHandler.git + version: 0f0f4a4ce718fcf2066a092a92cc2fdcd4d8bedd + - name: Arduino_SecureElement + version: 0.4.0 + - name: Arduino_CloudUtils + version: 1.1.1 + - source-url: https://github.com/arduino-libraries/Arduino_UniqueHWId.git + version: 7e1bfeb586cac00f043c39997a1e9937ed8152b0 + - source-url: https://github.com/arduino-libraries/Arduino_NetworkConfigurator.git + version: 3499628000f2b652e856db406e4e02140bf267a6 + # sketch paths to compile (recursive) for all boards + UNIVERSAL_SKETCH_PATHS: | + - examples/utility/Provisioning_2.0 + SKETCHES_REPORTS_PATH: sketches-reports + + strategy: + fail-fast: false + + matrix: + board: + - 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:mbed_portenta:envie_m7:split=100_0 + type: mbed_portenta + artifact-name-suffix: arduino-mbed_portenta-envie_m7 + - 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 + + # make board type-specific customizations to the matrix jobs + include: + # MKR WiFi 1010, Nano 33 IoT, Nano RP2040 Connect + - board: + type: nina + platforms: | + # Install samd and mbed_nano platform via Boards Manager + - name: arduino:samd + version: 1.8.14 + - name: arduino:mbed_nano + version: 4.3.1 + libraries: | + - name: RTCZero + version: 1.6.0 + - name: ArduinoECCX08 + version: 1.3.9 + - name: Adafruit SleepyDog Library + version: 1.6.5 + - name: ArduinoBearSSL + version: 1.7.6 + - source-url: https://github.com/pennam/WiFiNINA.git + version: b9a8d705f85fef8c19862c32e314367d4bba5734 + - source-url: https://github.com/arduino-libraries/SpiNINA.git + version: 4c8f2956b1b9cd421583393421c6c9276ba27614 + # Portenta + - board: + type: mbed_portenta + platforms: | + # Install mbed_portenta platform via Boards Manager + - name: arduino:mbed_portenta + version: 4.3.1 + libraries: | + - source-url: https://github.com/pennam/Arduino_Cellular.git + version: bfbd25791d200b113d640e16eed43ce547ab0b0c + - name: ArduinoECCX08 + version: 1.3.9 + - name: StreamDebugger + version: 1.0.1 + - name: TinyGsm + version: 0.12.0 + - name: ArduinoBearSSL + version: 1.7.6 + # Nicla Vision + - board: + type: mbed_nicla + platforms: | + # Install mbed_nicla platform via Boards Manager + - name: arduino:mbed_nicla + version: 4.3.1 + # Opta + - board: + type: mbed_opta + platforms: | + # Install mbed_opta platform via Boards Manager + - name: arduino:mbed_opta + version: 4.3.1 + libraries: | + - name: ArduinoECCX08 + version: 1.3.9 + - name: ArduinoBearSSL + version: 1.7.6 + # GIGA + - board: + type: mbed_giga + platforms: | + # Install mbed_giga platform via Boards Manager + - name: arduino:mbed_giga + version: 4.3.1 + libraries: | + - name: ArduinoECCX08 + version: 1.3.9 + - name: ArduinoBearSSL + version: 1.7.6 + # Portenta C33 + - board: + type: renesas_portenta + platforms: | + # Install renesas_portenta platform via Boards Manager + - name: arduino:renesas_portenta + version: 1.4.1 + libraries: | + - source-url: https://github.com/pennam/Arduino_Cellular.git + version: bfbd25791d200b113d640e16eed43ce547ab0b0c + - name: StreamDebugger + version: 1.0.1 + - name: TinyGsm + version: 0.12.0 + # UNO R4 WiFi + - board: + type: renesas_uno + platforms: | + # Install renesas_uno platform via Boards Manager + - name: arduino:renesas_uno + version: 1.4.1 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Clear cache + run: | + rm -rf ~/.cache + - name: Compile production provisioning sketch + uses: arduino/compile-sketches@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + platforms: ${{ matrix.platforms }} + fqbn: ${{ matrix.board.fqbn }} + libraries: | + ${{ env.UNIVERSAL_LIBRARIES }} + ${{ matrix.libraries }} + sketch-paths: | + ${{ env.UNIVERSAL_SKETCH_PATHS }} + ${{ matrix.sketch-paths }} + enable-deltas-report: "false" + sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} + cli-compile-flags: | + - --clean + - --verbose + - --output-dir + - ${{ runner.temp }}/provisioning-prod + - name: Compile staging provisioning sketch + uses: arduino/compile-sketches@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + platforms: ${{ matrix.platforms }} + fqbn: ${{ matrix.board.fqbn }} + libraries: | + ${{ env.UNIVERSAL_LIBRARIES }} + ${{ matrix.libraries }} + sketch-paths: | + ${{ env.UNIVERSAL_SKETCH_PATHS }} + ${{ matrix.sketch-paths }} + enable-deltas-report: "false" + sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} + cli-compile-flags: | + - --clean + - --verbose + - --build-property + - "build.extra_flags=-DCOMPILE_TEST=1" + - --output-dir + - ${{ runner.temp }}/provisioning-staging + - name: Write data to size trends report spreadsheet + # Update report on every push to the master branch + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + uses: arduino/report-size-trends@main + with: + sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} + google-key-file: ${{ secrets.GOOGLE_KEY_FILE }} + spreadsheet-id: 1I6NZkpZpf8KugBkE92adB1Z3_b7ZepOpCdYTOigJpN4 + + - name: Save memory usage change report as artifact + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@v4 + with: + name: sketches-report-${{ matrix.board.artifact-name-suffix }} + path: ${{ env.SKETCHES_REPORTS_PATH }} + + - name: Save production artifact + uses: actions/upload-artifact@v4 + with: + name: provisioning-prod-${{ matrix.board.artifact-name-suffix }} + path: ${{ runner.temp }}/provisioning-prod/ + + - name: Save staging artifact + uses: actions/upload-artifact@v4 + with: + name: provisioning-staging-${{ matrix.board.artifact-name-suffix }} + path: ${{ runner.temp }}/provisioning-staging/ From ea12f58a60348197b9c607e49a79549a5702b98d Mon Sep 17 00:00:00 2001 From: fabik111 Date: Tue, 9 Sep 2025 14:06:07 +0200 Subject: [PATCH 6/8] change compile flags --- .github/workflows/compile-provisioning.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile-provisioning.yml b/.github/workflows/compile-provisioning.yml index 391376c87..d26b8b8f9 100644 --- a/.github/workflows/compile-provisioning.yml +++ b/.github/workflows/compile-provisioning.yml @@ -216,7 +216,7 @@ jobs: - --clean - --verbose - --build-property - - "build.extra_flags=-DCOMPILE_TEST=1" + - "compiler.cpp.extra_flags=-DCOMPILE_TEST=1" - --output-dir - ${{ runner.temp }}/provisioning-staging - name: Write data to size trends report spreadsheet From 6180bffabed70b943ed98cad4881b5acdf4a03b9 Mon Sep 17 00:00:00 2001 From: fabik111 Date: Wed, 17 Sep 2025 11:59:12 +0200 Subject: [PATCH 7/8] fix for rp2040 crashes when getting board UHWID --- examples/utility/Provisioning_2.0/SecretsHelper.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/utility/Provisioning_2.0/SecretsHelper.h b/examples/utility/Provisioning_2.0/SecretsHelper.h index bdb6354d1..fba33e25b 100644 --- a/examples/utility/Provisioning_2.0/SecretsHelper.h +++ b/examples/utility/Provisioning_2.0/SecretsHelper.h @@ -14,6 +14,11 @@ inline String GetUHWID() { UniqueHWId Id; if (Id.begin()) { +#ifdef ARDUINO_NANO_RP2040_CONNECT + /*Delay added for avoiding device crashes + on Nano RP2040 Connect when reading the UHWID */ + delay(100); +#endif return Id.get(); } return ""; From 2916f54df07bd7204439ffde8add7d49641707da Mon Sep 17 00:00:00 2001 From: fabik111 Date: Wed, 17 Sep 2025 12:04:01 +0200 Subject: [PATCH 8/8] Provisioning sketch version 0.4.1 --- examples/utility/Provisioning_2.0/Provisioning_2.0.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/utility/Provisioning_2.0/Provisioning_2.0.ino b/examples/utility/Provisioning_2.0/Provisioning_2.0.ino index eb87b4b99..d0d8bd357 100644 --- a/examples/utility/Provisioning_2.0/Provisioning_2.0.ino +++ b/examples/utility/Provisioning_2.0/Provisioning_2.0.ino @@ -15,7 +15,7 @@ #include #include "utility/LEDFeedback.h" -const char *SKETCH_VERSION = "0.4.0"; +const char *SKETCH_VERSION = "0.4.1"; enum class DeviceState { HARDWARE_CHECK,