Created
February 24, 2016 21:43
-
-
Save rondagdag/b545bb76c4ed3615fed9 to your computer and use it in GitHub Desktop.
This is how I communicate with the webserver on the raspberry pi from Unity3d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System; | |
public class CylonCoroutine : MonoBehaviour { | |
public string MoveType = "look_down"; | |
string server = "http://192.168.43.149:3000/"; | |
//string server = "http://192.168.1.25:3000/"; | |
// Use this for initialization | |
void Start () { | |
StartCoroutine (UpdateHead ()); | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
IEnumerator UpdateHead() | |
{ | |
while (true) { | |
if (!string.IsNullOrEmpty (MoveType)) { | |
//http://192.168.43.149:3000/api/robots/boxhead/commands/look_down | |
var command = string.Empty; | |
switch (MoveType) { | |
case "look_up": | |
command = "look_up"; | |
break; | |
case "look_down": | |
command = "look_down"; | |
break; | |
case "look_left": | |
command = "look_left"; | |
break; | |
case "look_right": | |
command = "look_right"; | |
break; | |
default: | |
command = string.Empty; | |
break; | |
} | |
if (string.IsNullOrEmpty (command)) { | |
yield return null; | |
} else { | |
var webcommand = server + "api/robots/boxhead/commands/" + MoveType; | |
var www = new WWW (webcommand); | |
MoveType = null; | |
yield return www; | |
if (string.IsNullOrEmpty (www.error)) { | |
Debug.Log ("Return Value " + www.text); | |
} | |
} | |
} else { | |
yield return null; | |
} | |
} | |
} | |
public IEnumerator UpdateBoxHead() | |
{ | |
if (!string.IsNullOrEmpty(MoveType)) | |
{ | |
//http://192.168.43.149:3000/api/robots/boxhead/commands/look_down | |
var webcommand = "http://192.168.43.149:3000/api/robots/boxhead/commands/" + MoveType; | |
var www = new WWW (webcommand); | |
MoveType = null; | |
yield return www; | |
/*if (string.IsNullOrEmpty (www.error)) { | |
Debug.Log ("Return Value " + www.text); | |
}*/ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment