- Home /
Button Press with ESP8266 Working in Desktop Unity Program but not on Phone
Hello,
I've connected a 5-way tactile switch to an ESP8266 module and am using the Arduino IDE to program it. I've also connected my Arduino code to Unity3D. Essentially, if the button is pressed, my Arduino program prints the direction that the button was pressed in onto an automatically updating web server. In my Unity code, I read the text from the webpage and pan the scene according to the direction printed there. This is working perfectly on my laptop, but once I build and run the Unity program onto an Android phone, the panning no longer works. The phone and the ESP8266 are both on the same WiFi network. The button directions print fine when I go to the IP address on the phone, so I'm assuming that the problem is with the Unity code. Does anyone know what is wrong? Below is my code. Thank you!
using System;
using System.Collections;
using System.IO.Ports;
using System.Collections.Generic;
using UnityEngine;
public class StreetViewCamera: MonoBehaviour {
private string textFromWWW;
private string url = "http://192.168.1.10/"; // <-- enter your url here
IEnumerator GetTextFromWWW()
{
WWW www = new WWW(url);
yield return www;
if (www.error != null)
{
Debug.Log("Ooops, something went wrong...");
Debug.Log(www.error);
}
else
{
textFromWWW = www.text;
Debug.Log(textFromWWW);
}
}
private void Update()
{
StartCoroutine(GetTextFromWWW());
Boolean up = true;
Boolean down = true;
Boolean left = true;
Boolean right = true;
Boolean center = true;
Boolean empty = true;
try
{
//isolates the single letter indicating the direction from the rest of textFromWWW
string stringText = Convert.ToString(textFromWWW);
string substring = stringText.Split('^')[0];
Debug.Log("SUB: " + substring);
int index = ((substring.Length) - 1); //index of last character, which will be the direction reading
string reading = Convert.ToString(substring[index]); //convert to string from char
Debug.Log("READING: " + reading);
while (up && reading.Equals("U")){
movein();
up = false;
}
while (down && reading.Equals("D"))
{
moveout();
down = false;
}
while (left && reading.Equals("L"))
{
moveleft();
left = false;
}
while (right && reading.Equals("R"))
{
moveright();
right = false;
}
while (center && reading.Equals("C"))
{
Debug.Log("center running");
center = false;
}
while (empty && reading.Equals("E"))
{
Debug.Log("empty running");
empty = false;
}
subZInput = 0;
subXInput = 0;
}
catch (System.Exception)
{
}
}
private void movein(){
transform.position += transform.forward * 50 * Time.deltaTime;
}
private void moveout()
{
transform.position += transform.forward * -50 * Time.deltaTime;
}
private void moveleft()
{
transform.position += transform.right * -50 * Time.deltaTime;
}
private void moveright()
{
transform.position += transform.right * 50 * Time.deltaTime;
}
}
how about debugging the code? using adb logcat -s Unity or attaching your IDE setting break points?
I tried going to adb, but the ter$$anonymous$$al keeps saying [process completed] before I can type in a command. I've looked at my bash.profile, but there's nothing in it that causes the error that I can see. I'm creating a new server now on my laptop and trying to see if the problem is with the server or with the phone.
Your answer
Follow this Question
Related Questions
Weapon Switching 1 Answer
add case in swicth, from editor unity 0 Answers
Can the two of telephone system be linked and how? 0 Answers
How to switch and unlock game characters in real time 0 Answers