Search Unity

Question Hololens cannot send a request to the server .

Discussion in 'AR' started by juhaochitudouni, Jan 17, 2021.

  1. juhaochitudouni

    juhaochitudouni

    Joined:
    Jan 14, 2021
    Posts:
    4
    I'm using Hololens to control Raspberry Pi by HTTP Request.
    There is an error when sending HTTP Request:
    · Unity 2019.4.10f1
    · Hololens 1
    · Hololen SDK version :10.0.17134.0
    Through Hololens it shows:
    Curl error 7: Failed to connect to 39.107.26.58 port 5000.Bad Access.
    Code (CSharp):
    1. [code=CSharp][code=CSharp]using System.Collections;
    2.  
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5.  
    6.  
    7. public class lightcontroller : MonoBehaviour
    8. {
    9.     public GameObject LightObj;
    10.     public Light LightCon;
    11.     public bool isopen = true;
    12.  
    13.     private void Start()
    14.     {
    15.         LightCon = LightObj.GetComponent<Light>();
    16.     }
    17.  
    18.     public void OnSelect()
    19.     {
    20.         if (isopen)
    21.         {
    22.             LightCon.enabled = false;
    23.             StartCoroutine(Get("http://39.107.26.58:5000/ledflage"));
    24.             //StartCoroutine(GetRequest("http://baidu.com"));
    25.             isopen = false;
    26.             //Debug.Log(request);
    27.         }
    28.         else
    29.         {
    30.             LightCon.enabled = true;
    31.             StartCoroutine(Get("http://39.107.26.58:5000/ledflage"));
    32.             isopen = true;
    33.             Debug.Log("on");
    34.         }
    35.     }
    36.  
    37.     private void OnMouseDown()
    38.     {
    39.         if (isopen)
    40.         {
    41.             LightCon.enabled = false;
    42.             StartCoroutine(Get("http://39.107.26.58:5000/ledflage"));
    43.             //StartCoroutine(GetRequest("http://baidu.com"));
    44.             isopen = false;
    45.             //Debug.Log(request);
    46.         }
    47.         else
    48.         {
    49.             LightCon.enabled = true;
    50.             StartCoroutine(Get("http://39.107.26.58:5000/ledflage"));
    51.             isopen = true;
    52.             Debug.Log("on");
    53.         }
    54.     }
    55.  
    56.     IEnumerator Get(string url)
    57.     {
    58.         UnityWebRequest www = UnityWebRequest.Get(url);
    59.         yield return www.SendWebRequest();
    60.  
    61.         if (www.isNetworkError || www.isHttpError)
    62.         {
    63.             Debug.Log(www.error);
    64.         }
    65.         else
    66.         {
    67.             Debug.Log("ok");
    68.  
    69.         }
    70.     }
    71.  
    72. }
    [/code][/code]


    ·The server on Raspberry Pi is based on python flask. Here is the code:
    Code (CSharp):
    1. [code=CSharp][code=CSharp]from flask import Flask
    2. app = Flask(__name__)
    3. TEMPERATURE1 = 0
    4. HUMIDITY = 0
    5. LEDFLAGE = 0
    6.  
    7.  
    8.  
    9.  
    10. @app.route('/')
    11. def hello_world():
    12.     return 'Hello, World!'
    13.  
    14.  
    15. @app.route('/temperature/<temperature>')
    16. def getTempture(temperature):
    17.     # show the user profile for that user
    18.     global TEMPERATURE1
    19.     TEMPERATURE1 = temperature
    20.     return temperature
    21.  
    22.  
    23. @app.route('/humidity/<humidity>')
    24. def gethumidity(humidity):
    25.     # show the user profile for that user
    26.     global HUMIDITY
    27.     HUMIDITY = humidity
    28.     return humidity
    29.  
    30.  
    31. @app.route('/temperature')
    32. def return_temperature():
    33.     return TEMPERATURE1
    34.  
    35.  
    36. @app.route('/humidity')
    37. def return_humidity():
    38.     return HUMIDITY
    39.  
    40.  
    41. @app.route('/1')
    42. def readtemperatureandhumidity():
    43.     return "温度:" + TEMPERATURE1 + "湿度:"  + HUMIDITY
    44.  
    45.  
    46. @app.route('/ledflage')
    47. def changeLed1():
    48.     global LEDFLAGE
    49.     if LEDFLAGE == 0:
    50.         LEDFLAGE = 1
    51.         return "ledon"
    52.     else:
    53.         LEDFLAGE = 0
    54.         return "ledoff"
    55.  
    56.  
    57. @app.route('/2')
    58. def checkLed1():
    59.     global LEDFLAGE
    60.     if LEDFLAGE == 1:
    61.         return "ledon"
    62.     else:
    63.         return "ledoff"
    64.  
    65.  
    66. @app.route('/3')
    67. def text():
    68.     #return "fanhuishuju"
    69.     return '1', 200, [("Python", "Flask"), ("Python", "Tornado")]
     
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    I really don't have a good idea on this here, but have you checked firewall settings on the device to see if you need to open a port?