Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion examples/utility/Provisioning_2.0/CSRHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions examples/utility/Provisioning_2.0/CSRHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
80 changes: 80 additions & 0 deletions examples/utility/Provisioning_2.0/FactoryTester.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright (c) 2025 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 <ANetworkConfigurator_Config.h>

#ifdef BOARD_USE_NINA
#include "WiFiNINA.h"
#include "utility/wifi_drv.h"
#endif

inline void LedFactoryTest() {
#if defined(BOARD_HAS_RGB)
#if defined(BOARD_USE_NINA)
// MKR WiFi 1010, RP2040 Connect
WiFiDrv::pinMode(GREEN_LED, OUTPUT);
WiFiDrv::digitalWrite(GREEN_LED, LED_OFF);
WiFiDrv::pinMode(BLUE_LED, OUTPUT);
WiFiDrv::digitalWrite(BLUE_LED, LED_OFF);
WiFiDrv::pinMode(RED_LED, OUTPUT);
WiFiDrv::digitalWrite(RED_LED, LED_OFF);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LED_OFF);

for(uint8_t i = 0; i<2; i++){
digitalWrite(LED_BUILTIN, LED_ON);
WiFiDrv::digitalWrite(RED_LED, LED_ON);
delay(300);
digitalWrite(LED_BUILTIN, LED_OFF);
WiFiDrv::digitalWrite(RED_LED, LED_OFF);
WiFiDrv::digitalWrite(GREEN_LED, LED_ON);
delay(300);
digitalWrite(LED_BUILTIN, LED_ON);
WiFiDrv::digitalWrite(GREEN_LED, LED_OFF);
WiFiDrv::digitalWrite(BLUE_LED, LED_ON);
delay(300);
digitalWrite(LED_BUILTIN, LED_OFF);
WiFiDrv::digitalWrite(BLUE_LED, LED_OFF);
delay(200);
}
#else
// Portenta H7, Giga, Nicla Vision, Portenta C33
pinMode(GREEN_LED, OUTPUT);
digitalWrite(GREEN_LED, LED_OFF);
pinMode(RED_LED, OUTPUT);
digitalWrite(RED_LED, LED_OFF);
pinMode(BLUE_LED, OUTPUT);
digitalWrite(BLUE_LED, LED_OFF);
for(uint8_t i = 0; i<2; i++){
digitalWrite(RED_LED, LED_ON);
delay(300);
digitalWrite(RED_LED, LED_OFF);
digitalWrite(GREEN_LED, LED_ON);
delay(300);
digitalWrite(GREEN_LED, LED_OFF);
digitalWrite(BLUE_LED, LED_ON);
delay(300);
digitalWrite(BLUE_LED, LED_OFF);
delay(200);
}
#endif
#else // Nano 33 IoT
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LED_OFF);
uint32_t start = millis();
while(millis() - start < 2000) {
digitalWrite(LED_BUILTIN, LED_ON);
delay(300);
digitalWrite(LED_BUILTIN, LED_OFF);
delay(300);
}
#endif

}
9 changes: 7 additions & 2 deletions examples/utility/Provisioning_2.0/Provisioning_2.0.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <utility/SElementArduinoCloudDeviceId.h>
#include <utility/SElementArduinoCloudCertificate.h>
#include "utility/LEDFeedback.h"

const char *SKETCH_VERSION = "0.3.3";
#include "FactoryTester.h"
const char *SKETCH_VERSION = "0.5.0";

enum class DeviceState {
HARDWARE_CHECK,
Expand Down Expand Up @@ -57,6 +57,11 @@ void setup() {
setDebugMessageLevel(4);

initProperties();

#if !defined(ARDUINO_OPTA) && !defined(ARDUINO_UNOR4_WIFI)
LedFactoryTest();
#endif

AgentsManagerClass::getInstance().begin();
LEDFeedbackClass::getInstance().begin();
DEBUG_INFO("Starting Provisioning version %s", SKETCH_VERSION);
Expand Down
5 changes: 5 additions & 0 deletions examples/utility/Provisioning_2.0/SecretsHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down
1 change: 1 addition & 0 deletions examples/utility/Provisioning_2.0/thingProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <ArduinoIoTCloud.h>
#include <GenericConnectionHandler.h>
#include <Arduino_KVStore.h>
#include "Arduino_NetworkConfigurator.h"
#include "configuratorAgents/agents/BLEAgent.h"
#include "configuratorAgents/agents/SerialAgent.h"

Expand Down
3 changes: 2 additions & 1 deletion src/AIoTC_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading