// Update is called once per frame void Update() { while (client.Count() > 0) { string s = client.Receive(); msgq.Enqueue(s); Debug.Log("received :" + s); lastMessage = s; //GUILayout.Label(s); } if (Input.GetMouseButtonDown(0) == true) { client.Publish(topic, System.Text.Encoding.ASCII.GetBytes("nice click!")); } }
public void SendString(string data) { if (send) { Debug.Log("message sent to MQTT: " + data); client.Publish(topic, System.Text.Encoding.ASCII.GetBytes(data)); } }
public void Connect() { client = new MqttClient4Unity(brokerHostname, brokerPort, false, null); string clientId = Guid.NewGuid().ToString(); //client.WillMessage = System.Text.Encoding.ASCII.GetBytes("disconnected"); //client.WillTopic = "clients/" + clientId; //client.WillFlag = false; client.Connect(clientId, userName, password, false, MqttMsgConnect.QOS_LEVEL_AT_MOST_ONCE, true, "clients/" + clientId, "disconnected", true, 60); Debug.Log("MQTT Connecting"); client.Publish("test/clients/" + clientId, System.Text.Encoding.ASCII.GetBytes("connected")); }
// Use this for initialization void Awake() { if (brokerHostname != null && userName != null && password != null) { Connect(); client.Subscribe(topic); } client.Publish(topic, System.Text.Encoding.ASCII.GetBytes("0/OFF/0")); }
private void OnSplineUpdate(ColorSpline spline) { client.Publish(SPLINE_TOPIC, Encoding.ASCII.GetBytes(spline.ToJSON())); }
// Exit from application public void exitAppOnClick() { client.Publish(topic, System.Text.Encoding.ASCII.GetBytes("0")); Application.Quit(); }
/// <summary> /// Publish payload to the broker /// </summary> /// <param name="_topic">The topic to send</param> /// <param name="msg">Payload</param> public void Publish(string _topic, string msg) { client.Publish(_topic, Encoding.UTF8.GetBytes(msg), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); }