mqtt单例测试
This commit is contained in:
@@ -5,8 +5,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MQTTnet;
|
|
||||||
using MQTTnet.Client;
|
|
||||||
using MQTTnet.Protocol;
|
using MQTTnet.Protocol;
|
||||||
|
|
||||||
namespace JY.Inspection.Common
|
namespace JY.Inspection.Common
|
||||||
@@ -66,7 +64,9 @@ namespace JY.Inspection.Common
|
|||||||
|
|
||||||
if (useTls)
|
if (useTls)
|
||||||
{
|
{
|
||||||
optionsBuilder.WithTls();
|
optionsBuilder.WithTlsOptions(new MqttClientTlsOptions() {
|
||||||
|
UseTls = true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_options = optionsBuilder.Build();
|
_options = optionsBuilder.Build();
|
||||||
|
|||||||
Generated
+13
@@ -31,6 +31,7 @@
|
|||||||
this.btn_readCollectItemCfg = new MetroFramework.Controls.MetroButton();
|
this.btn_readCollectItemCfg = new MetroFramework.Controls.MetroButton();
|
||||||
this.btn_stationExit = new MetroFramework.Controls.MetroButton();
|
this.btn_stationExit = new MetroFramework.Controls.MetroButton();
|
||||||
this.btn_stationArrival = new MetroFramework.Controls.MetroButton();
|
this.btn_stationArrival = new MetroFramework.Controls.MetroButton();
|
||||||
|
this.btn_sendMQTTClient = new MetroFramework.Controls.MetroButton();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// btn_readCollectItemCfg
|
// btn_readCollectItemCfg
|
||||||
@@ -63,11 +64,22 @@
|
|||||||
this.btn_stationArrival.UseSelectable = true;
|
this.btn_stationArrival.UseSelectable = true;
|
||||||
this.btn_stationArrival.Click += new System.EventHandler(this.btn_stationArrival_Click_1);
|
this.btn_stationArrival.Click += new System.EventHandler(this.btn_stationArrival_Click_1);
|
||||||
//
|
//
|
||||||
|
// btn_sendMQTTClient
|
||||||
|
//
|
||||||
|
this.btn_sendMQTTClient.Location = new System.Drawing.Point(87, 229);
|
||||||
|
this.btn_sendMQTTClient.Name = "btn_sendMQTTClient";
|
||||||
|
this.btn_sendMQTTClient.Size = new System.Drawing.Size(125, 53);
|
||||||
|
this.btn_sendMQTTClient.TabIndex = 3;
|
||||||
|
this.btn_sendMQTTClient.Text = "mqtt客户端发数据";
|
||||||
|
this.btn_sendMQTTClient.UseSelectable = true;
|
||||||
|
this.btn_sendMQTTClient.Click += new System.EventHandler(this.btn_sendMQTTClient_Click);
|
||||||
|
//
|
||||||
// FrmTest
|
// FrmTest
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(998, 586);
|
this.ClientSize = new System.Drawing.Size(998, 586);
|
||||||
|
this.Controls.Add(this.btn_sendMQTTClient);
|
||||||
this.Controls.Add(this.btn_stationArrival);
|
this.Controls.Add(this.btn_stationArrival);
|
||||||
this.Controls.Add(this.btn_stationExit);
|
this.Controls.Add(this.btn_stationExit);
|
||||||
this.Controls.Add(this.btn_readCollectItemCfg);
|
this.Controls.Add(this.btn_readCollectItemCfg);
|
||||||
@@ -82,5 +94,6 @@
|
|||||||
private MetroFramework.Controls.MetroButton btn_readCollectItemCfg;
|
private MetroFramework.Controls.MetroButton btn_readCollectItemCfg;
|
||||||
private MetroFramework.Controls.MetroButton btn_stationExit;
|
private MetroFramework.Controls.MetroButton btn_stationExit;
|
||||||
private MetroFramework.Controls.MetroButton btn_stationArrival;
|
private MetroFramework.Controls.MetroButton btn_stationArrival;
|
||||||
|
private MetroFramework.Controls.MetroButton btn_sendMQTTClient;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using JY.Model.Excel;
|
using JY.Inspection.Common;
|
||||||
|
using JY.Model.Excel;
|
||||||
using JY.Utility;
|
using JY.Utility;
|
||||||
using MetroFramework.Forms;
|
using MetroFramework.Forms;
|
||||||
using System;
|
using System;
|
||||||
@@ -50,5 +51,19 @@ namespace JY.Inspection.Frm
|
|||||||
MessageBox.Show(ex.ToString());
|
MessageBox.Show(ex.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void btn_sendMQTTClient_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await MqttSingleton.Instance.InitializeAsync(
|
||||||
|
brokerHost: "127.0.0.1",
|
||||||
|
clientId: "EVE",
|
||||||
|
username: string.Empty,
|
||||||
|
password: string.Empty
|
||||||
|
);
|
||||||
|
|
||||||
|
string topic = "EVE/工厂编码/EQP/设备编码";
|
||||||
|
string payload = "测试数据";
|
||||||
|
await MqttSingleton.Instance.SendAsync(topic, payload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user