ILoveControl Posted December 15, 2014 Share Posted December 15, 2014 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_thermostatQUESTION: 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 More sharing options...
RyanE Posted December 15, 2014 Share Posted December 15, 2014 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 More sharing options...
ILoveControl Posted December 15, 2014 Author Share Posted December 15, 2014 I managed to get responses coming back. Is there a documented list of Json API calls supported by the lua implementation on C4? Can onr use your own Libs or is that limited in C4?Sent from my Nokia 930 Link to comment Share on other sites More sharing options...
ILoveControl Posted December 16, 2014 Author Share Posted December 16, 2014 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.endI 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 More sharing options...
RyanE Posted December 16, 2014 Share Posted December 16, 2014 I typically just include the library into the Lua source. Then if you encrypt the driver, all source is encrypted. RyanE Link to comment Share on other sites More sharing options...
ILoveControl Posted December 16, 2014 Author Share Posted December 16, 2014 Thanks Ryan, got it. BTW where does one get the encrypting tool the SDK just refers to it, it does not really say where. I do have a paid for developer account. Link to comment Share on other sites More sharing options...
RyanE Posted December 17, 2014 Share Posted December 17, 2014 Shoot me an email. RyanE Link to comment Share on other sites More sharing options...
MihaiP Posted September 4, 2015 Share Posted September 4, 2015 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 More sharing options...
MihaiP Posted September 4, 2015 Share Posted September 4, 2015 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 More sharing options...
msgreenf Posted September 4, 2015 Share Posted September 4, 2015 You can send that in a driver....Sent from my iPhone using Tapatalk Link to comment Share on other sites More sharing options...
MihaiP Posted September 5, 2015 Share Posted September 5, 2015 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 More sharing options...
msgreenf Posted September 5, 2015 Share Posted September 5, 2015 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 More sharing options...
zaphod Posted September 9, 2015 Share Posted September 9, 2015 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 More sharing options...
MihaiP Posted September 11, 2015 Share Posted September 11, 2015 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 More sharing options...
zaphod Posted January 5, 2018 Share Posted January 5, 2018 Anything changed in OAuth for C4 in the last three years? Any OAuth libs for DriverWorks? Link to comment Share on other sites More sharing options...
RyanE Posted January 6, 2018 Share Posted January 6, 2018 No built-in OAuth libraries in DriverWorks as of yet. Sorry. RyanE Link to comment Share on other sites More sharing options...
zaphod Posted January 6, 2018 Share Posted January 6, 2018 You say as of yet - is this something being contemplated for the future? Link to comment Share on other sites More sharing options...
msgreenf Posted January 6, 2018 Share Posted January 6, 2018 4 minutes ago, zaphod said: You say as of yet - is this something being contemplated for the future? he wont answer that Link to comment Share on other sites More sharing options...
zaphod Posted January 6, 2018 Share Posted January 6, 2018 Ok - but at least it wasn't - no that's the dumbest thing I have heard. I want to try developing a driver for an API that uses OAuth so I guess I will have to do all of the hard work myself. Link to comment Share on other sites More sharing options...
msgreenf Posted January 6, 2018 Share Posted January 6, 2018 Just now, zaphod said: I guess I will have to do all of the hard work myself Welcome to the club Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.