Exemplo n.º 1
0
        public async Task Set_Temperature(float temperature)
        {
            Console.WriteLine("{0}", temperature);
            HttpClient         hc   = new HttpClient();
            Aqua_Lamp_Lit_Json allj = new Aqua_Lamp_Lit_Json();

            allj.Lamp_ID     = Config_Client.m_Config.client_id;
            allj.Temperature = temperature.ToString();
            HttpContent http_content = new StringContent(JsonHelper.ToJson(allj, typeof(Aqua_Lamp_Lit_Json)));
            var         res          = await hc.PostAsync(Config_Client.m_Config.server_endpoint + "/api/lit/set_by_id/" + Config_Client.m_Config.client_id, http_content);
        }
Exemplo n.º 2
0
        public async Task <Aqua_Lamp_Lit_Json> Get_Aqua_Lamp_Lit(String id)
        {
            HttpClient hc  = new HttpClient();
            var        res = await hc.GetAsync(Config_Client.m_Config.server_endpoint + "/api/lit/query_by_id/" + id);

            var res_str = await res.Content.ReadAsStringAsync();

            Aqua_Lamp_Lit_Json allj = (Aqua_Lamp_Lit_Json)JsonHelper.FromJson(res_str, typeof(Aqua_Lamp_Lit_Json));

            return(allj);
        }
Exemplo n.º 3
0
        public async Task Start()
        {
            Lit            t_Lit      = new Lit();
            GpioController controller = new GpioController();

            controller.OpenPin(Config_Client.m_Config.GPIO_LIT, PinMode.Output);
            Aqua_Lamp_Lit_Json allj_global = new Aqua_Lamp_Lit_Json();

            Loop_Enable = true;
            while (Loop_Enable)
            {
                try
                {
                    var allj = await t_Lit.Get_Aqua_Lamp_Lit(Config_Client.m_Config.client_id);

                    allj_global = await t_Lit.Get_Aqua_Lamp_Lit("GLOBAL");

                    if (allj.Lit.Equals("On"))
                    {
                        controller.Write(Config_Client.m_Config.GPIO_LIT, PinValue.Low);
                    }
                    if (allj.Lit.Equals("Off"))
                    {
                        controller.Write(Config_Client.m_Config.GPIO_LIT, PinValue.High);
                    }
                    if (allj.Lit.Equals("High Impedance"))
                    {
                        bool     lamp_lit  = false;
                        String[] lit_array = allj_global.Script.Split("\n", StringSplitOptions.RemoveEmptyEntries);
                        for (int lit_array_index = 0; lit_array_index < lit_array.Length; lit_array_index++)
                        {
                            String[] time_zone = lit_array[lit_array_index].Split(" ", StringSplitOptions.RemoveEmptyEntries);
                            Int64    tz_from   = Convert.ToInt64(time_zone[0]);
                            Int64    tz_to     = Convert.ToInt64(time_zone[1]);
                            var      t_now     = DateTime.Now;
                            Int64    t_second  = t_now.Hour * 3600 + t_now.Minute * 60 + t_now.Second;
                            if (t_second >= tz_from && t_second <= tz_to)
                            {
                                lamp_lit = true;
                            }
                        }

                        if (lamp_lit)
                        {
                            controller.Write(Config_Client.m_Config.GPIO_LIT, PinValue.Low);
                        }
                        else
                        {
                            controller.Write(Config_Client.m_Config.GPIO_LIT, PinValue.High);
                        }
                    }
                    Thread.Sleep(3000);
                }catch (Exception e)
                {
                    bool     lamp_lit  = false;
                    String[] lit_array = allj_global.Script.Split("\n", StringSplitOptions.RemoveEmptyEntries);
                    for (int lit_array_index = 0; lit_array_index < lit_array.Length; lit_array_index++)
                    {
                        String[] time_zone = lit_array[lit_array_index].Split(" ", StringSplitOptions.RemoveEmptyEntries);
                        Int64    tz_from   = Convert.ToInt64(time_zone[0]);
                        Int64    tz_to     = Convert.ToInt64(time_zone[1]);
                        var      t_now     = DateTime.Now;
                        Int64    t_second  = t_now.Hour * 3600 + t_now.Minute * 60 + t_now.Second;
                        if (t_second >= tz_from && t_second <= tz_to)
                        {
                            lamp_lit = true;
                        }
                    }

                    if (lamp_lit)
                    {
                        controller.Write(Config_Client.m_Config.GPIO_LIT, PinValue.Low);
                    }
                    else
                    {
                        controller.Write(Config_Client.m_Config.GPIO_LIT, PinValue.High);
                    }
                    Console.WriteLine("L");
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.Data);
                }
            }
        }