add: mqtt host config option
This commit is contained in:
parent
b2ac46c0fd
commit
eefe50b3cd
5 changed files with 12 additions and 8 deletions
|
@ -5,6 +5,7 @@ name = new emgauwa device
|
||||||
discovery-port = 4421
|
discovery-port = 4421
|
||||||
: 1886 for testing; 1885 for dev-env; 1884 for testing-env; 1883 for prod-env
|
: 1886 for testing; 1885 for dev-env; 1884 for testing-env; 1883 for prod-env
|
||||||
mqtt-port = 1885
|
mqtt-port = 1885
|
||||||
|
mqtt-host = localhost
|
||||||
|
|
||||||
relay-count = 10
|
relay-count = 10
|
||||||
database = controller_db.lmdb
|
database = controller_db.lmdb
|
||||||
|
|
|
@ -17,12 +17,13 @@ typedef struct
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char *file;
|
char *file;
|
||||||
char *database;
|
char database[256];
|
||||||
log_level_t log_level;
|
log_level_t log_level;
|
||||||
run_type_t run_type;
|
run_type_t run_type;
|
||||||
char name[MAX_NAME_LENGTH + 1];
|
char name[MAX_NAME_LENGTH + 1];
|
||||||
uint16_t discovery_port;
|
uint16_t discovery_port;
|
||||||
uint16_t mqtt_port;
|
uint16_t mqtt_port;
|
||||||
|
char mqtt_host[256];
|
||||||
uint8_t relay_count;
|
uint8_t relay_count;
|
||||||
config_relay_t *relay_configs;
|
config_relay_t *relay_configs;
|
||||||
} config_t;
|
} config_t;
|
||||||
|
|
|
@ -10,7 +10,7 @@ struct mg_connection *global_connection_mqtt;
|
||||||
struct mg_connection*
|
struct mg_connection*
|
||||||
connection_discovery_bind(struct mg_mgr *mgr)
|
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);
|
sprintf(address, "udp://0.0.0.0:%u", global_controller->discovery_port);
|
||||||
struct mg_connection *c = mg_bind(mgr, address, handler_discovery);
|
struct mg_connection *c = mg_bind(mgr, address, handler_discovery);
|
||||||
return c;
|
return c;
|
||||||
|
@ -19,7 +19,7 @@ connection_discovery_bind(struct mg_mgr *mgr)
|
||||||
struct mg_connection*
|
struct mg_connection*
|
||||||
connection_command_bind(struct mg_mgr *mgr)
|
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);
|
sprintf(address, "tcp://0.0.0.0:%u", global_controller->command_port);
|
||||||
struct mg_connection *c = mg_bind(mgr, address, handler_command);
|
struct mg_connection *c = mg_bind(mgr, address, handler_command);
|
||||||
return c;
|
return c;
|
||||||
|
@ -28,8 +28,8 @@ connection_command_bind(struct mg_mgr *mgr)
|
||||||
struct mg_connection*
|
struct mg_connection*
|
||||||
connection_mqtt_connect(struct mg_mgr *mgr)
|
connection_mqtt_connect(struct mg_mgr *mgr)
|
||||||
{
|
{
|
||||||
char address[100];
|
char address[512];
|
||||||
sprintf(address, "tcp://127.0.0.1:%u", global_config.mqtt_port);
|
sprintf(address, "tcp://%s:%u", global_config.mqtt_host, global_config.mqtt_port);
|
||||||
struct mg_connection *c = mg_connect(mgr, address, handler_mqtt);
|
struct mg_connection *c = mg_connect(mgr, address, handler_mqtt);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ helper_load_config(IniDispatch *disp, void *config_void)
|
||||||
}
|
}
|
||||||
if(CONFINI_IS_KEY("controller", "database"))
|
if(CONFINI_IS_KEY("controller", "database"))
|
||||||
{
|
{
|
||||||
config->database = malloc(sizeof(char) * (strlen(disp->value) + 1));
|
|
||||||
strcpy(config->database, disp->value);
|
strcpy(config->database, disp->value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -75,6 +74,11 @@ helper_load_config(IniDispatch *disp, void *config_void)
|
||||||
config->mqtt_port = atoi(disp->value);
|
config->mqtt_port = atoi(disp->value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if(CONFINI_IS_KEY("controller", "mqtt-host"))
|
||||||
|
{
|
||||||
|
strcpy(config->mqtt_host, disp->value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if(CONFINI_IS_KEY("controller", "relay-count"))
|
if(CONFINI_IS_KEY("controller", "relay-count"))
|
||||||
{
|
{
|
||||||
config->relay_count = atoi(disp->value);
|
config->relay_count = atoi(disp->value);
|
||||||
|
|
|
@ -43,8 +43,6 @@ terminate(int signum)
|
||||||
LOG_DEBUG("freeing global controller\n");
|
LOG_DEBUG("freeing global controller\n");
|
||||||
controller_free(global_controller);
|
controller_free(global_controller);
|
||||||
|
|
||||||
LOG_DEBUG("freeing database config\n");
|
|
||||||
free(global_config.database);
|
|
||||||
LOG_DEBUG("freeing relay configs config\n");
|
LOG_DEBUG("freeing relay configs config\n");
|
||||||
free(global_config.relay_configs);
|
free(global_config.relay_configs);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue