Exemple #1
0
        private void POST_Thread(int waitTime)
        {
            var higherLimit = (MustSendTemperature) ? 40 : 100;
            var type        = (MustSendTemperature) ? "temperature" : "humidity";

            while (IsThreadActive)
            {
                var value    = GetRandomNumber(0, higherLimit);
                var response = Http.Post(DweetPostHttp, new NameValueCollection
                {
                    { "type", type },
                    { "value", value.ToString(CultureInfo.InvariantCulture) }
                });
                ThreadHelperClass.AppendText(this, txtMockStatus, $"\r\nSending {type} to DWEET.IO - Value: {value}");
                Thread.Sleep(waitTime * 1000);
            }
        }
Exemple #2
0
        private void GET_Thread(int waitTime)
        {
            var noTimeout    = false;
            var lastGet      = DateTime.MinValue;
            var timeoutLimit = int.Parse(txtTimeout.Text);

            while (IsThreadActive)
            {
                var response = Http.Get(DweetGetHttp);
                if (response != null)
                {
                    var lastNoTimeout = noTimeout;
                    noTimeout = (DateTime.Now - response.SendingDateTime).TotalSeconds > timeoutLimit;
                    if (!noTimeout)
                    {
                        if (lastNoTimeout)
                        {
                            ThreadHelperClass.AppendText(this, txtMockStatus, "\r\nAndroid device regained connection. Resuming...");
                        }
                        if (lastGet != response.SendingDateTime)
                        {
                            ThreadHelperClass.AppendText(this, txtMockStatus, $"\r\nRecieving {response.Type} from DWEET.IO - Value: {response.Value}");
                            lastGet = response.SendingDateTime;
                        }
                    }
                    else
                    {
                        if (lastNoTimeout)
                        {
                            ThreadHelperClass.AppendText(this, txtMockStatus, $"\r\nAndroid device has not sent information during the last {timeoutLimit} seconds. Waiting...");
                        }
                    }
                }
                Thread.Sleep(waitTime * 1000);
            }
        }