public class Mqtt : MqttClient
{
public Mqtt(string host) : base(host, 61613, false, MqttSslProtocols.None)
{
Connect(Guid.NewGuid().ToString(), "admin", "password");
Subscribe(new string[] { "atmo" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
// PostData("Hello World!");
}
public void RequestData(string msg)
{
Publish("atmo", Encoding.UTF8.GetBytes(msg));
}
public void PostData(string msg)
{
Publish("atmo", Encoding.UTF8.GetBytes(msg));
}
}
Sqlite实现:
要在UWP下使用Sqlite需要先安装VS扩展Sqlite for Universal Windows Platform和Nuget包SQLite.Net-PCL。关于sqlite的详细使用方法参照:http://www.cnblogs.com/yanxiaodi/p/4941312.html
下面是本系统中Database类:
public class DataBase : SQLiteConnection
{
public static string path = Path.Combine(ApplicationData.Current.LocalFolder.Path, "atmo.db");
public DataBase() : base(new SQLitePlatformWinRT(), path)
{
CreateTable<DataModel>();
}
}
INotifyPropertyChanged接口实现
public class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName]string name = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
树莓派GPIO图