From e1e92a7045e56d72e0335ae46937667c2fa9bccb Mon Sep 17 00:00:00 2001 From: "ethan.du" Date: Mon, 6 Jul 2020 17:39:45 +0800 Subject: [PATCH 1/2] modify dev model sample same as extend sample --- samples/dev_model/dev_model_sample.c | 33 ++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/samples/dev_model/dev_model_sample.c b/samples/dev_model/dev_model_sample.c index 6b8f4ae..2dcd41b 100644 --- a/samples/dev_model/dev_model_sample.c +++ b/samples/dev_model/dev_model_sample.c @@ -86,9 +86,28 @@ int property_post_cb(const char *request_id, const int ret_code){ return SUCCESS_RET; } +int g_set_temp_correct = 0; int command_cb(const char *request_id, const char *identifier, const char *input, char *output){ LOG_INFO("command_cb; request_id: %s; identifier: %s; input: %s", request_id, identifier, input); - HAL_Snprintf(output, 1000, "{\"result\":%d}", 1); + int temp = 0; + if((strlen(identifier) == strlen("set_temp_correction")) && (0 == strncmp(identifier, "set_temp_correction", strlen("set_temp_correction")))) + { + char *set_temp_correction_temp_correction = NULL; + set_temp_correction_temp_correction = LITE_json_value_of((char *)"temp_correction", (char *)input); + temp = atoi(set_temp_correction_temp_correction); + HAL_Free(set_temp_correction_temp_correction); + } + + if((temp <= 5) + && (temp >= -5)) + { + g_set_temp_correct = temp; + HAL_Snprintf(output, 100, "\"effect_temp_correction\":%d, \"correction_result\":%d", g_set_temp_correct, 0); + } + else + { + HAL_Snprintf(output, 100, "\"effect_temp_correction\":%d, \"correction_result\":%d", g_set_temp_correct, 1); + } return SUCCESS_RET; } @@ -144,10 +163,16 @@ int main(int argc, char **argv) IOT_DM_RegisterCallback(PROPERTY_SET , h_dm, property_set_cb); IOT_DM_Yield(h_dm, 200); + char *property_payload = (char *)HAL_Malloc(100); + char *event_payload = (char *)HAL_Malloc(100); for (i = 0; i < 20; i++) { - IOT_DM_Property_Report(h_dm, PROPERTY_POST, i * 2, "\"volume\": {\"Value\":50}"); - IOT_DM_TriggerEvent(h_dm, i * 2 + 1, "low_power_alert", "\"power\": 5"); - + HAL_Snprintf(property_payload, 100, "\"humidity\": {\"Value\": %d}, \"temperature\": {\"Value\": %d}", i*5 + g_set_temp_correct, i*3); + IOT_DM_Property_Report(h_dm, PROPERTY_POST, i * 2, property_payload); + if(i * 5 + g_set_temp_correct >= 80) + { + HAL_Snprintf(event_payload, 100, "\"temperature\": %d", i*5 + g_set_temp_correct); + IOT_DM_TriggerEvent(h_dm, i * 2 + 1, "high_temp", event_payload); + } IOT_DM_Yield(h_dm, 200); HAL_SleepMs(2000); } From 78523be2694639e2d52c191bc57af03c95d36338 Mon Sep 17 00:00:00 2001 From: "ethan.du" Date: Mon, 6 Jul 2020 17:41:44 +0800 Subject: [PATCH 2/2] add free in dev model sample --- samples/dev_model/dev_model_sample.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/dev_model/dev_model_sample.c b/samples/dev_model/dev_model_sample.c index 2dcd41b..d995c48 100644 --- a/samples/dev_model/dev_model_sample.c +++ b/samples/dev_model/dev_model_sample.c @@ -177,6 +177,8 @@ int main(int argc, char **argv) HAL_SleepMs(2000); } + HAL_Free(property_payload); + HAL_Free(event_payload); //等待属性设置及命令下发 IOT_DM_Yield(h_dm, 60000);