Example #1
0
    IEnumerator WRequest()
    {
        request = new WebStreamReader();
        request.Start(PhotonParticleURL);         //https://www.ourtechart.com//wp-content/uploads/2016/04/jsonAllData.txt");
        string stream = "";

        while (true)
        {
            string block = request.GetNextBlock();
            if (!string.IsNullOrEmpty(block))
            {
                stream += block;

                string[] data = stream.Split(new string[] { "\n\n" }, System.StringSplitOptions.None);
                //Debug.Log ("Data length: " + data.Length);
                stream = data[data.Length - 1];

                for (int i = 0; i < data.Length - 1; i++)
                {
                    if (!string.IsNullOrEmpty(data[i]))
                    {
                        //	Debug.Log ("Data: " + data [i]); // print all block of data (event + data)

                        if (data [i].Contains("LightIntensity"))
                        {
                            temperatureTrue = true;
                            lightTrue       = true;
                            motionTrue      = true;
                            ultravioletTrue = true;
                            humidityTrue    = true;
                            string output = data [i].Substring(data [i].IndexOf("{"));
                            parseDataTemperature = JsonUtility.FromJson <DataClassTemperature> (output);
                            //Debug.Log ("Data of waterlevel sensor: " + data [i]);
                        }
                        if (temperatureTrue)
                        {
                            gameObject.GetComponent <IoT> ().microTemperatureVal = parseDataTemperature.data;

                            humidityTrue    = false;
                            motionTrue      = false;
                            temperatureTrue = false;
                            lightTrue       = false;
                            ultravioletTrue = false;
                        }
                    }
                }
            }
            yield return(new WaitForSecondsRealtime(1));
        }
    }
    IEnumerator WRequest()
    {
        request = new WebStreamReader();
        request.Start(PhotonParticleURL);
        string stream = "";

        while (true)
        {
            string block = request.GetNextBlock();
            if (!string.IsNullOrEmpty(block))
            {
                stream += block;

                string[] data = stream.Split(new string[] { "\n\n" }, System.StringSplitOptions.None);
                //Debug.Log ("Data length: " + data.Length);
                stream = data[data.Length - 1];

                for (int i = 0; i < data.Length - 1; i++)
                {
                    if (!string.IsNullOrEmpty(data[i]))
                    {
                        //	Debug.Log ("Data: " + data [i]); // print all block of data (event + data)

                        if (data[i].Contains("ON"))
                        {
                            ButtonTrue = true;

                            string output = data[i].Substring(data[i].IndexOf("{"));
                            parseDataButton = JsonUtility.FromJson <DataClassButton>(output);
                            //Debug.Log (data [i]);
                            CreateTokenFunction();

                            //trigger1.SetActive(true);
                        }

                        else if (data[i].Contains("OFF"))
                        {
                            //trigger1.SetActive(false);
                            ResponseText.text = "The device is OFF. Please set your device ON by pressing the button!";
                        }
                    }
                }
            }
            yield return(new WaitForSecondsRealtime(1));
        }
    }
Example #3
0
    IEnumerator WRequest()
    {
        request = new WebStreamReader();
        request.Start(photonUrl);
        string stream = "";

        while (true)
        {
            string block = request.GetNextBlock();
            if (!string.IsNullOrEmpty(block))
            {
                stream += block;
                string[] data = stream.Split(new string[] { "\n\n" }, System.StringSplitOptions.None);
                stream = data[data.Length - 1];
                for (int i = 0; i < data.Length - 1; i++)
                {
                    if (!string.IsNullOrEmpty(data[i]))
                    {
                        if (data[i].Contains("Direction"))
                        {
                            Debug.Log(data[i]);
                            string output = data[i].Substring(data[i].IndexOf("{"));
                            Debug.Log(output);
                            parseDirection = JsonUtility.FromJson <DirectionData>(output);
                            Debug.Log(parseDirection.data);
                            printer.dir = parseDirection.data;
                        }
                        if (data[i].Contains("leftDistance"))
                        {
                            string output = data[i].Substring(data[i].IndexOf("{"));
                            parseLeft    = JsonUtility.FromJson <LeftSensorData>(output);
                            printer.left = parseLeft.data;
                        }
                        if (data[i].Contains("frontDistance"))
                        {
                            string output = data[i].Substring(data[i].IndexOf("{"));
                            parseFront    = JsonUtility.FromJson <FrontSensorData>(output);
                            printer.front = parseFront.data;
                        }
                    }
                }
            }
            yield return(new WaitForSeconds(1));
        }
    }
Example #4
0
    IEnumerator WRequest()
    {
        request = new WebStreamReader();
        request.Start(PhotonParticleURL);
        string stream = "";

        while (true)
        {
            string block = request.GetNextBlock();
            if (!string.IsNullOrEmpty(block))
            {
                stream += block;
                //Debug.Log ("Stream1: " + stream);
                string[] data = stream.Split(new string[] { "\n\n" }, System.StringSplitOptions.None);
                //Debug.Log ("Data length: " + data.Length);
                stream = data[data.Length - 1];

                for (int i = 0; i < data.Length - 1; i++)
                {
                    if (!string.IsNullOrEmpty(data[i]))
                    {
                        Debug.Log("Data: " + data [i]);          // print all block of data (event + data)
                        if (data[i].Contains("Dice"))
                        {
                            DiceTrue = true;
                            string output = data[i].Substring(data[i].IndexOf("{"));
                            parseDataDice = JsonUtility.FromJson <DataClassDice>(output);
                            dice.OnDataReceived();
                            //Debug.Log ("Data of Photoresistor: " + parseData.data);
                            //text.text = parseData.data.ToString ();
                            //gameObject.GetComponent<IoT> ().microPhotoresistorVal = parseDataLight.data;
                        }

                        DiceTrue = false;
                    }
                }
            }


            yield return(new WaitForSeconds(1));
        }
    }
Example #5
0
    IEnumerator WRequest()
    {
        request = new WebStreamReader();
        request.Start(LocalServerURL);         //https://www.ourtechart.com//wp-content/uploads/2016/04/jsonAllData.txt");
        string stream = "";

        while (true)
        {
            string block = request.GetNextBlock();
            if (!string.IsNullOrEmpty(block))
            {
                stream += block;
                //Debug.Log ("Stream1: " + stream);
                string[] data = stream.Split(new string[] { "\n\n" }, System.StringSplitOptions.None);
                //Debug.Log ("Data length: " + data.Length);
                stream = data[data.Length - 1];

                for (int i = 0; i < data.Length - 1; i++)
                {
                    if (!string.IsNullOrEmpty(data[i]))
                    {
                        //	Debug.Log ("Data: " + data [i]); // print all block of data (event + data)
                        if (data[i].Contains("IMS1"))
                        {
                            IMS3MachineStateTrue = true;
                            string output = data[i].Substring(data[i].IndexOf("{"));
                            parseDataIMS3MachineState = JsonUtility.FromJson <DataClassIMS3MachineState>(output);
                            //Debug.Log ("Data of Photoresistor: " + parseData.data);
                            //text.text = parseData.data.ToString ();
                            //gameObject.GetComponent<IoT> ().microPhotoresistorVal = parseDataLight.data;
                        }

                        if (data[i].Contains("IMS3A"))
                        {
                            IMS3AMachineStateTrue = true;
                            string output = data[i].Substring(data[i].IndexOf("{"));
                            parseDataIMS3AMachineState = JsonUtility.FromJson <DataClassIMS3AMachineState>(output);
                            //Debug.Log ("Data of Temperature sensor: " + parseData.data);
                            //text.text = parseData.data.ToString ();
                            //gameObject.GetComponent<IoT> ().microTemperatureVal = parseDataTemperature.data;
                        }
                        if (data[i].Contains("IMS3B"))
                        {
                            IMS3BMachineStateTrue = true;
                            string output = data[i].Substring(data[i].IndexOf("{"));
                            parseDataIMS3BMachineState = JsonUtility.FromJson <DataClassIMS3BMachineState>(output);
                            //Debug.Log ("Data of PIR sensor: " + parseData.data);
                            //text.text = parseData.data.ToString ();
                            //gameObject.GetComponent<IoT> ().motionDetectedBool = Convert.ToBoolean(parseDataMotion.data);
                        }
                        if (data[i].Contains("IMS4A"))
                        {
                            IMS4AMachineStateTrue = true;
                            string output = data[i].Substring(data[i].IndexOf("{"));
                            parseDataIMS4AMachineState = JsonUtility.FromJson <DataClassIMS4AMachineState>(output);
                            //Debug.Log ("Data of PIR ultraviolet: " + parseData.data);
                            //text.text = parseData.data.ToString ();
                            //gameObject.GetComponent<IoT> ().microUltravioletVal = parseDataUltraviolet.data;
                        }
                        if (data[i].Contains("IMS4B"))
                        {
                            IMS4BMachineStateTrue = true;
                            string output = data[i].Substring(data[i].IndexOf("{"));
                            parseDataIMS4BMachineState = JsonUtility.FromJson <DataClassIMS4BMachineState>(output);
                            //Debug.Log ("Data of Humidity: " + parseData.data);
                            //text.text = parseData.data.ToString ();
                            //gameObject.GetComponent<IoT> ().microHumidityVal = parseDataHumidity.data;
                        }
                        if (data[i].Contains("IMS5A"))
                        {
                            IMS5AMachineStateTrue = true;
                            string output = data[i].Substring(data[i].IndexOf("{"));
                            parseDataIMS5AMachineState = JsonUtility.FromJson <DataClassIMS5AMachineState>(output);
                            //Debug.Log ("Data of PIR ultraviolet: " + parseData.data);
                            //text.text = parseData.data.ToString ();
                            //gameObject.GetComponent<IoT> ().microUltravioletVal = parseDataUltraviolet.data;
                        }
                        if (data[i].Contains("IMS5B"))
                        {
                            IMS5BMachineStateTrue = true;
                            string output = data[i].Substring(data[i].IndexOf("{"));
                            parseDataIMS5BMachineState = JsonUtility.FromJson <DataClassIMS5BMachineState>(output);
                            //Debug.Log ("Data of PIR ultraviolet: " + parseData.data);
                            //text.text = parseData.data.ToString ();
                            //gameObject.GetComponent<IoT> ().microUltravioletVal = parseDataUltraviolet.data;
                        }
                        if (data[i].Contains("IMS7"))
                        {
                            IMS7MachineStateTrue = true;
                            string output = data[i].Substring(data[i].IndexOf("{"));
                            parseDataIMS7MachineState = JsonUtility.FromJson <DataClassIMS7MachineState>(output);
                            //Debug.Log ("Data of PIR ultraviolet: " + parseData.data);
                            //text.text = parseData.data.ToString ();
                            //gameObject.GetComponent<IoT> ().microUltravioletVal = parseDataUltraviolet.data;
                        }
                        //Debug.Log ("TEst: " + humidityTrue + temperatureTrue + lightTrue + ultravioletTrue);
                        if (IMS3MachineStateTrue && IMS3AMachineStateTrue && IMS3BMachineStateTrue && IMS4AMachineStateTrue &&
                            IMS4BMachineStateTrue && IMS5AMachineStateTrue && IMS5BMachineStateTrue && IMS7MachineStateTrue)
                        {
                            //Debug.Log ("PRINT ALLLLLLLLLLLLLL");
                            gameObject.GetComponent <IotDrive>().IMS3valtext  = parseDataIMS3MachineState.data;
                            gameObject.GetComponent <IotDrive>().IMS3Avaltext = parseDataIMS3AMachineState.data;
                            gameObject.GetComponent <IotDrive>().IMS3Bvaltext = parseDataIMS3BMachineState.data;
                            gameObject.GetComponent <IotDrive>().IMS4Avaltext = parseDataIMS4AMachineState.data;
                            gameObject.GetComponent <IotDrive>().IMS4Bvaltext = parseDataIMS4BMachineState.data;
                            gameObject.GetComponent <IotDrive>().IMS5Avaltext = parseDataIMS5AMachineState.data;
                            gameObject.GetComponent <IotDrive>().IMS5Bvaltext = parseDataIMS5BMachineState.data;
                            gameObject.GetComponent <IotDrive>().IMS7valtext  = parseDataIMS7MachineState.data;
                            IMS3MachineStateTrue  = false;
                            IMS3AMachineStateTrue = false;
                            IMS3BMachineStateTrue = false;
                            IMS4AMachineStateTrue = false;
                            IMS4BMachineStateTrue = false;
                            IMS5AMachineStateTrue = false;
                            IMS5BMachineStateTrue = false;
                            IMS7MachineStateTrue  = false;
                        }
                    }
                }
            }
            yield return(new WaitForSeconds(1));
        }
    }
Example #6
0
    IEnumerator WRequest()
    {
        request = new WebStreamReader();
        request.Start(PhotonParticleURL);         //https://www.ourtechart.com//wp-content/uploads/2016/04/jsonAllData.txt");
        string stream = "";

        while (true)
        {
            string block = request.GetNextBlock();
            if (!string.IsNullOrEmpty(block))
            {
                stream += block;
                //Debug.Log ("Stream1: " + stream);
                string[] data = stream.Split(new string[] { "\n\n" }, System.StringSplitOptions.None);
                //Debug.Log ("Data length: " + data.Length);
                stream = data[data.Length - 1];

                for (int i = 0; i < data.Length - 1; i++)
                {
                    if (!string.IsNullOrEmpty(data[i]))
                    {
                        //	Debug.Log ("Data: " + data [i]); // print all block of data (event + data)
                        if (data [i].Contains("light"))
                        {
                            lightTrue = true;
                            string output = data [i].Substring(data [i].IndexOf("{"));
                            parseDataLight = JsonUtility.FromJson <DataClassLight> (output);
                            //Debug.Log ("Data of Photoresistor: " + parseData.data);
                            //text.text = parseData.data.ToString ();
                            //gameObject.GetComponent<IoT> ().microPhotoresistorVal = parseDataLight.data;
                        }

                        if (data [i].Contains("temperature"))
                        {
                            temperatureTrue = true;
                            string output = data [i].Substring(data [i].IndexOf("{"));
                            parseDataTemperature = JsonUtility.FromJson <DataClassTemperature> (output);
                            //Debug.Log ("Data of Temperature sensor: " + parseData.data);
                            //text.text = parseData.data.ToString ();
                            //gameObject.GetComponent<IoT> ().microTemperatureVal = parseDataTemperature.data;
                        }
                        if (data [i].Contains("motion"))
                        {
                            motionTrue = true;
                            string output = data [i].Substring(data [i].IndexOf("{"));
                            parseDataMotion = JsonUtility.FromJson <DataClassMotion> (output);
                            //Debug.Log ("Data of PIR sensor: " + parseData.data);
                            //text.text = parseData.data.ToString ();
                            //gameObject.GetComponent<IoT> ().motionDetectedBool = Convert.ToBoolean(parseDataMotion.data);
                        }
                        if (data [i].Contains("ultraviolet"))
                        {
                            ultravioletTrue = true;
                            string output = data [i].Substring(data [i].IndexOf("{"));
                            parseDataUltraviolet = JsonUtility.FromJson <DataClassUltraviolet> (output);
                            //Debug.Log ("Data of PIR ultraviolet: " + parseData.data);
                            //text.text = parseData.data.ToString ();
                            //gameObject.GetComponent<IoT> ().microUltravioletVal = parseDataUltraviolet.data;
                        }
                        if (data [i].Contains("humidity"))
                        {
                            humidityTrue = true;
                            string output = data [i].Substring(data [i].IndexOf("{"));
                            parseDataHumidity = JsonUtility.FromJson <DataClassHumidity> (output);
                            //Debug.Log ("Data of Humidity: " + parseData.data);
                            //text.text = parseData.data.ToString ();
                            //gameObject.GetComponent<IoT> ().microHumidityVal = parseDataHumidity.data;
                        }
                        //Debug.Log ("TEst: " + humidityTrue + temperatureTrue + lightTrue + ultravioletTrue);
                        if (humidityTrue && temperatureTrue && lightTrue && ultravioletTrue)
                        {
                            //Debug.Log ("PRINT ALLLLLLLLLLLLLL");
                            gameObject.GetComponent <IoT> ().microPhotoresistorVal = parseDataLight.data;
                            gameObject.GetComponent <IoT> ().microTemperatureVal   = parseDataTemperature.data;
                            gameObject.GetComponent <IoT> ().motionDetectedBool    = Convert.ToBoolean(parseDataMotion.data);
                            gameObject.GetComponent <IoT> ().microUltravioletVal   = parseDataUltraviolet.data;
                            gameObject.GetComponent <IoT> ().microHumidityVal      = parseDataHumidity.data;
                            humidityTrue    = false;
                            motionTrue      = false;
                            temperatureTrue = false;
                            lightTrue       = false;
                            ultravioletTrue = false;
                        }
                    }
                }
            }
            yield return(new WaitForSeconds(1));
        }
    }