Exemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            speechSynthesizer = new SpeechSynthesizer();
            speechSynthesizer.SetOutputToDefaultAudioDevice();

            var timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(1)
            };

            timer.Tick += Timer_Tick;
            timer.Start();

            // Display today's sunset/sunrise times:

            DateTime sunriseToday, sunsetToday;

            SunTimes.GetSunTimes(out sunriseToday, out sunsetToday);

            lblSunriseVal.Content = sunriseToday.ToShortTimeString();
            lblSunsetVal.Content  = sunsetToday.ToShortTimeString();


            // We dont really have a way to get the current state of the AC & DC bus
            // So we just initialize the switches to 'off' state which may not be the true
            // state of the Netduino.

            BtnDCBus.IsChecked = false;
            BtnACBus.IsChecked = false;

            BtnDCBus.Checked   += BtnDCBus_Checked;
            BtnDCBus.Unchecked += BtnDCBus_Unchecked;

            BtnACBus.Checked   += BtnACBus_Checked;
            BtnACBus.Unchecked += BtnACBus_Unchecked;


            // Read in the configurtion:
            var deviceIP = string.Empty;

            try
            {
                deviceIP = ConfigurationManager.AppSettings["deviceIPAddress"];
            }
            catch (ConfigurationErrorsException)
            {
                MessageBox.Show("Error Reading Configuration File");
            }


            netDuino = NetDuinoPlus.Instance(deviceIP);
        }
Exemplo n.º 2
0
        private bool TimeAdjustment(HoraKala currentHoraKala)
        {
            currentHoraKala.KalaInterval = new KalaBase.TimeInterval(
                SunTimes.GetTimeAdjustedForSunTime(currentHoraKala.KalaInterval.StartTime, SunRise, SunSet)
                , SunTimes.GetTimeAdjustedForSunTime(currentHoraKala.KalaInterval.EndTime, SunRise, SunSet)
                , currentHoraKala.KalaInterval.IsVisha);

            if (currentHoraKala.KalaInterval.StartTime <= ThisDateTime && currentHoraKala.KalaInterval.EndTime >= ThisDateTime)
            {
                this.ThisHoraAdhipathiPlanet = currentHoraKala.KalaAdhipathiPlanet.ToString();
            }
            else
            {
                return(false);
            }

            foreach (PanchamaKala pKala in currentHoraKala.PanchamaKalaList)
            {
                pKala.KalaInterval = new KalaBase.TimeInterval(
                    SunTimes.GetTimeAdjustedForSunTime(pKala.KalaInterval.StartTime, SunRise, SunSet)
                    , SunTimes.GetTimeAdjustedForSunTime(pKala.KalaInterval.EndTime, SunRise, SunSet)
                    , pKala.KalaInterval.IsVisha);

                if (pKala.KalaInterval.StartTime <= ThisDateTime && pKala.KalaInterval.EndTime >= ThisDateTime)
                {
                    this.ThisPachamaHoraAdhipathiPlanet = pKala.KalaAdhipathiPlanet;
                    ThisPachamaHora = pKala.KalaInterval;
                }

                foreach (SukshamaKala sKala in pKala.SukshamaKalaList)
                {
                    sKala.KalaInterval = new KalaBase.TimeInterval(
                        SunTimes.GetTimeAdjustedForSunTime(sKala.KalaInterval.StartTime, SunRise, SunSet)
                        , SunTimes.GetTimeAdjustedForSunTime(sKala.KalaInterval.EndTime, SunRise, SunSet)
                        , sKala.KalaInterval.IsVisha);

                    if (sKala.KalaInterval.StartTime <= ThisDateTime && sKala.KalaInterval.EndTime >= ThisDateTime)
                    {
                        this.ThisSukshamaHoraAdhipathiPlanet = sKala.KalaAdhipathiPlanet;
                        this.ThisSukshamaHora = sKala.KalaInterval;
                    }
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        private async Task <SunTimes> GetSunTimesModelAsync()
        {
            _log.LogInformation("Getting sun times...");

            var result     = await new HttpClient().GetAsync(_url);
            var jsonString = await result.Content.ReadAsStringAsync();

            var parsedObject = JObject.Parse(jsonString);

            var sunTimes = new SunTimes
                           (
                parsedObject["results"]["sunrise"].ToString(),
                parsedObject["results"]["sunset"].ToString(),
                parsedObject["results"]["day_length"].ToString(),
                parsedObject["results"]["solar_noon"].ToString(),
                parsedObject["results"]["civil_twilight_end"].ToString(),
                parsedObject["results"]["nautical_twilight_end"].ToString()
                           );

            return(sunTimes);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sends commands to set the current state of the NetDuino Relay R2 (AC Relay) based on the
        /// configured OnTime and OffTime values
        /// </summary>
        /// <returns> returns a TimeSpan that tells us when we need to call this method again</returns>
        private async Task <TimeSpan> SetNetDuinoACRelay()
        {
            string result;
            var    alert = new AlertSender();

            // First calculate the DC Bus On Time value using Today's Sunset time &
            // given on Time offset value:
            DateTime sunriseToday, sunsetToday;

            SunTimes.GetSunTimes(out sunriseToday, out sunsetToday);

            var onTime  = sunsetToday - new TimeSpan(0, 0, acBusOnTimeOffset, 0);
            var offTime = acBusOffTime;

            if (onTime.TimeOfDay > offTime.TimeOfDay)
            {
                LogMessage("Invalid Configuration!. Please check the On/Off Time values");
                return(TimeSpan.MinValue);
            }

            // time to wait for next state change trigger
            TimeSpan stateChangeInterval;

            if (DateTime.Now.TimeOfDay < onTime.TimeOfDay)
            {
                // we are in daytime
                // energize the relay 1 to turn lights off and set the interval for next state change
                result = await netDuino.EnergizeRelay2();

                stateChangeInterval = onTime.TimeOfDay - DateTime.Now.TimeOfDay;
            }
            else if (DateTime.Now.TimeOfDay >= onTime.TimeOfDay && DateTime.Now.TimeOfDay <= offTime.TimeOfDay)
            {
                // we are in the onTime..
                // de-energize relay1 to turn the lights on and set then to turn off at offTime
                result = await netDuino.DenergizeRelay2();

                stateChangeInterval = offTime.TimeOfDay - DateTime.Now.TimeOfDay;
            }
            else
            {
                // Current time is between OffTime and midnight
                // energize the relays to turn the light off and set the interval to onTime + 1 Day
                result = await netDuino.EnergizeRelay2();

                stateChangeInterval = (new TimeSpan(1, 0, 0, 0) + onTime.TimeOfDay) - DateTime.Now.TimeOfDay;
            }

            if (result == "Success")
            {
                if (changeStateR2Timer == null)
                {
                    //This is the first time this method is executed
                    // set up the timer to trigger next time the Relay state change is needed:
                    changeStateR2Timer = new Timer(OnChangeStateR2Timer, null, stateChangeInterval, Timeout.InfiniteTimeSpan);
                }
            }
            else
            {
                // here we deal with the failure...
                // set the TimeSpan to min value to return an indication of failure and log appropriate messages and alerts
                stateChangeInterval = TimeSpan.MinValue;

                var @address = NetDuinoPlus.DeviceIPAddress.Substring(7, 13);

                var msg =
                    "Netduino has failed to respond to Energize/Denergize AC relay request(s) dispatched to address: " + @address + "in a timely fashion" +
                    $"{Environment.NewLine}Event Date & Time: {DateTime.Now.ToLongDateString()} {DateTime.Now.ToLongTimeString()} {Environment.NewLine}" +
                    $"{Environment.NewLine}Please check Netduino and make sure that it is still online!";

                LogMessage(alert.SendEmailAlert("Atert: Energize/Denergize AC Relay request to NetDuino Failed", bodyText: msg)
                    ? "Alert dispatch via Email completed successfully"
                    : "Attempt to send an email alert failed!");

                LogMessage(alert.SendSMSAlert("Atert: Energize/Denergize Relay request to NetDuino Failed", msg)
                    ? "Alert dispatch via SMS completed successfully"
                    : "Attempt to send an SMS alert failed!");
            }

            return(stateChangeInterval);
        }