Esempio n. 1
0
        public IHttpActionResult GiveFood()
        {
            // TODO: make api call to teleduino service
            var feeding = new Feeding
            {
                Quantity = 200,
                Time = DateTime.Now,
                UserId = this.userId
            };

            this.feedings.Add(feeding);
            this.feedings.SaveChanges();

            return this.Ok();
        }
Esempio n. 2
0
        public IHttpActionResult GiveFood()
        {
            var webClient = new WebClient();

            try
            {
                // Define servo
                webClient.DownloadString(string.Format(
                    "https://us01.proxy.teleduino.org/api/1.0/328.php?k={0}&r=defineServo&servo=0&pin={1}", TeleduinoKey, ServoPin));

                // Set initial servo position
                webClient.DownloadString(
                    string.Format("https://us01.proxy.teleduino.org/api/1.0/328.php?k={0}&r=setServo&servo=0&position=25", TeleduinoKey));

                // Open door
                webClient.DownloadString(
                    string.Format("https://us01.proxy.teleduino.org/api/1.0/328.php?k={0}&r=setServo&servo=0&position=70", TeleduinoKey));

                // Close door
                webClient.DownloadString(
                    string.Format("https://us01.proxy.teleduino.org/api/1.0/328.php?k={0}&r=setServo&servo=0&position=25", TeleduinoKey));

                var feeding = new Feeding
                {
                    Quantity = 200,
                    Time = DateTime.Now,
                    UserId = this.CurrentUserId
                };

                this.feedings.Add(feeding);
                this.feedings.SaveChanges();

                return this.Ok();
            }
            catch (Exception e)
            {
                return this.BadRequest(e.Message);
            }
        }