Code Monkey home page Code Monkey logo

astarte-device-sdk-esp32's People

Contributors

bettio avatar dependabot[bot] avatar drf avatar francescovaiani avatar harlem88 avatar matt-mazzucato avatar rbino avatar sorru94 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

astarte-device-sdk-esp32's Issues

Add checks on allowed endpoints parameters

The chars /, + and # should not be allowed in endpoint parameters.
This is due to MQTT specifications. As + and # are used as wildcards and / is used as a path separator.

Possible memory leak in `pairing`

Possible memory leak during the creation of the payload for the credentials request in the pairing API.
The data struct created with cJSON_CreateObject does not get deleted using cJSON_Delete.
Only the root parent gets deleted, but as specified in the cJSON documentation calling delete on an object does not delete its content.

cJSON *root = cJSON_CreateObject();
cJSON *data = cJSON_CreateObject();
cJSON_AddItemToObject(root, "data", data);
cJSON_AddStringToObject(data, "csr", csr);
payload = cJSON_PrintUnformatted(root);
cJSON_Delete(root);

Limited information on the interfaces

The struct astarte_interface_t contains all the information the libraries have regarding an existing interface.

typedef struct
{
const char *name; /**< Interface name */
int major_version; /**< Major version */
int minor_version; /**< Minor version */
astarte_interface_ownership_t ownership; /**< Ownership, see #astarte_interface_ownership_t */
astarte_interface_type_t type; /**< Type, see #astarte_interface_type_t */
} astarte_interface_t;

This is lacking information regarding the mappings. Subsequently, checks on the endpoint or payload validity are impossible.
Full validation could only be achieved with the complete interface specification available at runtime. This would require extending the astarte_interface_t struct to a full interface representation.
The extended struct could be filled in the source code by the application. However, this would be very error-prone requiring a lot of copy and paste from the json file used to install the interface in the Astarte instance.

An alternative would be to load in non-volatile memory the full json file and implement a deserialization utility that could parse the json file at runtime filling the struct dynamically.
To achieve this when using a FAT based file system the partition generator provided by ESP could be used.

Some credentials related functions are marked as "might change in the future" but miss a tracking issue

Some credentials functions are marked as "might change in the future" with the following message included in the docstring:

/*
* @brief store a credential using filesystem storage
*
* @details this API might change in future versions.
*/
astarte_err_t astarte_credentials_store(
void *opaque, enum credential_type_t cred_type, const void *credential, size_t length);

A tracking issue seems to be missing for those functions' status.

0.11 migration guide

When migrating to Astarte Device SDK ESP32 1.0 from 0.11 CONFIG_ASTARTE_HWID_ENABLE_UUID should be disabled, otherwise device id will be generated differently.
This step should be documented.

Add checks over the interfaces endpoint

The device knowledge regarding the interfaces is limited to name, version, ownership, and type.
It should be evaluated how to extend the knowledge of the device regarding the interfaces to include the endpoints of each interface.
This would allow checks to be performed before transmission.

Missing check over optional parameters

Some functions in the astarte BSON serializer use some of the arguments to provide outputs. However, they do not check the validity of such pointers.

const void *astarte_bson_serializer_get_document(
const struct astarte_bson_serializer_t *bs, int *size)
{
*size = bs->ba.size;
return bs->ba.buf;
}

Apart from being dangerous behaviour (considering as it's also not documented), this also makes it harder to use the API.
Users that do not require such outputs are forced to provide valid pointers anyway.

Export method to save/set credentials secret

In some use cases, the Credentials Secret might need to be set at runtime. As such, exporting the save_credentials_secret function (probably with a different name) would suffice to enable the user to autonomously set the credentials secret without resorting to build time configurations.

Add Empty Cache support

Astarte MQTT v1 strives to save bandwidth upon reconnections, to make sure even frequent reconnections don't affect bandwidth consumption. As such, upon connecting and if MQTT advertises a session present, both sides assume that data flow is ordered and consistent. However, there might be cases where this guarantee isn't respected by the device for a number of reasons (e.g.: new device, factory reset, cache lost...). In this case, a device might declare that it has no confidence about its status and its known properties, and can request to resynchronise entirely with Astarte.

In Astarte jargon this message is called empty cache and it is performed by publising 1 on the device /control/emptyCache topic.

After an empty cache message properties might be purged and Astarte might publish all the server owned properties again.

Enabling checks for clang-tidy

In #110 a series of checks have been disabled as they would generate warnings and block the CI.
The long-term objective is to re-enable some of those checks while fixing the generated warnings.
The list of checks that should be re-enabled is the following:

  • bugprone-macro-parentheses #139
    Ensures macros have parenthesis around their content.
  • bugprone-suspicious-string-compare #139
    Warns when using the result of strncmp() in a easy to misinterpret way.
  • cert-err33-c #150
    Forces to always use function results.
  • clang-analyzer-deadcode.DeadStores #139
    Warns when a value is assigned to a variable but never used.
  • clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling #139
    Identifies some obsolete and unsafe functions from the standard library. This check refers to functions not supported by the compiler we use, it should be ignored.
  • cppcoreguidelines-init-variables #145
    Warns when using uninitialized variables.
  • cppcoreguidelines-narrowing-conversions #148
    Warns on narrowing implicit conversion.
  • hicpp-signed-bitwise #146
    Warns on bitwise operations on signed numbers.
  • misc-unused-parameters #147
    Warns against dangling parameters.
  • readability-else-after-return #139
    Warns against useless else after a return.
  • readability-identifier-length #149
    Warns against too short identifiers.
  • readability-identifier-naming #151
    Sets some strict rules for naming of functions/variables/params/etc.
  • readability-inconsistent-declaration-parameter-name #139
    Warns when functions definition and declaration have different parameters names.
  • readability-magic-numbers #176
    Warns when magic numbers are used.
  • readability-uppercase-literal-suffix #139
    Warns when using literal suffices with non-capital letters (e.g. 1u is not ok, 1U is ok, 1 is ok).

The following rules are aliases for some of the rules above:

  • bugprone-narrowing-conversions (cppcoreguidelines-narrowing-conversions) #148
  • cppcoreguidelines-avoid-magic-numbers (readability-magic-numbers) #176
  • hicpp-uppercase-literal-suffix (readability-uppercase-literal-suffix) #139
  • llvm-else-after-return (readability-else-after-return) #139

Improve examples

The current example for this SDK presents the following problems:

  • No detailed how to start is present
  • Requires a button and an LED to be present on the board.
  • Only shows how to transmit/receive an individual datastream.

Missing documentation for `astarte_bson.h`

None of the functions in the astarte_bson.h file is documented, making them very difficult to use.

const void *astarte_bson_key_lookup(const char *key, const void *document, uint8_t *type);
void *astarte_bson_next_item(const void *document, const void *current_item);
const void *astarte_bson_first_item(const void *document);
const char *astarte_bson_key(const void *item);
const char *astarte_bson_value_to_string(const void *valuePtr, uint32_t *len);
const char *astarte_bson_value_to_binary(const void *valuePtr, uint32_t *len);
const void *astarte_bson_value_to_document(const void *valuePtr, uint32_t *len);
int8_t astarte_bson_value_to_int8(const void *valuePtr);
int32_t astarte_bson_value_to_int32(const void *valuePtr);
int64_t astarte_bson_value_to_int64(const void *valuePtr);
double astarte_bson_value_to_double(const void *valuePtr);
bool astarte_bson_check_validity(const void *document, unsigned int fileSize);
int32_t astarte_bson_document_size(const void *document);

N.B. These functions are to be used to parse a received BSON file.

Hardware ID generation with IDF v5.0

The hwid generated with IDF v5.0 is different compared to the one generated from previous versions of the IDF.
The issue spawns from the esp_chip_info function called in the astarte_hwid_get_id function.

esp_chip_info(&chip_info);

The field revision for the type esp_chip_info_t has changed content in this latest version of the ESP IDF.
In the newer version of the IDF the revision field contains the chip revision version, in the format MXX. Where M - wafer major version, XX - wafer minor version.
In previous versions of the IDF, only the major version was contained in the revision field.
Check out the related sections in the migration guide for more info.

Build error: enumeration value 'MQTT_EVENT_BEFORE_CONNECT' not handled in switch [-Werror=switch]

Hi,

Tried to build astarte-device-sdk-esp32 (master branch) SDK's 'toggle_led' example but the build system throws following error:
............................................................................................................................
astarte-device-sdk-esp32/astarte_device.c:554:5: error: enumeration value 'MQTT_EVENT_BEFORE_CONNECT' not handled in switch [-Werror=switch]
switch (event->event_id) {
^
cc1: some warnings being treated as errors
............................................................................................................................

Later, I tried to build the example from v0.10.0-rc.0 of the SDK but it results in the same error as above (after execution of 'make'). Please note that both the 'master' and 'v0.10.0-rc.0' versions of the SDK were built with the latest 'esp-idf'

Does the SDK example needs to be built with any specific snapshot of esp-idf? Please advice!

Thanks,
Sanju

Include in readme Free RTOS APIs usage

The Astarte ESP32 Device makes use of the free RTOS APIs.
Some of those APIs usage is relevant to developers using the Astarte ESP32 Device in their projects.
One example is the tasks spawned inside the device and the stack size they require to run.
Some information should be included in the README to ease integration.

Proposal moving the sources in a `src` folder

The sources are currently scattered around the main folder of this repository.
A cleaner configuration would be to move them into a dedicated folder called src.

See how this can be done in the PR related to the examples: #104.

Allow unsetting a property from the SDK

Right now the SDK doesn't allow to unset a property.
There are several approaches to achieve this:

  1. Add callback type *astarte_device_unset_event_callback_t.
  2. Change the bson_value_type received from server into BSON Type Null before call astarte_device_data_event_callback_t.
  3. etc...

Cluster upgrade caused device disconnection

A cluster upgrade from 0.11 to 1.0 caused a device disconnection (due to VMQ upgrade), and the device is not reconnecting.

Following output is displayed:

E (6312451) MQTT_CLIENT: Client has not connected
E (6312451) ASTARTE_DEVICE: Publish on test/gqaetex9L_V35MSPITlzlg/org.astarteplatform.esp32.DeviceDatastream/uptimeSeconds failed
E (6312551) esp-tls: mbedtls_ssl_handshake returned -0x50
E (6312561) esp-tls: Failed to open new connection
E (6312561) TRANS_SSL: Failed to open a new connection
E (6312561) MQTT_CLIENT: Error transport connect
I (6312571) ASTARTE_DEVICE: MQTT_EVENT_DISCONNECTED
I (6313371) ASTARTE_DEVICE: Publishing on test/gqaetex9L_V35MSPITlzlg/org.astarteplatform.esp32.DeviceDatastream/uptimeSeconds with QoS 0
E (6313371) MQTT_CLIENT: Client has not connected
E (6313371) ASTARTE_DEVICE: Publish on test/gqaetex9L_V35MSPITlzlg/org.astarteplatform.esp32.DeviceDatastream/uptimeSeconds failed
I (6314291) ASTARTE_DEVICE: Publishing on test/gqaetex9L_V35MSPITlzlg/org.astarteplatform.esp32.DeviceDatastream/uptimeSeconds with QoS 0
E (6314291) MQTT_CLIENT: Client has not connected
E (6314291) ASTARTE_DEVICE: Publish on test/gqaetex9L_V35MSPITlzlg/org.astarteplatform.esp32.DeviceDatastream/uptimeSeconds failed
I (6315221) ASTARTE_DEVICE: Publishing on test/gqaetex9L_V35MSPITlzlg/org.astarteplatform.esp32.DeviceDatastream/uptimeSeconds with QoS 0
E (6315221) MQTT_CLIENT: Client has not connected
E (6315221) ASTARTE_DEVICE: Publish on test/gqaetex9L_V35MSPITlzlg/org.astarteplatform.esp32.DeviceDatastream/uptimeSeconds failed
I (6316441) ASTARTE_DEVICE: Publishing on test/gqaetex9L_V35MSPITlzlg/org.astarteplatform.esp32.DeviceDatastream/uptimeSeconds with QoS 0
E (6316441) MQTT_CLIENT: Client has not connected
E (6316441) ASTARTE_DEVICE: Publish on test/gqaetex9L_V35MSPITlzlg/org.astarteplatform.esp32.DeviceDatastream/uptimeSeconds failed
I (6317371) ASTARTE_DEVICE: Publishing on test/gqaetex9L_V35MSPITlzlg/org.astarteplatform.esp32.DeviceDatastream/uptimeSeconds with QoS 0

astarte_device_start should return astarte_err_t

Right now the astarte_device_start function returns void, but it can actually fail (either because the reinit semaphore can't be taken or because esp_mqtt_client_start fails).

We should return an error value to notify the caller in case of failure.

Allow saving all credentials in the NVS

Right now the private key, CSR and Certificate are saved in a FAT partition. This is problematic in applications where the flash space is limited and there's no space for the astarte partition.

We should allow saving the private key, CSR and Certificate in the NVS if the users chooses to.

Introspection string is too long

Right now the SDK doesn't allow to send introspection string greater than 512 bytes.

  • Increase the introspection buffer.
  • Improve string introspection buffer measurement.

Simplify device by deleting task directly instead of sending a notification

The task astarte_device_reinit_task is terminated using a rtos notification from the main task.
This creates overhead and is more complex compared to deleting the task directly using vTaskDelete(task_handle).
The following:

xTaskNotify(ret->reinit_task_handle, NOTIFY_TERMINATE, eSetBits);

Could become:

        vTaskDelete(ret->reinit_task_handle);

Same for the other locations.

`uuid_to_string` misses a size parameter

The function uuid_to_string accepts a pointer to the buffer as a parameter. Such buffer is used to return the stringified UUID.
However, a parameter specifying the allocated memory for such a buffer is missing.
This could lead to writing out of the array's bounds if the allocated memory is insufficient.

Reinitializing Error, Repeated Restart

I have been using the astarte-device-sdk-esp32 for about a year now and I just updated to your recent sdk v0.11.4 for my project. There is a reinitialization issue where if the ESP32 loses its wifi signal and then gets it back it will reconnect to the wifi then 'reinitialize' and when it does this it gets stuck in a cycle where it will display 'MQTT_EVENT_CONNECTED' then 'MQTT_EVENT_DISCONNECTED' and will try to reinitialize again after it gets a 'Certificate error, notifying the reinit task' over and over. Once this starts then the device code will do this loop indefinitely until there is a hard reset.

I saw that in a older code version you had fixed this issue. Is there something that I am missing? If the device receives an MQTT EVENT during reinitialization will that cause it to go into an error state again and again?

Thank you,

I believe that I may have found the issue in my code. I will update you about this when I test some things out.

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.