Skip to content

Commit

Permalink
Merge pull request #118 from harlem88/fw-release-1.0
Browse files Browse the repository at this point in the history
Forward changes from release 1.0
  • Loading branch information
sorru94 authored Apr 7, 2023
2 parents e7c7496 + 51084ad commit 27e4b91
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.0.5] - 2023-04-07
### Added
- Add Empty Cache support.

## [1.1.0] - 2023-02-23
### Added
- Add support to ESP-IDF v5.0
Expand Down
21 changes: 21 additions & 0 deletions astarte_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static astarte_err_t publish_data(astarte_device_handle_t device, const char *in
const char *path, const void *data, size_t length, int qos);
static void setup_subscriptions(astarte_device_handle_t device);
static void send_introspection(astarte_device_handle_t device);
static void send_emptycache(astarte_device_handle_t device);
static void on_connected(astarte_device_handle_t device, int session_present);
static void on_disconnected(astarte_device_handle_t device);
static void on_incoming(
Expand Down Expand Up @@ -355,6 +356,11 @@ astarte_err_t astarte_device_init_connection(
.client_cert_pem = client_cert_pem,
.client_key_pem = key_pem,
.user_context = device,
// TODO: At this time, the device starts with a clean session every connection,
// to change this behavior, it is necessary to enable disable_clean_session.
// Before enable it pay attention if the #issue-29 has been solved
// (see: https://github.com/astarte-platform/astarte-device-sdk-esp32/issues/29).
// .disable_clean_session = true,
};
#endif

Expand Down Expand Up @@ -978,6 +984,20 @@ static void setup_subscriptions(astarte_device_handle_t device)
}
}

static void send_emptycache(astarte_device_handle_t device)
{
if (check_device(device) != ASTARTE_OK) {
return;
}

esp_mqtt_client_handle_t mqtt = device->mqtt_client;

char topic[TOPIC_LENGTH];
snprintf(topic, TOPIC_LENGTH, "%s/control/emptyCache", device->device_topic);
ESP_LOGD(TAG, "Sending emptyCache to %s", topic);
esp_mqtt_client_publish(mqtt, topic, "1", 1, 2, 0);
}

static void on_connected(astarte_device_handle_t device, int session_present)
{
device->connected = true;
Expand All @@ -995,6 +1015,7 @@ static void on_connected(astarte_device_handle_t device, int session_present)

setup_subscriptions(device);
send_introspection(device);
send_emptycache(device);
}

static void on_disconnected(astarte_device_handle_t device)
Expand Down

0 comments on commit 27e4b91

Please sign in to comment.