Skip to content
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

ArduinoCloudTCP: Separate the logic of the device and the logic of the thing in two different state machines #425

Closed

Conversation

mirkokurt
Copy link
Collaborator

@mirkokurt mirkokurt commented Feb 16, 2024

This PR aims to separate the logic of the device (connect to the physical network, connect to MQTT, connect to device topics...) from the logic of the thing (receive the thing id, connect to the thing topics, sync and send telemetry) splitting the whole connection logic in two different state machines.

To achieve this, a new ArduinoIoTCloudTCPThing class has been created as member of the ArduinoIoTCloudTCP class.
The new class implement a state machine dedicated to the thing logic. The device logic has been kept in the ArduinoIoTCloudTCP.

From the user perspective, the only difference is that now the device state machine is not blocked anymore waiting the thing id when the thing id is not provided by the backend. The device state machine is independent from the thing configuration and, theoretically, is able to perform an OTA even if not attached to a thing (theoretically because the backend does not allow this).

From the developer perspective, this refactor allows a better logical separation of behaviours, improved readability and maintainability, and it's preparatory to future enhancements of the OTA feature.

@CLAassistant
Copy link

CLAassistant commented Feb 16, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

codecov bot commented Feb 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c2a9992) 95.00% compared to head (63ff024) 95.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #425   +/-   ##
=======================================
  Coverage   95.00%   95.00%           
=======================================
  Files          27       27           
  Lines        1221     1221           
=======================================
  Hits         1160     1160           
  Misses         61       61           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

Memory usage change @ e745256

Board flash % RAM for global variables %
esp8266:esp8266:huzzah 🔺 +1988 - +2044 +0.19 - +0.2 🔺 +384 - +400 +0.47 - +0.49
Click for full report table
Board examples/ArduinoIoTCloud-Advanced
flash
% examples/ArduinoIoTCloud-Advanced
RAM for global variables
% examples/ArduinoIoTCloud-Basic
flash
% examples/ArduinoIoTCloud-Basic
RAM for global variables
% examples/ArduinoIoTCloud-Callbacks
flash
% examples/ArduinoIoTCloud-Callbacks
RAM for global variables
% examples/ArduinoIoTCloud-Schedule
flash
% examples/ArduinoIoTCloud-Schedule
RAM for global variables
% examples/utility/ArduinoIoTCloud_Travis_CI
flash
% examples/utility/ArduinoIoTCloud_Travis_CI
RAM for global variables
%
esp8266:esp8266:huzzah 1996 0.19 400 0.49 2012 0.19 400 0.49 2044 0.2 384 0.47 1988 0.19 396 0.48 1996 0.19 400 0.49
Click for full report CSV
Board,examples/ArduinoIoTCloud-Advanced<br>flash,%,examples/ArduinoIoTCloud-Advanced<br>RAM for global variables,%,examples/ArduinoIoTCloud-Basic<br>flash,%,examples/ArduinoIoTCloud-Basic<br>RAM for global variables,%,examples/ArduinoIoTCloud-Callbacks<br>flash,%,examples/ArduinoIoTCloud-Callbacks<br>RAM for global variables,%,examples/ArduinoIoTCloud-Schedule<br>flash,%,examples/ArduinoIoTCloud-Schedule<br>RAM for global variables,%,examples/utility/ArduinoIoTCloud_Travis_CI<br>flash,%,examples/utility/ArduinoIoTCloud_Travis_CI<br>RAM for global variables,%
esp8266:esp8266:huzzah,1996,0.19,400,0.49,2012,0.19,400,0.49,2044,0.2,384,0.47,1988,0.19,396,0.48,1996,0.19,400,0.49

@mirkokurt mirkokurt marked this pull request as ready for review February 19, 2024 13:10
@mirkokurt mirkokurt force-pushed the mirkokurt/arduino-iot-infra branch from 8b8e483 to 5675efc Compare February 19, 2024 15:00

#ifndef ARDUINO_AIOTC_TYPES_H_
#define ARDUINO_AIOTC_TYPES_H_

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <stdint.h>

TYPEDEF
******************************************************************************/

typedef enum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
typedef enum
typedef enum: uint8_t

We don't need and entire int32 to represent the R/W modes

Copy link

Memory usage change @ 63ff024

Board flash % RAM for global variables %
arduino:mbed_edge:edge_control 🔺 +1192 - +1264 +0.12 - +0.13 🔺 +320 - +328 +0.12 - +0.13
arduino:mbed_giga:giga 🔺 +1000 - +1512 +0.05 - +0.08 🔺 +320 - +352 +0.06 - +0.07
arduino:mbed_nano:nanorp2040connect 🔺 +989 - +1484 +0.01 - +0.01 🔺 +328 - +328 +0.12 - +0.12
arduino:mbed_nicla:nicla_vision 🔺 +992 - +1512 +0.05 - +0.08 🔺 +320 - +352 +0.06 - +0.07
arduino:mbed_opta:opta 🔺 +936 - +1512 +0.05 - +0.08 🔺 +320 - +352 +0.06 - +0.07
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
arduino:renesas_portenta:portenta_c33 🔺 +888 - +1320 +0.04 - +0.06 🔺 +320 - +320 +0.06 - +0.06
arduino:renesas_uno:unor4wifi 🔺 +1192 - +1320 +0.45 - +0.5 🔺 +328 - +328 +1.0 - +1.0
arduino:samd:mkr1000 🔺 +872 - +1344 +0.33 - +0.51 🔺 +320 - +320 +0.98 - +0.98
arduino:samd:mkrgsm1400 🔺 +880 - +1352 +0.34 - +0.52 🔺 +328 - +328 +1.0 - +1.0
arduino:samd:mkrnb1500 🔺 +872 - +1352 +0.33 - +0.52 🔺 +320 - +320 +0.98 - +0.98
arduino:samd:mkrwan1300 🔺 +728 - +984 +0.28 - +0.38 🔺 +48 - +64 +0.15 - +0.2
arduino:samd:mkrwifi1010 🔺 +904 - +1392 +0.34 - +0.53 🔺 +328 - +328 +1.0 - +1.0
arduino:samd:nano_33_iot 🔺 +904 - +1392 +0.34 - +0.53 🔺 +328 - +328 +1.0 - +1.0
esp8266:esp8266:huzzah 🔺 +1572 - +1708 +0.15 - +0.16 🔺 +368 - +380 +0.45 - +0.46
Click for full report table
Board examples/ArduinoIoTCloud-Advanced
flash
% examples/ArduinoIoTCloud-Advanced
RAM for global variables
% examples/ArduinoIoTCloud-Basic
flash
% examples/ArduinoIoTCloud-Basic
RAM for global variables
% examples/ArduinoIoTCloud-Callbacks
flash
% examples/ArduinoIoTCloud-Callbacks
RAM for global variables
% examples/ArduinoIoTCloud-Schedule
flash
% examples/ArduinoIoTCloud-Schedule
RAM for global variables
% examples/utility/ArduinoIoTCloud_Travis_CI
flash
% examples/utility/ArduinoIoTCloud_Travis_CI
RAM for global variables
% examples/ArduinoIoTCloud-DeferredOTA
flash
% examples/ArduinoIoTCloud-DeferredOTA
RAM for global variables
% examples/utility/Provisioning
flash
% examples/utility/Provisioning
RAM for global variables
% examples/utility/SelfProvisioning
flash
% examples/utility/SelfProvisioning
RAM for global variables
%
arduino:mbed_edge:edge_control 1192 0.12 328 0.13 1264 0.13 320 0.12 1256 0.13 328 0.13 1192 0.12 328 0.13 1192 0.12 320 0.12
arduino:mbed_giga:giga 1384 0.07 352 0.07 1448 0.07 352 0.07 1512 0.08 320 0.06 1320 0.07 320 0.06 1376 0.07 320 0.06 1448 0.07 320 0.06 1000 0.05 320 0.06
arduino:mbed_nano:nanorp2040connect 1386 0.01 328 0.12 1474 0.01 328 0.12 1482 0.01 328 0.12 1386 0.01 328 0.12 1408 0.01 328 0.12 1484 0.01 328 0.12 989 0.01 328 0.12 989 0.01 328 0.12
arduino:mbed_nicla:nicla_vision 1320 0.07 320 0.06 1448 0.07 352 0.07 1448 0.07 320 0.06 1320 0.07 352 0.07 1320 0.07 352 0.07 1512 0.08 320 0.06 992 0.05 320 0.06
arduino:mbed_opta:opta 1320 0.07 320 0.06 1448 0.07 352 0.07 1512 0.08 320 0.06 1320 0.07 352 0.07 1376 0.07 352 0.07 1448 0.07 320 0.06 936 0.05 320 0.06
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A
arduino:renesas_portenta:portenta_c33 1176 0.06 320 0.06 1312 0.06 320 0.06 1320 0.06 320 0.06 1184 0.06 320 0.06 1200 0.06 320 0.06 888 0.04 320 0.06
arduino:renesas_uno:unor4wifi 1192 0.45 328 1.0 1304 0.5 328 1.0 1320 0.5 328 1.0 1200 0.46 328 1.0 1192 0.45 328 1.0
arduino:samd:mkr1000 1256 0.48 320 0.98 1336 0.51 320 0.98 1344 0.51 320 0.98 1256 0.48 320 0.98 1280 0.49 320 0.98 872 0.33 320 0.98
arduino:samd:mkrgsm1400 1264 0.48 328 1.0 1352 0.52 328 1.0 1352 0.52 328 1.0 1264 0.48 328 1.0 1280 0.49 328 1.0 880 0.34 328 1.0
arduino:samd:mkrnb1500 1256 0.48 320 0.98 1344 0.51 320 0.98 1352 0.52 320 0.98 1256 0.48 320 0.98 1272 0.49 320 0.98 872 0.33 320 0.98
arduino:samd:mkrwan1300 744 0.28 64 0.2 752 0.29 64 0.2 984 0.38 48 0.15 728 0.28 48 0.15 784 0.3 48 0.15
arduino:samd:mkrwifi1010 1296 0.49 328 1.0 1376 0.52 328 1.0 1392 0.53 328 1.0 1296 0.49 328 1.0 1320 0.5 328 1.0 1392 0.53 328 1.0 912 0.35 328 1.0 904 0.34 328 1.0
arduino:samd:nano_33_iot 1296 0.49 328 1.0 1376 0.52 328 1.0 1392 0.53 328 1.0 1296 0.49 328 1.0 1320 0.5 328 1.0 1392 0.53 328 1.0 904 0.34 328 1.0 912 0.35 328 1.0
esp8266:esp8266:huzzah 1580 0.15 368 0.45 1692 0.16 368 0.45 1708 0.16 368 0.45 1572 0.15 380 0.46 1596 0.15 368 0.45
Click for full report CSV
Board,examples/ArduinoIoTCloud-Advanced<br>flash,%,examples/ArduinoIoTCloud-Advanced<br>RAM for global variables,%,examples/ArduinoIoTCloud-Basic<br>flash,%,examples/ArduinoIoTCloud-Basic<br>RAM for global variables,%,examples/ArduinoIoTCloud-Callbacks<br>flash,%,examples/ArduinoIoTCloud-Callbacks<br>RAM for global variables,%,examples/ArduinoIoTCloud-Schedule<br>flash,%,examples/ArduinoIoTCloud-Schedule<br>RAM for global variables,%,examples/utility/ArduinoIoTCloud_Travis_CI<br>flash,%,examples/utility/ArduinoIoTCloud_Travis_CI<br>RAM for global variables,%,examples/ArduinoIoTCloud-DeferredOTA<br>flash,%,examples/ArduinoIoTCloud-DeferredOTA<br>RAM for global variables,%,examples/utility/Provisioning<br>flash,%,examples/utility/Provisioning<br>RAM for global variables,%,examples/utility/SelfProvisioning<br>flash,%,examples/utility/SelfProvisioning<br>RAM for global variables,%
arduino:mbed_edge:edge_control,1192,0.12,328,0.13,1264,0.13,320,0.12,1256,0.13,328,0.13,1192,0.12,328,0.13,1192,0.12,320,0.12
arduino:mbed_giga:giga,1384,0.07,352,0.07,1448,0.07,352,0.07,1512,0.08,320,0.06,1320,0.07,320,0.06,1376,0.07,320,0.06,1448,0.07,320,0.06,1000,0.05,320,0.06
arduino:mbed_nano:nanorp2040connect,1386,0.01,328,0.12,1474,0.01,328,0.12,1482,0.01,328,0.12,1386,0.01,328,0.12,1408,0.01,328,0.12,1484,0.01,328,0.12,989,0.01,328,0.12,989,0.01,328,0.12
arduino:mbed_nicla:nicla_vision,1320,0.07,320,0.06,1448,0.07,352,0.07,1448,0.07,320,0.06,1320,0.07,352,0.07,1320,0.07,352,0.07,1512,0.08,320,0.06,992,0.05,320,0.06,,,,
arduino:mbed_opta:opta,1320,0.07,320,0.06,1448,0.07,352,0.07,1512,0.08,320,0.06,1320,0.07,352,0.07,1376,0.07,352,0.07,1448,0.07,320,0.06,936,0.05,320,0.06,,,,
arduino:mbed_portenta:envie_m7,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,,,,
arduino:renesas_portenta:portenta_c33,1176,0.06,320,0.06,1312,0.06,320,0.06,1320,0.06,320,0.06,1184,0.06,320,0.06,1200,0.06,320,0.06,,,,,888,0.04,320,0.06,,,,
arduino:renesas_uno:unor4wifi,1192,0.45,328,1.0,1304,0.5,328,1.0,1320,0.5,328,1.0,1200,0.46,328,1.0,1192,0.45,328,1.0,,,,,,,,,,,,
arduino:samd:mkr1000,1256,0.48,320,0.98,1336,0.51,320,0.98,1344,0.51,320,0.98,1256,0.48,320,0.98,1280,0.49,320,0.98,,,,,872,0.33,320,0.98,,,,
arduino:samd:mkrgsm1400,1264,0.48,328,1.0,1352,0.52,328,1.0,1352,0.52,328,1.0,1264,0.48,328,1.0,1280,0.49,328,1.0,,,,,880,0.34,328,1.0,,,,
arduino:samd:mkrnb1500,1256,0.48,320,0.98,1344,0.51,320,0.98,1352,0.52,320,0.98,1256,0.48,320,0.98,1272,0.49,320,0.98,,,,,872,0.33,320,0.98,,,,
arduino:samd:mkrwan1300,744,0.28,64,0.2,752,0.29,64,0.2,984,0.38,48,0.15,728,0.28,48,0.15,784,0.3,48,0.15,,,,,,,,,,,,
arduino:samd:mkrwifi1010,1296,0.49,328,1.0,1376,0.52,328,1.0,1392,0.53,328,1.0,1296,0.49,328,1.0,1320,0.5,328,1.0,1392,0.53,328,1.0,912,0.35,328,1.0,904,0.34,328,1.0
arduino:samd:nano_33_iot,1296,0.49,328,1.0,1376,0.52,328,1.0,1392,0.53,328,1.0,1296,0.49,328,1.0,1320,0.5,328,1.0,1392,0.53,328,1.0,904,0.34,328,1.0,912,0.35,328,1.0
esp8266:esp8266:huzzah,1580,0.15,368,0.45,1692,0.16,368,0.45,1708,0.16,368,0.45,1572,0.15,380,0.46,1596,0.15,368,0.45,,,,,,,,,,,,

@pennam pennam closed this Mar 5, 2024
@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants