示例#1
0
    /// <summary> Performs a call to the growkit api to fetch the preset.</summary>
    private IEnumerator RequestPresetData()
    {
        bool succesfullyRequested = false;

        do
        {
            UnityWebRequest request = UnityWebRequest.Get(GrowKitAPI.StickEndpoint(_stickId));
            yield return(request.SendWebRequest());

            if (request.isNetworkError || request.isHttpError)
            {
                Debug.Log(request.error);
            }
            else
            {
                _preset = JsonUtility.FromJson <Preset>(request.downloadHandler.text);

                succesfullyRequested = true;
            }
        } while (!succesfullyRequested);
    }
示例#2
0
    private IEnumerator RequestStickData()
    {
        do
        {
            UnityWebRequest request = UnityWebRequest.Get(GrowKitAPI.StickEndpoint(_stickId));
            yield return(request.SendWebRequest());

            if (request.isNetworkError || request.isHttpError)
            {
                yield return(new WaitForSecondsRealtime(30));

                continue;
            }

            _stick = JsonUtility.FromJson <SensorStick>(request.downloadHandler.text);

            _waterText.text       = $"{(_stick.Moisture < _preset.Moisture[0] ? "too little water" : _stick.Moisture < _preset.Moisture[1] ? "Ok" : "too much water")} ({_stick.Moisture})";
            _lightText.text       = $"{(_stick.Light < _preset.Light[0] ? "too little light" : _stick.Light < _preset.Light[1] ? "Ok" : "too much light")} ({_stick.Light})";
            _temperatureText.text = $"{(_stick.Temperature < _preset.Temperature[0] ? "temperature too low" : _stick.Temperature < _preset.Temperature[1] ? "Ok" : "temperature too high")} ({_stick.Temperature})";

            yield return(new WaitForSecondsRealtime(10));
        } while (true);
    }