Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        UControlAPI api = new UControlAPI();

        string sess = api.GetSessionId();



        // הדלקה כרגע
        dynamic Json = new JObject();

        Json.auth = new JObject(new JProperty("sessionId", sess));
        Json.Add("1", (new JObject(new JProperty("command", "method.exec"),
                                   new JProperty("params", new JObject(new JProperty("thingKey", "899720203753622046"),
                                                                       new JProperty("method", "ctu"),
                                                                       new JProperty("params",

                                                                                     new JObject(

                                                                                         new JProperty("ctu", "id(8) rlyoutcngopen drnplss(10)")
                                                                                         )
                                                                                     )
                                                                       )))));


        //id(8) rlyoutcngopen drnplss(10)

        //string resp = api.TelitAPI(Json.ToString());


        //// הדלקה כרגע
        //dynamic Json = new JObject();
        //Json.auth = new JObject(new JProperty("sessionId", sess));
        //Json.Add("1", (new JObject(new JProperty("command", "alarm.publish"),
        //    new JProperty("params", new JObject(new JProperty("thingKey", "rly_22"),
        //                                        new JProperty("key", "alarm"),
        //                                          new JProperty("state", "1")
        //                                        )))));

        //string resp = api.TelitAPI(Json.ToString());

        // קריאת מצב נתון

        //dynamic Json = new JObject();
        //Json.auth = new JObject(new JProperty("sessionId", sess));

        //for (int i = 0; i < 3; i++)
        //{
        //    Json.Add(i.ToString(), (new JObject(new JProperty("command", "alarm.current"),
        //    new JProperty("params", new JObject(new JProperty("thingKey", "rly_2" + i.ToString()), new JProperty("key", "alarm"))))));

        //}



        string resp  = api.TelitAPI(Json.ToString());
        JToken token = JObject.Parse(resp);

        foreach (var item in token)
        {
            string res = (string)item.SelectToken("..state");
        }



        //   string json = "{\"auth\":{\"sessionId\":\"584542d93447634334324f45\"},\"1\":{\"command\":\"alarm.current\",\"params\":{\"thingKey\":\"rly_22\",\"key\":\"alarm\"}}}";
    }
Esempio n. 2
0
    public void Control_GetAllUConnectSchedular()
    {
        try
        {
            DataTable dt = Dal.ExeSp("Control_GetAllUConnectSchedular");
            if (dt.Rows.Count > 0)
            {
                UControlAPI api = new UControlAPI();

                DataTable UDepDataTable = new DataTable();
                // בדיקה אם יש תלויים כגון חיישן
                var UDepDataRows = dt.Select("UConnIdDep is not null");
                if (UDepDataRows.Length != 0)
                {
                    UDepDataTable = UDepDataRows.CopyToDataTable();

                    GetStateObjFromTELIT(UDepDataTable, api, "UConnKeyDep"); // כגון dig_226


                    for (int i = 0; i < UDepDataTable.Rows.Count; i++)
                    {
                        string val = UDepDataTable.Rows[i]["Value"].ToString();           //  ערך מהיחידה המקושרת כגון טמפ
                                                                                          // חיישן אקבל כאן 0 או 1
                                                                                          // טמפרטורה אקבל כאן 19.2

                        string status       = UDepDataTable.Rows[i]["status"].ToString(); // המצב המבוקש מדטהבייס
                        string UConnectId   = UDepDataTable.Rows[i]["UConnectId"].ToString();
                        string LastStatus   = UDepDataTable.Rows[i]["LastStatus"].ToString();
                        string UConnType    = UDepDataTable.Rows[i]["UConnType"].ToString();    // סוג יחידה מתח או מזגן פולסים
                        string UConnTypeDep = UDepDataTable.Rows[i]["UConnTypeDep"].ToString(); // חיישן 4 טמפ 3
                        string UtempStart   = UDepDataTable.Rows[i]["UtempStart"].ToString();
                        string UtempEnd     = UDepDataTable.Rows[i]["UtempEnd"].ToString();



                        if (status == "1")// חסר לבדוק מצב מזגן
                        {
                            // במידה ומדובר בחיישן והערך נשאר כמקודם אל תעשה שום פקודה
                            // אם מדובר בטמפרטורה תבדוק אם זה בטווח
                            if (
                                (UConnTypeDep == "4" && val == LastStatus)
                                ||
                                (UConnTypeDep == "3" && IsValTempOutRange(val, UtempStart, UtempEnd))
                                )
                            {
                                var rows = dt.Select("UConnectId = " + UConnectId);
                                rows[0].Delete();
                                dt.AcceptChanges();
                            }
                            else
                            {
                                Dal.ExeSp("Control_UpdateStatus", UConnectId, "1");
                            }
                        }
                        else
                        {
                            Dal.ExeSp("Control_UpdateStatus", UConnectId, "0");
                        }
                    }
                }// end UDepDataTable



                string resp = SetActionTOUControl(dt, "", "", "Action", "1");

                if (resp.Contains("Authentication session is invalid"))
                {
                    SessionOfWebTelit = api.GetSessionId();

                    SetActionTOUControl(dt, "", "", "Action", "1");
                }

                //// את המתאמים שידרתי והערתי את הבקר , עכשיו לעשות עוד פקודה
                //UDepDataRows = UDepDataTable.Select("UConnType=2"); // אך ורק מזגן פולסים
                //if (UDepDataRows.Count() > 0)
                //{
                //    //המתנה 3 שניות אחרי שעוררתי את היחידה
                //    System.Threading.Thread.Sleep(3000);
                //    resp = SetActionTOUControl(UDepDataRows.CopyToDataTable(), "", "", "Action", "1");
                //}
            }
        }
        catch (Exception ex)
        {
        }
    }