Beispiel #1
0
        /// <summary>
        /// Set the device alias
        /// </summary>
        /// <param name="pNewAlias">New alias</param>
        /// <returns>Return the result of this operation</returns>
        /// <remarks>Only (A-Z a-z 0-9 @ ' . - _ spaces), other characters will be removed</remarks>
        public DeviceActionResult SetDeviceAlias(string pNewAlias)
        {
            DeviceActionResult dev_result = new DeviceActionResult();

            //Delete invalid characters
            pNewAlias = Regex.Replace(pNewAlias, @"[^A-Za-z0-9@'\.\-_\s]", "");

            //Prepare the command
            string comando = Common.StringParams("{\"system\":{\"set_dev_alias\":{\"alias\":\"{0}\"}}}", pNewAlias);

            //Send the command to the device and get the Json string result
            string sJsonResult = this.ExecuteAndRead(comando);

            try
            {
                JObject json_object = JObject.Parse(sJsonResult);
                dev_result.LoadFromJson(json_object["system"]["set_dev_alias"]);
            }
            catch (Exception ex)
            {
                throw new NonCompatibleDeviceException(ex.Message, ex);
            }

            return(dev_result);
        }
Beispiel #2
0
        /// <summary>
        /// Delete all count down rules
        /// </summary>
        /// <returns>Return the result of this operation</returns>
        public DeviceActionResult DeleteAllCountDownRules()
        {
            DeviceActionResult dev_result = new DeviceActionResult();

            //Prepare the command
            string comando = "{\"count_down\":{\"delete_all_rules\":null}}";

            //Send the command to the device and get the Json string result
            string sJsonResult = this.ExecuteAndRead(comando);

            try
            {
                JObject json_object = JObject.Parse(sJsonResult);
                dev_result.LoadFromJson(json_object["count_down"]["delete_all_rules"]);
            }
            catch (Exception ex)
            {
                throw new NonCompatibleDeviceException(ex.Message, ex);
            }

            return(dev_result);
        }
Beispiel #3
0
        /// <summary>
        /// Delete specific count down rule
        /// </summary>
        /// <param name="pCountDownID">Count down ID</param>
        /// <returns>Return the result of this operation</returns>
        public DeviceActionResult DeleteCountDownRule(string pCountDownID)
        {
            DeviceActionResult dev_result = new DeviceActionResult();

            //Prepare the command
            string comando = Common.StringParams("{\"count_down\":{\"delete_rule\":{\"id\":\"{0}\"}}}", pCountDownID);

            //Send the command to the device and get the Json string result
            string sJsonResult = this.ExecuteAndRead(comando);

            try
            {
                JObject json_object = JObject.Parse(sJsonResult);
                dev_result.LoadFromJson(json_object["count_down"]["delete_rule"]);
            }
            catch (Exception ex)
            {
                throw new NonCompatibleDeviceException(ex.Message, ex);
            }

            return(dev_result);
        }
Beispiel #4
0
        /// <summary>
        /// Set time zone
        /// </summary>
        /// <param name="pYear">Year</param>
        /// <param name="pMonth">Month</param>
        /// <param name="pDay">Day</param>
        /// <param name="pHour">Hour</param>
        /// <param name="pMinutes">Minutes</param>
        /// <param name="pSeconds">Seconds</param>
        /// <param name="pTimeZoneIndex">Time zone index</param>
        /// <returns>Return the result of this operation</returns>
        public DeviceActionResult SetTimeZone(int pYear, int pMonth, int pDay, byte pHour, byte pMinutes, byte pSeconds, byte pTimeZoneIndex)
        {
            DeviceActionResult dev_result = new DeviceActionResult();

            //Prepare the command
            string comando = Common.StringParams("{\"time\":{\"set_timezone\":{\"year\":{0},\"month\":{1},\"mday\":{2},\"hour\":{3},\"min\":{4},\"sec\":{5},\"index\":{6}}}}", pYear.ToString(), pMonth.ToString(), pDay.ToString(), pHour.ToString(), pMinutes.ToString(), pSeconds.ToString(), pTimeZoneIndex.ToString());

            //Send the command to the device and get the Json string result
            string sJsonResult = this.ExecuteAndRead(comando);

            try
            {
                JObject json_object = JObject.Parse(sJsonResult);
                dev_result.LoadFromJson(json_object["time"]["set_timezone"]);
            }
            catch (Exception ex)
            {
                throw new NonCompatibleDeviceException(ex.Message, ex);
            }

            return(dev_result);
        }
Beispiel #5
0
        /// <summary>
        /// Switch the led state
        /// </summary>
        /// <param name="pNewLedState">New led state</param>
        /// <returns>Return the result of this operation</returns>
        public DeviceActionResult SwitchLedState(LedAction pNewLedState)
        {
            DeviceActionResult dev_result = new DeviceActionResult();

            //Prepare the command
            string comando = Common.StringParams("{\"system\":{\"set_led_off\":{\"off\":{0}}}}", (pNewLedState == LedAction.TurnOff) ? "1" : "0");

            //Send the command to the device and get the Json string result
            string sJsonResult = this.ExecuteAndRead(comando);

            try
            {
                JObject json_object = JObject.Parse(sJsonResult);
                dev_result.LoadFromJson(json_object["system"]["set_led_off"]);
            }
            catch (Exception ex)
            {
                throw new NonCompatibleDeviceException(ex.Message, ex);
            }

            return(dev_result);
        }
Beispiel #6
0
        /// <summary>
        /// Connect to AP with given SSID and Password
        /// </summary>
        /// <param name="pSSID">SSID</param>
        /// <param name="pPassword">Password</param>
        /// <param name="pWLanType">Wireless type</param>
        /// <returns>Return the result of this operation</returns>
        public DeviceActionResult SetAccessPoint(string pSSID, string pPassword, WirelessType pWLanType)
        {
            DeviceActionResult dev_result = new DeviceActionResult();

            //Prepare the command
            string comando = "{\"netif\":{\"set_stainfo\":{\"ssid\":\"{0}\",\"password\":\"{1}\",\"key_type\":{2}}}}";

            comando = Common.StringParams(comando, pSSID, pPassword, Convert.ToString((byte)pWLanType));

            //Send the command to the device and get the Json string result
            string sJsonResult = this.ExecuteAndRead(comando);

            try
            {
                JObject json_object = JObject.Parse(sJsonResult);
                dev_result.LoadFromJson(json_object["netif"]["set_stainfo"]);
            }
            catch (Exception ex)
            {
                throw new NonCompatibleDeviceException(ex.Message, ex);
            }

            return(dev_result);
        }