From 3c57c4f3d9fff345198846817ac59caf4a1dba66 Mon Sep 17 00:00:00 2001 From: Masahiro NAKAI Date: Mon, 31 May 2021 08:40:12 +0900 Subject: [PATCH 1/3] Modified according to IoT Plug and Play rules --- src/azureiot/ReButtonClient2.cpp | 22 ++++++++++++++-------- src/azureiot/ReButtonClient2.h | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/azureiot/ReButtonClient2.cpp b/src/azureiot/ReButtonClient2.cpp index b2d1feb..8f190fb 100644 --- a/src/azureiot/ReButtonClient2.cpp +++ b/src/azureiot/ReButtonClient2.cpp @@ -170,9 +170,10 @@ void ReButtonClient2::ReceivedProperties(JSON_Object* reportedObject) void ReButtonClient2::ReceivedSettings(JSON_Object* desiredObject, bool complete) { - if (strlen(Config.CustomMessagePropertyName) >= 1 && json_object_dothas_value_of_type(desiredObject, stringformat("%s.value", Config.CustomMessagePropertyName).c_str(), JSONBoolean)) + if (strlen(Config.CustomMessagePropertyName) >= 1 && json_object_dothas_value_of_type(desiredObject, stringformat("%s", Config.CustomMessagePropertyName).c_str(), JSONBoolean)) { - int customMessageEnable = json_object_dotget_boolean(desiredObject, stringformat("%s.value", Config.CustomMessagePropertyName).c_str()); + int customMessageEnable = json_object_dotget_boolean(desiredObject, stringformat("%s", Config.CustomMessagePropertyName).c_str()); + int version = json_object_dotget_number(desiredObject, "$version"); switch (customMessageEnable) { case 1: @@ -186,26 +187,29 @@ void ReButtonClient2::ReceivedSettings(JSON_Object* desiredObject, bool complete Serial.print("CustomMessageEnable = "); Serial.println(CustomMessageEnable ? "true" : "false"); - SendPropertyCustomMessageEnableAsync(); + SendPropertyCustomMessageEnableAsync(200, version); } - if (json_object_dothas_value_of_type(desiredObject, stringformat("%s.value", PROPERTY_TELEMETRY_INTERVAL).c_str(), JSONNumber)) + if (json_object_dothas_value_of_type(desiredObject, stringformat("%s", PROPERTY_TELEMETRY_INTERVAL).c_str(), JSONNumber)) { - TelemetryInterval = json_object_dotget_number(desiredObject, stringformat("%s.value", PROPERTY_TELEMETRY_INTERVAL).c_str()); + TelemetryInterval = json_object_dotget_number(desiredObject, stringformat("%s", PROPERTY_TELEMETRY_INTERVAL).c_str()); + int version = json_object_dotget_number(desiredObject, "$version"); Serial.print("TelemetryInterval = "); Serial.println(TelemetryInterval); - SendPropertyTelemetryIntervalAsync(); + SendPropertyTelemetryIntervalAsync(200, version); } } -void ReButtonClient2::SendPropertyCustomMessageEnableAsync() +void ReButtonClient2::SendPropertyCustomMessageEnableAsync(int ackCode, int ackVersion) { JSON_Value* reportedValue = json_value_init_object(); JSON_Object* reportedObject = json_value_get_object(reportedValue); json_object_dotset_boolean(reportedObject, Config.CustomMessagePropertyName, CustomMessageEnable); + json_object_dotset_number(reportedObject, "ac", ackCode); + json_object_dotset_number(reportedObject, "av", ackVersion); AzureDeviceClient::UpdateReportedPropertyAsync(reportedObject); @@ -224,12 +228,14 @@ void ReButtonClient2::SendPropertyActionCountAsync() json_value_free(reportedValue); } -void ReButtonClient2::SendPropertyTelemetryIntervalAsync() +void ReButtonClient2::SendPropertyTelemetryIntervalAsync(int ackCode, int ackVersion) { JSON_Value* reportedValue = json_value_init_object(); JSON_Object* reportedObject = json_value_get_object(reportedValue); json_object_dotset_number(reportedObject, PROPERTY_TELEMETRY_INTERVAL, TelemetryInterval); + json_object_dotset_number(reportedObject, "ac", ackCode); + json_object_dotset_number(reportedObject, "av", ackVersion); AzureDeviceClient::UpdateReportedPropertyAsync(reportedObject); diff --git a/src/azureiot/ReButtonClient2.h b/src/azureiot/ReButtonClient2.h index 206f1a8..f81646d 100644 --- a/src/azureiot/ReButtonClient2.h +++ b/src/azureiot/ReButtonClient2.h @@ -34,9 +34,9 @@ class ReButtonClient2 : public AzureDeviceClient void ReceivedProperties(JSON_Object* reportedObject); void ReceivedSettings(JSON_Object* desiredObject, bool complete); - void SendPropertyCustomMessageEnableAsync(); + void SendPropertyCustomMessageEnableAsync(int ackCode, int ackVersion); void SendPropertyActionCountAsync(); - void SendPropertyTelemetryIntervalAsync(); + void SendPropertyTelemetryIntervalAsync(int ackCode, int ackVersion); protected: virtual void DeviceTwinReceived(JSON_Object* deviceTwinObject); From 871aa9f208f7c1ddb00f7df6079ef3a135dcd5ec Mon Sep 17 00:00:00 2001 From: Masahiro NAKAI Date: Mon, 31 May 2021 19:14:26 +0900 Subject: [PATCH 2/3] fix reported format --- src/azureiot/ReButtonClient2.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/azureiot/ReButtonClient2.cpp b/src/azureiot/ReButtonClient2.cpp index 8f190fb..588756a 100644 --- a/src/azureiot/ReButtonClient2.cpp +++ b/src/azureiot/ReButtonClient2.cpp @@ -207,9 +207,9 @@ void ReButtonClient2::SendPropertyCustomMessageEnableAsync(int ackCode, int ackV JSON_Value* reportedValue = json_value_init_object(); JSON_Object* reportedObject = json_value_get_object(reportedValue); - json_object_dotset_boolean(reportedObject, Config.CustomMessagePropertyName, CustomMessageEnable); - json_object_dotset_number(reportedObject, "ac", ackCode); - json_object_dotset_number(reportedObject, "av", ackVersion); + json_object_dotset_boolean(reportedObject, stringformat("%s.value", Config.CustomMessagePropertyName).c_str(), CustomMessageEnable); + json_object_dotset_number(reportedObject, stringformat("%s.ac", Config.CustomMessagePropertyName).c_str(), ackCode); + json_object_dotset_number(reportedObject, stringformat("%s.av", Config.CustomMessagePropertyName).c_str(), ackVersion); AzureDeviceClient::UpdateReportedPropertyAsync(reportedObject); @@ -233,9 +233,9 @@ void ReButtonClient2::SendPropertyTelemetryIntervalAsync(int ackCode, int ackVer JSON_Value* reportedValue = json_value_init_object(); JSON_Object* reportedObject = json_value_get_object(reportedValue); - json_object_dotset_number(reportedObject, PROPERTY_TELEMETRY_INTERVAL, TelemetryInterval); - json_object_dotset_number(reportedObject, "ac", ackCode); - json_object_dotset_number(reportedObject, "av", ackVersion); + json_object_dotset_number(reportedObject, stringformat("%s.value", PROPERTY_TELEMETRY_INTERVAL).c_str(), TelemetryInterval); + json_object_dotset_number(reportedObject, stringformat("%s.ac", PROPERTY_TELEMETRY_INTERVAL).c_str(), ackCode); + json_object_dotset_number(reportedObject, stringformat("%s.av", PROPERTY_TELEMETRY_INTERVAL).c_str(), ackVersion); AzureDeviceClient::UpdateReportedPropertyAsync(reportedObject); From 33616a009a4ba98b716c558c0d9aa09aef06507b Mon Sep 17 00:00:00 2001 From: Masahiro NAKAI Date: Thu, 1 Jul 2021 14:28:55 +0900 Subject: [PATCH 3/3] Added acknowledgement description(ad) on reported property --- src/azureiot/ReButtonClient2.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/azureiot/ReButtonClient2.cpp b/src/azureiot/ReButtonClient2.cpp index 588756a..4fe8c45 100644 --- a/src/azureiot/ReButtonClient2.cpp +++ b/src/azureiot/ReButtonClient2.cpp @@ -210,6 +210,8 @@ void ReButtonClient2::SendPropertyCustomMessageEnableAsync(int ackCode, int ackV json_object_dotset_boolean(reportedObject, stringformat("%s.value", Config.CustomMessagePropertyName).c_str(), CustomMessageEnable); json_object_dotset_number(reportedObject, stringformat("%s.ac", Config.CustomMessagePropertyName).c_str(), ackCode); json_object_dotset_number(reportedObject, stringformat("%s.av", Config.CustomMessagePropertyName).c_str(), ackVersion); + json_object_dotset_string(reportedObject, stringformat("%s.ad", Config.CustomMessagePropertyName).c_str(), + stringformat("Successfully updated %s", Config.CustomMessagePropertyName).c_str()); AzureDeviceClient::UpdateReportedPropertyAsync(reportedObject); @@ -236,6 +238,8 @@ void ReButtonClient2::SendPropertyTelemetryIntervalAsync(int ackCode, int ackVer json_object_dotset_number(reportedObject, stringformat("%s.value", PROPERTY_TELEMETRY_INTERVAL).c_str(), TelemetryInterval); json_object_dotset_number(reportedObject, stringformat("%s.ac", PROPERTY_TELEMETRY_INTERVAL).c_str(), ackCode); json_object_dotset_number(reportedObject, stringformat("%s.av", PROPERTY_TELEMETRY_INTERVAL).c_str(), ackVersion); + json_object_dotset_string(reportedObject, stringformat("%s.ad", PROPERTY_TELEMETRY_INTERVAL).c_str(), + stringformat("Successfully updated %s", PROPERTY_TELEMETRY_INTERVAL).c_str()); AzureDeviceClient::UpdateReportedPropertyAsync(reportedObject);