Skip to content

Fix thing reconfiguration after wifi connection loss #455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
059b318
Move properties containers inside class implementation
pennam Apr 9, 2024
6bc1aa8
Add commands definitions
andreagilardoni Feb 5, 2024
220c04e
Add MessageStream interface
pennam Mar 7, 2024
2294fd7
Add CloudProcess interface
pennam Mar 7, 2024
7d266e8
Add ArduinoCloudThing
pennam Apr 11, 2024
ef6b3a6
TimeService: make isTimeValid public
pennam Feb 28, 2024
20831f5
ArduinoIoTCloudTCP: Use isTimeValid() to check NTP time
pennam Feb 28, 2024
0d69bbb
ArduinoIoTCloudTCP: adapt state machine to use Thing process
pennam Apr 11, 2024
af14054
Add ArduinoCloudDevice
pennam Apr 11, 2024
8420fde
ArduinoIoTCloudTCP: adapt state machine to use Device process
pennam Apr 16, 2024
358194b
Cloud: initialize thing id to non null
pennam Apr 15, 2024
20d24e4
Defining encoder/decoder interfaces
andreagilardoni Feb 5, 2024
b98e3d2
CBOR encoder and decoder implementation for Command protocol model
andreagilardoni Apr 17, 2024
f13300a
Add tests for encoder and decoder
andreagilardoni Apr 17, 2024
24de8e6
Extend Commands.h to include new Command protocol model
andreagilardoni Mar 19, 2024
8f0c243
ArduinoIoTCloudTCP: switch to messages
pennam Feb 29, 2024
0008b17
ArduinoIoTCloudDevice: switch to messages
pennam Mar 20, 2024
52bf98d
BearSSLClient: allow configuration after object creation
pennam Mar 19, 2024
fbf03e1
BearSSLClient: allow clients to stop independently
andreagilardoni Apr 16, 2024
8e6184a
BearSSLClient: removing trailing white spaces
andreagilardoni Apr 16, 2024
1ba3e3a
BearSSLClient: adding FIXME comment
andreagilardoni Apr 16, 2024
fa514ea
Add TLSClientMqtt
pennam Mar 19, 2024
a92a57c
Add TLSClientOta
pennam Mar 25, 2024
34e8ad5
BearSLL: increase input buffer size to allow file downloading
pennam Mar 25, 2024
63b0840
Removing x509_crt_bundle_len since not used anywhere
andreagilardoni Apr 17, 2024
561c767
Add ArduinoLCC certificate inside certificate bundle
pennam Apr 9, 2024
af78334
BearSSL Trust Anchors: remove ces.iot.arduino.cc
pennam Apr 24, 2024
a42f164
UNO R4 WiFi: remove unused certificate bundle
pennam Apr 24, 2024
6b0883b
CI: added ArduinoHttpClient as dependency
andreagilardoni Apr 18, 2024
8569ac1
removing unused dependencies: ESP and Portente OTA
andreagilardoni Mar 12, 2024
b6bd5af
CI: removed unused libraries
andreagilardoni Apr 18, 2024
232e25a
changing include enrtypoint for OTA
andreagilardoni Feb 21, 2024
e36cf27
included LZSSDecoder library beforme making it a library
andreagilardoni Feb 21, 2024
e616374
removed FlashSHA256.h
andreagilardoni Apr 15, 2024
6258eb0
adjusting OTA.h
andreagilardoni Apr 15, 2024
8ac52a9
defining OTAInterface
andreagilardoni Apr 15, 2024
ddef056
renamed files containing implementation of OTA HAL functions
andreagilardoni Feb 21, 2024
6ae5393
added stub implementation of OTA HAL classes
andreagilardoni Mar 4, 2024
b010d91
implemented stm32h7 ota class
andreagilardoni Mar 25, 2024
86cbcab
implemented rp2040 ota class
andreagilardoni Feb 29, 2024
c7ed12b
implemented unor4 ota class
andreagilardoni Feb 29, 2024
7f9476c
implemented esp32 ota class
andreagilardoni Feb 29, 2024
60d2886
implemented samd ota class
andreagilardoni Feb 29, 2024
eb6311c
disabling ota on mkrgsm1400
andreagilardoni Mar 18, 2024
c4b0110
ArduinoIoTCloud integration
pennam Mar 15, 2024
7648544
Ota default interface: making the download run at least a configurabl…
andreagilardoni Apr 24, 2024
d79280a
Ota interface Default: adding download progress status report
andreagilardoni Apr 24, 2024
25e3252
Fix thing reconfiguration after wifi connection loss
pennam May 7, 2024
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
9 changes: 1 addition & 8 deletions .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
# Install the ArduinoIoTCloud library from the repository
- source-path: ./
- name: Arduino_ConnectionHandler
- name: ArduinoHttpClient
- name: Arduino_DebugUtils
- name: ArduinoMqttClient
- name: Arduino_SecureElement
Expand Down Expand Up @@ -169,7 +170,6 @@ jobs:
- name: arduino:mbed_portenta
libraries: |
- name: ArduinoECCX08
- name: Arduino_Portenta_OTA
sketch-paths: |
- examples/ArduinoIoTCloud-DeferredOTA
- examples/utility/Provisioning
Expand All @@ -180,7 +180,6 @@ jobs:
# Install mbed_nicla platform via Boards Manager
- name: arduino:mbed_nicla
libraries: |
- name: Arduino_Portenta_OTA
sketch-paths: |
- examples/ArduinoIoTCloud-DeferredOTA
- examples/utility/Provisioning
Expand All @@ -192,7 +191,6 @@ jobs:
- name: arduino:mbed_opta
libraries: |
- name: ArduinoECCX08
- name: Arduino_Portenta_OTA
sketch-paths: |
- examples/ArduinoIoTCloud-DeferredOTA
- examples/utility/Provisioning
Expand All @@ -204,7 +202,6 @@ jobs:
- name: arduino:mbed_giga
libraries: |
- name: ArduinoECCX08
- name: Arduino_Portenta_OTA
sketch-paths: |
- examples/ArduinoIoTCloud-DeferredOTA
- examples/utility/Provisioning
Expand All @@ -228,8 +225,6 @@ jobs:
platforms: |
# Install arduino_esp32 platform via Boards Manager
- name: arduino:esp32
libraries: |
- name: Arduino_ESP32_OTA
sketch-paths: |
- examples/ArduinoIoTCloud-DeferredOTA
# Edge Control
Expand All @@ -256,8 +251,6 @@ jobs:
# Install ESP32 platform via Boards Manager
- 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: |
- examples/ArduinoIoTCloud-DeferredOTA

Expand Down
5 changes: 5 additions & 0 deletions extras/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ set(TEST_SRCS
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
Expand All @@ -55,6 +57,9 @@ set(TEST_DUT_SRCS
../../src/property/PropertyContainer.cpp
../../src/cbor/CBORDecoder.cpp
../../src/cbor/CBOREncoder.cpp
../../src/cbor/MessageDecoder.cpp
../../src/cbor/MessageEncoder.cpp
../../src/cbor/CBOR.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
Expand Down
736 changes: 736 additions & 0 deletions extras/test/src/test_command_decode.cpp

Large diffs are not rendered by default.

322 changes: 322 additions & 0 deletions extras/test/src/test_command_encode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,322 @@
/*
Copyright (c) 2024 Arduino. All rights reserved.
*/

/******************************************************************************
INCLUDE
******************************************************************************/

#include <catch.hpp>

#include <memory>

#include <util/CBORTestUtil.h>
#include <MessageEncoder.h>

/******************************************************************************
TEST CODE
******************************************************************************/

SCENARIO("Test the encoding of command messages") {
/****************************************************************************/

WHEN("Encode the OtaBeginUp message")
{
OtaBeginUp command;
uint8_t sha[SHA256_SIZE] = {0x01, 0x02, 0x03, 0x04};
memcpy(command.params.sha, sha, SHA256_SIZE);

command.c.id = CommandId::OtaBeginUpId;

uint8_t buffer[512];
size_t bytes_encoded = sizeof(buffer);

CBORMessageEncoder encoder;
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);

uint8_t expected_result[] = {
0xda, 0x00, 0x01, 0x00, 0x00, 0x81, 0x58, 0x20,
0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

// Test the encoding is
// DA 00010000 # tag(65536)
// 81 # array(1)
// 58 20 # bytes(32)
// 01020304
THEN("The encoding is successful") {
REQUIRE(err == Encoder::Status::Complete);
REQUIRE(bytes_encoded == sizeof(expected_result));
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
}
}


/****************************************************************************/

WHEN("Encode the ThingBeginCmd message")
{
ThingBeginCmd command;
String thing_id = "thing_id";
strcpy(command.params.thing_id, thing_id.c_str());

command.c.id = CommandId::ThingBeginCmdId;

uint8_t buffer[512];
size_t bytes_encoded = sizeof(buffer);

CBORMessageEncoder encoder;
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);

uint8_t expected_result[] = {
0xda, 0x00, 0x01, 0x03, 0x00, 0x81, 0x68, 0x74,
0x68, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64
};

// Test the encoding is
// DA 00010300 # tag(66304)
// 81 # array(1)
// 68 # text(8)
// 7468696E675F6964 # "thing_id"

THEN("The encoding is successful") {
REQUIRE(err == Encoder::Status::Complete);
REQUIRE(bytes_encoded == sizeof(expected_result));
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
}
}

/****************************************************************************/

WHEN("Encode the LastValuesBeginCmd message")
{
LastValuesBeginCmd command;
command.c.id = CommandId::LastValuesBeginCmdId;

uint8_t buffer[512];
size_t bytes_encoded = sizeof(buffer);

CBORMessageEncoder encoder;
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);

uint8_t expected_result[] = {
0xda, 0x00, 0x01, 0x05, 0x00, 0x80
};

// Test the encoding is
// DA 00010500 # tag(66816)
// 80 # array(0)
THEN("The encoding is successful") {
REQUIRE(err == Encoder::Status::Complete);
REQUIRE(bytes_encoded == sizeof(expected_result));
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
}
}

/**************************************************************************/

WHEN("Encode the DeviceBeginCmd message")
{
DeviceBeginCmd command;
String lib_version = "2.0.0";
strcpy(command.params.lib_version, lib_version.c_str());

command.c.id = CommandId::DeviceBeginCmdId;

uint8_t buffer[512];
size_t bytes_encoded = sizeof(buffer);

CBORMessageEncoder encoder;
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);

uint8_t expected_result[] = {
0xda, 0x00, 0x01, 0x07, 0x00, 0x81, 0x65, 0x32,
0x2e, 0x30, 0x2e, 0x30
};

// Test the encoding is
// DA 00010700 # tag(67328)
// 81 # array(1)
// 65 # text(5)
// 322E302E30 # "2.0.0"
THEN("The encoding is successful") {
REQUIRE(err == Encoder::Status::Complete);
REQUIRE(bytes_encoded == sizeof(expected_result));
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
}
}

/****************************************************************************/

WHEN("Encode the OtaProgressCmdUp message")
{
OtaProgressCmdUp command;
command.params.time = 2;

uint8_t id[ID_SIZE] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
memcpy(command.params.id, id, ID_SIZE);
command.params.state = 1;
command.params.state_data = -1;
command.params.time = 100;

command.c.id = CommandId::OtaProgressCmdUpId;

uint8_t buffer[512];
size_t bytes_encoded = sizeof(buffer);

CBORMessageEncoder encoder;
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);

uint8_t expected_result[] = {
0xda, 0x00, 0x01, 0x02, 0x00, 0x84, 0x50, 0x00,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0xe1,
0x20, 0x18, 0x64
};

// Test the encoding is
// DA 00010200 # tag(66048)
// 84 # array(4)
// 50 # bytes(16)
// 000102030405060708090A0B0C0D0E0F # "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f"
// E1 # primitive(1)
// 20 # negative(0)
// 18 64 # unsigned(100)
THEN("The encoding is successful") {
REQUIRE(err == Encoder::Status::Complete);
REQUIRE(bytes_encoded == sizeof(expected_result));
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
}
}

/****************************************************************************/

WHEN("Encode the TimezoneCommandUp message")
{
TimezoneCommandUp command;
command.c.id = CommandId::TimezoneCommandUpId;

uint8_t buffer[512];
size_t bytes_encoded = sizeof(buffer);

CBORMessageEncoder encoder;
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);

uint8_t expected_result[] = {
0xda, 0x00, 0x01, 0x08, 0x00, 0x80
};

// Test the encoding is
// DA 00010800 # tag(67584)
// 80 # array(0)
THEN("The encoding is successful") {
REQUIRE(err == Encoder::Status::Complete);
REQUIRE(bytes_encoded == sizeof(expected_result));
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
}
}

/****************************************************************************/

WHEN("Encode the ThingUpdateCmdId message")
{
ThingUpdateCmd command;
command.c.id = CommandId::ThingUpdateCmdId;

String thing_id = "e4494d55-872a-4fd2-9646-92f87949394c";
strcpy(command.params.thing_id, thing_id.c_str());

uint8_t buffer[512];
size_t bytes_encoded = sizeof(buffer);

CBORMessageEncoder encoder;
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);

THEN("The encoding is unsuccessful - ThingUpdateCmdId is not supported") {
REQUIRE(err == Encoder::Status::Error);
}
}

/****************************************************************************/

WHEN("Encode the SetTimezoneCommand message")
{
TimezoneCommandDown command;
command.c.id = CommandId::TimezoneCommandDownId;

command.params.offset = 1708963873;
command.params.until = 2024579473;

uint8_t buffer[512];
size_t bytes_encoded = sizeof(buffer);

CBORMessageEncoder encoder;
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);

THEN("The encoding is unsuccessful - SetTimezoneCommand is not supported") {
REQUIRE(err == Encoder::Status::Error);
}
}

/****************************************************************************/

WHEN("Encode the LastValuesUpdateCmd message")
{
LastValuesUpdateCmd command;
command.c.id = CommandId::LastValuesUpdateCmdId;

command.params.length = 13;
uint8_t last_values[13] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x10, 0x11, 0x12};
command.params.last_values = last_values;

uint8_t buffer[512];
size_t bytes_encoded = sizeof(buffer);

CBORMessageEncoder encoder;
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);

THEN("The encoding is unsuccessful - LastValuesUpdateCmd is not supported") {
REQUIRE(err == Encoder::Status::Error);
}
}

/****************************************************************************/

WHEN("Encode the OtaUpdateCmdDown message")
{
OtaUpdateCmdDown command;
command.c.id = CommandId::OtaUpdateCmdDownId;

uint8_t buffer[512];
size_t bytes_encoded = sizeof(buffer);

CBORMessageEncoder encoder;
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);

THEN("The encoding is unsuccessful - OtaUpdateCmdDown is not supported") {
REQUIRE(err == Encoder::Status::Error);
}
}

/****************************************************************************/

WHEN("Encode a message with unknown command Id")
{
OtaUpdateCmdDown command;
command.c.id = CommandId::UnknownCmdId;

uint8_t buffer[512];
size_t bytes_encoded = sizeof(buffer);

CBORMessageEncoder encoder;
Encoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);

THEN("The encoding is unsuccessful - UnknownCmdId is not supported") {
REQUIRE(err == Encoder::Status::Error);
}
}
}
Loading
Loading