Author Topic: My Notes on remote access for UI6  (Read 21351 times)

Offline garrettwp

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6371
  • Karma: +227/-128
  • Vera 3, Lite, ISY994
Re: My Notes on remote access for UI6
« Reply #30 on: December 15, 2014, 09:23:31 am »
I should have been more descriptive, as Richard stated only check local access if on WiFi.

- Garrett


Offline sgruby

  • Jr. Member
  • **
  • Posts: 62
  • Karma: +3/-1
Re: My Notes on remote access for UI6
« Reply #31 on: December 15, 2014, 01:48:00 pm »
Thanks for the replies; I was hoping to have a better way than to make a local call (if on WiFi), wait for it to fail, and then use the relay server.

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 10091
  • Karma: +763/-142
Re: My Notes on remote access for UI6
« Reply #32 on: December 15, 2014, 01:49:54 pm »
A local connection will fail quickly if Vera is not available.

Offline shrik

  • Newbie
  • *
  • Posts: 13
  • Karma: +0/-0
Re: My Notes on remote access for UI6
« Reply #33 on: December 18, 2014, 01:57:53 am »

Re: UI6 and HTTPS access (remote) Problems
? Reply #9 on: August 05, 2014, 03:32:45 am ?
I have two accounts one is running ui5 and other is ui6.

Create scene works perfect with ui5. I am using same data format to request for a UI6 unit.

I am sending the json string as a POST parameter because the string is very long.

Every thing is work fine with UI5. But dont know what is the issue with UI6.

Following are the details for your reference

URL :

https://vera-us-oem-relay12.mios.com/relay/relay/relay/device/35020991/port_3480/data_request?id=scene&action=create

POST data

{"scene_name":"if master bed is off then 2 thrmostat is heat on","name":"if master bed is off then 2 thrmostat is heat on","groups":[{"delay":0,"actions":[{"device":"11","service":"urn:upnp-org:serviceId:HVAC_UserOperatingMode1","action":"SetModeTarget","arguments":[{"name":"NewModeTarget","value":"HeatOn"}]}]}],"triggers":[{"name":"testing tiggers","enabled":1,"device":"9","template":"1","arguments":[{"id":1,"value":"Off"}]}],"timers":[],"lua":""}


we post data using curl with MMSSession token


$ch = curl_init ($url);               
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array("MMSSession:$sessionToken"));
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
      curl_setopt($ch, CURLOPT_TIMEOUT, 60); //timeout in seconds
      if($aPostData != null)
      {
         $fields_string = '';
         foreach($aPostData as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
         $fields_string = rtrim($fields_string, '&');
         curl_setopt($ch,CURLOPT_POST, count($aPostData));
         curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
         //print_r(count($aPostData));
         //print_r($aPostData);
         
         
      }
     
      $result = curl_exec($ch);
     

if i am print this  $result varible then it's show 'ERROR'     



Please advice








Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 10091
  • Karma: +763/-142
Re: My Notes on remote access for UI6
« Reply #34 on: December 18, 2014, 08:27:54 am »
Sorry I do not have a clue ...
But you might want to verify every little detail.

i.e.
1) Are you sure the Token is correct .. i.e. can you successfully make a relay call before/after this failure.
2) Can you do a Simple Scene Create with GET method (Small string)
3) Can you do a Simple Scene Create with PUT method (Same small string)

Offline garrettwp

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6371
  • Karma: +227/-128
  • Vera 3, Lite, ISY994
Re: My Notes on remote access for UI6
« Reply #35 on: December 18, 2014, 09:05:27 am »
Also can you do this locally.

- Garrett


Offline ravinator

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Re: My Notes on remote access for UI6
« Reply #36 on: January 17, 2015, 03:24:24 am »
Hi Paul,

I've implemented .NET authentication for UI7 (i.e. MMS), but it is part of a larger project which is created as an extension of this project here: http://veradotnet.codeplex.com/.

The project on Codeplex does however not include the MMS authentication part so I extended that part myself.

Anyhow, I've tried to pull out the pieces that you're asking for in the attached. I hope you can use it. If not please ping me directly here on the forum and I'll see if I can assist you to sort it out.


Good luck and let me know how it goes. :-)

Hi jasperhb thanks so much for that, i'm also trying to get MMS auth working through veradotnet. I added your code parts but there is still a class type missing 'MiosRequestHeader'

Offline ravinator

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Re: My Notes on remote access for UI6
« Reply #37 on: January 18, 2015, 01:22:09 am »
ignore my last post - i got it working, thanks again

Offline jasperhb

  • Sr. Newbie
  • *
  • Posts: 46
  • Karma: +1/-0
Re: My Notes on remote access for UI6
« Reply #38 on: January 20, 2015, 11:41:26 am »
ignore my last post - i got it working, thanks again

Great. I'm happy that it was helpful. Took me a couple of days to do it myself.

Offline niko86

  • Newbie
  • *
  • Posts: 8
  • Karma: +2/-0
Re: My Notes on remote access for UI6
« Reply #39 on: February 02, 2015, 05:23:30 am »
i have created a bunch of helper functions to talk to UI7 from php, so far i implemented pretty much everything i found in the wiki.
If there is interest in that, i can do some code cleanup, documentation and publish it on github.

Online amg0

  • Sr. Hero Member
  • ******
  • Posts: 2991
  • Karma: +203/-8
Re: My Notes on remote access for UI6
« Reply #40 on: February 18, 2015, 06:03:21 pm »
Hello all

Thanks to Richard excellent notes which I followed strictly , I managed to build a HTML / JS page which gets user login & pwd and do all the MMS protocol to get the list of units. it works absolutely fine and I get back the expected device table in JSON like these:

{"PK_Device":"35101627","PK_DeviceType":"1","PK_DeviceSubType":"2","MacAddress":"00:0e:8f:7f:71:ab","Server_Device":"vera-us-oem-device12.mios.com","Server_Device_Alt":"vera-us-oem-device11.mios.com","PK_Installation":"256712","DeviceAssigned":"2015-01-31 22:55:10"}

{"PK_Device":"45101392","PK_DeviceType":"1","PK_DeviceSubType":"2","MacAddress":"d4:21:22:fc:cc:ad","Server_Device":"vera-us-oem-device11.mios.com","Server_Device_Alt":"vera-us-oem-device12.mios.com","PK_Installation":"256712","Using_2G":"0","DeviceAssigned":"2015-02-16 12:10:46"}


But ...

it only works when I disable Chrome Same Origin Domain policy ( with the cmd line flag --disable-web-security ).  this is normal & expected because the web server hosting my page is not in the same domain as VERA MMS servers and the VERA MMS servers do not have the proper CORS allowance headers in the response.

Now the question is how do I get around that ? I need to offer a login page which is available when I am out of the home to perform the authentication and then to access VERA remotely.  How do people go around the some domain origin issue ? is it because I use jQuery ?

attached my page code ( single page , and a screen shot that shows the result when it works by disabling same domain origin security )

thx for your help
Alexis

Online amg0

  • Sr. Hero Member
  • ******
  • Posts: 2991
  • Karma: +203/-8
Re: My Notes on remote access for UI6
« Reply #41 on: February 20, 2015, 12:53:24 pm »
I gave up and did the whole thing in PHP.
plus , note that once you have the relay server token, you can pass it on the url as described here
http://forum.micasaverde.com/index.php/topic,30863.msg221291.html#msg221291

Offline sirpinky

  • Sr. Newbie
  • *
  • Posts: 37
  • Karma: +0/-0
Re: My Notes on remote access for UI6
« Reply #42 on: April 02, 2015, 05:30:44 pm »
Hello all

Thanks to Richard excellent notes which I followed strictly , I managed to build a HTML / JS page which gets user login & pwd and do all the MMS protocol to get the list of units. it works absolutely fine and I get back the expected device table in JSON like these:

{"PK_Device":"35101627","PK_DeviceType":"1","PK_DeviceSubType":"2","MacAddress":"00:0e:8f:7f:71:ab","Server_Device":"vera-us-oem-device12.mios.com","Server_Device_Alt":"vera-us-oem-device11.mios.com","PK_Installation":"256712","DeviceAssigned":"2015-01-31 22:55:10"}

{"PK_Device":"45101392","PK_DeviceType":"1","PK_DeviceSubType":"2","MacAddress":"d4:21:22:fc:cc:ad","Server_Device":"vera-us-oem-device11.mios.com","Server_Device_Alt":"vera-us-oem-device12.mios.com","PK_Installation":"256712","Using_2G":"0","DeviceAssigned":"2015-02-16 12:10:46"}


But ...

it only works when I disable Chrome Same Origin Domain policy ( with the cmd line flag --disable-web-security ).  this is normal & expected because the web server hosting my page is not in the same domain as VERA MMS servers and the VERA MMS servers do not have the proper CORS allowance headers in the response.

Now the question is how do I get around that ? I need to offer a login page which is available when I am out of the home to perform the authentication and then to access VERA remotely.  How do people go around the some domain origin issue ? is it because I use jQuery ?

attached my page code ( single page , and a screen shot that shows the result when it works by disabling same domain origin security )

thx for your help
Alexis

Thanks a lot for this javascript sample! exactly what I was looking for!

Did you ever get it to work?

Could the unexplained error be when running this script from a local folder and not from a valid address?

I'll start debugging your code right away, If you did resolve it however please let me know.

Offline sirpinky

  • Sr. Newbie
  • *
  • Posts: 37
  • Karma: +0/-0
Re: My Notes on remote access for UI6
« Reply #43 on: April 02, 2015, 05:58:45 pm »
Hello all

Thanks to Richard excellent notes which I followed strictly , I managed to build a HTML / JS page which gets user login & pwd and do all the MMS protocol to get the list of units. it works absolutely fine and I get back the expected device table in JSON like these:

{"PK_Device":"35101627","PK_DeviceType":"1","PK_DeviceSubType":"2","MacAddress":"00:0e:8f:7f:71:ab","Server_Device":"vera-us-oem-device12.mios.com","Server_Device_Alt":"vera-us-oem-device11.mios.com","PK_Installation":"256712","DeviceAssigned":"2015-01-31 22:55:10"}

{"PK_Device":"45101392","PK_DeviceType":"1","PK_DeviceSubType":"2","MacAddress":"d4:21:22:fc:cc:ad","Server_Device":"vera-us-oem-device11.mios.com","Server_Device_Alt":"vera-us-oem-device12.mios.com","PK_Installation":"256712","Using_2G":"0","DeviceAssigned":"2015-02-16 12:10:46"}


But ...

it only works when I disable Chrome Same Origin Domain policy ( with the cmd line flag --disable-web-security ).  this is normal & expected because the web server hosting my page is not in the same domain as VERA MMS servers and the VERA MMS servers do not have the proper CORS allowance headers in the response.

Now the question is how do I get around that ? I need to offer a login page which is available when I am out of the home to perform the authentication and then to access VERA remotely.  How do people go around the some domain origin issue ? is it because I use jQuery ?

attached my page code ( single page , and a screen shot that shows the result when it works by disabling same domain origin security )

thx for your help
Alexis


I played with your html/scripts (which is kind of a specialty of mine in case anyone else need/want help)
There is one bug I think I found:

in getSessionToken you build the URL "https://"+server+"/info/session/token";
but according to the TO text file notes, this request needs to go to this URL hard coded: "https://us-authd11.mios.com/info/session/token";

changed that, but still not working. I'm getting an error my server is not allowed to make CORS requests to us-authd11.mios.com, this is something they block on their server. This it why it would work from .NET or other platforms, and won't work from JavaScript.
You are using local file - which will never work with CORS, I hosted it on my http://localhost:4422 and it was still rejected.

One more note: you should use request type "jsonp" for cross origin support, but again if it is blocked at the server there is nothing you can do.

shame :(

Did anyone get any luck accessing this via pure JavaScript? This is something I would be very interested in, as I could build a very simple mobile friendly responsive UI page that does the basic day to day operations without bothering with hosting/running server side code.

Online amg0

  • Sr. Hero Member
  • ******
  • Posts: 2991
  • Karma: +203/-8
Re: My Notes on remote access for UI6
« Reply #44 on: April 03, 2015, 01:42:23 am »
Hello all

Thanks to Richard excellent notes which I followed strictly , I managed to build a HTML / JS page which gets user login & pwd and do all the MMS protocol to get the list of units. it works absolutely fine and I get back the expected device table in JSON like these:

{"PK_Device":"35101627","PK_DeviceType":"1","PK_DeviceSubType":"2","MacAddress":"00:0e:8f:7f:71:ab","Server_Device":"vera-us-oem-device12.mios.com","Server_Device_Alt":"vera-us-oem-device11.mios.com","PK_Installation":"256712","DeviceAssigned":"2015-01-31 22:55:10"}

{"PK_Device":"45101392","PK_DeviceType":"1","PK_DeviceSubType":"2","MacAddress":"d4:21:22:fc:cc:ad","Server_Device":"vera-us-oem-device11.mios.com","Server_Device_Alt":"vera-us-oem-device12.mios.com","PK_Installation":"256712","Using_2G":"0","DeviceAssigned":"2015-02-16 12:10:46"}


But ...

it only works when I disable Chrome Same Origin Domain policy ( with the cmd line flag --disable-web-security ).  this is normal & expected because the web server hosting my page is not in the same domain as VERA MMS servers and the VERA MMS servers do not have the proper CORS allowance headers in the response.

Now the question is how do I get around that ? I need to offer a login page which is available when I am out of the home to perform the authentication and then to access VERA remotely.  How do people go around the some domain origin issue ? is it because I use jQuery ?

attached my page code ( single page , and a screen shot that shows the result when it works by disabling same domain origin security )

thx for your help
Alexis


I played with your html/scripts (which is kind of a specialty of mine in case anyone else need/want help)
There is one bug I think I found:

in getSessionToken you build the URL "https://"+server+"/info/session/token";
but according to the TO text file notes, this request needs to go to this URL hard coded: "https://us-authd11.mios.com/info/session/token";

changed that, but still not working. I'm getting an error my server is not allowed to make CORS requests to us-authd11.mios.com, this is something they block on their server. This it why it would work from .NET or other platforms, and won't work from JavaScript.
You are using local file - which will never work with CORS, I hosted it on my http://localhost:4422 and it was still rejected.

One more note: you should use request type "jsonp" for cross origin support, but again if it is blocked at the server there is nothing you can do.

shame :(

Did anyone get any luck accessing this via pure JavaScript? This is something I would be very interested in, as I could build a very simple mobile friendly responsive UI page that does the basic day to day operations without bothering with hosting/running server side code.

Sirpinky
I think the "https://"+server+"/info/session/token"  is correct, it is the doc which is wrong i believe ( not 100% sure ), I believe we are supposed to dynamically get the server name for load balancing or High availability reason. However it does not make a great deal of difference

the BIG problem is the lack of CORS support on vera side servers. without that, and without them supporting jsonp we cannot have a javascript client side approach unfortunately.   I think with a command flag when you launch chrome you can disable all the CORS security enforcement made by the browser and in that case you will see it working fine if I remember  ("Chrome --args --disable-web-security")

so I did get this whole thing working but with PHP.  This url https://vera-ui.strongcubedfitness.com/Veralogin.php is the external MMS login facitiliy for my ALTUI plugin (http://apps.mios.com/plugin.php?id=8246)