Example #1
0
        public override void Session()
        {
            base.Session();


            if (WorkState == WorkStates.Error)
            {
                Transport.Close();
                Transport         = new TcpTransport(connArgs.Hostname, connArgs.Port);
                Transport.Version = connArgs.Version;
                Transport.SetTimeouts(connArgs.ReadTimeout, connArgs.WriteTimeout);

                Send(MakeConnectMessage(connArgs));
                ReceiveConnack();
                ResumeOutgoingFlows();
                if (sp.Topics.Length > 0)
                {
                    Subscribe(sp);
                }
                WorkState = WorkStates.Normal;
                WriteToLog(Localization.UseRussian ? "Повторяем подключение с брокером MQTT" : "Retry connect in MQTT broker");
                return;
            }


            WorkState = WorkStates.Normal;

            Send(new PingreqPacket());
            ReceivePacket();
            MQTTPTs = RSrv.GetValues(MQTTPTs);
            NumberFormatInfo nfi = new NumberFormatInfo();

            foreach (MQTTPubTopic mqtttp in MQTTPTs)
            {
                if (!mqtttp.IsPub)
                {
                    continue;
                }
                nfi.NumberDecimalSeparator = mqtttp.NumberDecimalSeparator;
                Publish(new PublishPacket()
                {
                    Topic    = mqtttp.TopicName,
                    QosLevel = mqtttp.QosLevels,
                    Message  = Encoding.UTF8.GetBytes(mqtttp.Value.ToString(nfi))
                });
                mqtttp.IsPub = false;
            }

            Thread.Sleep(ReqParams.Delay);
        }
Example #2
0
 public override void OnCommLineTerminate()
 {
     RSrv.Disconn();
     Send(new DisconnectPacket());
     Transport.Close();
     WriteToLog(Localization.UseRussian ? "Отключение от MQTT брокера" : "Disconnect from MQTT broker");
     WorkState = WorkStates.Undefined;
 }
Example #3
0
 public void Dispose()
 {
     Transport.Close();
 }