Browse Source

Added support for remote

Per Mårtensson 2 weeks ago
parent
commit
a7eb0e5d85
4 changed files with 37 additions and 11 deletions
  1. 6 4
      rtl_airband.conf
  2. 7 0
      src/config.cpp
  3. 21 7
      src/rtl_airband.cpp
  4. 3 0
      src/rtl_airband.h

+ 6 - 4
rtl_airband.conf

@@ -6,9 +6,9 @@ bel_wave_out_level = 0.1;
 bel_wave_in_level = 10.0;
 bel_blink_time = 60;
 bel_mqtt_server = "icecast.westfly.se";
-bel_mqtt_client_id = "0";
-bel_mqtt_user_id = "xxxxx";
-bel_mqtt_password = "xxxxxx";
+bel_mqtt_client_id = "3";
+bel_mqtt_user_id = "SE0001";
+bel_mqtt_password = "dsfj458asdjla923A1";
 pidfile = "/tmp/rtl_airband.pid";
 devices: (
   {
@@ -24,13 +24,15 @@ devices: (
 	      squelch_threshold = -48;
         banbel = 1;
         modulation = "am";
+        label = "ESXX 123.350";
+        mountpoint = "ESXX.mp3";
         outputs: (
           {
             type = "icecast";
             server = "icecast.westfly.se";
             port = 8000;
             mountpoint = "ESXX.mp3";
-            name = "ESXX 121.500";
+            name = "ESXX 123.350";
             genre = "ATC";
             username = "XX";
             password = "XXX";

+ 7 - 0
src/config.cpp

@@ -357,6 +357,13 @@ static int parse_channels(libconfig::Setting& chans, device_t* dev, int i) {
             warn_if_freq_not_in_range(i, j, channel->freqlist[0].frequency, dev->input->centerfreq, dev->input->sample_rate);
             if (chans[j].exists("label")) {
                 channel->freqlist[0].label = strdup(chans[j]["label"]);
+            }else{
+                channel->freqlist[0].label = strdup("NULL");
+            }
+            if (chans[j].exists("mountpoint")) {
+                channel->freqlist[0].mountpoint  = strdup(chans[j]["mountpoint"]);
+            }else{
+                channel->freqlist[0].mountpoint  = strdup("NULL");
             }
             channel->freqlist[0].modulation = channel_modulation;
             if (chans[j].exists("banbel")) {

+ 21 - 7
src/rtl_airband.cpp

@@ -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);
                                 }

+ 3 - 0
src/rtl_airband.h

@@ -232,6 +232,7 @@ struct freq_t {
     enum modulations modulation;
     int banbel;
     int oldstatus;
+    char* mountpoint;
 };
 struct channel_t {
     float wavein[WAVE_LEN];      // FFT output waveform
@@ -291,6 +292,8 @@ struct mqtt_msg_t {
     int sq;
     int audio;
     int freq;
+    char* name;
+    char* mountpoint;
 };
 struct mixinput_t {
     float* wavein;