public ActionResult <dynamic> Post([FromForm] float humidity, [FromForm] float temperature, [FromForm] float lux, [FromForm] float relay, [FromForm] float roride)
        {
            _logger.LogInformation("POST triggered.");

            ArduinoMega     relayInputModel     = new ArduinoMega(temperature, humidity, lux);
            ArduinoMegaJSON relayInputModelJSON = new ArduinoMegaJSON(Convert.ToInt32(relay), Convert.ToInt32(roride), relayInputModel);


            try
            {
                //convert object to json string.
                string json = JsonConvert.SerializeObject(relayInputModelJSON);

                //export data to json file.
                using (TextWriter tw = new StreamWriter(this.path))
                {
                    tw.WriteLine(json);
                };
                //return new StatusCodeResult(200);

                _logger.LogInformation("Data stored.");
            }
            catch (Exception ex)
            {
                _logger.LogError("Something unexpectedly broke while trying to fetch arduino data.");
                _logger.LogError(ex.Message.ToString());
                return(new StatusCodeResult(502));
            }
            return(new StatusCodeResult(200));
        }
Ejemplo n.º 2
0
 public ArduinoMegaJSON(int relay, int roride, ArduinoMega Mega) : base(Mega.temperature, Mega.humidity, Mega.lux)
 {
     this.relay  = relay;
     this.roride = roride;
 }