Exemple #1
0
        private void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
        {
            Console.WriteLine("Received = " + Encoding.UTF8.GetString(e.Message) + " on topic " + e.Topic);
            using (var db = new RawMQTTDataModel())
            {
                var message = new MQTTMessage{
                    Topic=e.Topic, Message = Encoding.UTF8.GetString(e.Message), ReceivedDateTime = DateTime.Now
                };

                db.Messages.Add(message);
                db.SaveChanges();
            }
        }
Exemple #2
0
 static void Main(string[] args)
 {
     using (var db = new RawMQTTDataModel())
     {
         db.Database.EnsureCreated();
         db.Database.Migrate();
     }
     MQQT client = new MQQT();
     client.Connect("192.168.2.122");
     client.Subscribe("myhome/test/#");
     client.Publish("TEST NET");
     Console.ReadLine();
     client.Disconnect();
 }