Ejemplo n.º 1
0
        private string SaveWeatherLinkData(WeatherLinkData weatherLinkData)
        {
            string pressure       = weatherLinkData.Barometer.ToString("f2");
            float  inTemperature  = weatherLinkData.InternalTemperature;
            int    inHumidity     = weatherLinkData.InternalHumidity;
            float  outTemperature = weatherLinkData.ExternalTemperature;
            int    outHumidity    = weatherLinkData.ExternalHumidity;
            int    windDirection  = weatherLinkData.WindDirection;
            int    windSpeed      = weatherLinkData.CurrentWindSpeed;
            float  dailyRain      = weatherLinkData.DailyRain;

            var dataBuilder = new StringBuilder();

            if (!File.ReadLines(_configFile).Any())
            {
                dataBuilder.Append("Pressão").Append(",");
                dataBuilder.Append("Temperatura Interna").Append(",");
                dataBuilder.Append("Umidade Interna").Append(",");
                dataBuilder.Append("Temperatura Externa").Append(",");
                dataBuilder.Append("Umidade Externa").Append(",");
                dataBuilder.Append("Direção do Vento").Append(",");
                dataBuilder.Append("Velocidade do Vento").Append(",");
                dataBuilder.Append("Chuva Diária").Append(Environment.NewLine);
            }

            dataBuilder.Append(pressure).Append(",");
            dataBuilder.Append(inTemperature).Append(",");
            dataBuilder.Append(inHumidity).Append(",");
            dataBuilder.Append(outTemperature).Append(",");
            dataBuilder.Append(outHumidity).Append(",");
            dataBuilder.Append(windDirection).Append(",");
            dataBuilder.Append(windSpeed).Append(",");
            dataBuilder.Append(dailyRain).Append(Environment.NewLine);

            string data = dataBuilder.ToString();

            string csvFilePath = File.ReadLines(_configFile).Last();

            File.AppendAllText(csvFilePath, data);

            return(data);
        }
Ejemplo n.º 2
0
        private void UpdateInterface(object sender, EventArgs e)
        {
            int newInterval = Convert.ToInt32(File.ReadLines(_configFile).Skip(2).Take(1).First());

            if (_timer.Interval != newInterval)
            {
                _timer.Interval = newInterval;
            }

            using (TcpClient socket = CreateSocketConnection())
            {
                if (socket == null)
                {
                    return;
                }

                _weatherLinkSocket = socket;

                if (WakeWeatherLink())
                {
                    byte[] response = GetWeatherLinkResponse("LOOP 1", 95);
                    if (response == null)
                    {
                        ShowMessage(@"Lost connection with WeatherLink");
                        return;
                    }

                    var weatherLinkData = new WeatherLinkData();
                    weatherLinkData.FromByteArray(response);

                    LogTb.Text = weatherLinkData.Pretty();

                    ShowMessage(SaveWeatherLinkData(weatherLinkData));
                }
                else
                {
                    ShowMessage(@"Unable to connect to WeatherLink");
                }
            }
        }