【问题标题】:FirebaseSharp nest-api set thermostat valueFirebaseSharp nest-api 设置恒温器值
【发布时间】:2015-02-26 09:18:12
【问题描述】:

我正在尝试使用 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 );
        }
    }

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

【问题讨论】:

  • 我对 FirebaseSharp 一无所知,但这似乎不是一个有效的路径://devices//thermostats////target_temperature_high_c。您是否忘记将 替换为您的实际 ID?
  • - 我写的是这个而不是我的实际设备 ID。

标签: c# firebase nest-api


【解决方案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() );
            }
        }
    }

【讨论】:

  • 很高兴听到您想通了?知道您在原始代码中做错了什么吗?
  • 嗨弗兰克,我使用 Http put 而不是 FirebaseSharp。
猜你喜欢
  • 2014-08-19
  • 2016-07-09
  • 1970-01-01
  • 1970-01-01
  • 2022-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多