add: mqtt host config option

This commit is contained in:
Tobias Reisinger 2020-07-14 20:43:58 +02:00
parent b2ac46c0fd
commit eefe50b3cd
5 changed files with 12 additions and 8 deletions

View file

@ -5,6 +5,7 @@ name = new emgauwa device
discovery-port = 4421
: 1886 for testing; 1885 for dev-env; 1884 for testing-env; 1883 for prod-env
mqtt-port = 1885
mqtt-host = localhost
relay-count = 10
database = controller_db.lmdb

View file

@ -17,12 +17,13 @@ typedef struct
typedef struct
{
char *file;
char *database;
char database[256];
log_level_t log_level;
run_type_t run_type;
char name[MAX_NAME_LENGTH + 1];
uint16_t discovery_port;
uint16_t mqtt_port;
char mqtt_host[256];
uint8_t relay_count;
config_relay_t *relay_configs;
} config_t;

View file

@ -10,7 +10,7 @@ struct mg_connection *global_connection_mqtt;
struct mg_connection*
connection_discovery_bind(struct mg_mgr *mgr)
{
char address[100];
char address[32];
sprintf(address, "udp://0.0.0.0:%u", global_controller->discovery_port);
struct mg_connection *c = mg_bind(mgr, address, handler_discovery);
return c;
@ -19,7 +19,7 @@ connection_discovery_bind(struct mg_mgr *mgr)
struct mg_connection*
connection_command_bind(struct mg_mgr *mgr)
{
char address[100];
char address[32];
sprintf(address, "tcp://0.0.0.0:%u", global_controller->command_port);
struct mg_connection *c = mg_bind(mgr, address, handler_command);
return c;
@ -28,8 +28,8 @@ connection_command_bind(struct mg_mgr *mgr)
struct mg_connection*
connection_mqtt_connect(struct mg_mgr *mgr)
{
char address[100];
sprintf(address, "tcp://127.0.0.1:%u", global_config.mqtt_port);
char address[512];
sprintf(address, "tcp://%s:%u", global_config.mqtt_host, global_config.mqtt_port);
struct mg_connection *c = mg_connect(mgr, address, handler_mqtt);
return c;
}

View file

@ -26,7 +26,6 @@ helper_load_config(IniDispatch *disp, void *config_void)
}
if(CONFINI_IS_KEY("controller", "database"))
{
config->database = malloc(sizeof(char) * (strlen(disp->value) + 1));
strcpy(config->database, disp->value);
return 0;
}
@ -75,6 +74,11 @@ helper_load_config(IniDispatch *disp, void *config_void)
config->mqtt_port = atoi(disp->value);
return 0;
}
if(CONFINI_IS_KEY("controller", "mqtt-host"))
{
strcpy(config->mqtt_host, disp->value);
return 0;
}
if(CONFINI_IS_KEY("controller", "relay-count"))
{
config->relay_count = atoi(disp->value);

View file

@ -43,8 +43,6 @@ terminate(int signum)
LOG_DEBUG("freeing global controller\n");
controller_free(global_controller);
LOG_DEBUG("freeing database config\n");
free(global_config.database);
LOG_DEBUG("freeing relay configs config\n");
free(global_config.relay_configs);