Пример #1
0
        internal async Task PublishAssetStateAsync(string deviceId, string name, AssetState state)
        {
            var toSend = JObject.FromObject(state.State).ToString();
            var topic  = $"device/{deviceId}/asset/{name}/state";

            var message = new MqttApplicationMessageBuilder()
                          .WithTopic(topic)
                          .WithPayload(Encoding.UTF8.GetBytes(toSend))
                          .Build();

            if (_mqtt.IsConnected)
            {
                await _mqtt.PublishAsync(message).ConfigureAwait(false);

                _logger.Trace("Message published, topic: {0}, content: {1}", topic, toSend);
            }
            else
            {
                _logger.Error("MQTT not connected");
            }
        }
Пример #2
0
 internal void OnAssetState(AssetState state)
 {
     State = state;
     OnCommand?.Invoke(this, this);
 }