Пример #1
0
        private async void MoveBlind(int blind, String command, int?ms = null)
        {
            Debug.WriteLine("COMMAND => " + command);

            await MoveToPosition(blind);

            if (command == "up")
            {
                _btnUpOut.Write(GpioPinValue.High);
                await Task.Delay(1000);

                _btnUpOut.Write(GpioPinValue.Low);
                await _mqttClient.PublishAsync($"mancave/status/blinds/{blind}/{command}");
            }
            else if (command == "down")
            {
                Debug.WriteLine("DOWN");
                _btnDownOut.Write(GpioPinValue.High);
                await Task.Delay(1000);

                _btnDownOut.Write(GpioPinValue.Low);
                Debug.WriteLine("DONE");
                await _mqttClient.PublishAsync($"mancave/status/blinds/{blind}/{command}");
            }
            else if (command == "stop")
            {
                _btnCntrOut.Write(GpioPinValue.High);
                await Task.Delay(1000);

                _btnCntrOut.Write(GpioPinValue.Low);
                await _mqttClient.PublishAsync($"mancave/status/blinds/{blind}/{command}");
            }

            if (ms.HasValue)
            {
                await Task.Delay(ms.Value);

                _btnCntrOut.Write(GpioPinValue.High);
                await Task.Delay(500);

                _btnCntrOut.Write(GpioPinValue.Low);
            }
        }
        private async Task <InvokeResult> SendMQTTGeoMessage(MessageTransmissionPlan plan)
        {
            var messageTemplate = plan.Message.Value;

            var pointArray  = messageTemplate.TextPayload.Split('\r');
            var geoLocation = pointArray[_pointIndex++];
            var parts       = geoLocation.Split(',');
            var lat         = Convert.ToDouble(parts[0]);
            var lon         = Convert.ToDouble(parts[1]);
            var delay       = Convert.ToInt32(parts[2]) * 1000;

            await _mqttClient.PublishAsync(ReplaceTokens(_instance, plan, messageTemplate.Topic), $"{lat},{lon}");

            await _notificationPublisher.PublishTextAsync(Targets.WebSocket, Channels.Simulator, InstanceId, $"Queue up point {_pointIndex} to send.");

            if (this._pointIndex < pointArray.Length)
            {
                await _notificationPublisher.PublishTextAsync(Targets.WebSocket, Channels.Simulator, InstanceId, $"Queue up point {_pointIndex} to send.");

                _timer = new Timer(SendMqttGeoRequest, plan, delay, Timeout.Infinite);
            }

            return(InvokeResult.Success);
        }