mqttdatabase

This commit is contained in:
2025-05-26 11:02:10 +09:00
parent a3126007e6
commit 4a38967218
7 changed files with 71 additions and 13 deletions

View File

@@ -15,11 +15,6 @@ namespace Octopus.Simulator
[Serializable]
public class BaseSimulationMessage
{
public string type;
public string _event;
public string component_type;
public string component_id;
//public List<string> data;
public string timestamp;
}
}

View File

@@ -22,7 +22,7 @@ namespace Octopus.Simulator
[Serializable]
public class SimulatorPostClass
{
public int status=null;
public int status;
public string code;
public string message;
public SimulationData data = new SimulationData();

View File

@@ -0,0 +1,28 @@
using UnityEngine;
using System.Collections.Generic;
public class MQTTDataBase : MonoBehaviour
{
public static MQTTDataBase Instance;
public Dictionary<string,List<string>> mqttDataBase;
private void Awake()
{
mqttDataBase = new Dictionary<string, List<string>>();
Instance = this;
}
public void AddDict(string key, string value)
{
if (mqttDataBase.ContainsKey(key))
{
mqttDataBase[key].Add(value);
}
else
{
var values = new List<string>();
values.Add(value);
mqttDataBase.Add(key, values);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: edf9e532e5ff77f47bc99037340faf31

View File

@@ -115,8 +115,12 @@ namespace Octopus.Simulator.Networks
private void OnMessage(MQTTClient client, SubscriptionTopic topic, string topicName, ApplicationMessage message)
{
var payload = Encoding.UTF8.GetString(message.Payload.Data, message.Payload.Offset, message.Payload.Count);
Debug.Log(payload);
//basemessage = JsonConvert.DeserializeObject<BaseSimulationMessage>(payload);
//Debug.Log(payload);
if (payload.Contains("_event"))
{
basemessage = JsonConvert.DeserializeObject<BaseSimulationMessage>(payload);
MQTTDataBase.Instance.AddDict(basemessage._event, payload);
}
//onMessageReceived?.Invoke(topicName, payload);
}

View File

@@ -12,6 +12,7 @@ GameObject:
- component: {fileID: 1756997497928447498}
- component: {fileID: 8164125700257988699}
- component: {fileID: 6191105916327120908}
- component: {fileID: 8343195631698366838}
m_Layer: 0
m_Name: NetworkManager
m_TagString: Untagged
@@ -47,11 +48,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
basemessage:
type:
_event:
component_type:
component_id:
timestamp:
MQTTpath: /MQTTConfig.json
_topic:
--- !u!114 &8164125700257988699
@@ -117,6 +114,18 @@ MonoBehaviour:
references:
version: 2
RefIds: []
--- !u!114 &8343195631698366838
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1392524223077930677}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: edf9e532e5ff77f47bc99037340faf31, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &2069922514250663687
GameObject:
m_ObjectHideFlags: 0