public async void SendMessage(HappyModel model) { var messageString = JsonConvert.SerializeObject(model); var message = new Message(Encoding.ASCII.GetBytes(messageString)); await deviceClient.SendEventAsync(message); }
private void DisplayModel(HappyModel model) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("storeID : {0}\n", model.storeID); sb.AppendFormat("time : {0}\n", model.time); sb.AppendFormat("Anger : {0}\n", model.Anger); sb.AppendFormat("Contempt : {0}\n", model.Contempt); sb.AppendFormat("Disgust : {0}\n", model.Disgust); sb.AppendFormat("Fear : {0}\n", model.Fear); sb.AppendFormat("Happiness : {0}\n", model.Happiness); sb.AppendFormat("Neutral : {0}\n", model.Neutral); sb.AppendFormat("Sadness : {0}\n", model.Sadness); sb.AppendFormat("Surprise : {0}\n", model.Surprise); sb.AppendFormat("Temperature: {0}\n", model.temperature); sb.AppendFormat("Humidity: {0}\n", model.humidity); textbox.Text = sb.ToString(); }
private async void Timer_Tick(object sender, object e) { try { //emotion api calling float humidity = BMP280.GetHumidity(); float temperature = BMP280.GetTemperature(); Scores scores = await client.RecognizeAsync(Person[PersonIndex]); HappyModel model = new HappyModel(Store[StoreIndex].StoreName, temperature, humidity, Store[StoreIndex].Longitude.ToString(), Store[StoreIndex].Latitude.ToString(), scores); DisplayModel(model); //Image setting Image img = sender as Image; BitmapImage bitmapImage = new BitmapImage(); bitmapImage.UriSource = new Uri(Person[PersonIndex]); imgPerson.Source = bitmapImage; //Map Setting Windows.Devices.Geolocation.BasicGeoposition geo = new Windows.Devices.Geolocation.BasicGeoposition(); geo.Latitude = Store[StoreIndex].Latitude; geo.Longitude = Store[StoreIndex].Longitude; Windows.UI.Xaml.Controls.Maps.MapIcon icon = new Windows.UI.Xaml.Controls.Maps.MapIcon(); icon.Location = new Windows.Devices.Geolocation.Geopoint(geo); icon.NormalizedAnchorPoint = new Point(1, 1); icon.Title = Store[StoreIndex].StoreName; mapStoreLocation.MapElements.Clear(); mapStoreLocation.MapElements.Add(icon); await mapStoreLocation.TrySetViewAsync(new Windows.Devices.Geolocation.Geopoint(geo), 18, 0, 0, Windows.UI.Xaml.Controls.Maps.MapAnimationKind.Bow); //IoTHubProxy data sending try { IoTProxy.SendMessage(model); } catch (Exception ex) { Debug.WriteLine("IoTHub======" + ex.Message); } PersonIndex++; StoreIndex++; //Init index if (PersonIndex == Person.Count() - 1) { PersonIndex = 0; } if (StoreIndex == Store.Count() - 1) { StoreIndex = 0; } } catch (Exception ex) { Debug.WriteLine("System======" + ex.Message); } }