Exemple #1
0
        private void OnValueChanged(object sender, StateObjectChangedEventArgs e)
        {
            //récupération des nouvelles valeurs
            PackageHost.WriteInfo("values are : {0}", this.PushValues.DynamicValue);
            latitude  = e.NewState.DynamicValue.Latitude;
            longitude = e.NewState.DynamicValue.Longitude;
            login     = e.NewState.DynamicValue.Login;
            pass      = e.NewState.DynamicValue.Pass;
            myGuid    = Auth(pass, login, latitude, longitude);
            String myGuidString = myGuid.ToString();

            PackageHost.WriteInfo("generated token : {0}", myGuid);
            PackageHost.WriteInfo("Sending generated token");

            if (myGuid != Guid.Empty) //si token valide généré par Auth, envoi à la Raspberry
            {
                //communication avec la Raspberry
                MessageScope.Create("ConstellationPackagePython2").OnSagaResponse((response) =>
                {
                    //premier envoi du token, récupération de ce même token
                    PackageHost.WriteInfo("Sending generated token");
                    PackageHost.WriteInfo("Raspberry response : {0}", response);
                    String responseC = myGuidString + "fr42kilj8";   //deuxième envoi du token + clé de sécurite
                    PackageHost.WriteInfo(" Sending token + key ");
                    PackageHost.SendMessage(MessageScope.Create("ConstellationPackagePython2"), "reponse", responseC);
                }).GetProxy().question <String>(myGuidString);
            }
        }
Exemple #2
0
        public TimeAndPlace GetWakeUpHour()
        {
            var TimeReveil = new TimeAndPlace();
            List <EventnTraffic> ListEvent = Events.DynamicValue.ToObject <List <EventnTraffic> >();

            foreach (var evenement in ListEvent)
            {
                if (DateTime.Now < DateTime.Parse(evenement.DateDebut))
                {
                    PackageHost.WriteInfo("Le prochain évènement est le {0}", evenement.DateDebut.ToString());
                    TimeReveil.Time = DateTime.Parse(evenement.DateDebut);
                    try
                    {
                        TimeReveil.TimeTraffic = TimeSpan.Parse(evenement.TimeTrafficFromHouse.ToString());
                        TimeReveil.Place       = evenement.Lieu;
                    }
                    catch
                    {
                        var title = "Absence lieu pour le lendemain";
                        var body  = "Aucun lieu n'a été enregistré pour demain, le temps de trajet ne sera pas pris en compte";
                        PackageHost.SendMessage(MessageScope.Create("PushBullet"), "PushNote", new object[] { title as System.String, body as System.String });
                        TimeReveil.TimeTraffic = new TimeSpan();
                    }
                    return(TimeReveil);
                }
            }
            return(TimeReveil);
        }
        public override void OnStart()
        {
            PackageHost.WriteInfo("Package starting - IsRunning: {0} - IsConnected: {1}", PackageHost.IsRunning, PackageHost.IsConnected);

            while (PackageHost.IsRunning)
            {
                int Heure  = DateTime.Now.Hour;
                int Minute = DateTime.Now.Minute;

                if (DateTime.Now.Date != dateProcessedFeeding.Date && Heure == 13 && Minute == 30)
                {
                    dateProcessedFeeding = DateTime.Now;
                    PackageHost.SendMessage(MessageScope.Create("FishtNess"), "Feeding", null);
                }

                if (DateTime.Now.Date != dateProcessedSwitchON.Date && Heure == 11 && Minute == 30)
                {
                    dateProcessedSwitchON = DateTime.Now;
                    PackageHost.SendMessage(MessageScope.Create("FishtNess"), "SwitchState", true);
                }

                if (DateTime.Now.Date != dateProcessedSwitchOFF.Date && Heure == 21 && Minute == 30)
                {
                    dateProcessedSwitchOFF = DateTime.Now;
                    PackageHost.SendMessage(MessageScope.Create("FishtNess"), "SwitchState", false);
                }


                if (DateTime.Now.Date != dateProcessedPushBullet1.Date && Heure == 8)
                {
                    dateProcessedPushBullet1 = DateTime.Now;
                    PackageHost.CreateMessageProxy("PushBullet").PushNote("ATTENTION", "La température de l'aquarium est : {0}°C.", this.Temperature.DynamicValue);
                }

                else if (DateTime.Now.Date != dateProcessedPushBullet2.Date && Heure == 15)
                {
                    dateProcessedPushBullet2 = DateTime.Now;
                    PackageHost.CreateMessageProxy("PushBullet").PushNote("ATTENTION", "La température de l'aquarium est : {0}°C.", this.Temperature.DynamicValue);
                }

                else if (DateTime.Now.Date != dateProcessedPushBullet3.Date && Heure == 8)
                {
                    dateProcessedPushBullet3 = DateTime.Now;
                    PackageHost.CreateMessageProxy("PushBullet").PushNote("ATTENTION", "L'acidite (pH) de l'aquarium est : {0}.", this.Acidity.DynamicValue);
                }

                else if (DateTime.Now.Date != dateProcessedPushBullet4.Date && Heure == 15)
                {
                    dateProcessedPushBullet4 = DateTime.Now;
                    PackageHost.CreateMessageProxy("PushBullet").PushNote("ATTENTION", "L'acidite (pH) de l'aquarium est : {0}.", this.Acidity.DynamicValue);
                }



                Thread.Sleep(PackageHost.GetSettingValue <int>("Interval"));
            }
        }
Exemple #4
0
        public void ModeAuto()
        {
            TimeAndPlace WakeUp = GetWakeUpHour();
            TimeSpan     prep_time = new TimeSpan();
            string       title, body;

            try
            {
                prep_time = new TimeSpan(0, int.Parse(PackageHost.GetSettingValue("TpsPrep")), 0);
            }
            catch
            {
                prep_time = new TimeSpan(0, 45, 0);
                PackageHost.WriteWarn("Paramètre du temps de préparation non récupéré, le temps de 45mn sera considéré");
            }
            Alarme NewAlarm = new Alarme();

            NewAlarm.IsRinging      = false;
            NewAlarm.TimeFirstEvent = WakeUp.Time.ToString();

            if (WakeUp.Time.Subtract(DateTime.Now) < new TimeSpan(1, 0, 0, 0)) //Si le réveil doit sonner dans + de 24h on active pas encore l'alarme et on attends le refresh journalier
            {
                if (WakeUp.TimeTraffic != new TimeSpan())
                {
                    WakeUp.Time           = WakeUp.Time.Subtract(prep_time + WakeUp.TimeTraffic);
                    NewAlarm.TimeTraffic  = WakeUp.TimeTraffic.ToString();
                    NewAlarm.AlarmHour    = WakeUp.Time.Hour;
                    NewAlarm.AlarmMinutes = WakeUp.Time.Minute;
                    title = "Alarme en mode automatique";
                    body  = string.Format("L'alarme sonnera à {0}:{1}", NewAlarm.AlarmHour.ToString("00"), NewAlarm.AlarmMinutes.ToString("00"));
                    PackageHost.SendMessage(MessageScope.Create("PushBullet"), "PushNote", new object[] { title as System.String, body as System.String });
                    ChangeAlarm(NewAlarm);
                    return;
                }
                else
                {
                    title = "Erreur temps de trajet";
                    body  = "Impossible de récuperer le temps de trajet, le temps de trajet ne sera pas pris en compte";
                    PackageHost.SendMessage(MessageScope.Create("PushBullet"), "PushNote", new object[] { title as System.String, body as System.String });
                    WakeUp.Time           = WakeUp.Time.Subtract(prep_time);
                    NewAlarm.AlarmHour    = WakeUp.Time.Hour;
                    NewAlarm.AlarmMinutes = WakeUp.Time.Minute;
                    NewAlarm.TimeTraffic  = new TimeSpan().ToString();
                    ChangeAlarm(NewAlarm);
                    return;
                }
            }
            else
            {
                PackageHost.WriteInfo("Pas de réveil automatique prévu d'ici les 24h prochaines heures !");
            }
        }
Exemple #5
0
 public void ModeManuel()
 {
     if (int.Parse(ParametresServeur.DynamicValue.AlarmHour.ToString()) > 0 && int.Parse(ParametresServeur.DynamicValue.AlarmMinutes.ToString()) > 0)
     {
         PackageHost.WriteInfo("Mode de réveil = 1");
         Alarme NewAlarm = new Alarme();
         NewAlarm.IsRinging    = false;
         NewAlarm.AlarmHour    = int.Parse(ParametresServeur.DynamicValue.ManualAlarmHour.ToString());
         NewAlarm.AlarmMinutes = int.Parse(ParametresServeur.DynamicValue.ManualAlarmMinute.ToString());
         var title = "Alarme en mode manuel";
         var body  = string.Format("L'alarme sonnera à {0}:{1}", NewAlarm.AlarmHour.ToString("00"), NewAlarm.AlarmMinutes.ToString("00"));
         PackageHost.SendMessage(MessageScope.Create("PushBullet"), "PushNote", new object[] { title as System.String, body as System.String });
         ChangeAlarm(NewAlarm);
         return;
     }
     else
     {
         var title = "Erreur mode manuel";
         var body  = string.Format("L'heure entrée pour le mode manuel n'est pas correct !");
         PackageHost.SendMessage(MessageScope.Create("PushBullet"), "PushNote", new object[] { title as System.String, body as System.String });
     }
 }
Exemple #6
0
 private void reset()
 {
     PackageHost.SendMessage(MessageScope.Create("ConstellationPackagePython2"), "reset", null);
 }
Exemple #7
0
        //fonction d'authentification
        private Guid Auth(String pass, String login, Double latitude, Double longitude)
        {
            //communication avec le serveur
            PackageHost.WriteInfo("Sending data to server");
            WebRequest request = WebRequest.Create("http://192.168.137.121/phpproj18/test.php");

            request.Method = "POST";
            //envoi données au serveur + identité du package
            string postData = "login="******"&passwd=" + pass + "&latitude=" + latitude + "&longitude=" + longitude + "&sender=123";

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            WebResponse response = request.GetResponse();

            Console.WriteLine(((HttpWebResponse)response).StatusDescription);
            dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            //récupération de la réponse serveur
            string responseFromServer = reader.ReadToEnd();

            Console.WriteLine(responseFromServer);

            //cas selon la réponse du serveur
            if (responseFromServer == "youshallpass")
            {
                //accès autorisé, génération d'un token valide
                Guid g;
                g = Guid.NewGuid();
                Console.WriteLine(g);
                if (push == true)
                {
                    PackageHost.SendMessage(MessageScope.Create("PushBullet"), "PushNote", new object[] { "Safe Opening Request", "Access Granted" });
                }
                PackageHost.WriteInfo("Server response : Access Granted");
                reader.Close();
                dataStream.Close();
                response.Close();
                return(g);
            }
            if (responseFromServer == "login")
            {
                //erreur de login, génération d'un token nul
                Guid l = Guid.Empty;;
                Console.WriteLine(l);
                PackageHost.WriteInfo("Server response : Wrong Credentials, access denied");
                if (push == true)
                {
                    PackageHost.SendMessage(MessageScope.Create("PushBullet"), "PushNote", new object[] { "Safe Opening Request", "Wrong Credentials, access denied" });
                }
                reader.Close();
                dataStream.Close();
                response.Close();
                reset();
                return(l);
            }
            if (responseFromServer == "coord")
            {
                //erreur de position, génération d'un token nul
                Guid g = Guid.Empty;;
                Console.WriteLine(g);
                PackageHost.WriteInfo("Server response : Wrong location, access denied");
                if (push)
                {
                    PackageHost.SendMessage(MessageScope.Create("PushBullet"), "PushNote", new object[] { "Safe Opening Request", "Wrong Location, access denied" });
                }
                reader.Close();
                dataStream.Close();
                response.Close();
                reset();
                return(g);
            }
            if (responseFromServer == "lock")
            {
                //système verouillé par l'administrateur, génération d'un token nul
                Guid q = Guid.Empty;;
                Console.WriteLine(q);
                PackageHost.WriteInfo("Server response : System Locked, access denied");
                if (push == true)
                {
                    PackageHost.SendMessage(MessageScope.Create("PushBullet"), "PushNote", new object[] { "Safe Opening Request", "System Locked by admin, access denied" });
                }
                reader.Close();
                dataStream.Close();
                response.Close();
                reset();
                return(q);
            }
            //autre cas
            reader.Close();
            dataStream.Close();
            response.Close();
            Console.WriteLine(responseFromServer);
            Guid w = Guid.NewGuid();

            //Guid w = Guid.Empty;
            Console.WriteLine(w);
            PackageHost.WriteInfo("Server response : granted");
            if (push == true)
            {
                PackageHost.SendMessage(MessageScope.Create("PushBullet"), "PushNote", new object[] { "Safe Opening Request", "Unexpected error" });
            }
            reset();
            return(w);
        }