C#使用M2Mqtt库进行MQTT简单通讯
M2Mqtt库资源
一开始有查找Mqttnet的源码,但是比较乱,编译不过去,后来选择了M2Mqtt。源码清晰简洁,使用靠谱。
1、M2Mqtt 下载代码自己生成一下就可以在BIN文件夹里面找到相关的库。
2、在NuGet库里面直接查找M2Mqtt也可以安装库。
MQTT连接
public MqttClient mqttClient {
get; set; }
private static string EMQX_BROKER_IP = "192.168.10.165";
private static int EMQX_BROKER_PORT = 1884;
// 建立MQTT连接
private void mqttConnect()
{
EMQX_CLIENT_ID = Guid.NewGuid().ToString();
try
{
//建立连接
mqttClient = new