Move initialization of mqtt

This commit is contained in:
Andrew Pamment 2018-06-19 09:14:18 +10:00
parent 5853f46f5b
commit 50f4b9a5a8

View File

@ -882,24 +882,6 @@ void runbbs_real(int socket, char *ip, int ssh) {
int tries;
int fno;
// initialize mqtt
if (conf.broadcast_enable && conf.broadcast_address != NULL && conf.broadcast_port != 0) {
mosquitto_lib_init();
mosq = mosquitto_new(NULL, 1, NULL);
if (conf.broadcast_user != NULL && conf.broadcast_pass != NULL) {
mosquitto_username_pw_set(mosq, conf.broadcast_user, conf.broadcast_pass);
}
if(mosquitto_connect(mosq, conf.broadcast_address, conf.broadcast_port, 60)){
dolog("Unable to connect to MQTT server.");
conf.broadcast_enable = 0;
} else {
if (mosquitto_loop_start(mosq) != MOSQ_ERR_SUCCESS) {
dolog("Unable to start MQTT loop.");
conf.broadcast_enable = 0;
}
}
}
atexit(exit_bbs);
usertimeout = 10;
@ -978,6 +960,24 @@ void runbbs_real(int socket, char *ip, int ssh) {
exit(1);
}
// initialize mqtt
if (conf.broadcast_enable && conf.broadcast_address != NULL && conf.broadcast_port != 0) {
mosquitto_lib_init();
mosq = mosquitto_new(NULL, 1, NULL);
if (conf.broadcast_user != NULL && conf.broadcast_pass != NULL) {
mosquitto_username_pw_set(mosq, conf.broadcast_user, conf.broadcast_pass);
}
if(mosquitto_connect(mosq, conf.broadcast_address, conf.broadcast_port, 60)){
dolog("Unable to connect to MQTT server.");
conf.broadcast_enable = 0;
} else {
if (mosquitto_loop_start(mosq) != MOSQ_ERR_SUCCESS) {
dolog("Unable to start MQTT loop.");
conf.broadcast_enable = 0;
}
}
}
broadcast("USER: unknown; NODE:%d; STATUS: Logging in.", mynode);
dolog("Incoming %s connection on node %d", (ssh ? "SSH" : "Telnet"), mynode);