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
2 changes: 1 addition & 1 deletion examples/utility/Provisioning_2.0/Provisioning_2.0.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <utility/SElementArduinoCloudCertificate.h>
#include "utility/LEDFeedback.h"

const char *SKETCH_VERSION = "0.3.3";
const char *SKETCH_VERSION = "0.4.1";

enum class DeviceState {
HARDWARE_CHECK,
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