diff --git a/controllers/api_v1_controllers.cc b/controllers/api_v1_controllers.cc index b4d4f96..61ecffb 100644 --- a/controllers/api_v1_controllers.cc +++ b/controllers/api_v1_controllers.cc @@ -1,5 +1,6 @@ #include #include +#include #include "api_v1_controllers.h" using namespace api::v1; @@ -86,6 +87,7 @@ controllers::put_one_by_id(const HttpRequestPtr &req, std::functionupdate()) { + controllers[0]->command(config::command_code_set_name, controllers[0]->name); resp = HttpResponse::newHttpJsonResponse(controllers[0]->to_json()); } else diff --git a/controllers/api_v1_devices_relays.cc b/controllers/api_v1_controllers_relays.cc similarity index 100% rename from controllers/api_v1_devices_relays.cc rename to controllers/api_v1_controllers_relays.cc diff --git a/models/controller_dbo.cc b/models/controller_dbo.cc index c4f5c7d..038dfe1 100644 --- a/models/controller_dbo.cc +++ b/models/controller_dbo.cc @@ -10,7 +10,10 @@ controller_dbo::~controller_dbo() { - relay_dbo::free_list(this->relays); + if(this->relays) + { + relay_dbo::free_list(this->relays); + } } static bool controller_db_update_insert(controller_dbo *controller, sqlite3_stmt *stmt) @@ -214,16 +217,18 @@ controller_dbo::get_by(helpers::sql_filter_builder **filters) bool controller_dbo::command(int command_code, const char *payload) { - char port[6]; - sprintf(port, "%d", this->port); + char port_str[6]; + sprintf(port_str, "%d", this->port); - int controller_socket = helpers::open_tcp_connection(this->ip, port); + int controller_socket = helpers::open_tcp_connection(this->ip, port_str); if(!controller_socket) { + LOG_ERROR << "Can't open command socket " << this->ip << ":" << port_str; return false; } + LOG_DEBUG << "Commanding (" << command_code << ") " << payload; send(controller_socket, &command_code, 1, 0); send(controller_socket, payload, strlen(payload), 0); close(controller_socket);