HTTP.Request UpdateLight(Light l) { Color prevColor = l.LastColor(); float prevFade = l.LastFade(); if (!l.ShouldPush()) return null; string apiCall = "/api/" + User + "/lights/" + l.id + "/state"; float fade = Mathf.Clamp01(l.fade); HueHSBColor hsbColor = new HueHSBColor(l.color); int transitionTime = (int)(l.transitionTime * 10.0f); //this is specified in hundreds of millisecs (i.e 10 = 1000 ms = 1s) bool on = (l.on && (fade > 0.0f)); string body = "{\"on\": " + (on ? "true" : "false") + " \"hue\": " + (int)(hsbColor.h * 65535.0f) + " \"sat\": " + (int)(hsbColor.s * 255.0f) + " \"bri\": " + (int)(hsbColor.b * fade * 255.0f) + " \"transitiontime\": " + transitionTime + //" \"effect\":\"colorloop\"" + "}"; /* on = true; string body = "{\"on\": " + (on ? "true" : "false") + " \"effect\":\"colorloop\"" + "}";*/ string url = "http://" + BridgeIP + apiCall; //Debug.Log("URL: " + url + " body: " + body + " at Time: " + Time.time + " deltaSinceLastUpdate: " + l.TimeSinceLastUpdate() + "\n"); HTTP.Request request = new HTTP.Request("put", "http://" + BridgeIP + apiCall, JSON.JsonDecode(body) as Hashtable); request.Send(); l.Pushed(); //notify anyone who cares SendEvents(l, prevColor, prevFade); return request; }