void OnEnable() { selected = function.FindSelected(); garden_name.text = selected.getName(); length.text = selected.getLength().ToString(); width.text = selected.getWidth().ToString(); temperature.text = selected.getIdealTemperature().ToString(); humidity.text = selected.getIdealHumidity().ToString(); }
void SaveOnClick() { foreach (InputField e in required) { function.RequiredInputOnEndEdit(e); } foreach (Text e in warning) { if (e.IsActive()) { return; } } if (function.InputFieldRequired(required)) { if (garden_name.text != selected.getName() || temperature.text != selected.getIdealTemperature().ToString() || humidity.text != selected.getIdealHumidity().ToString() || length.text != selected.getLength().ToString() || width.text != selected.getWidth().ToString()) { HTTPRequest request = new HTTPRequest(new Uri(data.IP + "/updateGarden"), HTTPMethods.Post, (req, res) => { switch (req.State) { case HTTPRequestStates.Finished: Debug.Log(res.DataAsText); function.FreshGarden(selected); break; default: Debug.Log("Error!Status code:" + res.StatusCode); break; } }); request.AddHeader("Content-Type", "application/json"); JsonData newGarden = new JsonData(); newGarden["id"] = selected.getId().ToString(); newGarden["userId"] = data.m_user.getId().ToString(); newGarden["width"] = width.text; newGarden["length"] = length.text; newGarden["name"] = garden_name.text; newGarden["idealTemperature"] = temperature.text; newGarden["idealWetness"] = humidity.text; request.RawData = System.Text.Encoding.UTF8.GetBytes(newGarden.ToJson()); request.Send(); } GameObject.Find("Canvas/cover").SetActive(false); GameObject.Find("Canvas/garden_info").SetActive(false); } }
private void OnEnable() { selected = function.FindSelected(); ideal = (int)selected.getIdealHumidity(); test(); }
public static void GetSensors(m_garden garden) { List <sensor> sensors = new List <sensor>(); HTTPRequest request_getSensor1 = new HTTPRequest(new Uri(data.IP + "/getTemperatureSensorByGardenId?gardenId=" + garden.getId()), HTTPMethods.Get, (req_sensor1, res_sensor1) => { Debug.Log(res_sensor1.DataAsText); JArray array = JArray.Parse(res_sensor1.DataAsText); foreach (var e in array) { sensor temp = new sensor(); temp.setId((long)e["id"]); temp.setName((string)e["name"]); temp.setX((int)e["x"] * data.width / garden.getLength()); temp.setY((int)e["y"] * data.length / garden.getWidth()); temp.setType(true); sensors.Add(temp); } garden.addSensor(sensors); }).Send(); HTTPRequest request_getSensor2 = new HTTPRequest(new Uri(data.IP + "/getWetnessSensorByGardenId?gardenId=" + garden.getId()), HTTPMethods.Get, (req_sensor2, res_sensor2) => { Debug.Log(res_sensor2.DataAsText); JArray array = JArray.Parse(res_sensor2.DataAsText); foreach (var e in array) { sensor temp = new sensor(); temp.setId((long)e["id"]); temp.setName((string)e["name"]); temp.setX((int)e["x"] * data.width / garden.getLength()); temp.setY((int)e["y"] * data.length / garden.getWidth()); temp.setType(false); sensors.Add(temp); } garden.addSensor(sensors); }).Send(); HTTPRequest request_getSensorData1 = new HTTPRequest(new Uri(data.IP + "/getLatestTemperatureByGardenId?gardenId=" + garden.getId()), HTTPMethods.Get, (req_data1, res_data1) => { Debug.Log(res_data1.DataAsText); JArray array = JArray.Parse(res_data1.DataAsText); foreach (var e in array) { foreach (sensor n in garden.getSensors()) { if (n.getId() == (long)e["id"] && n.getType()) { n.setData((float)e["temperature"]); } } } foreach (sensor e in garden.getSensors()) { if (e.getType() && e.getData() != 0) { MapBG.drawOne(e.getId(), e.getName(), e.getX(), e.getY(), MapBG.SensorControllerType.Temperature, true, e.getData(), garden.getIdealTemperature() * (float)1.2, garden.getIdealTemperature() * (float)0.8); } else if (e.getType() && e.getData() == 0) { MapBG.drawOne(e.getId(), e.getName(), e.getX(), e.getY(), MapBG.SensorControllerType.Temperature, false, garden.getIdealTemperature(), garden.getIdealTemperature() * (float)1.2, garden.getIdealTemperature() * (float)0.8); } } }).Send(); HTTPRequest request_getSensorData2 = new HTTPRequest(new Uri(data.IP + "/getLatestWetnessByGardenId?gardenId=" + garden.getId()), HTTPMethods.Get, (req_data2, res_data2) => { Debug.Log(res_data2.DataAsText); JArray array = JArray.Parse(res_data2.DataAsText); foreach (var e in array) { foreach (sensor n in garden.getSensors()) { if (n.getId() == (long)e["id"] && !n.getType()) { n.setData((float)e["wetness"]); } } } foreach (sensor e in garden.getSensors()) { if (!e.getType() && e.getData() != 0) { MapBG.drawOne(e.getId(), e.getName(), e.getX(), e.getY(), MapBG.SensorControllerType.Humidity, true, e.getData(), garden.getIdealHumidity() * (float)1.2, garden.getIdealHumidity() * (float)0.8); } else if (!e.getType() && e.getData() == 0) { MapBG.drawOne(e.getId(), e.getName(), e.getX(), e.getY(), MapBG.SensorControllerType.Humidity, false, garden.getIdealHumidity(), garden.getIdealHumidity() * (float)1.2, garden.getIdealHumidity() * (float)0.8); } } }).Send(); return; }