public void SetAirpressureData(WeatherInfoSet weatherinfoset)
        {
            TimeSpan span = new TimeSpan(0, 3, 0, 0, 0);

            DateTime now = DateTime.Now.ToUniversalTime().Subtract(span);

            string datetimeframe_start_str = now.ToString("yyyy") + '-' + now.ToString("MM") + '-' + now.ToString("dd") +
                                             ' ' + now.ToString("HH") + ':' + now.ToString("mm") + ':' + now.ToString("ss");

            string query = String.Format("SELECT * FROM airpressuredata WHERE datetime >= '{0}'", datetimeframe_start_str);

            MySqlCommand myCommand = new MySqlCommand(query);
            myCommand.Connection = Mycon;

            MySqlDataReader reader = myCommand.ExecuteReader();

            while (reader.Read())
            {
                DateTime date = (DateTime)reader[0];
                float airpressure = (float)reader[1];

                // JavaScript Date constructor accepts number of milliseconds since Unix epoch (1 January 1970 00:00:00 UTC).
                long datetimemin = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks;
                long datetime = (date.ToUniversalTime().Ticks - datetimemin) / 10000;

                weatherinfoset.AirpressureInfoList.Add(new AirpressureInfo() { Airpressure = airpressure, DateTime = datetime });
            }

            weatherinfoset.JsonAirpressureInfoList = JsonConvert.SerializeObject(weatherinfoset.AirpressureInfoList);

            reader.Close();
        }
        public ActionResult HumidityGraph()
        {
            WeatherInfoSet weatherinfoset = new WeatherInfoSet()
            {
                PullDownInfoList =  { new SelectListItem() { Text = "Humidity", Value = Url.Action("HumidityGraph", "WeatherStation") },
                                      new SelectListItem() { Text = "Temperature", Value = Url.Action("TemperatureGraph", "WeatherStation") },
                                      new SelectListItem() { Text = "Air Pressure", Value = Url.Action("AirpressureGraph", "WeatherStation") } }
            };

            WeatherStationDatabase weatherdatabase = new WeatherStationDatabase();

            try
            {
                weatherdatabase.OpenDatabase();
                weatherdatabase.SetTemperatureData(weatherinfoset);
                weatherdatabase.SetHumidityData(weatherinfoset);
                weatherdatabase.SetAirpressureData(weatherinfoset);
                weatherdatabase.SetImageData(weatherinfoset);
            }
            catch (MySqlException ex)
            {
                throw (ex);
            }

            ViewBag.WeatherUndergroundAvailable = true;

            try
            {
                weatherdatabase.SetWindData(weatherinfoset);
            }
            catch (System.Net.WebException)
            {
                ViewBag.WeatherUndergroundAvailable = false;
            }

            if (ViewBag.WeatherUndergroundAvailable)
                weatherinfoset.UpdateWeatherType();

            try
            {
                weatherdatabase.CloseDatabase();
            }
            catch (MySqlException ex)
            {
                throw (ex);
            }

            Response.AddHeader("Refresh", "60");

            return View(weatherinfoset);
        }
        public void SetWindData(WeatherInfoSet weatherinfoset)
        {
            string ApiKey = "3e36ad78b6a9da44";
            String url = String.Format("http://api.wunderground.com/api/{0}/conditions/q/Netherlands/Eelde.json", ApiKey);
            WebRequest request = WebRequest.Create(url);
            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    var json = reader.ReadToEnd();
                    JObject searchResult = JObject.Parse(json);
                    string wind_direction = searchResult["current_observation"]["wind_dir"].ToString();

                    weatherinfoset.Windinfo = new WindInfo() { WindDirection = wind_direction };
                }
            }
        }
        public void SetImageData(WeatherInfoSet weatherinfoset)
        {
            string query = String.Format("SELECT image FROM imagedata");

            MySqlCommand myCommand = new MySqlCommand(query);
            myCommand.Connection = Mycon;

            MySqlDataReader reader = myCommand.ExecuteReader();

            while (reader.Read())
            {
                long bytesize = reader.GetBytes(0, 0, null, 0, 0);
                byte[] ImageBytes = new byte[bytesize];
                reader.GetBytes(0, 0, ImageBytes, 0, (int)bytesize);
                weatherinfoset.WeatherImageURL = "data:image/jpg;base64," + Convert.ToBase64String(ImageBytes);
            }

            reader.Close();
        }