It is currently Mon May 29, 2017 9:00 pm



Welcome
Welcome to britishgashive

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today!





 Page 6 of 8 [ 74 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7, 8  Next
Author Message
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Sun Mar 20, 2016 5:34 pm 

Joined: Fri Mar 18, 2016 7:10 pm
Posts: 20
Has thanked: 0 time
Have thanks: 4 time
Has anyone figured out the API calls for the new ActivePlugs yet?


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Mon Mar 21, 2016 1:54 am 

Joined: Thu Mar 06, 2014 1:15 am
Posts: 10
Has thanked: 0 time
Have thanks: 1 time
No not yet, its probably simple enough. I just need someone that has an ActivePlug to get me their node information (i can guide) and i cam figure it out.


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Wed Mar 23, 2016 10:27 pm 

Joined: Fri Mar 18, 2016 7:10 pm
Posts: 20
Has thanked: 0 time
Have thanks: 4 time
Thanks Danny, I have just had a play with 6.1 and see how easy it is. Like you say if we had an ActivePlug it will be easy to work out what the calls API calls will be. Just can't afford to buy one right now!


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Sun Mar 27, 2016 4:42 pm 

Joined: Sat Mar 26, 2016 6:47 pm
Posts: 7
Has thanked: 5 time
Have thanks: 0 time
Guys and girls,

this thread has been running a while and during that time there seems to have been several (possibly numerous) API changes. The documentation site (https://api.prod.bgchprod.info/api/docs) seems interesting and has proved useful but I have struggled to use it and thus have reverted to https://api.hivehome.com/v5/login for authentication as well as https://api.hivehome.com/v5/users/<MY_USERNAME>/widgets/temperature to retrieve a JSON object containing some useful data from my Hive. I've used the C# language to achieve this, and whilst the SSL cert issues caused me some troubles, I managed to work around it. Even submitting the response authentication cookie to the next request only slowed me down for a while. I used http://json2csharp.com/# to create C# object to receive the JSON response object and I now have the code to get inside and outside temps as well as the other information returned.

My Authentication code looks like this:
            Uri url = new Uri(@"https://api.hivehome.com/v5/login");
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.CookieContainer = cookieContainer;
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.KeepAlive = true;
            using (Stream s = request.GetRequestStream())
            {
                string content = "username=MyUserName&password=MyPassword";
                ASCIIEncoding encoding = new ASCIIEncoding();
                byte[] data = encoding.GetBytes(content);
                s.Write(data, 0, data.Length);
            }

            ServicePointManager.ServerCertificateValidationCallback += ignoreSSL;

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                if(response.StatusCode != HttpStatusCode.OK)
                {
                    textBox1.Text = string.Format("Server Error (HTTP {0} : {1}).", response.StatusCode, response.StatusDescription);
                }
                textBox1.Text = string.Format("Server Error (HTTP {0} : {1}).", response.StatusCode, response.ToString());

                using (Stream s = response.GetResponseStream())
                {
                    ASCIIEncoding encoding = new ASCIIEncoding();
                    StreamReader reader = new StreamReader(s, encoding);
                    string data = reader.ReadToEnd();
                    content = JsonConvert.DeserializeObject<AuthenicatedContent>(data);
                    textBox1.Text = content.username + "\r\n" + content.ApiSession.ToString();
                }
            }


And the following get the response from https://api.hivehome.com/v5/users/My_Account/widgets/temperature

            Uri url = new Uri(@"https://api.hivehome.com/v5/users/My_Account/widgets/temperature");
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.CookieContainer = cookieContainer;
            request.Method = "GET";
            request.ContentType = "application/json";
            request.KeepAlive = true;

            ServicePointManager.ServerCertificateValidationCallback += ignoreSSL;

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                if(response.StatusCode != HttpStatusCode.OK)
                {
                    textBox1.Text = string.Format("Server Error (HTTP {0} : {1}).", response.StatusCode, response.StatusDescription);
                }
                textBox1.Text = string.Format("Server Error (HTTP {0} : {1}).", response.StatusCode, response.ToString());

                using (Stream s = response.GetResponseStream())
                {
                    ASCIIEncoding encoding = new ASCIIEncoding();
                    StreamReader reader = new StreamReader(s, encoding);
                    string data = reader.ReadToEnd();
                    widgetTemp = JsonConvert.DeserializeObject<WidgetTemperature>(data);
                    textBox1.Text = "Indoor Temperature is " + widgetTemp.inside.now.ToString() + " C\r\n" ;
                    textBox1.Text += "Outdoor Temperature is " + widgetTemp.outside.now.ToString() + " C";
                }
            }



I'd like to delve more into the API but I am having trouble formatting the request to set the target temperature. This is what I have tried so far:

            Uri url = new Uri(@"https://api.hivehome.com/v5/users/My_Account/widgets/climate/targetTemperature");
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.CookieContainer = cookieContainer;
            request.Method = "POST";
            request.ContentType = "application/json";
            request.KeepAlive = true;

            using (Stream s = request.GetRequestStream())
            {
                Temperature temp = new Temperature() { temperature = 19, temperatureUnit="C" };
                ASCIIEncoding encoding = new ASCIIEncoding();
                var t = JsonConvert.SerializeObject(temp);
                byte[] data = encoding.GetBytes(t);
                s.Write(data, 0, data.Length);
            }

            ServicePointManager.ServerCertificateValidationCallback += ignoreSSL;

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                if(response.StatusCode != HttpStatusCode.OK)
                {
                    textBox1.Text = string.Format("Server Error (HTTP {0} : {1}).", response.StatusCode, response.StatusDescription);
                }
                textBox1.Text = string.Format("Server Error (HTTP {0} : {1}).", response.StatusCode, response.ToString());
                using (Stream s = response.GetResponseStream())
                {
                    ASCIIEncoding encoding = new ASCIIEncoding();
                    StreamReader reader = new StreamReader(s, encoding);
                    string data = reader.ReadToEnd();
                }
            }
        }



The URL seems accurate (but may not be correct), I the response tells me I have an invalid parameter, temperature.

Any thoughts on what I'm doing wrong? Is there any better documentation? Should a new thread be started with comprehensive working current documentation or api calls?

Thanks in advance.

Jason.


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Sun Mar 27, 2016 6:54 pm 

Joined: Sat Mar 26, 2016 6:47 pm
Posts: 7
Has thanked: 5 time
Have thanks: 0 time
I've placed my project into GitHub in case anyone is interested. I'll try and keep it updated with my progress.

https://github.com/jamesjl/HiveHomeController


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Sun Mar 27, 2016 7:27 pm 

Joined: Fri Mar 18, 2016 7:10 pm
Posts: 20
Has thanked: 0 time
Have thanks: 4 time
Are you also sending 'temperatureUnit' as a parameter? This lets hive know whether F or C.

See http://www.smartofthehome.com/2016/03/hive-api-v5/ Temperature Set section.


jamesleesaunders has been thanked by:
Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Sun Mar 27, 2016 8:12 pm 

Joined: Sat Mar 26, 2016 6:47 pm
Posts: 7
Has thanked: 5 time
Have thanks: 0 time
It was simply the formatting of the content. It doesn't want to be JSON formatted, simply temperature=20&temperatureUnit=C

Works like a charm.

Thanks for the link too. I'll be sure to check it out thoroughly.


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Sun Mar 27, 2016 9:52 pm 

Joined: Fri Mar 18, 2016 7:10 pm
Posts: 20
Has thanked: 0 time
Have thanks: 4 time
Hi All,

I have put together a couple of Postman collections for the Hive v5 and v6.1 API's which may be of use.

Postman is a really cool Chrome extension application which allows you to test REST API's and save them into a library. You can download Postman here:
https://chrome.google.com/webstore/deta ... omop?hl=en

Once installed you should then be able to add the following 'Collections' to your Postman app:
* Hive API v5 https://www.getpostman.com/collections/ ... 3e7640b07e
* Hive API v6.1 https://www.getpostman.com/collections/ ... 59222e8b39

I have configured these to use session variables and it should populate variables such as hubId and sessionId automatically on login, but You may need to configure your own environment variables for:
"v6url" : "https://api.prod.bgchprod.info:443/omnia"
"v5url" : "https://api.bgchlivehome.co.uk/v5"
"username" : "[email protected]"
"password" : "pa$$word"

If you find these useful ir have and additions or corrections please do share your ideas - I am happy to add further to these. I may pop them on GitHub to share.

Jim


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Mon Mar 28, 2016 1:44 pm 

Joined: Sat Mar 26, 2016 6:47 pm
Posts: 7
Has thanked: 5 time
Have thanks: 0 time
Things are going well and I even have a Universal Windows App (Phone and Windows Store) working will temperatures (getting and setting) as well as indoor and outdoor temps and weather. I'd like to add some hot water functions and add a BOOST function but the API documentation is fighting me all the way.

Can anyone help with working calls for the above mentioned functionality?

Thanks,

J.


Offline
 Profile  
 
 Post subject: Re: Automated JSON Feed retrieval
PostPosted: Mon Mar 28, 2016 7:15 pm 

Joined: Fri Mar 18, 2016 7:10 pm
Posts: 20
Has thanked: 0 time
Have thanks: 4 time
HI James,

I believe the Boost facility is only available on API v6+ (not on v5). You best bet is to see previous post in this post thread by 'dannydev' Thu Nov 12, 2015 12:48 am (Page 5) in which it has an example.

If any use you could also see the 'Thermometer Boost' example I have just added to my Postman examples (see previous post).

Jim


jamesleesaunders has been thanked by:
Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 6 of 8 [ 74 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7, 8  Next


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

cron

suspicion-preferred