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

Dev adding toggle value and housemode changed from #122

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ezlopi-core/ezlopi-core-api/ezlopi_core_api_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ CLOUD_METHOD("hub.network.get", network_get, NULL)
CLOUD_METHOD("hub.network.wifi.scan.start", network_wifi_scan_start, NULL)
CLOUD_METHOD("hub.network.wifi.scan.stop", network_wifi_scan_stop, NULL)

#ifdef CONFIG_EZPI_ENABLE_OTA
#if defined(CONFIG_EZPI_ENABLE_OTA)
CLOUD_METHOD("cloud.firmware.info.get", firmware_info_get, NULL)
CLOUD_METHOD("hub.firmware.update.start", firmware_update_start, NULL)
#endif // CONFIG_EZPI_ENABLE_OTA
#endif //CONFIG_EZPI_ENABLE_OTA

CLOUD_METHOD("hub.device.settings.list", ezlopi_device_settings_list_v3, NULL)
CLOUD_METHOD("hub.device.setting.value.set", ezlopi_device_settings_value_set_v3, NULL)
Expand All @@ -61,7 +61,7 @@ CLOUD_METHOD("hub.time.location.list", EZPI_CLOUD_location_list, NULL)
CLOUD_METHOD("hub.time.location.set", EZPI_CLOUD_location_set, NULL)
CLOUD_METHOD("hub.time.location.get", EZPI_CLOUD_location_get, NULL)

#ifdef CONFIG_EZPI_SERV_ENABLE_MESHBOTS
#if defined(CONFIG_EZPI_SERV_ENABLE_MESHBOTS)
CLOUD_METHOD("hub.scenes.list", scenes_list, NULL)
CLOUD_METHOD("hub.scenes.create", scenes_create, scene_added)
CLOUD_METHOD("hub.scenes.run", scenes_run, NULL)
Expand All @@ -75,7 +75,7 @@ CLOUD_METHOD("hub.scenes.notification.add", scenes_notification_add, scene_chang
CLOUD_METHOD("hub.scenes.notification.remove", scenes_notification_remove, scene_changed)
CLOUD_METHOD("hub.scenes.status.get", scenes_status_get, NULL) // Incomplete
CLOUD_METHOD("hub.scenes.block.status.reset", scenes_block_status_reset, NULL)
#endif // CONFIG_EZPI_SERV_MESHBOT_EN
#endif //CONFIG_EZPI_SERV_ENABLE_MESHBOTS

CLOUD_METHOD("hub.room.list", room_list, NULL)
CLOUD_METHOD("hub.room.create", room_create, room_created)
Expand All @@ -85,7 +85,7 @@ CLOUD_METHOD("hub.room.get", room_get, NULL)
CLOUD_METHOD("hub.room.delete", room_delete, room_deleted)
CLOUD_METHOD("hub.room.all.delete", room_all_delete, NULL)

#ifdef CONFIG_EZPI_SERV_ENABLE_MESHBOTS
#if defined(CONFIG_EZPI_SERV_ENABLE_MESHBOTS)
CLOUD_METHOD("hub.scenes.scripts.list", scenes_scripts_list, NULL)
CLOUD_METHOD("hub.scenes.scripts.add", scenes_scripts_add, NULL)
CLOUD_METHOD("hub.scenes.scripts.get", scenes_scripts_get, NULL)
Expand All @@ -96,7 +96,7 @@ CLOUD_METHOD("hub.scenes.scripts.run", scenes_scripts_run, NULL)
CLOUD_METHOD("hub.scenes.expressions.set", scenes_expressions_set, NULL)
CLOUD_METHOD("hub.scenes.expressions.list", scenes_expressions_list, NULL)
CLOUD_METHOD("hub.scenes.expressions.delete", scenes_expressions_delete, NULL)
#endif // CONFIG_EZPI_SERV_MESHBOT_EN
#endif //CONFIG_EZPI_SERV_ENABLE_MESHBOTS

CLOUD_METHOD("hub.nma.register.repeat", register_repeat, NULL)

Expand Down
2 changes: 1 addition & 1 deletion ezlopi-core/ezlopi-core-ezlopi/ezlopi_core_ezlopi.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void ezlopi_init(void)
ezlopi_scenes_scripts_init();
ezlopi_scenes_expressions_init();
ezlopi_scenes_init_v2();
#endif // CONFIG_EZPI_SERV_MESHBOT_EN
#endif // CONFIG_EZPI_SERV_ENABLE_MESHBOTS

#if defined(CONFIG_EZPI_CORE_ENABLE_ETH)
ezlopi_ethernet_init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int ezlopi_core_ezlopi_broadcast_add_to_queue(cJSON* cj_data)
return ret;
}

void ezlopi_core_broadcast_log_cjson(cJSON* cj_log_data)
int ezlopi_core_broadcast_log_cjson(cJSON* cj_log_data)
{
int ret = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ void ezlopi_core_ezlopi_broadcast_remove_method(f_broadcast_method_t broadcast_m
void ezlopi_core_ezlopi_broadcast_methods_set_queue(int (*func)(cJSON*));
l_broadcast_method_t* ezlopi_core_ezlopi_broadcast_method_add(f_broadcast_method_t broadcast_method, char* method_name, uint32_t retries);

void ezlopi_core_broadcast_log_cjson(cJSON* cj_log_data);
int ezlopi_core_broadcast_log_cjson(cJSON* cj_log_data);

#endif // __EZLOPI_CORE_EZLOPI_BROADCAST_H__
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ extern "C"
\"id_item\": 2,\
\"gpio_in\": 0,\
\"gpio_out\": 25,\
\"gpio_out\": 25,\
\"pullup_ip\": false,\
\"pullup_op\": false,\
\"is_ip\": false,\
Expand Down
8 changes: 6 additions & 2 deletions ezlopi-core/ezlopi-core-http/ezlopi_core_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,19 @@ void ezlopi_core_http_mbedtls_req(s_ezlopi_core_http_mbedtls_t* config)

// Ready-Up 'request' buffer
TRACE_I("request[capacity: %d]:\n\n%s[%d]", request_len, request, strlen(request));
TRACE_D("Minimum free heap size: %d bytes\n", esp_get_minimum_free_heap_size());
TRACE_E("&result==[%p]", &(config->response));
// TRACE_D("Minimum free heap size: %d bytes\n", esp_get_minimum_free_heap_size());
// TRACE_E("&result==[%p]", &(config->response));
ezlopi_core_http_request_via_mbedTLS(config->web_server, (config->web_port), request, &(config->response));
if (config->response)
{
TRACE_D("*result[%p] =>\n[%d]\n%s", config->response, strlen(config->response), config->response);
free(config->response); // return to destination buffer
config->response = NULL;
}
else
{
TRACE_E("*http_result => NULL");
}
free(request);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void ezlopi_scenes_populate_scene(l_scenes_list_v2_t* new_scene, cJSON* cj_scene
new_scene->task_handle = NULL;
new_scene->status = EZLOPI_SCENE_STATUS_STOPPED;

CJSON_GET_VALUE_DOUBLE(cj_scene, ezlopi_enabled_str, new_scene->enabled);
CJSON_GET_VALUE_BOOL(cj_scene, ezlopi_enabled_str, new_scene->enabled);
CJSON_GET_VALUE_DOUBLE(cj_scene, ezlopi_is_group_str, new_scene->is_group);

CJSON_GET_VALUE_STRING_BY_COPY(cj_scene, ezlopi_group_id_str, new_scene->group_id);
Expand Down
80 changes: 34 additions & 46 deletions ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_then_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,6 @@ int ezlopi_scene_then_toggle_value(l_scenes_list_v2_t* curr_scene, void* arg)
{
TRACE_W(" toggle_value ");
int ret = 0;
#if 0
if (curr_scene)
{
uint32_t item_id = 0; /* item */
Expand Down Expand Up @@ -574,60 +573,50 @@ int ezlopi_scene_then_toggle_value(l_scenes_list_v2_t* curr_scene, void* arg)
{
if (curr_item->func(EZLOPI_ACTION_GET_EZLOPI_VALUE, curr_item, (void*)cj_tmp_value, NULL))
{
CJSON_TRACE("value", cj_tmp_value)/*value formatted & value only*/
}
else
{
TRACE_E("here");
}
CJSON_TRACE("present_gpio_value", cj_tmp_value);/*value formatted & value only*/

cJSON* cj_val = cJSON_GetObjectItem(cj_tmp_value, ezlopi_value_str);
cJSON* cj_valuetype = cJSON_GetObjectItem(cj_tmp_value, ezlopi_valueType_str);
if (cj_val && cj_valuetype)
{
TRACE_W("here");
cJSON* cj_result_value = cJSON_CreateObject();
if (cj_result_value)
cJSON* cj_val = cJSON_GetObjectItem(cj_tmp_value, ezlopi_value_str);
if (cj_val)
{

cJSON_AddStringToObject(cj_result_value, ezlopi__id_str, __id_string);
if (0 == strncmp(cj_valuetype->valuestring, value_type_bool, 6))
cJSON* cj_result_value = cJSON_CreateObject();
if (cj_result_value)
{
TRACE_S("1. getting 'item_id[%d]' ; bool_value = %s ", item_id, cj_val->valuestring); // "false" or "true"
if (0 == strncmp(cj_val->valuestring, "false", 6))
cJSON_AddStringToObject(cj_result_value, ezlopi__id_str, __id_string);
if ((0 == strncmp(curr_item->cloud_properties.value_type, value_type_bool, 5)) && cJSON_IsBool(cj_val))
{
cJSON_AddBoolToObject(cj_result_value, ezlopi_value_str, true);
TRACE_S("1. getting 'item_id[%d]' ; bool_value = %s ", item_id, (cj_val->type == cJSON_True) ? "true" : "false"); // "false" or "true"
if (cj_val->type == cJSON_True)
{
cJSON_AddBoolToObject(cj_result_value, ezlopi_value_str, true);
}
else if (cj_val->type == cJSON_False)
{
cJSON_AddBoolToObject(cj_result_value, ezlopi_value_str, false);
}
ret = 1;
curr_item->func(EZLOPI_ACTION_SET_VALUE, curr_item, cj_result_value, curr_item->user_arg);
}
else
else if ((0 == strncmp(curr_item->cloud_properties.value_type, value_type_int, 4)) && cJSON_IsNumber(cj_val))
{
cJSON_AddBoolToObject(cj_result_value, ezlopi_value_str, false);
TRACE_S("2. getting 'item_id[%d]' ; int_value = %d ", item_id, (int)cj_val->valuedouble);
if (cj_val->valuedouble == 0) // either '0' or '1'.
{
cJSON_AddNumberToObject(cj_result_value, ezlopi_value_str, 1);
}
else if (cj_val->valuedouble == 1)
{
cJSON_AddNumberToObject(cj_result_value, ezlopi_value_str, 0);
}
ret = 1;
curr_item->func(EZLOPI_ACTION_SET_VALUE, curr_item, cj_result_value, curr_item->user_arg);
}
TRACE_W("here");
ret = 1;
curr_item->func(EZLOPI_ACTION_SET_VALUE, curr_item, cj_result_value, curr_item->user_arg);
}
else if (0 == strncmp(cj_valuetype->valuestring, value_type_int, 6))
{
TRACE_S("2. getting 'item_id[%d]' ; int_value = %d ", item_id, (int)cj_val->valuedouble);
if (cj_val->valuedouble == 0) // either '0' or '1'.
{
cJSON_AddNumberToObject(cj_result_value, ezlopi_value_str, 1);
}
else if (cj_val->valuedouble == 1)
else
{
cJSON_AddNumberToObject(cj_result_value, ezlopi_value_str, 0);
ret = 0;
TRACE_E(" 'item_id[%d]' neither 'boolean' nor 'int' ; Value-type mis-matched! ", item_id);
}

TRACE_W("here");
ret = 1;
curr_item->func(EZLOPI_ACTION_SET_VALUE, curr_item, cj_result_value, curr_item->user_arg);
}
else
{
ret = 0;
TRACE_E(" 'item_id[%d]' neither 'boolean' nor 'int' ; Value-type mis-matched! ", item_id);
cJSON_Delete(cj_result_value);
}
cJSON_Delete(cj_result_value);
}
}
}
Expand Down Expand Up @@ -658,7 +647,6 @@ int ezlopi_scene_then_toggle_value(l_scenes_list_v2_t* curr_scene, void* arg)
}
}
}
#endif
return ret;
}
#endif // CONFIG_EZPI_SERV_ENABLE_MESHBOTS
37 changes: 17 additions & 20 deletions ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_when_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,22 @@ int ezlopi_scene_when_is_button_state(l_scenes_list_v2_t* scene_node, void* arg)

int ezlopi_scene_when_is_sun_state(l_scenes_list_v2_t* scene_node, void* arg)
{
// TRACE_W(" is_SunState ");
TRACE_W(" is_SunState ");
int ret = 0;
l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;
if (when_block && scene_node)
{
if (0 < ezlopi_event_group_wait_for_event(EZLOPI_EVENT_NMA_REG, 100, false))
{
return 0;
}

time_t rawtime = 0;
time(&rawtime);
struct tm* info;
info = localtime(&rawtime);


// list of function for extracting field parameter
const s_issunstate_method_t __issunstate_field[] = {
{.field_name = "sunrise", .field_func = issunstate_get_suntime},
Expand Down Expand Up @@ -416,8 +422,8 @@ int ezlopi_scene_when_is_house_mode_changed_to(l_scenes_list_v2_t* scene_node, v
{
ret = 1;
}
house_mode_id_array->user_arg = (void*)house_mode_id;
TRACE_E("house-mode-changed-to: %d", house_mode_id);
house_mode_id_array->user_arg = (void*)house_mode_id; // updates every evaluation
// TRACE_E("house-mode-changed-to: %d", house_mode_id);
}
}
}
Expand All @@ -430,7 +436,6 @@ int ezlopi_scene_when_is_house_mode_changed_from(l_scenes_list_v2_t* scene_node,
{
TRACE_W(" isHouse_mode_changed_from");
int ret = 0;
#if 0
l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;

if (when_block)
Expand All @@ -457,21 +462,25 @@ int ezlopi_scene_when_is_house_mode_changed_from(l_scenes_list_v2_t* scene_node,
{
if (cj_house_mode_id->valuestring)
{
uint32_t house_mode_id = strtoul(cj_house_mode_id->valuestring, NULL, 16);
uint32_t house_mode_id = strtoul(cj_house_mode_id->valuestring, NULL, 16); // "value": [ "1", "2"]
s_ezlopi_modes_t* modes = ezlopi_core_modes_get_custom_modes();
if ((uint32_t)house_mode_id_array->user_arg != modes->current_mode_id) /* first check if there is transition */
{
if ((uint32_t)house_mode_id_array->user_arg == house_mode_id) /* if : old_state == desired */
{
ret = 1;
house_mode_id_array->user_arg = (void*)house_mode_id; // updates every evaluation
break;
}
else
{
house_mode_id_array->user_arg = (void*)house_mode_id; // updates every evaluation
}
house_mode_id_array->user_arg = (void*)house_mode_id;
TRACE_E("house-mode-changed-to: %d", house_mode_id);
// TRACE_E("house-mode-changed-to: %d", house_mode_id);
}
}
}
}
#endif
return ret;
}

Expand Down Expand Up @@ -539,7 +548,6 @@ int ezlopi_scene_when_is_House_Mode_Switch_to_Range(l_scenes_list_v2_t* scene_no
int ezlopi_scene_when_is_device_state(l_scenes_list_v2_t* scene_node, void* arg)
{
TRACE_W(" isDevice_state. ");
// TRACE_W("Warning: when-method 'is_device_state' not implemented!");
int ret = 0;

l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;
Expand Down Expand Up @@ -605,7 +613,6 @@ int ezlopi_scene_when_is_network_state(l_scenes_list_v2_t* scene_node, void* arg
int ezlopi_scene_when_is_scene_state(l_scenes_list_v2_t* scene_node, void* arg)
{
TRACE_W(" isScene_state ");
// TRACE_W("Warning: when-method 'is_scene_state' not implemented!");
int ret = 0;
l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;
if (when_block && scene_node)
Expand Down Expand Up @@ -690,7 +697,6 @@ int ezlopi_scene_when_is_group_state(l_scenes_list_v2_t* scene_node, void* arg)

int ezlopi_scene_when_is_cloud_state(l_scenes_list_v2_t* scene_node, void* arg)
{
// TRACE_W(" isCloud_state ");
int ret = 0;
l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;
if (when_block && scene_node)
Expand All @@ -714,12 +720,10 @@ int ezlopi_scene_when_is_cloud_state(l_scenes_list_v2_t* scene_node, void* arg)
if (0 < ezlopi_event_group_wait_for_event(EZLOPI_EVENT_NMA_REG, 100, false))
{
ret = (0 == strncmp(value_field->field_value.u_value.value_string, "connected", 10));
// TRACE_S("NMA_CONNECTED, ret = %d", ret);
}
else
{
ret = (0 == strncmp(value_field->field_value.u_value.value_string, "disconnected", 14));
// TRACE_S("NMA_DISCONNECTED, ret = %d", ret);
}
}
}
Expand Down Expand Up @@ -894,7 +898,6 @@ int ezlopi_scene_when_compare_number_range(l_scenes_list_v2_t* scene_node, void*
int ezlopi_scene_when_compare_strings(l_scenes_list_v2_t* scene_node, void* arg)
{
TRACE_W(" Compare_strings ");
// TRACE_W("Warning: when-method 'compare_strings' not implemented!");
int ret = 0;
l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;
if (when_block && scene_node)
Expand Down Expand Up @@ -954,7 +957,6 @@ int ezlopi_scene_when_compare_strings(l_scenes_list_v2_t* scene_node, void* arg)
int ezlopi_scene_when_string_operation(l_scenes_list_v2_t* scene_node, void* arg)
{
TRACE_W(" Compare_string_op ");
// TRACE_W("Warning: when-method 'string_operation' not implemented!");
int ret = 0;
l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;
if (when_block && scene_node)
Expand Down Expand Up @@ -1012,7 +1014,6 @@ int ezlopi_scene_when_string_operation(l_scenes_list_v2_t* scene_node, void* arg
int ezlopi_scene_when_in_array(l_scenes_list_v2_t* scene_node, void* arg)
{
TRACE_W(" Compare_inArray ");
// TRACE_W("Warning: when-method 'in_array' not implemented!");
int ret = 0;
l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;
if (when_block && scene_node)
Expand Down Expand Up @@ -1068,7 +1069,6 @@ int ezlopi_scene_when_in_array(l_scenes_list_v2_t* scene_node, void* arg)
int ezlopi_scene_when_compare_values(l_scenes_list_v2_t* scene_node, void* arg)
{
TRACE_W(" Compare_values ");
// TRACE_W("Warning: when-method 'is_group_state' not implemented!");
int ret = 0;
l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;
if (when_block && scene_node)
Expand Down Expand Up @@ -1135,7 +1135,6 @@ int ezlopi_scene_when_compare_values(l_scenes_list_v2_t* scene_node, void* arg)
int ezlopi_scene_when_has_atleast_one_dictionary_value(l_scenes_list_v2_t* scene_node, void* arg)
{
TRACE_W(" atleast_one_diction_val ");
// TRACE_W("Warning: when-method 'atleast_one_dictionary_value' not implemented!");
int ret = 0;
l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;
if (scene_node && when_block)
Expand Down Expand Up @@ -1175,7 +1174,6 @@ int ezlopi_scene_when_has_atleast_one_dictionary_value(l_scenes_list_v2_t* scene
int ezlopi_scene_when_is_firmware_update_state(l_scenes_list_v2_t* scene_node, void* arg)
{
TRACE_W(" firmware_update ");
// TRACE_W("Warning: when-method 'firmware_update_state' not implemented!");
int ret = 0;
#ifdef CONFIG_EZPI_ENABLE_OTA
l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;
Expand Down Expand Up @@ -1221,7 +1219,6 @@ int ezlopi_scene_when_is_firmware_update_state(l_scenes_list_v2_t* scene_node, v
int ezlopi_scene_when_is_dictionary_changed(l_scenes_list_v2_t* scene_node, void* arg)
{
TRACE_W(" isDictionary_changed ");
// TRACE_W("Warning: when-method 'is_dictionary_changed' not implemented!");
int ret = 0;
l_when_block_v2_t* when_block = (l_when_block_v2_t*)arg;
if (scene_node && when_block)
Expand Down
Loading