Пример #1
0
 private static void TryReconnectMClientPark(object sender, EventArgs e)
 {
     mutexReconnect.WaitOne();
     if (mClientPark == null || !mClientPark.IsConnected)
     {
         Console.WriteLine("##############Try to reconnect mClientPark#############");
         mClientPark = Mosquitto.connectMosquittoGuaranteeThatTryToConnect(ipsParkDACE);
         if (mClientPark == null || !mClientPark.IsConnected)
         {
             System.Environment.Exit(1);
         }
         mClientPark.ConnectionClosed += TryReconnectMClientPark;
         Mosquitto.configFunctionMosquitto(mClientPark, mClientPark_MqttMsgPublishReceived);
         Mosquitto.subscribedMosquitto(mClientPark, topicsParkDACE[0]);
     }
     mutexReconnect.ReleaseMutex();
     mutex.ReleaseMutex();
 }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("#################################################################################");
            Console.WriteLine("###################################   INIT   ####################################");
            Console.WriteLine("#################################################################################\n\n");
            parkingsNameSubscribed = new List <string>();
            Console.WriteLine("#####################MOSQUITTO#####################");

            Console.WriteLine("####Connect to the topic " + topicsParkDACE[0] + "####");
            mClientPark = Mosquitto.connectMosquittoGuaranteeThatTryToConnect(ipsParkDACE);
            if (mClientPark == null || !mClientPark.IsConnected)
            {
                return;
            }
            mClientPark.ConnectionClosed += TryReconnectMClientPark;
            Console.WriteLine("####Connect to the other topics ####");
            mClient = Mosquitto.connectMosquittoGuaranteeThatTryToConnect(ipsParkDACE);
            if (mClient == null || !mClient.IsConnected)
            {
                return;
            }
            mClient.ConnectionClosed += TryReconnectMClient;
            Console.WriteLine("#####################END-Connection##################\n");

            String topicsSubscribe = "";

            Console.WriteLine("#######Config the mClientPark on topic " + topicsParkDACE[0] + "#######");
            Mosquitto.configFunctionMosquitto(mClientPark, mClientPark_MqttMsgPublishReceived);
            topicsSubscribe += "\n\t\t\t-'" + topicsParkDACE[0] + "'";
            Console.WriteLine("#####################END-Config##################\n");

            Console.WriteLine("#######Config the mClient on new topics#######");
            Mosquitto.configFunctionMosquitto(mClient, mClient_MqttMsgPublishReceived);
            Console.WriteLine("#####################END-Config##################\n");

            Console.WriteLine("You will be subscribe to the topic:" + topicsSubscribe);
            Console.WriteLine("#################END-Config-MOSQUITTO###############\n");
            Console.WriteLine("\n\n\n#################################################################################");
            Console.WriteLine("###########################   Starting Application   ############################");
            Console.WriteLine("#################################################################################\n\n");
            Mosquitto.subscribedMosquitto(mClientPark, topicsParkDACE[0]);
            mutexReconnect.ReleaseMutex();
            mutex.ReleaseMutex();
        }