Exemplo n.º 1
0
    private DataTable GetStateObjFromTELIT(DataTable dt, UControlAPI api, string ColName)
    {
        dt.Columns.Add("Value");


        try
        {
            JToken  token;
            dynamic Json;
            string  resp = "";


            Json      = new JObject();
            Json.auth = new JObject(new JProperty("sessionId", HttpContext.Current.Request.Cookies["UserData"]["APISessionId"].ToString()));

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Json.Add((i + 1).ToString(), (new JObject(new JProperty("command", "thing.find"),
                                                          new JProperty("params", new JObject(new JProperty("key", dt.Rows[i][ColName].ToString()))))));
            }

            resp  = api.TelitAPI(Json.ToString());
            token = JObject.Parse(resp);
            string Value = "";
            for (int i = 1; i <= token.Count(); i++)
            {
                string connType = dt.Rows[i - 1]["UConnTypeDep"].ToString();

                // אם מדובר בחיישן
                //   if (connType == "4")
                //     Value = (string)token[i.ToString()].SelectToken("params.alarms.alarm.state");

                // אם מדובר בטמפרטורה
                // if (connType == "3")
                Value = (string)token[i.ToString()].SelectToken("params.properties.status.value");

                dt.Rows[i - 1]["Value"] = Value;
            }
        }
        catch (Exception ex)
        {
        }

        return(dt);
    }
Exemplo n.º 2
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\"}}}";
    }
Exemplo n.º 3
0
    public string SetActionTOUControl(DataTable dt, string uStatus, string uStaticOnHour, string FieldNameForAction, string se = "0")
    {
        string Action = "";

        string Pulses = "200";

        switch (uStatus)
        {
        case "1":
            if (string.IsNullOrEmpty(uStaticOnHour) || uStaticOnHour == "0")
            {
                //אם מדובר המזגן העובד לפי פולסים
                if (dt.Rows[0]["UConnType"].ToString() == "2")
                {
                    Action = "rlyoutcngopen drnplsms(" + Pulses + ")";
                }
                else
                {
                    Action = "rlyoutcngopen fixed";
                }
            }
            else
            {
                //אם מדובר המזגן העובד לפי פולסים
                if (dt.Rows[0]["UConnType"].ToString() == "2")
                {
                    Action = "rlyoutcngopen drnplsms(" + Pulses + ")";
                }
                else
                {
                    int SecOpen = Convert.ToInt32(uStaticOnHour) * 3600;
                    Action = "rlyoutcngopen drnplss(" + SecOpen.ToString() + ")";
                }
            }

            break;

        case "0":
            //אם מדובר המזגן העובד לפי פולסים
            if (dt.Rows[0]["UConnType"].ToString() == "2")
            {
                Action = "rlyoutcngopen drnplsms(" + Pulses + ")";
            }
            else
            {
                Action = "rlyoutcngclose fixed";
            }
            break;

        case "2":
            return("0");   //Action = "rlyoutcngclose fixed";
                           // break;
        }

        UControlAPI api = new UControlAPI();


        JToken  token;
        dynamic Json;
        string  resp = "";



        Json = new JObject();

        if (se == "0")
        {
            Json.auth = new JObject(new JProperty("sessionId", HttpContext.Current.Request.Cookies["UserData"]["APISessionId"].ToString()));
        }
        else
        {
            Json.auth = new JObject(new JProperty("sessionId", SessionOfWebTelit));
        }



        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (!string.IsNullOrEmpty(FieldNameForAction))
            {
                Action = dt.Rows[i][FieldNameForAction].ToString();
                if (string.IsNullOrEmpty(Action))
                {
                    break;
                }
            }


            Json.Add((i + 1).ToString(), (new JObject(new JProperty("command", "method.exec"),
                                                      new JProperty("params", new JObject(new JProperty("thingKey", dt.Rows[i]["UCommKey"].ToString()),
                                                                                          new JProperty("method", "ctu"),
                                                                                          new JProperty("params",
                                                                                                        new JObject(
                                                                                                            new JProperty("ctu", "id(" + dt.Rows[i]["UConnId"].ToString() + ")" + Action)
                                                                                                            )
                                                                                                        )
                                                                                          )))));
        }

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

        return(resp);
    }