Hello!
I am working on an AR project, visualising data from a sensor to Unity.
Particle photon is the microprocessor that receives data and publishes them online. Then this data is linked to a text mesh, whose values change accordingly.
The problem is that although data is sent to the cloud, unity does not receive any values. Nothing inside yield return is read, according to Debug.Log
Any ideas how this could be implemented would be great
using UnityEngine;
using System.Collections;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class talktoCyberPlant : MonoBehaviour
{
string JSON_Rate;
string path;
string Url;
float temp;
public float MoistureInput;
string Zero;
WWW myRequest;
string url = "https://api.particle.io/v1/devices/3a001d001847393035313137/MoistureInput?access_token=1d905201546329bf6eb90a4265a4c57f796cc16f";
void Start() // Use this for initialization
{
myRequest = new WWW(url);
StartCoroutine(WaitForRequest(myRequest));
}
IEnumerator WaitForRequest(WWW myRequest)
{
Debug.Log("inside WaitForRequest");
yield return myRequest;
// check for errors
if (myRequest.error == null)
{
Debug.Log("Inside if ");
string work = myRequest.text; //text was data on other code?
_Particle fields = JsonUtility.FromJson<_Particle>(work);
JSON_Rate = fields.result;
temp = float.Parse (JSON_Rate);
//MoistureInput = Mathf.FloorToInt(temp);
MoistureInput = temp;
//Debug.Log (MoistureInput);
} else {
Debug.Log("Inside else ");
}
}
// Update is called once per frame
void Update()
{
Debug.Log("Inside component ");
//This is to text connectivity with Unity, text should appear on TextMesh when code is loaded
GetComponent<TextMesh>().text = MoistureInput.ToString()+"degrees";
Debug.Log(" State Moisture Data ");
}
[System.Serializable]
public class _Particle{
public string name;
public string result;
}
}