forked from TRU-E-Bike-Project/bg96sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IMqttClient.cs
33 lines (26 loc) · 1013 Bytes
/
IMqttClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace BG96Sharp
{
public delegate void MqttMessageReceivedHandler(object sender, MqttMessageReceivedEventArgs e);
public interface IMqttClient
{
event MqttMessageReceivedHandler MessageReceived;
event EventHandler Connected;
Task<bool> SendMqttMessageAsync(string topic, string data);
Task<bool> SendMqttMessageAsync(string topic, byte[] data);
Task<bool> SendMqttMessageAsync(string topic, byte[] data, CancellationToken cancellationToken);
Task<bool> SubscribeToTopicAsync(string topic);
Task<bool> ConnectAsync();
Task<bool> CloseAsync();
bool IsConnected { get; }
}
public class MqttMessageReceivedEventArgs : EventArgs
{
public string Topic { get; set; }
public byte[] Content { get; set; }
public string Message { get => Encoding.Unicode.GetString(Content, 0, Content.Length); }
}
}