Esempio n. 1
0
 public void Delete(int id)
 {
     using (IrigationDBEntities1 context = new IrigationDBEntities1())
     {
         Senzori senzor = context.Senzoris.FirstOrDefault(s => s.Id == id);
         context.Senzoris.Remove(senzor);
         context.SaveChanges();
     }
 }
Esempio n. 2
0
 // DELETE api/values/5
 public void Delete(int id)
 {
     using (IrigationDBEntities1 context = new IrigationDBEntities1())
     {
         Value value = context.Values.Include(val => val.Senzori).FirstOrDefault(v => v.Id == id);
         context.Values.Remove(value);
         context.SaveChanges();
     }
 }
Esempio n. 3
0
 public void Put(Senzori sen)
 {
     using (IrigationDBEntities1 context = new IrigationDBEntities1())
     {
         Senzori senzor = context.Senzoris.FirstOrDefault(s => s.Id == sen.Id);
         senzor.Locatie = sen.Locatie;
         context.SaveChanges();
     }
 }
Esempio n. 4
0
 public Senzori Post(Senzori senzor)
 {
     using (IrigationDBEntities1 context = new IrigationDBEntities1())
     {
         // value.Senzori = context.Senzoris.Include(sen => sen.Values).Include(sen => sen.Istorics).Where(sen => sen.Id == value.Id_senzor).First();
         context.Senzoris.Add(senzor);
         context.SaveChanges();
     }
     return(senzor);
 }
Esempio n. 5
0
 // DELETE api/values/05-Dec-18 7:33:57 PM
 public void Delete(DateTime timestemp)
 {
     using (IrigationDBEntities1 context = new IrigationDBEntities1())
     {
         //istorics = context.Istorics.Include(i => i.Senzori).Where(i => i.Data.Equals(datetime)).ToList<Istoric>();
         // istorics.ForEach(x => x.Senzori = null);
         Value value = context.Values.Include(val => val.Senzori).FirstOrDefault(v => v.Timestemp == timestemp);
         context.Values.Remove(value);
         context.SaveChanges();
     }
 }
Esempio n. 6
0
 // PUT api/values/5
 public void Put(int id, string pompa)
 {
     using (IrigationDBEntities1 context = new IrigationDBEntities1())
     {
         Value value = context.Values.FirstOrDefault(v => v.Id == id);
         value.Timestemp = DateTime.Now;
         // value.Temperatura = temp;
         //value.Umiditate = umiditate;
         value.Pompa = pompa;
         context.SaveChanges();
     }
 }
Esempio n. 7
0
        public void Put(Value value)
        {
            using (IrigationDBEntities1 context = new IrigationDBEntities1())
            {
                Value value2 = context.Values.FirstOrDefault(v => v.Id == value.Id);
                value2.Timestemp = DateTime.Now;
                if (value.Temperatura != null)
                {
                    value2.Temperatura = value.Temperatura;
                }
                if (value.Umiditate != null)
                {
                    value2.Umiditate = value.Umiditate;
                }
                if (value.Pompa != null)
                {
                    value2.Pompa = value.Pompa;
                }

                context.SaveChanges();
            }
        }
Esempio n. 8
0
        // This function will get triggered/executed when a new message is written
        // on an Azure Queue called queue.
        public static void ProcessQueueMessage([ServiceBusTrigger("queue")] BrokeredMessage message, TextWriter log)
        {
            try {
                //byte[] msg = message.Body;
                //string json = Encoding.UTF8.GetString(msg);
                //var json = Encoding.Unicode.GetString(message);
                //Value value = message.GetBody<Value>();

                // Value value = JsonConvert.DeserializeObject<Value>(json);
                // Console.WriteLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber} Body:{Encoding.UTF8.GetString(message.Body)}");

                Value value = new Value();
                value.Temperatura = (double)message.Properties["Temperatura"];
                value.Umiditate   = (double)message.Properties["Umiditate"];
                value.Pompa       = message.Properties["Pompa"].ToString();
                value.Id_senzor   = (int)message.Properties["Id_senzor"];
                message.Complete();

                double previousTemp     = 0;
                double tempTreshold     = 10;
                double tempMax          = 50;
                double tempMin          = -50;
                double umidityTreshhold = 35;
                double umidityUpLimit   = 80;

                using (IrrigationAPI.Models.IrigationDBEntities1 context = new IrigationDBEntities1())
                {
                    Value previousvalue = context.Values.Include(val => val.Senzori).Where(s => s.Id_senzor == value.Id_senzor).ToList().LastOrDefault();
                    if (previousvalue != null)
                    {
                        previousTemp = (double)previousvalue.Temperatura;
                    }
                    else
                    {
                        previousTemp = 0;
                    }

                    //  Verify data
                    if (value.Umiditate > 100)
                    {
                        value.Umiditate = 100;
                    }
                    else if (value.Umiditate < 0)
                    {
                        value.Umiditate = 0;
                    }

                    //Start pompa if umiditate is below umidityTreshhold
                    if (value.Umiditate < umidityTreshhold)
                    {
                        value.Pompa = "On";
                    }
                    else if (value.Umiditate > umidityUpLimit)
                    {
                        value.Pompa = "Off";
                    }

                    if (previousTemp == 0)
                    {
                        if (value.Temperatura > tempMax)
                        {
                            previousTemp = tempMax;
                        }
                        else if (value.Temperatura < tempMin)
                        {
                            previousTemp = tempMin;
                        }
                        else
                        {
                            previousTemp = (double)value.Temperatura;
                        }
                    }

                    if (value.Temperatura < previousTemp - tempTreshold)
                    {
                        value.Temperatura = previousTemp - tempTreshold;
                        previousTemp      = (double)value.Temperatura;
                    }
                    else if (value.Temperatura > previousTemp + tempTreshold)
                    {
                        value.Temperatura = previousTemp + tempTreshold;
                        previousTemp      = (double)value.Temperatura;
                    }
                    else
                    {
                        previousTemp = (double)value.Temperatura;
                    }


                    //value.Senzori = context.Senzoris.Include(sen => sen.Values).Where(sen => sen.Id == value.Id_senzor).First();
                    value.Timestemp = DateTime.Now;
                    context.Values.Add(value);
                    context.SaveChanges();
                    // Thread.Sleep(5000);
                }
            }

            catch (Exception e)
            {
                // Thread.Sleep(5000);
                //message.RenewLock();
            }
        }
Esempio n. 9
0
        //                                 every day at 00:00:00
        public static void Run([TimerTrigger("0 0 0 * * *")] TimerInfo myTimer, TraceWriter log)
        {
            double tempmin, tempmax, tempavg, umidmin, umidmax, umidavg;
            int    count;

            using (IrigationDBEntities1 context = new IrigationDBEntities1())
            {
                //                                         .Include(val => val.Values).Include(val => val.Istorics)
                List <Senzori> senzoriList = context.Senzoris.ToList();
                foreach (Senzori s in senzoriList)
                {
                    tempmin = 100;
                    tempmax = -100;
                    tempavg = 0;
                    umidmin = 100;
                    umidmax = 0;
                    umidavg = 0;
                    List <Value> valuesList = context.Values.Where(v => v.Id_senzor == s.Id).ToList();
                    //list.ForEach(x => x.Senzori = null);
                    count = valuesList.Count;
                    foreach (Value v in valuesList)
                    {
                        tempavg += (double)v.Temperatura;
                        umidavg += (double)v.Umiditate;
                        if (v.Umiditate > umidmax)
                        {
                            umidmax = (double)v.Umiditate;
                        }
                        if (v.Temperatura > tempmax)
                        {
                            tempmax = (double)v.Temperatura;
                        }
                        if (v.Umiditate < umidmin)
                        {
                            umidmin = (double)v.Umiditate;
                        }
                        if (v.Temperatura < tempmin)
                        {
                            tempmin = (double)v.Temperatura;
                        }
                        //delete value
                        context.Values.Remove(v);
                        context.SaveChanges();
                    }
                    umidavg /= count;
                    tempavg /= count;
                    Istoric istoric = new Istoric();
                    istoric.Id_senzor        = s.Id;
                    istoric.MaxTemperatura   = tempmax;
                    istoric.MinTemperatura   = tempmin;
                    istoric.MedieTemperatura = tempavg;
                    istoric.MaxUmiditate     = umidmax;
                    istoric.MaxUmiditate     = umidmax;
                    istoric.MedieUmiditate   = umidavg;
                    istoric.Data             = DateTime.Now;
                    context.Istorics.Add(istoric);
                    context.SaveChanges();
                }
            }
            //log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
        }