/// <summary> /// Encodes the request to import the list of associated names /// </summary> /// <returns></returns> IEnumerator sendConfigurationRequest() { SmartPlugCommand cmd = new SmartPlugCommand(); cmd.type = "SmartPlugDiscovery"; string json = JsonUtility.ToJson(cmd); byte[] myData = System.Text.Encoding.UTF8.GetBytes(json); UnityWebRequest www = UnityWebRequest.Put(address, myData); yield return(www.Send()); if (www.isNetworkError) { if (www.error == "Cannot connect to destination host") { MagicRoomAppliancesManager_active = false; } } else { Debug.Log(www.downloadHandler.text); ServerSmartPlugConfiguration conf = new ServerSmartPlugConfiguration(); conf = JsonUtility.FromJson <ServerSmartPlugConfiguration>(www.downloadHandler.text); listofAssociatedNames = conf.configuration; string log = ""; foreach (string s in listofAssociatedNames) { log += "Found " + s + " on the network, "; } Logger.addToLogNewLine("ServerSP", log); } }
/// <summary> /// Encodes the request to import the lst of associated names /// </summary> /// <returns></returns> IEnumerator sendConfigurationRequest() { LightCommand cmd = new LightCommand(); cmd.Action = "getConfiguration"; string json = JsonUtility.ToJson(cmd); byte[] myData = System.Text.Encoding.UTF8.GetBytes(json); UnityWebRequest www = UnityWebRequest.Put(address, myData); yield return(www.Send()); if (www.isNetworkError) { if (www.error == "Cannot connect to destination host") { MagicRoomLightManager_active = false; } } else { Debug.Log(www.downloadHandler.text); ServerSmartPlugConfiguration conf = new ServerSmartPlugConfiguration(); conf = JsonUtility.FromJson <ServerSmartPlugConfiguration>(www.downloadHandler.text); listofAssociatedNames = conf.configuration; } }
private void SendConfigurationRequest() { LightCommand cmd = new LightCommand { action = "getConfiguration" }; StartCoroutine(SendCommand(cmd, (body) => { ServerSmartPlugConfiguration conf = JsonUtility.FromJson <ServerSmartPlugConfiguration>(body); Lights.Clear(); Lights.AddRange(conf.configuration); })); }
private void SendConfigurationRequest() { SmartPlugCommand cmd = new SmartPlugCommand { type = "SmartPlugDiscovery" }; StartCoroutine(SendCommand(cmd, (body) => { Debug.Log(body); ServerSmartPlugConfiguration conf = JsonUtility.FromJson <ServerSmartPlugConfiguration>(body); Appliances.Clear(); Appliances.AddRange(conf.configuration); MagicRoomManager.instance.Logger.AddToLogNewLine("ServerSP", Appliances.ToString()); })); }