I heard you guys liked obscure problems
I’m currently experimenting with controlling a Philips Hue bulb from Unity but I am seeing a lot of lag that I can’t explain. I am using the UnityHTTP plugin and the following C# code:
using UnityEngine;
using System.Collections;
using SimpleJSON;
public Hashtable lightSettings = new Hashtable();
void Start () {
myUrl = "http://" + <bridge url> + "/api/newdeveloper/lights/" + <light number> + "/state"; // where am I accessing it?
}
void Update () {
if (Input.GetKeyDown (KeyCode.X))
{
updateMyLight();
}
}
public void updateMyLight() {
updateHashtable();
sendToLight();
}
public void sendToLight() {
HTTP.Request theRequest = new HTTP.Request( "PUT", myUrl, lightSettings ); // build the request
theRequest.Send(); // send the request
}
public void updateHashtable() {
lightSettings.Clear();
lightSettings.Add("transitiontime", 1);
lightSettings.Add("bri", 100);
lightSettings.Add("sat", 0);
lightSettings.Add("hue", 50000);
lightSettings.Add("on", true);
}
Using this code I can change the properties of the light, however there appears to be a 1+ second delay between Unity sending the message and the light reflecting these changes. I do not see this delay when I control the bulb via Philips’ own browser-based debug tool.
Unfortunately I am fairly new to both Unity and network coding. Is there something obvious I’m missing? Perhaps a series of checks Unity automatically performs?
I’ve been stuck for 48 hours now. Any tips would be much appreciated!