Esempio n. 1
0
 void YCheck()
 {
     if (location_y.text == "")
     {
         y_illegal.gameObject.SetActive(false);
         xy_pass.gameObject.SetActive(false);
         return;
     }
     if (int.Parse(location_y.text) > selected.getWidth())
     {
         y_out.gameObject.SetActive(true);
         xy_pass.gameObject.SetActive(false);
         return;
     }
     if (!data.xy.IsMatch(location_y.text))
     {
         y_illegal.gameObject.SetActive(true);
         xy_existed.gameObject.SetActive(false);
         xy_pass.gameObject.SetActive(false);
         return;
     }
     y_illegal.gameObject.SetActive(false);
     y_out.gameObject.SetActive(false);
     if (function.XyCheck(selected, int.Parse(location_x.text), int.Parse(location_y.text)))
     {
         xy_existed.gameObject.SetActive(true);
     }
     else
     {
         xy_existed.gameObject.SetActive(false);
     }
 }
Esempio n. 2
0
 void OnEnable()
 {
     selected             = function.FindSelected();
     controller_name.text = show.getName();
     location_x.text      = "x:   " + show.getX() * selected.getLength() / data.length;
     location_y.text      = "y:   " + show.getY() * selected.getWidth() / data.width;
     on.isOn = show.getState();
 }
Esempio n. 3
0
 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();
 }
Esempio n. 4
0
 void OnEnable()
 {
     selected         = function.FindSelected();
     sensor_name.text = show.getName();
     location_x.text  = "x:   " + show.getX() * selected.getLength() / data.length;
     location_y.text  = "y:   " + show.getY() * selected.getWidth() / data.width;
     if (show.getType())
     {
         temperature.isOn = true;
     }
     else
     {
         humidity.isOn = true;
     }
 }
Esempio n. 5
0
    public static void GetControllers(m_garden garden)
    {
        List <controller> controllers           = new List <controller>();
        HTTPRequest       request_getController = new HTTPRequest(new Uri(data.IP + "/getControllerByGardenId?gardenId=" + garden.getId()), HTTPMethods.Get, (req_controller, res_controller) => {
            Debug.Log(res_controller.DataAsText);
            JArray array = JArray.Parse(res_controller.DataAsText);
            foreach (var e in array)
            {
                controller temp = new controller();
                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.setState((bool)e["valid"]);
                controllers.Add(temp);
                MapBG.drawOne(temp.getId(), temp.getName(), temp.getX(), temp.getY(), MapBG.SensorControllerType.Irrigation, temp.getState(), 0, 0, 0);
            }
            garden.addController(controllers);
        }).Send();

        return;
    }
Esempio n. 6
0
    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);
        }
    }
Esempio n. 7
0
    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;
    }