MQTTCommand.cs 482 B

123456789101112131415161718192021
  1. using Blue;
  2. public class MQTTCommand : ICommand
  3. {
  4. private IMQTTService mQTTService;
  5. private string topic;
  6. private string message;
  7. public MQTTCommand(string topic,string message)
  8. {
  9. this.topic = topic;
  10. this.message = message;
  11. }
  12. public void OnExcute()
  13. {
  14. if(mQTTService==null)
  15. {
  16. mQTTService = this.GetService<IMQTTService>();
  17. }
  18. mQTTService.Publish(topic,message);
  19. }
  20. }