Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality. If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers. And always feel free to hit us up on Twitter @MxdRealityDev.

How to change the IPD from a Unity App

Hello all,

I am trying to change the ipd from a Unity App that is running on my HoloLens.

Currently I am only able to change the ipd from a remote PC. It works over WLAN with the "https://192.168.0.101" IP and also via USB and https://127.0.0.1:10080.

On my Hololens I am using the same code. I tried connecting to https://127.0.0.1 and https://127.0.0.1:10080 and to the devie IP. Also I am using UnityWebRequest and have checked InternetClient ,InternetClientServer Capabilities in Unity.

In Visual Studio I get the following Output: "Cannot connect to destination host" while it is running perfectly on the remote PC.

I also tried switching off SSL in the HoloLens device portal. In this scenario I used http instead of https. Again, from the PC it works fine but on the HoloLens I get the same error.

This is the script I am currently using for testing:

Thanks in advance!

using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using UnityEngine.Networking;

public class HttpPostRequest : MonoBehaviour {

private string CsrfToken = "";

public string url = "https://192.168.0.101";
public string path = "/api/holographic/os/settings/ipd";

public string username;
public string password;

private string urlOptions = "ipd=70000";


private void Start()
{
    InvokeRepeating("test", 3.0f, 3.0f);
}


void test()
{
    int rand = Random.Range(50000, 80000);
    DoHTTPPost("ipd=" + rand);
}


public void DoHTTPPost(string urlOptions)
{
    this.urlOptions = urlOptions;
    StartCoroutine(SendAuthRequest());
}

IEnumerator SendAuthRequest()
{

    UnityWebRequest request = UnityWebRequest.Get(url);

    request.SetRequestHeader("Authorization", "Basic " +
        System.Convert.ToBase64String(
            System.Text.Encoding.ASCII.GetBytes("username:password")));


    yield return request.Send();


    if (request.error != null)
    {
        Debug.Log("There was an error sending request to " + request.url + " : " + request.error + " " + request.isError);
    }
    else
    {

        CsrfToken = request.GetResponseHeader("Set-Cookie");
        Debug.Log(request.GetResponseHeader("Set-Cookie"));

        StartCoroutine(SendIPDChangePost());
    }

}

IEnumerator SendIPDChangePost()
{

    UnityWebRequest request = UnityWebRequest.Post(url + path + "?" + urlOptions,"");


    Debug.Log("PostRequestUrl: " + request.url);

    request.SetRequestHeader("cookie", CsrfToken);
    request.SetRequestHeader("X-Requested-With" , "XMLHttpRequest");
    request.SetRequestHeader("Authorization", "Basic " +
        System.Convert.ToBase64String(
            System.Text.Encoding.ASCII.GetBytes("username:password")));

    request.SetRequestHeader("x-csrf-token", CsrfToken.Replace("CSRF-Token=", ""));


    yield return request.Send();

    if(request.error != null)
    {
        Debug.Log("Error: " + request.error);
    } else
    {
        Debug.Log("Request Success");
    }
}

}

Best Answers

Answers

  • Thanks a lot for the fast response!

    In our scenario we will have a server nearby. We will try next to ask the server for setting the IPD from outside.

    Thanks! I will have a look at the FitBoxIPD Application.

  • Thanks for the plug @mGravitus. @HoloLee I wrote the FitBoxIPD above. There is unfortunately no UWP API to set the IPD so I had to talk to Device Portal. As @DavidKlineMS points out, you will not be able to deploy an app that uses this approach into the store because only sideloaded applications can do network loopback. Once they're published to the store loopback is not allowed.

    I'm hoping they add a managed API for this at some point in the future, but I don't have access to the roadmap.

    Our Holographic world is here

    RoadToHolo.com      WikiHolo.net      @jbienz
    I work in Developer Experiences at Microsoft. My posts are based on my own experience and don't represent Microsoft or HoloLens.

  • Hi. Any updates on a possible availability of this API? Thx

Sign In or Register to comment.