Ejemplo n.º 1
0
 private void PublishDeviceToMqtt(IDevice device)
 {
     if (device != null)
     {
         TryCall(device,
                 item => _mqttService.Publish(item.ConfigTopic, JsonConvert.SerializeObject(item)));
     }
 }
Ejemplo n.º 2
0
 public void DeleteRetainedMessage(string topic)
 {
     _mqttService.Publish(new MqttPublishParameters
     {
         Topic   = topic,
         Payload = Array.Empty <byte>(),
         QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce,
         Retain = true
     });
 }
Ejemplo n.º 3
0
        public async Task Execute(CancellationToken ct, Routine routine, string date)
        {
            var topic = $"{_mqttConfig.TopicNamespace}/routine/{routine.Id.ToLowerInvariant()}";

            this.Log().Info($"[ST => MQTT] Executing routine: {topic} ({date})");

            await _mqtt.Publish(ct, topic, date, QualityOfService.ExcatlyOnce, retain : false);

            this.Log().Info($"[ST => MQTT] Executed routine: {topic} ({date})");
        }
Ejemplo n.º 4
0
        private void TimerOnTick(object sender, object e)
        {
            try
            {
                var movements = DataService.GetMovements();

                foreach (var movement in movements)
                {
                    try
                    {
                        dynamic movementDto = new JObject();
                        movementDto.CardId     = movement.CardId;
                        movementDto.DeviceId   = _deviceId;
                        movementDto.InLocation = movement.InLocation ? 1 : 0;
                        movementDto.SwipeTime  = movement.SwipeTime;

                        MqttService.Publish(_topic, movementDto);
                        Debug.WriteLine("[MovementManager] Movement published!!");
                        DataService.DeleteMovement(movement.Id);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("[MovementManager] TimerTick ERROR: {0}", ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("[MovementManager] TimerTick ERROR: {0}", ex.Message);
            }
        }
Ejemplo n.º 5
0
        public async Task PostPublish(string topic, int qos = 0, bool retain = false)
        {
            if (topic == null)
            {
                throw new ArgumentNullException(nameof(topic));
            }

            var buffer = new byte[Request.ContentLength ?? 0];

            if (buffer.Length > 0)
            {
                await Request.Body.ReadAsync(buffer, 0, buffer.Length);
            }

            _mqttService.Publish(new MqttPublishParameters
            {
                Topic   = topic,
                Payload = buffer,
                QualityOfServiceLevel = (MqttQualityOfServiceLevel)qos,
                Retain = retain
            });
        }
Ejemplo n.º 6
0
        public void publish(PythonDictionary parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var topic   = Convert.ToString(parameters.get("topic"));
            var payload = parameters.get("payload", new byte[0]);
            var qos     = Convert.ToInt32(parameters.get("qos", 0));
            var retain  = Convert.ToBoolean(parameters.get("retain", false));

            _mqttService.Publish(new MqttPublishParameters
            {
                Topic   = topic,
                Payload = ConvertPayload(payload),
                QualityOfServiceLevel = (MqttQualityOfServiceLevel)qos,
                Retain = retain
            });
        }
Ejemplo n.º 7
0
        private async Task Publish(string clientId, int qos, string topic, string message)
        {
            await _mqttService.Publish(clientId, qos, topic, message);

            SetUpMain();
        }
Ejemplo n.º 8
0
        public IActionResult Set(string deviceName, string message)
        {
            _mqttService.Publish($"{Settings.MQTT_BASE_TOPIC}/{deviceName}/set", Encoding.ASCII.GetBytes(message));

            return(Ok(null));
        }