public async Task MtqqMessageTest() { MessageHandler messageHandler = new MessageHandler(); var client = await MQTT.StartClient(messageHandler); /** * PublicChatMessage|{"author":"sokcuri","message":"hello world"} */ await MQTT.Publish(client, "chat", "PublicChatMessage", "{'author': 'Sokcuri', 'message': 'hello world'}"); await MQTT.Publish(client, "chat", "WhisperMessage", "{'sender': 'foo', 'receiver': 'bar', 'message': 'message'}"); await MQTT.Publish(client, "notice", "NoticeMessage", "{'notice': 'notice message', 'important': 2, 'sticky': true}"); if (!WaitHandle.WaitAll(new WaitHandle[] { noticeEvent, publicChatEvent, whisperEvent }, TimeSpan.FromSeconds(5))) { Assert.Fail("Timeout"); } Assert.AreEqual("Sokcuri", publicChatMessage.author); Assert.AreEqual("hello world", publicChatMessage.message); Assert.AreEqual("foo", whisperMessage.sender); Assert.AreEqual("bar", whisperMessage.receiver); Assert.AreEqual("message", whisperMessage.message); Assert.AreEqual("notice message", noticeMessage.notice); Assert.AreEqual(2, noticeMessage.important); Assert.AreEqual(true, noticeMessage.sticky); }
static void Main(string[] args) { //Intailize the Broker Settings BrokerModel _Broker = new BrokerModel(); _Broker.Url = "tailor.cloudmqtt.com"; _Broker.Username = "******"; _Broker.Password = "******"; _Broker.Port = 11300; _Broker.SSLPort = 21300; _Broker.WebSocketPort = 31300; //Connect to Server MQTT mQTT = new MQTT(); mQTT.Initailize(_Broker); mQTT.Connect(); while (true) { if (mQTT.Connected) { //publish string mQTT.Publish("StringValue", "5"); //publish json Object Sensor Sensor = new Sensor(); var result = Sensor.CreateSensor(); string Jsonresult = JsonConvert.SerializeObject(result); mQTT.Publish("SensorObject", Jsonresult); //publish json List of Objectss var resultList = Sensor.CreateSensorList(); string JsonresultList = JsonConvert.SerializeObject(resultList); mQTT.Publish("SensorList", JsonresultList); } Thread.Sleep(10000); } }
public Payload MQTTPost([FromForm] Payload FormData) { DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Payload)); MemoryStream msObj = new MemoryStream(); js.WriteObject(msObj, FormData); msObj.Position = 0; StreamReader sr = new StreamReader(msObj); string json = sr.ReadToEnd(); MQTT.Publish(json); //MQTT Publish return(FormData); //Return Input Data }
public IActionResult OnPostSubmit() { string Reply = ""; bool Veri = SQL.Verification(DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'"), OTP); if (Veri == true) { MQTT.Publish(); Reply = "Success"; } else { Reply = "Incorrect OTP"; } return(RedirectToPage("Success", "Message", new { msg = Reply })); }
private void Publish(string topic, string message) { MQTT.Publish(topic, message); }