Commit 746946a4 authored by 潘梓豪's avatar 潘梓豪

更新传感器数据脚本

parent 8a423d39
using LitJson;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Networking; using UnityEngine.Networking;
using TMPro;
public class SensorDataManger : MonoBehaviour public class SensorDataManger : MonoBehaviour
{ {
...@@ -24,6 +26,11 @@ public class SensorDataManger : MonoBehaviour ...@@ -24,6 +26,11 @@ public class SensorDataManger : MonoBehaviour
public string lineId2; public string lineId2;
private JsonData line_jd1 = new JsonData();
private JsonData line_jd2 = new JsonData();
void Start() void Start()
{ {
//foreach (GameObject item in model1) //foreach (GameObject item in model1)
...@@ -35,6 +42,8 @@ public class SensorDataManger : MonoBehaviour ...@@ -35,6 +42,8 @@ public class SensorDataManger : MonoBehaviour
//{ //{
// Create3dUI(item, _parent2); // Create3dUI(item, _parent2);
//} //}
StartCoroutine(GetThreeModelSensorData1());
} }
// Update is called once per frame // Update is called once per frame
...@@ -75,7 +84,7 @@ public class SensorDataManger : MonoBehaviour ...@@ -75,7 +84,7 @@ public class SensorDataManger : MonoBehaviour
public IEnumerator GetThreeModelSensorData1() public IEnumerator GetThreeModelSensorData1()
{ {
string jsonData = "{\"lineId\":\"" + lineId1 + "\"}"; string jsonData = "{\"lineId\":\"" + lineId1 + "\"}";
string post = ""; string post = "https://apifoxmock.com/m1/3550441-0-default/maintenance/bigScreen/sensor/getThreeModelSensorData";
while (true) while (true)
{ {
using (UnityWebRequest request = UnityWebRequest.PostWwwForm(post, jsonData)) using (UnityWebRequest request = UnityWebRequest.PostWwwForm(post, jsonData))
...@@ -97,7 +106,13 @@ public class SensorDataManger : MonoBehaviour ...@@ -97,7 +106,13 @@ public class SensorDataManger : MonoBehaviour
else else
{ {
// 解析响应数据 // 解析响应数据
string responseJson = request.downloadHandler.text; line_jd1 = JsonMapper.ToObject<JsonData>(request.downloadHandler.text);
if (line_jd1!=null && line_jd1.ContainsKey("data"))
{
setData(_parent1, line_jd1);
}
} }
} }
...@@ -108,7 +123,7 @@ public class SensorDataManger : MonoBehaviour ...@@ -108,7 +123,7 @@ public class SensorDataManger : MonoBehaviour
public IEnumerator GetThreeModelSensorData2() public IEnumerator GetThreeModelSensorData2()
{ {
string jsonData = "{\"lineId\":\"" + lineId2 + "\"}"; string jsonData = "{\"lineId\":\"" + lineId2 + "\"}";
string post = ""; string post = "https://apifoxmock.com/m1/3550441-0-default/maintenance/bigScreen/sensor/getThreeModelSensorData";
while (true) while (true)
{ {
using (UnityWebRequest request = UnityWebRequest.PostWwwForm(post, jsonData)) using (UnityWebRequest request = UnityWebRequest.PostWwwForm(post, jsonData))
...@@ -130,14 +145,77 @@ public class SensorDataManger : MonoBehaviour ...@@ -130,14 +145,77 @@ public class SensorDataManger : MonoBehaviour
else else
{ {
// 解析响应数据 // 解析响应数据
string responseJson = request.downloadHandler.text; line_jd2 = JsonMapper.ToObject<JsonData>(request.downloadHandler.text);
if (line_jd2 != null && line_jd2.ContainsKey("data"))
{
setData(_parent2, line_jd2);
}
} }
} }
yield return new WaitForSeconds(1f); yield return new WaitForSeconds(1f);
} }
} }
public void setData(GameObject parent,JsonData line_jd)
{
foreach (JsonData item in line_jd["data"])
{
GameObject _obj = parent.transform.Find(item["equipmentName"].ToString()).gameObject;
if (_obj)
{
_obj.transform.Find("设备名称").Find("Text-名称").GetComponent<TMP_Text>().text = item["equipmentName"].ToString();
switch (item["sensorType"].ToString())
{
case "TILT":
_obj.transform.Find("倾角").gameObject.SetActive(true);
_obj.transform.Find("倾角").Find("Text-名称").GetComponent<TMP_Text>().text = item["data"].ToString();
_obj.transform.Find("倾角").Find("Text-名称").GetComponent<TMP_Text>().color = int.Parse(item["data"].ToString()).Equals(1) ? Color.red : Color.green;
break;
case "NOISE":
_obj.transform.Find("噪声").gameObject.SetActive(true);
_obj.transform.Find("噪声").Find("Text-名称").GetComponent<TMP_Text>().text = item["data"].ToString();
_obj.transform.Find("噪声").Find("Text-名称").GetComponent<TMP_Text>().color = int.Parse(item["data"].ToString()).Equals(1) ? Color.red : Color.green;
break;
case "PRESSURE":
_obj.transform.Find("压力").gameObject.SetActive(true);
_obj.transform.Find("压力").Find("Text-名称").GetComponent<TMP_Text>().text = item["data"].ToString();
_obj.transform.Find("压力").Find("Text-名称").GetComponent<TMP_Text>().color = int.Parse(item["data"].ToString()).Equals(1) ? Color.red : Color.green;
break;
case "TEMPERATURE":
_obj.transform.Find("温度").gameObject.SetActive(true);
_obj.transform.Find("温度").Find("Text-名称").GetComponent<TMP_Text>().text = item["data"].ToString();
_obj.transform.Find("温度").Find("Text-名称").GetComponent<TMP_Text>().color = int.Parse(item["data"].ToString()).Equals(1) ? Color.red : Color.green;
break;
case "HUMIDITY":
_obj.transform.Find("湿度").gameObject.SetActive(true);
_obj.transform.Find("湿度").Find("Text-名称").GetComponent<TMP_Text>().text = item["data"].ToString();
_obj.transform.Find("湿度").Find("Text-名称").GetComponent<TMP_Text>().color = int.Parse(item["data"].ToString()).Equals(1) ? Color.red : Color.green;
break;
case "SMOG":
_obj.transform.Find("烟雾").gameObject.SetActive(true);
_obj.transform.Find("烟雾").Find("Text-名称").GetComponent<TMP_Text>().text = item["data"].ToString();
_obj.transform.Find("烟雾").Find("Text-名称").GetComponent<TMP_Text>().color = int.Parse(item["data"].ToString()).Equals(1) ? Color.red : Color.green;
break;
case "PM2.5_E":
_obj.transform.Find("PM2.5").gameObject.SetActive(true);
_obj.transform.Find("PM2.5").Find("Text-名称").GetComponent<TMP_Text>().text = item["data"].ToString();
_obj.transform.Find("PM2.5").Find("Text-名称").GetComponent<TMP_Text>().color = int.Parse(item["data"].ToString()).Equals(1) ? Color.red : Color.green;
break;
case "PM10_E":
_obj.transform.Find("PM10").gameObject.SetActive(true);
_obj.transform.Find("PM10").Find("Text-名称").GetComponent<TMP_Text>().text = item["data"].ToString();
_obj.transform.Find("PM10").Find("Text-名称").GetComponent<TMP_Text>().color = int.Parse(item["data"].ToString()).Equals(1) ? Color.red : Color.green;
break;
case "PM1.0_E":
_obj.transform.Find("PM1.0").gameObject.SetActive(true);
_obj.transform.Find("PM1.0").Find("Text-名称").GetComponent<TMP_Text>().text = item["data"].ToString();
_obj.transform.Find("PM1.0").Find("Text-名称").GetComponent<TMP_Text>().color = int.Parse(item["data"].ToString()).Equals(1) ? Color.red : Color.green;
break;
}
}
}
}
} }
{"code":200,"message":"操作成功","data":[{"equipmentName":"检定单元1","lineId":"EB6F0348492C181DE055000000000001","data":"27.1℃","flag":0,"sensorType":"TEMPERATURE"},{"equipmentName":"检定单元2","lineId":"EB6F0348492C181DE055000000000001","data":"25.9℃","flag":0,"sensorType":"TEMPERATURE"},{"equipmentName":"检定单元3","lineId":"EB6F0348492C181DE055000000000001","data":"31.6℃","flag":0,"sensorType":"TEMPERATURE"},{"equipmentName":"检定单元4","lineId":"EB6F0348492C181DE055000000000001","data":"28.3℃","flag":0,"sensorType":"TEMPERATURE"},{"equipmentName":"检定单元5","lineId":"EB6F0348492C181DE055000000000001","data":"26.6℃","flag":0,"sensorType":"TEMPERATURE"},{"equipmentName":"检定单元6","lineId":"EB6F0348492C181DE055000000000001","data":"26.9℃","flag":0,"sensorType":"TEMPERATURE"},{"equipmentName":"检定单元7","lineId":"EB6F0348492C181DE055000000000001","data":"25.7℃","flag":0,"sensorType":"TEMPERATURE"},{"equipmentName":"检定单元8","lineId":"EB6F0348492C181DE055000000000001","data":"26.0℃","flag":0,"sensorType":"TEMPERATURE"},{"equipmentName":"检定单元9","lineId":"EB6F0348492C181DE055000000000001","data":"26.8℃","flag":0,"sensorType":"TEMPERATURE"},{"equipmentName":"检定单元10","lineId":"EB6F0348492C181DE055000000000001","data":"26.5℃","flag":0,"sensorType":"TEMPERATURE"},{"equipmentName":"拆垛机","lineId":"EB6F0348492C181DE055000000000001","data":"58.0DB","flag":0,"sensorType":"NOISE"},{"equipmentName":"空箱拆码垛机","lineId":"EB6F0348492C181DE055000000000001","data":"60.4DB","flag":0,"sensorType":"NOISE"},{"equipmentName":"码垛机","lineId":"EB6F0348492C181DE055000000000001","data":"64.0DB","flag":0,"sensorType":"NOISE"},{"equipmentName":"检定单元1","lineId":"EB6F0348492C181DE055000000000001","data":"4.1PPM","flag":0,"sensorType":"SMOG"},{"equipmentName":"检定单元2","lineId":"EB6F0348492C181DE055000000000001","data":"2.4PPM","flag":0,"sensorType":"SMOG"},{"equipmentName":"检定单元3","lineId":"EB6F0348492C181DE055000000000001","data":"1.4PPM","flag":0,"sensorType":"SMOG"},{"equipmentName":"检定单元4","lineId":"EB6F0348492C181DE055000000000001","data":"3.0PPM","flag":0,"sensorType":"SMOG"},{"equipmentName":"检定单元5","lineId":"EB6F0348492C181DE055000000000001","data":"2.5PPM","flag":0,"sensorType":"SMOG"},{"equipmentName":"检定单元6","lineId":"EB6F0348492C181DE055000000000001","data":"1.5PPM","flag":0,"sensorType":"SMOG"},{"equipmentName":"检定单元7","lineId":"EB6F0348492C181DE055000000000001","data":"2.1PPM","flag":0,"sensorType":"SMOG"},{"equipmentName":"检定单元8","lineId":"EB6F0348492C181DE055000000000001","data":"3.2PPM","flag":0,"sensorType":"SMOG"},{"equipmentName":"检定单元9","lineId":"EB6F0348492C181DE055000000000001","data":"1.7PPM","flag":0,"sensorType":"SMOG"},{"equipmentName":"检定单元10","lineId":"EB6F0348492C181DE055000000000001","data":"2.0PPM","flag":0,"sensorType":"SMOG"},{"equipmentName":"博世线","lineId":"EB6F0348492C181DE055000000000001","data":"63.0%RH","flag":0,"sensorType":"HUMIDITY"},{"equipmentName":"博世线","lineId":"EB6F0348492C181DE055000000000001","data":"22.0℃","flag":0,"sensorType":"TEMPERATURE"},{"equipmentName":"博世线","lineId":"EB6F0348492C181DE055000000000001","data":"1.0μg/m3","flag":0,"sensorType":"PM2.5"},{"equipmentName":"辊筒线","lineId":"EB6F0348492C181DE055000000000001","data":"63.0%RH","flag":0,"sensorType":"HUMIDITY"},{"equipmentName":"辊筒线","lineId":"EB6F0348492C181DE055000000000001","data":"21.0℃","flag":0,"sensorType":"TEMPERATURE"},{"equipmentName":"辊筒线","lineId":"EB6F0348492C181DE055000000000001","data":"2.0μg/m3","flag":0,"sensorType":"PM2.5"}]}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment