fix: store IP on rediscover

This commit is contained in:
Tobias Reisinger 2020-08-20 11:37:21 +02:00
parent 73033354b5
commit 435110e61d
3 changed files with 10 additions and 9 deletions

View file

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project(core
VERSION 0.2.16
VERSION 0.2.17
LANGUAGES C)
add_executable(core src/main.c)

View file

@ -228,10 +228,11 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
{
if(uuid_compare(known_controllers[i]->uid, discovered_id) == 0)
{
LOGGER_DEBUG("rediscovered a known controller\n");
LOGGER_DEBUG("rediscovered a known controller at %s\n", inet_ntoa(addr.sin_addr));
known_controllers[i]->active = 1;
strncpy(known_controllers[i]->name, discovered_name, discovered_name_len);
strcpy(discovered_controller->ip, inet_ntoa(addr.sin_addr));
known_controllers[i]->name[discovered_name_len] = '\0';
known_controllers[i]->port = discovered_command_port;
known_controllers[i]->relay_count = discovered_relay_count;
@ -251,7 +252,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
if(!found_discovered_in_list)
{
LOGGER_DEBUG("discovered a new controller\n");
LOGGER_DEBUG("discovered a new controller at %s\n", inet_ntoa(addr.sin_addr));
controller_t *discovered_controller = malloc(sizeof(controller_t));
discovered_controller->id = 0;

View file

@ -59,7 +59,7 @@ status_init()
void
status_reload_entry(int relay_id)
{
LOGGER_DEBUG("reloading relay status\n");
LOGGER_DEBUG("reloading relay %d\n", relay_id);
relay_t **relays = global_relay_status_list;
for(int i = 0; relays[i] != NULL; ++i)
{
@ -70,13 +70,13 @@ status_reload_entry(int relay_id)
int is_on_backup = relays[i]->is_on;
relay_t *updated_relay = relay_get_by_id(relay_id);
updated_relay->is_on = is_on_backup;
relay_free(relays[i]);
relays[i] = updated_relay;
relays[i]->is_on = is_on_backup;
invalidate_json_str_cache();
cache_invalidate_relay(relay_id);
invalidate_json_str_cache();
}
}
@ -91,11 +91,11 @@ status_update_entry(int relay_id, int is_on)
{
continue;
}
relays[i]->is_on = is_on;
invalidate_json_str_cache();
cache_invalidate_relay(relay_id);
invalidate_json_str_cache();
}
}