public MainPage()
        {
            this.InitializeComponent();
#pragma warning disable 4014
            IoTClient.Start(this);
#pragma warning restore 4014
        }
Ejemplo n.º 2
0
        void Run()
        {
            CancellationTokenSource tokenSource       = new CancellationTokenSource();
            CancellationToken       cancellationToken = tokenSource.Token;

            var task = Task.Run(() =>
            {
                // already canceled
                cancellationToken.ThrowIfCancellationRequested();

                string connectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];
                string eventhubentity   = ConfigurationManager.AppSettings["EventHubName"];

                IIoTClient iotClient = new IoTClient("emulgadgeteer", Guid.NewGuid().ToString(), connectionString, eventhubentity);
                iotClient.Open();

                IDictionary bag = new Hashtable();

                while (true)
                {
                    bag.Clear();
                    bag.Add(SensorType.Temperature, this.GetRandomNumber(23, 25));
                    bag.Add(SensorType.Humidity, this.GetRandomNumber(40, 50));
                    bag.Add(SensorType.Accelerometer, new double[] { this.GetRandomNumber(-1, 1), this.GetRandomNumber(-1, 1), this.GetRandomNumber(-1, 1) });

                    iotClient.SendAsync(bag);

                    // check if cancellation requested
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    Thread.Sleep(1000);
                }

                iotClient.Close();
            }, cancellationToken);

            Console.WriteLine("Click a button to end the emulator ...");
            Console.ReadLine();

            tokenSource.Cancel();

            try
            {
                task.Wait();
            }
            catch (AggregateException e)
            {
                foreach (var v in e.InnerExceptions)
                {
                    Console.WriteLine(e.Message + " " + v.Message);
                }
            }
            finally
            {
                tokenSource.Dispose();
            }
        }
Ejemplo n.º 3
0
        private void InitializeIoTClient()
        {
            if (_iotClient != null)
            {
                return;
            }

            string token = (Application.Current.Properties["State"] as ManagedDevice)?.IoTToken;

            if (token != null)
            {
                _iotClient = new IoTClient(token);
            }
        }
Ejemplo n.º 4
0
        internal IkController(InverseKinematics inverseKinematics,
                              SparkFunSerial16X2Lcd display,
                              IoTClient ioTClient,
                              Gps.Gps gps)
        {
            _inverseKinematics = inverseKinematics;
            _display           = display;
            _ioTClient         = ioTClient;
            _gps = gps;

            _perimeterInInches = 15;

            _selectedIkFunction = SelectedIkFunction.BodyHeight;
            _behavior           = Behavior.Bounce;
        }
Ejemplo n.º 5
0
        internal IkController(InverseKinematics inverseKinematics, 
                              SparkFunSerial16X2Lcd display, 
                              IoTClient ioTClient,
                              Gps.Gps gps)
        {
            _inverseKinematics = inverseKinematics;
            _display = display;
            _ioTClient = ioTClient;
            _gps = gps;

            _perimeterInInches = 15;

            _selectedIkFunction = SelectedIkFunction.BodyHeight;
            _behavior = Behavior.Bounce;
        }
        private void tempValueChanged(object sender, RangeBaseValueChangedEventArgs e)
        {
            SendToastNotification();
            int newTemp = (int)e.NewValue;

            HeaterCommand heatercommand = new HeaterCommand();

            heatercommand.command       = "SetDesiredTemp";
            heatercommand.parameterName = "temperature";
            heatercommand.parameter     = newTemp;

            String command = JsonConvert.SerializeObject(heatercommand);

            settemp.Text = "Desired Temp: " + newTemp + "C";

            IoTClient.SendEvent(command);
        }
        private void toggleHandler(object sender, RoutedEventArgs e)
        {
            SendToastNotification();

            //TODO disable receiving new commands while this command gets to device
            SendToastNotification();
            int param = 0;

            HeaterCommand heatercommand = new HeaterCommand();
            string        command;

            if (toggleSwitch.IsOn)
            {
                heatercommand.command = "TurnHeaterOn";
            }
            else
            {
                heatercommand.command       = "TurnHeaterOff";
                heatercommand.parameterName = "reason";
                heatercommand.parameter     = param;
            }
            command = JsonConvert.SerializeObject(heatercommand);
            IoTClient.SendEvent(command);
        }
        private async void UpdateDemographics(ImageAnalyzer img)
        {
            if (this.lastSimilarPersistedFaceSample != null)
            {
                bool demographicsChanged = false;
                // Update the Visitor collection (either add new entry or update existing)
                foreach (var item in this.lastSimilarPersistedFaceSample)
                {
                    Visitor visitor;
                    String  unique = "1";
                    if (this.visitors.TryGetValue(item.SimilarPersistedFace.PersistedFaceId, out visitor))
                    {
                        visitor.Count++;
                        unique = "0";
                    }
                    else
                    {
                        demographicsChanged = true;

                        visitor = new Visitor {
                            UniqueId = item.SimilarPersistedFace.PersistedFaceId, Count = 1
                        };
                        this.visitors.Add(visitor.UniqueId, visitor);
                        this.demographics.Visitors.Add(visitor);

                        // Update the demographics stats. We only do it for new visitors to avoid double counting.
                        AgeDistribution genderBasedAgeDistribution = null;
                        if (string.Compare(item.Face.FaceAttributes.Gender, "male", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            this.demographics.OverallMaleCount++;
                            genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.MaleDistribution;
                        }
                        else
                        {
                            this.demographics.OverallFemaleCount++;
                            genderBasedAgeDistribution = this.demographics.AgeGenderDistribution.FemaleDistribution;
                        }

                        if (item.Face.FaceAttributes.Age < 16)
                        {
                            genderBasedAgeDistribution.Age0To15++;
                        }
                        else if (item.Face.FaceAttributes.Age < 20)
                        {
                            genderBasedAgeDistribution.Age16To19++;
                        }
                        else if (item.Face.FaceAttributes.Age < 30)
                        {
                            genderBasedAgeDistribution.Age20s++;
                        }
                        else if (item.Face.FaceAttributes.Age < 40)
                        {
                            genderBasedAgeDistribution.Age30s++;
                        }
                        else if (item.Face.FaceAttributes.Age < 50)
                        {
                            genderBasedAgeDistribution.Age40s++;
                        }
                        else
                        {
                            genderBasedAgeDistribution.Age50sAndOlder++;
                        }
                    }
                    if (lastEmotionSample != null)
                    {
                        Random rand = new Random();
                        Dictionary <String, String> dictionary = new Dictionary <String, String>();

                        dictionary["id"]        = item.SimilarPersistedFace.PersistedFaceId.ToString();
                        dictionary["gender"]    = item.Face.FaceAttributes.Gender.ToString();
                        dictionary["age"]       = item.Face.FaceAttributes.Age.ToString();
                        dictionary["date"]      = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                        dictionary["smile"]     = item.Face.FaceAttributes.Smile.ToString();
                        dictionary["glasses"]   = item.Face.FaceAttributes.Glasses.ToString();
                        dictionary["avgs"]      = rand.Next(5, 8).ToString();
                        dictionary["avgrank"]   = (3 + rand.NextDouble() * 1.5).ToString();
                        dictionary["isunique"]  = unique;
                        dictionary["anger"]     = lastEmotionSample.First().Scores.Anger.ToString();
                        dictionary["contempt"]  = lastEmotionSample.First().Scores.Contempt.ToString();
                        dictionary["disgust"]   = lastEmotionSample.First().Scores.Disgust.ToString();
                        dictionary["fear"]      = lastEmotionSample.First().Scores.Fear.ToString();
                        dictionary["happiness"] = lastEmotionSample.First().Scores.Happiness.ToString();
                        dictionary["neutral"]   = lastEmotionSample.First().Scores.Neutral.ToString();
                        dictionary["sadness"]   = lastEmotionSample.First().Scores.Sadness.ToString();
                        dictionary["surprise"]  = lastEmotionSample.First().Scores.Surprise.ToString();

                        //#pragma warning restore 4014
                        System.Diagnostics.Debug.WriteLine("here!!!!!!!!");
                        var name   = "null";
                        var person = "";
                        System.Diagnostics.Debug.WriteLine("Identify? : " + lastIdentifiedPersonSample == null);
                        if (null != lastIdentifiedPersonSample)
                        {
                            name   = lastIdentifiedPersonSample.First().Item2.Person.Name.ToString();
                            person = lastIdentifiedPersonSample.First().Item2.Person.PersonId.ToString();
                        }
                        System.Diagnostics.Debug.WriteLine("Name: " + name);
                        System.Diagnostics.Debug.WriteLine("ID: " + person);
                        dictionary["personid"]   = person;
                        dictionary["personname"] = name;
                        ////#pragma warning disable 4014
                        String str = SettingsHelper.Instance.IoTHubConnectString;
                        await IoTClient.Start(dictionary, SettingsHelper.Instance.IoTHubConnectString);
                    }
                }

                if (demographicsChanged)
                {
                    this.ageGenderDistributionControl.UpdateData(this.demographics);
                }

                this.overallStatsControl.UpdateData(this.demographics);
            }
        }