Exemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ConnectTheDotsSensor sensor = ctdHelper.sensors.Find(item => item.measurename == "Temperature");

            sensor.value = counter++;
            ctdHelper.SendSensorData(sensor);
        }
Exemplo n.º 2
0
        public static async Task InvokeRequestResponseService(ConnectTheDotsSensor sensr)
        {
            try
            {
                //string tmp = "50";
                //string tmp = Convert.ToInt32(sensr.temperatureC).ToString();
                using (var client = new HttpClient())
                {
                    var scoreRequest = new
                    {

                        Inputs = new Dictionary<string, StringTable>() {
                        {
                            "input1",
                            new StringTable()
                            {
                                ColumnNames = new string[] {"Celsius"},
                                Values = new string[,] {  { Convert.ToInt32(sensr.temperatureC).ToString() },  { "0" },  }
                            }
                        },
                                        },
                        GlobalParameters = new Dictionary<string, string>()
                        {
                        }
                    };
                    const string apiKey = "gStaeRqaDSv1VwuYroAmuHtgtILXDHheoacm+Aa1cXe3Ke03GVIiKiCix1zaydkrpV509wyp5Dp8gCyCk/bUww=="; // Replace this with the API key for the web service
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

                    client.BaseAddress = new Uri("https://ussouthcentral.services.azureml.net/workspaces/d61f99ed585a48b8ae817d9c3dd305cb/services/3ef0b80bb0d843b584a514eae915c158/execute?api-version=2.0&details=true");

                    // WARNING: The 'await' statement below can result in a deadlock if you are calling this code from the UI thread of an ASP.Net application.
                    // One way to address this would be to call ConfigureAwait(false) so that the execution does not attempt to resume on the original context.
                    // For instance, replace code such as:
                    //      result = await DoSomeTask()
                    // with the following:
                    //      result = await DoSomeTask().ConfigureAwait(false)


                    HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest);

                    if (response.IsSuccessStatusCode)
                    {
                        string result = await response.Content.ReadAsStringAsync();
                        RootObject publicFeed = new RootObject();
                        publicFeed = JsonConvert.DeserializeObject<RootObject>(result);
                        sensr.tempAnomaly = publicFeed.Results.output1.value.Values[0][0].ToString();
                        System.Diagnostics.Debug.WriteLine("Anomaly reading: " + sensr.tempAnomaly);
                        //Console.WriteLine("Result: {0}", result);
                    }
                    else
                    {
                        //Console.WriteLine(string.Format("The request failed with status code: {0}", response.StatusCode));

                        // Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
                        //Console.WriteLine(response.Headers.ToString());

                        string responseContent = await response.Content.ReadAsStringAsync();
                        //Console.WriteLine(responseContent);
                    }
                }
            }
            catch (Exception ex) { throw ex; }
        }
 public void SendSensorData(ConnectTheDotsSensor sensor)
 {
     sensor.timecreated = DateTime.UtcNow.ToString("o");
     sendMessage(sensor.ToJson());
 }
Exemplo n.º 4
0
 public void SendSensorData(ConnectTheDotsSensor sensor)
 {
     sensor.timecreated = DateTime.UtcNow.ToString("o");
     sendMessage(sensor.ToJson());  //mjw send to memory stream via JSON
 }
Exemplo n.º 5
0
 public void SendSensorData(ConnectTheDotsSensor sensor)
 {
     sensor.timecreated = DateTime.UtcNow.ToString("o");
     sendMessage(sensor.ToJson());
 }