简体   繁体   English

FirebaseSharp nest-api设置恒温器值

[英]FirebaseSharp nest-api set thermostat value

I am trying to set thermostat using FirebaseSharp with no success. 我试图使用FirebaseSharp设置恒温器,但未成功。 I've downloaded padmore's example from http://www.codeproject.com/Articles/818265/NET-Works-with-Nest-Guide-to-calling-Nest-API-fro?msg=5010020#xx5010020xx . 我已经从http://www.codeproject.com/Articles/818265/NET-Works-with-Nest-Guide-to-calling-Nest-API-fro?msg=5010020#xx5010020xx下载了padmore的示例。 I am getting event when i change the value from the virtual device. 从虚拟设备更改值时发生事件。 I set thermostat to read/write as well. 我还将恒温器也设置为读/写。 This is what is do: The problem is that firebaseClient.Post and firebaseClient.Put are called and never returned. 这是做什么的:问题是将调用firebaseClient.Post和firebaseClient.Put且从不返回。 also there is no exception. 也不例外。

    private void buttonPost_Click( object sender, RoutedEventArgs e )
    {
        string data = "30";
        string fullPath = "//devices//thermostats//<device id>//target_temperature_high_c";;

        string t;            
        try
        {
            t = firebaseClient.Post( fullPath, data );
            string i = string.Format( "firebaseClient.Post: {0}", t );
            OutMessage( i );
            return;
        }
        catch(Exception ex)
        {
            string i = string.Format( "firebaseClient.Post: exception {0}", ex.Message );
            OutMessage( i );
        }

        try
        {
            t = firebaseClient.Put( fullPath, data );
            string i = string.Format( "firebaseClient.Put: {0}", t );
            OutMessage( i );
        }
        catch(Exception ex)
        {
            string i = string.Format( "firebaseClient.Put: exception {0}", ex.Message );
            OutMessage( i );
        }
    }

So what am I doing wrong? 那我在做什么错? I appreciate your help. 我感谢您的帮助。

Ok, just got it. 好的,知道了。

Using following sample: Need Working Example of Nest REST API without using Firebase API . 使用以下示例: 不使用Firebase API的Nest REST API的工作示例

    private async void changeAway( string structureid, string thermostateId)
    {
        using(HttpClient http = new HttpClient())
        {
            string url =   "https://developer-api.nest.com/";
            StringContent content = null;

            if((string)comboBoxDataType.SelectedValue == "Structures")
            {
                string away = comboBoxDataAway.SelectedValue.ToString();
                url += "structures/" + structureid + "/?auth=" + _accessToken;
                content = new StringContent( "{\"away\":\"" + away + "\"}" );
            }
            else
            {
                if(textBoxPostData.Text == string.Empty )
                {
                    OutMessage( "data can not be empty" );
                    return;
                }

                int data = 0;
                if(int.TryParse( textBoxPostData.Text, out data ) == false)
                {
                    OutMessage( "data must be number" );
                    return;                    
                }

                url += "devices/thermostats/" + thermostateId + "/?auth=" + _accessToken;
                content = new StringContent( "{\"target_temperature_high_c\":" + textBoxPostData.Text + "}" );
            }

            HttpResponseMessage rep = await http.PutAsync( new Uri( url ), content );
            if(null != rep)
            {
                OutMessage( "http.PutAsync2=" + rep.ToString() );
            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM