'How to get only one message from MQTT, when messages receiving in C#?
I developed simple IOT device using nodemcu module with 03 sensors. When device is connected, device sent sensor's data to mqtt broker as well. After I getting that data to my .net back end using M2QTT libraries. According to my code, client_MqttMsgPublishReceived method is works as loop. But I need to get that data message, only one time (As I requesting).
I used libraries as:
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
My Code :
private void button2_Click(object sender, EventArgs e)
{
var client = new MqttClient(IPAddress.Parse("172.30.30.21"));
client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
var clientId = Guid.NewGuid().ToString();
client.Connect(clientId);
client.Subscribe(new string[] { "topic" }, new byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
}
static void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
{
string result = Encoding.UTF8.GetString(e.Message);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
