Beispiel #1
0
        public bool IsCameraDone(int retries = 1, int delay = 0)
        {
            // Get PTZ Check State
            HttpReq req3 = new HttpReq();

            req3.Open("Post", "http://ccacamp.hopto.org:1961/api.cgi?cmd=GetPtzCheckState&token=" + _token); // &user=admin&password=Red35845!");

            req3.AddHeaderProp("Connection: keep-alive");
            req3.AddHeaderProp("Accept: */*");
            req3.AddHeaderProp("Accept-Encoding: gzip, deflate, br");
            req3.AddBody("[{\"cmd\":\"GetPtzCheckState\",\"action\":0,\"param\":{\"channel\":0}}]", "application/json; charset=utf-8");

            for (int i = 0; i < retries; ++i)
            {
                var     sRespStat3 = req3.Send(out string sResult3);
                dynamic PostResp3  = JsonConvert.DeserializeObject(sResult3);
                // PtzCheckState 0:idle, 1:doing, 2:finish
                if (PostResp3[0].value != null)
                {
                    //Debug.WriteLine("GetPtzCheckState PtzCheckState=" + (int)(PostResp3[0].value.PtzCheckState));
                    if (PostResp3[0].value.PtzCheckState != 1)
                    {
                        return(true);
                    }
                }
                //Thread.Sleep(delay);
            }
            return(false);
        }
Beispiel #2
0
        public int TurnOnAlarm(int times)
        {
            try
            {
                // Get Light State
                HttpReq req = new HttpReq();
                req.Open("Post", "http://ccacamp.hopto.org:1961/api.cgi?cmd=AudioAlarmPlay&token=" + _token);

                req.AddHeaderProp("Connection: keep-alive");
                req.AddHeaderProp("Accept: */*");
                req.AddHeaderProp("Accept-Encoding: gzip, deflate, br");

                req.AddBody("[{\"cmd\": \"AudioAlarmPlay\",\"action\": 0,\"param\": {\"alarm_mode\": \"times\",\"manual_switch\": 0,\"times\":" + times + ",\"channel\": 0}}]", "application/json; charset=utf-8");
                var sRespStat = req.Send(out string sResult);

                // "rspCode" : 200
                dynamic LoginResp = JsonConvert.DeserializeObject(sResult);
                //return (LoginResp[0].value.rspCode == 200);
            }
            catch (Exception e)
            {
                _ = e;
            }
            return(0);
        }
Beispiel #3
0
        public int GetPresetPicture(IWebHostEnvironment hostEnv, int preset)
        {
            try
            {
                if ((preset >= 1) && (preset <= 99))
                {
                    // Get Picture by Preset #
                    HttpReq req = new HttpReq();
                    req.Open("Post", "http://ccacamp.hopto.org:1961/api.cgi?cmd=PtzCtrl&token=" + _token);

                    req.AddHeaderProp("Connection: keep-alive");
                    req.AddHeaderProp("Accept: */*");
                    req.AddHeaderProp("Accept-Encoding: gzip, deflate, br");
                    req.AddBody("[{\"cmd\":\"PtzCtrl\",\"param\":{\"channel\":0,\"op\":\"ToPos\",\"id\":" + preset + ",\"speed\":32}}]", "application/json; charset=utf-8");
                    var sRespStat = req.Send(out string sResult);

                    // "rspCode" : 200
                    dynamic LoginResp = JsonConvert.DeserializeObject(sResult);
                    if (LoginResp[0].value.rspCode != 200)
                    {
                        return(0);
                    }

                    return(CheckForSomeStability());
                }
                return(0);
            }
            catch (Exception e)
            {
                _ = e;
                return(0);
            }
        }
Beispiel #4
0
        public bool Logout()
        {
            if (string.IsNullOrEmpty(_token))
            {
                return(false);
            }

            var tok = _token;

            _token = "";
            try
            {
                // Get Token
                HttpReq req = new HttpReq();
                req.Open("Post", "http://ccacamp.hopto.org:1961/api.cgi?cmd=Logout&token=" + tok);

                req.AddHeaderProp("Connection: keep-alive");
                req.AddHeaderProp("Accept: */*");
                req.AddHeaderProp("Accept-Encoding: gzip, deflate, br");

                req.AddBody("[{\"cmd\":\"Logout\",\"param\":{}}]", "application/json; charset=utf-8");
                var sRespStat = req.Send(out string sResult);

                // "name" : "8da4c31df166a94"
                dynamic LogoutResp = JsonConvert.DeserializeObject(sResult);
                return(LogoutResp[0].value.rspCode == 200);
            }
            catch
            {
            }
            return(false);
        }
Beispiel #5
0
        public bool Login()
        {
            try
            {
                // Get Token
                HttpReq req = new HttpReq();
                req.Open("Post", "http://ccacamp.hopto.org:1961/api.cgi?cmd=Login");

                req.AddHeaderProp("Connection: keep-alive");
                req.AddHeaderProp("Accept: */*");
                req.AddHeaderProp("Accept-Encoding: gzip, deflate, br");

                req.AddBody("[{\"cmd\":\"Login\",\"param\":{\"User\":{\"userName\":\"admin\", \"password\":\"Red35845!\" }}}]", "application/json; charset=utf-8");
                var sRespStat = req.Send(out string sResult);

                // "name" : "8da4c31df166a94"
                dynamic LoginResp = JsonConvert.DeserializeObject(sResult);
                _token = LoginResp[0].value.Token.name;
                return(!string.IsNullOrEmpty(_token));
            }
            catch
            {
                return(false);
            }
        }
Beispiel #6
0
        public int GetPtzPicture(IWebHostEnvironment hostEnv, int op)
        {
            try
            {
                if (op < 200)
                {
                    return(0);
                }

                // Perform PTZ op
                HttpReq req = new HttpReq();
                req.Open("Post", "http://ccacamp.hopto.org:1961/api.cgi?cmd=PtzCtrl&token=" + _token); // &user=admin&password=Red35845!");

                req.AddHeaderProp("Connection: keep-alive");
                req.AddHeaderProp("Accept: */*");
                req.AddHeaderProp("Accept-Encoding: gzip, deflate, br");
                req.AddBody("[{\"cmd\":\"PtzCtrl\",\"action\":0,\"param\":{\"channel\":0,\"op\":\"" + COpToStr[(COp)op] + "\",\"speed\":16}}]", "application/json; charset=utf-8");
                var     sRespStat = req.Send(out string sResult);
                dynamic PostResp  = JsonConvert.DeserializeObject(sResult);
                if ((PostResp[0].value != null) && (PostResp[0].value.rspCode != 200)) // "rspCode" : 200
                {
                    return(0);
                }

                // Perform Stop
                HttpReq req2 = new HttpReq();
                req2.Open("Post", "http://ccacamp.hopto.org:1961/api.cgi?cmd=PtzCtrl&token=" + _token); // &user=admin&password=Red35845!");

                req2.AddHeaderProp("Connection: keep-alive");
                req2.AddHeaderProp("Accept: */*");
                req2.AddHeaderProp("Accept-Encoding: gzip, deflate, br");
                req2.AddBody("[{\"cmd\":\"PtzCtrl\",\"action\":0,\"param\":{\"channel\":0,\"op\":\"Stop\"}}]", "application/json; charset=utf-8");
                var     sRespStat2 = req2.Send(out string sResult2);
                dynamic PostResp2  = JsonConvert.DeserializeObject(sResult2);
                if ((PostResp2[0].value != null) && (PostResp2[0].value.rspCode != 200)) // "rspCode" : 200
                {
                    return(0);
                }

                var delay = CheckForSomeStability();
                if (delay == 500)
                {
                    return(0); // no need for that extra snap with non-preset
                }
                return(delay);
            }
            catch (Exception e)
            {
                _ = e;
                return(0);
            }
        }
Beispiel #7
0
        public int ToggleLight()
        {
            try
            {
                // Get Light State
                HttpReq req = new HttpReq();
                req.Open("Post", "http://ccacamp.hopto.org:1961/api.cgi?cmd=GetWhiteLed&token=" + _token);

                req.AddHeaderProp("Connection: keep-alive");
                req.AddHeaderProp("Accept: */*");
                req.AddHeaderProp("Accept-Encoding: gzip, deflate, br");

                req.AddBody("[{\"cmd\": \"GetWhiteLed\",\"action\": 0,\"param\": {\"channel\": 0}}]", "application/json; charset=utf-8");
                var sRespStat = req.Send(out string sResult);

                // value.PowerLed.state : 0 | 1
                dynamic GWLResp  = JsonConvert.DeserializeObject(sResult);
                var     newState = (GWLResp[0].value.WhiteLed.state == 0) ? 1 : 0;
                var     SetJson  = JsonConvert.SerializeObject(GWLResp);

                HttpReq req2 = new HttpReq();
                req2.Open("Post", "http://ccacamp.hopto.org:1961/api.cgi?cmd=SetWhiteLed&token=" + _token);

                req2.AddHeaderProp("Connection: keep-alive");
                req2.AddHeaderProp("Accept: */*");
                req2.AddHeaderProp("Accept-Encoding: gzip, deflate, br");

                req2.AddBody("[{\"cmd\": \"SetWhiteLed\",\"param\": {\"WhiteLed\": {\"state\":" + newState + ",\"channel\": 0,\"mode\": 1,\"bright\": 85,\"LightingSchedule\": {\"EndHour\": 6,\"EndMin\": 0,\"StartHour\": 18,\"StartMin\": 0},\"wlAiDetectType\": {\"dog_cat\": 1,\"face\": 0,\"people\": 1,\"vehicle\": 0}}}}]", "application /json; charset=utf-8");
                sRespStat = req2.Send(out sResult);

                return(500); // need time to turn off light. This may be reduced.
            }
            catch (Exception e)
            {
                _ = e;
            }
            return(0);
        }
Beispiel #8
0
        public SearchCmd GetVideos(DateTime sdt, DateTime edt) // TBD : Dates
        {
            try
            {
                HttpReq req = new HttpReq();
                req.Open("Post", "http://ccacamp.hopto.org:1961/cgi-bin/api.cgi?cmd=Search&rs=adshf4549f&user=admin&password=Red35845!");

                req.AddHeaderProp("content-type: application/json");
                req.AddHeaderProp("accept: application/json");
                req.AddHeaderProp("accept-encoding: en-US,en;q=0.8");
                req.AddHeaderProp("user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36");
//                req.AddBody("[{\"cmd\": \"Search\",\"action\": 0,\"param\": {\"Search\": {\"channel\": 0,\"onlyStatus\": 0,\"streamType\": \"main\",\"StartTime\": {\"year\": 2022,\"mon\": 3,\"day\": 6,\"hour\": 1,\"min\": 0,\"sec\": 0},\"EndTime\": {\"year\": 2022,\"mon\": 3,\"day\": 6,\"hour\": 15,\"min\": 0,\"sec\": 0}}}}]");
                req.AddBody("[{\"cmd\": \"Search\",\"action\": 0,\"param\": {\"Search\": {\"channel\": 0,\"onlyStatus\": 0,\"streamType\": \"main\",\"StartTime\": {\"year\": " + sdt.Year + ",\"mon\": " + sdt.Month + ",\"day\": " + sdt.Day + ",\"hour\": " + sdt.Hour + ",\"min\": " + sdt.Minute + ",\"sec\": " + sdt.Second + "},\"EndTime\": {\"year\": " + edt.Year + ",\"mon\": " + edt.Month + ",\"day\": " + edt.Day + ",\"hour\": " + edt.Hour + ",\"min\": " + edt.Minute + ",\"sec\": " + edt.Second + "}}}}]");
                var          resp       = req.Send(out string sResult);
                SearchCmd [] searchCmds = JsonConvert.DeserializeObject <SearchCmd[]>(sResult);
                return((searchCmds.Count() >= 1) ? searchCmds[0] : null);
            }
            catch (Exception e)
            {
                _ = e;
                return(null);
            }
        }
Beispiel #9
0
        //http://IPC_IP/api.cgi?cmd=GetZoomFocus&token=TOKEN
        public bool GetZoomAndFocus(out int zoom, out int focus)
        {
            zoom = focus = -1;

            // Get PTZ Check State
            HttpReq req3 = new HttpReq();

            req3.Open("Post", "http://ccacamp.hopto.org:1961/api.cgi?cmd=GetZoomFocus&token=" + _token); // &user=admin&password=Red35845!");

            req3.AddHeaderProp("Connection: keep-alive");
            req3.AddHeaderProp("Accept: */*");
            req3.AddHeaderProp("Accept-Encoding: gzip, deflate, br");
            req3.AddBody("[{\"cmd\":\"GetZoomFocus\",\"action\":0,\"param\":{\"channel\":0}}]", "application/json; charset=utf-8");

            var     sRespStat3 = req3.Send(out string sResult3);
            dynamic PostResp3  = JsonConvert.DeserializeObject(sResult3);

            if ((PostResp3[0].value != null) && (PostResp3[0].value.ZoomFocus != null))
            {
                try
                {
                    zoom  = PostResp3[0].value.ZoomFocus.zoom.pos;
                    focus = PostResp3[0].value.ZoomFocus.focus.pos;
                }
                catch
                {
                    zoom  = -1;
                    focus = -1;
                    //Debug.WriteLine("GetZoomAndFocus FAIL Zoom=" + zoom + " Focus=" + focus);
                }
                //Debug.WriteLine("GetZoomAndFocus Zoom=" + zoom + " Focus=" + focus);
                return(true);
            }
            //Debug.WriteLine("GetZoomAndFocus FAIL Zoom=" + zoom + " Focus=" + focus);
            return(false);
        }