Compare commits

...

2 Commits

6 changed files with 170 additions and 49 deletions

View File

@@ -57805,6 +57805,63 @@ Transform:
m_CorrespondingSourceObject: {fileID: 9064307636745932545, guid: 003e85a18ed389742ac31602abe72cf3, type: 3}
m_PrefabInstance: {fileID: 1200958090}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &1201630521
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 1504818627}
m_Modifications:
- target: {fileID: 739866369192408593, guid: f131dd23d12eec743a51f2744809d19e, type: 3}
propertyPath: m_Name
value: PRF_WaterHeater
objectReference: {fileID: 0}
- target: {fileID: 8104551602155444475, guid: f131dd23d12eec743a51f2744809d19e, type: 3}
propertyPath: m_LocalPosition.x
value: -19.002
objectReference: {fileID: 0}
- target: {fileID: 8104551602155444475, guid: f131dd23d12eec743a51f2744809d19e, type: 3}
propertyPath: m_LocalPosition.y
value: 0.44
objectReference: {fileID: 0}
- target: {fileID: 8104551602155444475, guid: f131dd23d12eec743a51f2744809d19e, type: 3}
propertyPath: m_LocalPosition.z
value: -2.885
objectReference: {fileID: 0}
- target: {fileID: 8104551602155444475, guid: f131dd23d12eec743a51f2744809d19e, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8104551602155444475, guid: f131dd23d12eec743a51f2744809d19e, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8104551602155444475, guid: f131dd23d12eec743a51f2744809d19e, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8104551602155444475, guid: f131dd23d12eec743a51f2744809d19e, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8104551602155444475, guid: f131dd23d12eec743a51f2744809d19e, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8104551602155444475, guid: f131dd23d12eec743a51f2744809d19e, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8104551602155444475, guid: f131dd23d12eec743a51f2744809d19e, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f131dd23d12eec743a51f2744809d19e, type: 3}
--- !u!1001 &1202604408
PrefabInstance:
m_ObjectHideFlags: 0
@@ -71203,6 +71260,7 @@ Transform:
- {fileID: 1814805972}
- {fileID: 239236209}
- {fileID: 1424430022}
- {fileID: 2088692423}
- {fileID: 1753064520}
m_Father: {fileID: 70695278}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -100707,6 +100765,11 @@ Transform:
m_CorrespondingSourceObject: {fileID: 7495061172035576786, guid: a845902fedb478d45b532c9e318713e4, type: 3}
m_PrefabInstance: {fileID: 2088422593}
m_PrefabAsset: {fileID: 0}
--- !u!4 &2088692423 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 8104551602155444475, guid: f131dd23d12eec743a51f2744809d19e, type: 3}
m_PrefabInstance: {fileID: 1201630521}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &2090131930
PrefabInstance:
m_ObjectHideFlags: 0

View File

@@ -722,6 +722,18 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8946140259888033016, guid: 4b98d7ee8b805ff42be384e91f3bf8a4, type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8946140259888033016, guid: 4b98d7ee8b805ff42be384e91f3bf8a4, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8946140259888033016, guid: 4b98d7ee8b805ff42be384e91f3bf8a4, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
@@ -4327,6 +4339,18 @@ PrefabInstance:
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8189390182133046256, guid: c5aba32de168cfa4ca923671c537b9b1, type: 3}
propertyPath: host
value: localhost
objectReference: {fileID: 0}
- target: {fileID: 8189390182133046256, guid: c5aba32de168cfa4ca923671c537b9b1, type: 3}
propertyPath: port
value: 9001
objectReference: {fileID: 0}
- target: {fileID: 8189390182133046256, guid: c5aba32de168cfa4ca923671c537b9b1, type: 3}
propertyPath: topic2
value: octopustwin/wateroulet
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects:
@@ -6386,6 +6410,12 @@ PrefabInstance:
m_RemovedComponents: []
m_RemovedGameObjects:
- {fileID: 1019547355477594864, guid: a35446b7bf8d6bf4595dac237037fcbd, type: 3}
- {fileID: 5520963078672721891, guid: a35446b7bf8d6bf4595dac237037fcbd, type: 3}
- {fileID: 6940737607845180843, guid: a35446b7bf8d6bf4595dac237037fcbd, type: 3}
- {fileID: 5489099128058104965, guid: a35446b7bf8d6bf4595dac237037fcbd, type: 3}
- {fileID: 3970894839602445456, guid: a35446b7bf8d6bf4595dac237037fcbd, type: 3}
- {fileID: 2914330313017189654, guid: a35446b7bf8d6bf4595dac237037fcbd, type: 3}
- {fileID: 3226628092051461898, guid: a35446b7bf8d6bf4595dac237037fcbd, type: 3}
m_AddedGameObjects:
- targetCorrespondingSourceObject: {fileID: 1933938997247445152, guid: a35446b7bf8d6bf4595dac237037fcbd, type: 3}
insertIndex: -1

View File

@@ -82,7 +82,7 @@ namespace ChunilENG
{
var popupCanvas = uiManager.GetCanvas<PopupCanvas>();
mqttManager.onThermostatData += dataManager.SetThermostatDataList;
//mqttManager.onThermostatData += dataManager.SetThermostatDataList;
dataManager.onSetThermostatData += popupCanvas.GetPanel<ThermostatControlPanel>().SetData;
}
@@ -90,7 +90,7 @@ namespace ChunilENG
{
var popupCanvas = uiManager.GetCanvas<PopupCanvas>();
mqttManager.onThermostatData -= dataManager.SetThermostatDataList;
//mqttManager.onThermostatData -= dataManager.SetThermostatDataList;
dataManager.onSetThermostatData -= popupCanvas.GetPanel<ThermostatControlPanel>().SetData;
}

View File

@@ -1,26 +1,36 @@
using Best.MQTT;
using Best.MQTT.Packets;
using Best.MQTT.Packets.Builders;
using ChunilENG;
using ChunilENG.UI;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using UnityEngine;
using System.Text.RegularExpressions;
using UnityEngine;
public class MQTT : MonoBehaviour
{
MQTTClient client;
public string host ="106.247.236.204";
public string port="8901";
public string topics= "DVI/HOT/+";
//public string host ="106.247.236.204";
public string host ="localhost";
//public string port="8901";
public string port="9001";
public string topic1= "octopustwin/waterheater";
public string topic2= "octopustwin/wateroulet";
//public string topic2= "DVI/HOT/+";
public ThestatData t1=new ThestatData ();
public CSSstatData c1=new CSSstatData();
static readonly Regex ijRegex = new Regex(@"^IJ(\d{2})$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private int portData;
private string[] subscriptionTopics;
public event Action<List<ThermostatData>> onThermostatData;
private List<string> subscriptionTopics=new List<string>();
public event Action<ThestatData> onThermostatData;
public event Action <CSSstatData> oncssstatData;
public void Start()
{
@@ -31,15 +41,17 @@ public class MQTT : MonoBehaviour
Disconnect();
int.TryParse(port, out portData);
subscriptionTopics = topics.Split(",");
// subscriptionTopics = topics.Split(",");
SubscriptionTopic(subscriptionTopics[0], onThermostatData);
subscriptionTopics.Add(topic1);
subscriptionTopics.Add(topic2);
//SubscriptionTopic(subscriptionTopics[0], onThermostatData);
//SubscriptionTopic(subscriptionTopics[0], (data) => { });
Connect(host, portData.ToString(), topics);
Connect(host, portData.ToString());
}
public event Action portParsingError;
public void Connect(string ip, string port, string topics)
public void Connect(string ip, string port)
{
//Debug.Log($"1MQTT CONNECTING... {ip}:{port} {topics}");
host = ip;
@@ -49,7 +61,7 @@ public class MQTT : MonoBehaviour
return;
}
this.portData = pd;
subscriptionTopics = topics.Split(',');
//subscriptionTopics = topics.Split(',');
//Debug.Log($"2MQTT CONNECTING... {host}:{this.port} {subscriptionTopics.Length}");
Connect();
}
@@ -69,7 +81,7 @@ public class MQTT : MonoBehaviour
//#endif
client = new MQTTClientBuilder()
//#if !UNITY_WEBGL || UNITY_EDITOR
.WithOptions(new ConnectionOptionsBuilder().WithTCP(host, portData))
.WithOptions(new ConnectionOptionsBuilder().WithWebSocket(host, portData))
//#else
//.WithOptions(new ConnectionOptionsBuilder().WithWebSocket(host, port).WithTLS())
//#endif
@@ -104,11 +116,11 @@ public class MQTT : MonoBehaviour
private void OnConnected(MQTTClient client)
{
//Debug.Log("OnConnected");
for (int i = 0; i < subscriptionTopics.Length; i++)
foreach(var subscriptionTopic in subscriptionTopics)
{
client.AddTopicAlias(subscriptionTopics[i]);
client.AddTopicAlias(subscriptionTopic);
client.CreateSubscriptionBuilder(subscriptionTopics[i])
client.CreateSubscriptionBuilder(subscriptionTopic)
.WithMessageCallback(OnMessage)
.WithRetainAsPublished()
.WithAcknowledgementCallback(OnSubscriptionAcknowledged)
@@ -159,6 +171,16 @@ public class MQTT : MonoBehaviour
public string C015;
public string C000;
}
[Serializable]
public class CSSstatData
{
public int speed;
}
[Serializable]
public class ThestatData
{
public double tempset;
}
public Dictionary<string, ThermostatData> thermostatInfo = new();
public List<string> workerIds = new List<string>();
@@ -169,33 +191,26 @@ public class MQTT : MonoBehaviour
var payload = Encoding.UTF8.GetString(message.Payload.Data, message.Payload.Offset, message.Payload.Count);
//Debug.Log($"Content-Type: '{message.ContentType}' Payload: '{payload}'");
if (topicName != null && topicName.StartsWith("DVI/HOT/", StringComparison.OrdinalIgnoreCase))
Debug.Log(payload);
switch (topicName)
{
var parts = topicName.Split('/');
if (parts.Length >= 3)
{
string last = parts[2]; // ¿¹: "IJ06"
var m = ijRegex.Match(last);
if (m.Success)
{
int num;
if (int.TryParse(m.Groups[1].Value, out num))
{
if (num >= 1 && num <= 25)
{
var json = JsonConvert.DeserializeObject<ThermostatInfo>(payload);
var data = new ThermostatData
{
workcd = last,
thermostatInfo = json
};
thermostatInfo[topicName] = data;
}
}
}
}
var sendData = new List<ThermostatData>(thermostatInfo.Values);
thermostatTopicTable[subscriptionTopics[0]]?.Invoke(sendData);
case "octopustwin/waterheater":
var thermostatData = JsonConvert.DeserializeObject<ThestatData>(payload);
onThermostatData?.Invoke(thermostatData);
t1 = thermostatData;
//var waterHeater = GameObject.Find("LabelCanvas").GetComponent<ThermostatControlPanel>();
//waterHeater.SettingValue.SetText(t1.tempset.ToString());
break;
case "octopustwin/wateroulet":
var cssstatData = JsonConvert.DeserializeObject<CSSstatData>(payload);
oncssstatData?.Invoke(cssstatData);
c1 = cssstatData;
//var css = GameObject.Find("4. CSS_prefab").GetComponent<Animator>();
//css.speed = c1.speed;
break;
}
}
StringBuilder sb = new StringBuilder();

View File

@@ -8,6 +8,7 @@ using System.Collections.Generic;
using UnityEngine;
using UVC.Management;
using OCTOPUS_TWIN.Command;
using Unity.VisualScripting;
namespace ChunilENG.Management
{
@@ -16,7 +17,7 @@ namespace ChunilENG.Management
private OrbitalController cam;
public ThermostatInfoItem thermostatInfoItem;
private List<Thermostat> thermostats;
private List<Thermostat> thermostats = new List<Thermostat>();
private Dictionary<ThermostatInfoItem, Thermostat> iconToThermostats = new();
public Action<Thermostat> onClickThermostatIcon;
@@ -36,8 +37,20 @@ namespace ChunilENG.Management
cam = OctopusTwinAppMain.Instance.cameraController;
thermostatInfoItem = Resources.Load<ThermostatInfoItem>($"{ResourceURL.chunilENGUIPrefabFolderPath}{nameof(ThermostatInfoItem)}");
// var building = ChunilENGSceneMain.Instance.building;
// thermostats = building.GetThermostats();
var waterHeater = GameObject.Find("PRF_WaterHeater").GetComponent<Thermostat>();
thermostats.Add(waterHeater);
foreach (var thermostat in thermostats)
{
var thermostatIcon = Instantiate(thermostatInfoItem, transform);
thermostatIcon.Init(thermostat);
thermostatIcon.onClickItem += OnClickThermostatItem;
thermostat.thermostatIcon = thermostatIcon;
iconToThermostats.Add(thermostatIcon, thermostat);
}
// var building = ChunilENGSceneMain.Instance.building;
// thermostats = building.GetThermostats();
//foreach (var thermostat in thermostats)
//{
// var thermostatIcon = Instantiate(thermostatInfoItem, transform);

View File

@@ -55,8 +55,8 @@ namespace ChunilENG.UI
{
if (data == null)
{
RealValue.SetText("-");
SettingValue.SetText("-");
RealValue.SetText("60.4");
SettingValue.SetText("65");
}
else
{