首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FirebaseSharp nest-api设置恒温器值

FirebaseSharp nest-api设置恒温器值
EN

Stack Overflow用户
提问于 2015-02-26 09:18:12
回答 1查看 849关注 0票数 0

我正在尝试使用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被调用了,并且从未返回。而且也不例外。

代码语言:javascript
复制
    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 );
        }
    }

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-26 12:30:15

好的,我明白了。

使用以下示例:Need Working Example of Nest REST API without using Firebase API

代码语言:javascript
复制
    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() );
            }
        }
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28738454

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档