Ejemplo n.º 1
0
        private async Task PostReading(CavityTemp rd)
        {
            client = new HttpClient();
            try
            {
                string resourceAddress = "http://192.168.43.49/moosareback/api/cavitytemps";
                //var gg = await client.GetStringAsync(resourceAddress);
                //Console.WriteLine("plop:  " + gg);
                string postBody = Common.JsonSerializer(rd);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var response = await client.PostAsync(resourceAddress, new StringContent(postBody, Encoding.UTF8, "application/json"));

                //Console.WriteLine("response:  " + response);
            }
            catch (Exception ex)
            {
                Console.WriteLine("error:  " + ex.Message);
                string error2 = ex.Message;
            }
        }
Ejemplo n.º 2
0
        public async Task GetCavityTemp()
        {
            try {
                ProcessStartInfo start = new ProcessStartInfo();
                start.FileName               = "php";   //"/etc/php5/cli/php.ini";
                start.Arguments              = "/home/pi/sensors_php/cavityTemp.php";
                start.UseShellExecute        = false;
                start.RedirectStandardOutput = true;
                string     line = "";
                CavityTemp cp   = new CavityTemp()
                {
                    _id       = Guid.NewGuid(),
                    ok        = 1,
                    msg       = "OK",
                    sensor    = "cavity_temp",
                    ip        = "pi_sensor_1",
                    time      = DateTime.Now,
                    createdAt = DateTime.Now
                };

                using (Process process = Process.Start(start))
                {
                    using (StreamReader reader = process.StandardOutput)
                    {
                        while ((line = reader.ReadLine()) != null)
                        {
                            cpReading rd = JsonConvert.DeserializeObject <cpReading>(line);
                            cp._time = new DateTime(rd.time * 1000);
                            cp.val   = rd.data;
                        }
                    }
                }
                await PostReading(cp);
            }
            catch (Exception ex)
            {
                Console.WriteLine("error:  " + ex.Message);
                string error2 = ex.Message;
            }
        }