12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System.Collections.Generic;
- using Blue;
- using UnityEngine;
- using uPLibrary.Networking.M2Mqtt.Messages;
- public class MQTTTest : AbstractController
- {
- private List<string> topics = new List<string>()
- {
- "client/manage",
- "client/mqttx_d4c106a3",
- "client/mqttx_b4c02ddc",
- "client/mqttx_ab869d21"
- };
- private string[] topicSub = new string[4]
- {
- "client/manage",
- "client/mqttx_d4c106a3",
- "client/mqttx_b4c02ddc",
- "client/mqttx_ab869d21"
- };
- private IMQTTService mQTTService;
- private void Start()
- {
- mQTTService = this.GetService<IMQTTService>();
- }
- void Update()
- {
- if(Input.GetKeyDown(KeyCode.A))
- {
- mQTTService.SubscribeTopics(topicSub, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE , MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE , MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
- }
- else if(Input.GetKeyDown(KeyCode.S))
- {
- mQTTService.UnsubscribeTopics(topicSub);
- }
- if(Input.GetKeyDown(KeyCode.D))
- {
- mQTTService.Connect();
- }
- if(Input.GetKeyDown(KeyCode.Q))
- {
- this.SendCommand(new MQTTCommand(topics[0],"KeyCode.Q"));
- }
- else if(Input.GetKeyDown(KeyCode.W))
- {
- this.SendCommand(new MQTTCommand(topics[1],"KeyCode.W"));
- }
- else if(Input.GetKeyDown(KeyCode.E))
- {
- this.SendCommand(new MQTTCommand(topics[2],"KeyCode.E"));
- }
- else if(Input.GetKeyDown(KeyCode.R))
- {
- this.SendCommand(new MQTTCommand(topics[3],"KeyCode.R"));
- }
- }
- }
|