コード例 #1
0
ファイル: MqttWinclient.cs プロジェクト: simonAndre/MQTT
        public MqttWinclient()
        {
            InitializeComponent();

            displaystate(false);

            serversett = new serversettings();
            propertyGrid3.SelectedObject = serversett;
            propertyGrid3.PropertyValueChanged += PropertyGrid3_PropertyValueChanged;
            uitopics.ListChanged += Uitopics_ListChanged;
            
            mqtt = new Mqttclient_handler();
            this.dataGridView_topics.DataSource = uitopics;
            this.dataGridView_topics.CellContentClick += DataGridView_topics_CellValueChanged;
            this.dataGridView_topics.CurrentCellChanged += DataGridView_topics_CurrentCellChanged;
            this.dataGridView_topics.MouseClick += DataGridView_topics_MouseClick;
            this.dataGridView_topics.Columns[0].ReadOnly = true;
            this.dataGridView_topics.Columns[0].Width = 130;
            this.dataGridView_topics.Columns[1].Width = 60;
            this.dataGridView_topics.Columns[2].Width = 30;

            this.FormClosing += MqttManager_FormClosing;
            addExistingsettingsToMenu();
            saveSettingsToolStripMenuItem.Enabled = false;
            this.splitContainer1.Panel1.Click += disableControlClick;
            this.splitContainer2.Panel2.Click += disableControlClick;
            plugExternalEvents();

            this.Text = "MqttManager -S.Andre  jan 2016 - v" + this.GetType().Assembly.GetName().Version.ToString();
        }
コード例 #2
0
ファイル: mqttservice.cs プロジェクト: simonAndre/MQTT
        public bool Start(HostControl hc)
        {
            mqtt.MqttConnect(serveur, clientid);
            mqtt = new Mqttclient_handler();
            foreach (var tokv in topicsStr.Split(';'))
            {
                string topicname = tokv.Split('=')[0];
                string topicvalue = tokv.Split('=')[1];
                mqtt.subscribe(topicvalue, 0);
                // topicNames.Add(topicvalue, topicname);
            }

            t = new Timer(WriteMessages, null, 10000, 10 * 60000);

            // Console.WriteLine("mqtt isconnected : {0}", mqtt.IsConnected);
            mqtt.OnMessageArrived += (Mqttclient_handler sender, MessPublishEventArgs e) =>
            {
                Console.WriteLine("at {0} from {1} : {2}", e.Message.Date, e.Message.Topic, e.Message.GetStringMessage());
                if (!messagesByTopic.ContainsKey(e.Message.Topic))
                    messagesByTopic.Add(e.Message.Topic, new List<MqttMessage>());
                messagesByTopic[e.Message.Topic].Add(e.Message);
                if (messagesByTopic[e.Message.Topic].Count > 20)
                {
                    SaveMessages(messagesByTopic[e.Message.Topic], e.Message.Topic, FileType.csv);
                    messagesByTopic[e.Message.Topic].Clear();
                }
            };
            return true;
         /*  do
            {
                Thread.Sleep(50);
            } while (true);*/
        }
コード例 #3
0
ファイル: MqttWinclient.cs プロジェクト: simonAndre/MQTT
        private void Mqtt_OnConnected(Mqttclient_handler sender, EventArgs e)
        {

            this.toolStripStatusLabel_server.BackColor = Color.Green;
            displaystate(true);
        }