FirebaseSharp nest-api 设置恒温器值
FirebaseSharp nest-api set thermostat value
我正在尝试使用 FirebaseSharp 设置恒温器但没有成功。
我已经从 http://www.codeproject.com/Articles/818265/NET-Works-with-Nest-Guide-to-calling-Nest-API-fro?msg=5010020#xx5010020xx 下载了 padmore 的示例。
当我更改虚拟设备的值时,我收到了事件。我也将恒温器设置为 read/write。
这是要做的:
问题是 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 );
}
}
那我做错了什么?
感谢您的帮助。
好的,刚收到。
使用以下示例: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() );
}
}
}
我正在尝试使用 FirebaseSharp 设置恒温器但没有成功。 我已经从 http://www.codeproject.com/Articles/818265/NET-Works-with-Nest-Guide-to-calling-Nest-API-fro?msg=5010020#xx5010020xx 下载了 padmore 的示例。 当我更改虚拟设备的值时,我收到了事件。我也将恒温器设置为 read/write。 这是要做的: 问题是 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 );
}
}
那我做错了什么? 感谢您的帮助。
好的,刚收到。
使用以下示例: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() );
}
}
}