FirebaseSharp nest-api设置恒温器值

时间:2015-02-26 09:18:12

标签: c# firebase nest-api

我正在尝试使用FirebaseSharp设置恒温器但没有成功。 我已经从http://www.codeproject.com/Articles/818265/NET-Works-with-Nest-Guide-to-calling-Nest-API-fro?msg=5010020#xx5010020xx下载了padmore的示例。 当我从虚拟设备更改值时,我收到事件。我将恒温器设置为读/写。 这是做什么的: 问题是firebaseClient.Post和firebaseClient.Put被调用,永远不会返回。也没有例外。

    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 );
        }
    }

那么我做错了什么? 感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

好的,得到它。

使用以下示例:Need Working Example of Nest REST API without using Firebase 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() );
            }
        }
    }