Ejemplo n.º 1
0
        //    /blink1/input/ifttt -- Add and Start watching messages from IFTTT webservice
        static string Ublink1InputIfttt(HttpRequest request, Blink1Server blink1Server)
        {
            string pname    = request.Query.Get("pname");
            string iname    = request.Query.Get("iname");
            string rulename = request.Query.Get("arg1");
            string test     = request.Query.Get("test");

            if (pname == null)
            {
                pname = iname;
            }
            Boolean testmode = (test == null) ? false : (test.Equals("on") || test.Equals("true"));

            string statusstr = "must specifiy 'iname' and 'arg1' (rulename)";

            Blink1Input input = null;

            if (rulename != null && iname != null)
            {
                statusstr = "input ifttt";
                rulename  = rulename.Trim();
                input     = new Blink1Input(blink1Server, iname, pname, "ifttt", rulename);

                if (testmode)   // override periodic fetch for immediate fetch
                {
                    Blink1Input.getIftttResponse(false);
                }
                input.updateIftttInput();
                if (!testmode)
                {
                    blink1Server.inputs[iname] = input; // NOTE: this replaces input if already exists
                }
            }
            blink1Server.saveSettings();

            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("status", statusstr);
            result.Add("input", input);
            return(JsonConvert.SerializeObject(result, Formatting.Indented, jsonSerializerSettings));
        }
Ejemplo n.º 2
0
        // currently unimplemented URL API calls

        //    /blink1/input/scriptlist -- List available scripts to run

        //    /blink1/input/cpuload -- Add and Start CPU load watching input

        //    /blink1/input/netload -- Start network load watching input


        #endregion


        // ----------------------------------------------------------------------------------------
        // updates to inputs handling
        //

        /// <summary>
        /// Periodically update the inputs, triggering color patterns if needed
        /// Runs every 15(?) seconds
        /// </summary>
        public void updateInputs(Object stateInfo)
        {
            if (!inputsEnable)
            {
                return;
            }
            Log("updateInputs");

            Blink1Input.getIftttResponse(true);

            foreach (var pair in inputs)
            {
                Blink1Input input = pair.Value;
                input.update();

                // FIXME: maybe do a logging of inputs that cause triggers like:
                // if( input.update() ) {
                //   alertLog.Add( Now(), input.name );
                // }
                // and then have a "/blink1/alertlog" URL
            }
        }