/// <summary> /// Event which triggers if the MQTT listener receives a new publish from the server. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) { adsCon.Reading("/test/topic"); String recvMessage = "Received = " + Encoding.UTF8.GetString(e.Message) + " on topic " + e.Topic; Debug.WriteLine(recvMessage); adsCon.Writing(Encoding.UTF8.GetString(e.Message)); recvMessage = String.Empty; }
private void btnCorDMQTT_Click(object sender, EventArgs e) { if (!ADSConnected) { MessageBox.Show("Please connect to ads before connecting to a mqtt broker."); return; } if (MQTTConnected) { ADS.RemoveBroker(MQTTHandle); btnCorDMQTT.Text = "Connect To MQTT"; MQTTConnected = false; } else { try { //MessageBox.Show("Given MQTT IP: " + txtBoxMQTTIP.Text); if (!ADS.AddBroker(txtBoxMQTTIP.Text, qos, MQTTHandle)) { MessageBox.Show("Broker connection could not be created."); return; } string topic = "/test/topic"; ADS.MQTTBrokers[0].Connect("username", "password"); ADS.MQTTBrokers[0].Subscribe(topic); ADS.Reading(topic); } catch (Exception ex) { MessageBox.Show("Please add a valid ip to MQTT IP.\nError Message: " + ex.Message); ADS.RemoveBroker(MQTTHandle); return; } btnCorDMQTT.Text = "Disconnect From MQTT"; MQTTConnected = true; } }