Jump to content
C4 Forums | Control4

Question for RyanE - oAuth


ILoveControl
 Share

Recommended Posts

I have seen a post around oAuth before and RyanE you were asking it depends on how its constructed and how it responds. Well I have the construct and the response :) I would like to know a few things around C4 specifically in a ic4 file.

 

I want to create a driver that returns a set of data from my weather station. The weather station has a pretty simple interface, you create an app on its website it gives you a client ID, app ID and you pass it your user name and password. The return from the oAuth service is a accessCode. On the Access Code you then use to query data. For example:

 

In pure HTTP Request fashion:

 

 

POST /oauth2/token HTTP/1.1
    Host: api.netatmo.net
    Content-Type: application/x-www-form-urlencoded;charset=UTF-8

    grant_type=password
    client_id=[YOUR_APP_ID]
    client_secret=[YOUR_CLIENT_SECRET]
    username=[uSER_MAIL]
    password=[uSER_PASSWORD]
    scope=[sCOPES_SPACE_SEPARATED]

 

QUESTION: Ryan I am assuming one could translate the request above into a URL (I have confirmed the oAuth URL is https://api.netatmo.net/oauth2/token):

https://api.netatmo.net/oauth2/token?grant_type=password&client_id=5xxxxaaaaBbbb3333&client_secret=ASDASD897ASDAASDA232&username=MyUserRocks&password=PasswordsAreSoOldFasioned&scope=read_station%20read_thermostat%20write_thermostat

QUESTION: If NOT then is there a way to construct a SPECIFIC oAuth request in C4 with LUA, I see many libs' people have created online for LUA to handle oAuth requests. I am asking if there is one already in the LUA engine that C4 runs or am I going to have to manually create something?

 

That should in turn return something like in a pure HTTP request:

 

 

HTTP/1.1 200 OK
    Content-Type: application/json;charset=UTF-8
    Cache-Control: no-store
    Pragma: no-cache

    {
    "access_token":"2YotnFZFEjr1zCsicMWpAA",
    "expires_in":10800,
    "refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
    }

 

 

Thats the tough part :) once I have that back (well really depending on HOW it comes back, I can then use the access_token to get the information I need.

 

Question: Is there no sample anywhere that shows how we can interact with oAuth, I recall somewhere once there being one.

Question: Does the LUA implementation on C4 2.6 have a Json parser like the other LUA implementations?

Link to comment
Share on other sites


QUESTION: Ryan I am assuming one could translate the request above into a URL (I have confirmed the oAuth URL is https://api.netatmo.net/oauth2/token):

 

QUESTION: If NOT then is there a way to construct a SPECIFIC oAuth request in C4 with LUA, I see many libs' people have created online for LUA to handle oAuth requests. I am asking if there is one already in the LUA engine that C4 runs or am I going to have to manually create something?

 

Question: Is there no sample anywhere that shows how we can interact with oAuth, I recall somewhere once there being one.

 

Question: Does the LUA implementation on C4 2.6 have a Json parser like the other LUA implementations?

 

1) Not necessarily.  It depends on the API.  Some require the auth data to be sent in the header, or require a *post* for the auth data.

 

2) You are going to have to do it manually.  DriverWorks does not have any oAuth libraries.

 

3) I don't know of any samples, and unfortunately, the oAuth I've done is in encrypted drivers, for partners that do not allow us to publish the code.

 

4) 2.6 has a pure Lua JSON library available, in the library path on the controller.  Alternatively, you could find one online, and use that.  

 

 

Sorry.

 

RyanE

Link to comment
Share on other sites

4) 2.6 has a pure Lua JSON library available, in the library path on the controller.  Alternatively, you could find one online, and use that.  

 

 

Sorry.

 

RyanE

 

Ryan, I found the JSON file on the controller, within the LUA code I would assume you would call it within a function as follows:

function CallSomeJSON(SomSortOfDecodingValues) JSON = (loadfile "JSON.lua")() -- one-time load of the routines local lua_value = JSON:decode(SomSortOfDecodingValues) -- decode example--do something with the values.end

I read the comments in the file and tried this but I get a :

 

attempt to call a nil value

 

on the line where I am: JSON = (loadfile "JSON.lua")()

 

Do you have an example of how to call or initialize the file so that we can call the JSON functions?

Link to comment
Share on other sites

  • 8 months later...

Hi everyone,

 

I just bought a NetAtmo Whether Station thinking that is easy to read inside air parameters from excel (for some automatics). Found way to difficult, it need an API.

The subject is very poor on internet. In fact, only here I found references for this kind of API. I'm old style programmer (from Fortran and GWBasic to VBA -office 2003), so all these are new for me. The NetAtmo site give some info, but one has to have the background to understand, witch I have not.

I saw that you studied that in december 2014 trying to read your values.

I manage easy to read outside values (they are public, one may retrieve them as .xml file from wunderground.com relatively easy) but I have problems reading inside values, witch are not public. I found no references to learn how to bring that values, more of that, I need them be read from Excel 2003 (or written to).

I tried your URL example https://api.netatmo.net/oauth2/token?gran... replaced with my API values, but no luck (from Chrome).

Can you help me?

 

tks,

Link to comment
Share on other sites

Hi again,

 

Till now, I found that is not possible to send this

 

POST /oauth2/token HTTP/1.1
    Host: api.netatmo.net
    Content-Type: application/x-www-form-urlencoded;charset=UTF-8

    grant_type=password
    client_id=[MY_ID]
    client_secret=[MY_SECRET]
    username=[MY_MAIL]
    password=[MY_PASSWORD]
    scope=[just_station]

 

with a browser (like your ex. https://api....), so I'm lost.

Link to comment
Share on other sites

Thanks for answering.
 

Can you give me an example of how I would do that? I know that you need to communicate with a server using ouath2. However I don't know how I would do the whole thing in VBA or any other programming language for that matter. What do I send? How do I send it? Where would I get the response?

Link to comment
Share on other sites

Thanks for answering.

Can you give me an example of how I would do that? I know that you need to communicate with a server using ouath2. However I don't know how I would do the whole thing in VBA or any other programming language for that matter. What do I send? How do I send it? Where would I get the response?

This is a control4 site not a weather station site. You find out how to do vba here.

Sent from my iPhone using Tapatalk

Link to comment
Share on other sites

A general comment on pulling data from personal weather stations - if you can connect your weather station to Weather Underground then they have a pretty good API that you can access and retrieve JSON data.  I pull down some data from my weather station using Python code.  You just need to get an API key and then you don't need any other authentication.

 

Here is more on the Weather Underground API http://www.wunderground.com/weather/api/d/docs?d=resources/code-samples

Link to comment
Share on other sites

Thank you for your answer. I already do that for outside temperature and humidity, including forecast. I read them directly as .xml in Excel, and after some corrections I put them on nice graphs for inside and outside forecast. It told me if I should open windows (or mechanical ventilation), when and how long and what will happen with inside air in the next hours if I open windows. This is important because the humidity get in immediately, but not the same for the outside cold- the temperature change much slowly, it takes many hours and this period of transition could be very unpleasant . Bad part is that I can't read the inside values of Temp and Humidity so I have to write the  manually and so I can not start automatically ventilation or AC and that was the main reason for buying this station.

I red the suggested API from NetAtmo (they said what to do but not how to do), google it and found same info only here. I thought that I may found help for an example of code written especially for NetAtmo, doesn't matter of language (C, html, java, etc).

On internet I already found one part or another of needed code (found some how to...) but trying and put it together goes wrong for me and couldn't authenticate at NetAtmo.

From discussion above, I found that ILoveControl has success reading values, that is why I dare to ask here for help, even if the site is C4 dedicated.

 

I could gladly share my knowledge of weather, wunderground or inside air parameters if one need it.

 

Thank you all for your help,

 

Mihai

Link to comment
Share on other sites

  • 2 years later...
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...