|
@@ -101,7 +101,7 @@ int bel_prolong_time = 0;
|
|
|
float bel_wave_out_level = 0;
|
|
|
float bel_wave_in_level = 0;
|
|
|
int bel_blink_time = 0;
|
|
|
-
|
|
|
+bool mqtt_activate=false;
|
|
|
char* bel_mqtt_server;
|
|
|
char* bel_mqtt_client_id;
|
|
|
char* bel_mqtt_user_id;
|
|
@@ -196,6 +196,11 @@ public:
|
|
|
token=token;
|
|
|
std::cout << "Message delivered" << std::endl;
|
|
|
}
|
|
|
+ void message_arrived (mqtt::const_message_ptr msg) override
|
|
|
+ {
|
|
|
+ std::cout << "Message arrived: " << msg->get_payload_str() << std::endl;
|
|
|
+ mqtt_activate=true;
|
|
|
+ }
|
|
|
};
|
|
|
void* mqtt_control_thread(void*){
|
|
|
string address = bel_mqtt_server,
|
|
@@ -216,6 +221,8 @@ void* mqtt_control_thread(void*){
|
|
|
connOpts.set_user_name(username);
|
|
|
connOpts.set_password(password);
|
|
|
connOpts.set_ssl(ssl_options);
|
|
|
+
|
|
|
+ connOpts.set_automatic_reconnect(10, 40);
|
|
|
struct timespec ts;
|
|
|
try
|
|
|
{
|
|
@@ -224,7 +231,8 @@ void* mqtt_control_thread(void*){
|
|
|
|
|
|
mqtt::token_ptr connectionToken = client.connect(connOpts);
|
|
|
connectionToken->wait();
|
|
|
-
|
|
|
+ mqtt::token_ptr subToken = client.subscribe(TOPIC2, QOS);
|
|
|
+ subToken->wait();
|
|
|
while (true)
|
|
|
{
|
|
|
int sem_try=0;
|
|
@@ -239,9 +247,13 @@ void* mqtt_control_thread(void*){
|
|
|
Json::Value event;
|
|
|
event["sq"]=temp_mess.sq;
|
|
|
event["freq"]=temp_mess.freq;
|
|
|
+ event["name"]=temp_mess.name;
|
|
|
+ event["mountpoint"]=temp_mess.mountpoint;
|
|
|
Json::StreamWriterBuilder builder;
|
|
|
- mqtt::message_ptr pubMessage = mqtt::make_message(TOPIC1,Json::writeString(builder, event), QOS, false);
|
|
|
- client.publish(pubMessage)->wait();
|
|
|
+ if (client.is_connected()){
|
|
|
+ mqtt::message_ptr pubMessage = mqtt::make_message(TOPIC1,Json::writeString(builder, event), QOS, false);
|
|
|
+ client.publish(pubMessage)->wait();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -266,12 +278,12 @@ void* belysning_control_thread(void*){
|
|
|
bool sq_status = false;
|
|
|
long int audio_start_time=0;
|
|
|
bool active=false;
|
|
|
+
|
|
|
int status_data_temp=0;
|
|
|
gettimeofday(&tv, 0);
|
|
|
start_time=tv.tv_sec;
|
|
|
stop_time=tv.tv_sec+1;
|
|
|
while (!do_exit) {
|
|
|
- //double t;
|
|
|
status_data=status_data;
|
|
|
int sem_try=0;
|
|
|
bool activate=false;
|
|
@@ -312,9 +324,10 @@ void* belysning_control_thread(void*){
|
|
|
}
|
|
|
gettimeofday(&tv, 0);
|
|
|
//First time activation
|
|
|
- if (active==false && activate==true){
|
|
|
+ if ((active==false && activate==true) || mqtt_activate){
|
|
|
start_time=tv.tv_sec;
|
|
|
stop_time=tv.tv_sec+bel_start_on_time;
|
|
|
+ mqtt_activate=false;
|
|
|
active=true;
|
|
|
if (tui)
|
|
|
printf("Start\n");
|
|
@@ -920,7 +933,8 @@ void* demodulate(void* params) {
|
|
|
mqtt_msg.audio =(audio_status << 1);
|
|
|
mqtt_msg.sq = squelch_status;
|
|
|
mqtt_msg.freq = channel->freqlist->frequency;
|
|
|
-
|
|
|
+ mqtt_msg.name = fparms->label;
|
|
|
+ mqtt_msg.mountpoint = fparms->mountpoint;
|
|
|
if (sem_wait(&mutex_unlock_main_thread_mqtt) == -1){
|
|
|
perror ("sem_post: mutex_unlock_main_thread"); exit (1);
|
|
|
}
|