Ejemplo n.º 1
0
        public void Setup(string roolLevel)
        {
            MQTTRootTopicLevel = roolLevel;

            Listener = new Listener($"{MQTTRootTopicLevel}/#", DevicePropertyHandler);
            MQTTManager.AddListner(Listener);

            NodeListener = new Listener($"{MQTTRootTopicLevel}/+/\\$type", DeviceNodeHandler);
            MQTTManager.AddListner(NodeListener);
        }
Ejemplo n.º 2
0
        //[InjectionConstructor]
        public HomieDevice(MQTTManager mqttManger, IHubContext <HomieHub> homieHub, ILogger <HomieDevice> logger) : base(true)
        {
            HMDeviceID = Guid.NewGuid();
            Nodes      = new List <DeviceNode>();

            Logger      = logger;
            HomieHub    = homieHub;
            MQTTManager = mqttManger;

            ChangeEvent += OnPropertyChange;
        }
        public HomieDeviceManager(MQTTManager mqttManger, ILogger <HomieDeviceManager> logger, IServiceProvider serviceProvider)
        {
            Logger          = logger;
            ServiceProvider = serviceProvider;
            MQTTManager     = mqttManger;

            Devices = new List <HomieDevice>();

            Listener = new Listener(".+/\\$homie", DeviceTopicHandler);
            MQTTManager.AddListner(Listener);
        }
Ejemplo n.º 4
0
 public bool Reset()
 {
     try
     {
         MQTTManager.Publish(new PublishMessage(GetResetTopic(), "true"));
         return(true);
     }
     catch (Exception ex)
     {
         Logger.LogError("An Error Occured: {0} \r\nStack: {1}", ex.Message, ex.StackTrace);
         return(false);
     }
 }
Ejemplo n.º 5
0
            public DeviceNode(string roolLevel, string nodeID, MQTTManager mqttManager) : base(true)
            {
                Properties = new List <NodeProperty>();

                MQTTManager = mqttManager;

                MQTTRootTopicLevel = roolLevel;
                NodeID             = nodeID;

                Listener = new Listener($"{MQTTRootTopicLevel}/#", NodePropertyHandler);
                MQTTManager.AddListner(Listener);

                base.ChangeEvent += DeviceNode_ChangeEvent;
            }
Ejemplo n.º 6
0
 //Public
 public bool UpDateConfig(DeviceConfig newConfig)
 {
     try
     {
         var change = DeviceConfig.CreateChangeObject(Config, newConfig);
         var json   = change.ToJSON();
         if (json != "{}")
         {
             MQTTManager.Publish(new PublishMessage(GetConfigTopic() + "/set", json));
         }
         return(true);
     }
     catch (Exception ex)
     {
         Logger.LogError("An Error Occured: {0} \r\nStack: {1}", ex.Message, ex.StackTrace);
         return(false);
     }
 }
Ejemplo n.º 7
0
 public (bool sent, string code) SendFirmware(string checksum, string firmware)
 {
     try
     {
         var publishSuccess = MQTTManager.Publish(new PublishMessage(GetFWChecksumTopic(checksum), firmware));
         if (publishSuccess)
         {
             var code = MQTTManager.WaitForMessage(GetFWStatusTopic(), doSee: false, timeout: TimeSpan.FromSeconds(20)).Result;
             return(true, code?.Message ?? "Faild to recive status");
         }
         else
         {
             return(false, "Faild to publish");
         }
     }
     catch (Exception ex)
     {
         Logger.LogError("An Error Occured: {0} \r\nStack: {1}", ex.Message, ex.StackTrace);
         return(false, "An Error Occured");
     }
 }