how to save data in temp and pass to view
var messageBuilder = new MqttClientOptionsBuilder() .WithClientId(clientId) .WithCredentials(mqttUser, mqttPassword) .WithTcpServer(mqttURI, mqttPort) .WithCleanSession(); var options = mqttSecure ? messageBuilder .WithTls() .Build() : messageBuilder .Build(); var managedOptions = new ManagedMqttClientOptionsBuilder() .WithAutoReconnectDelay(TimeSpan.FromSeconds(5)) .WithClientOptions(options) .Build(); IManagedMqttClient client = new MqttFactory().CreateManagedMqttClient(); client.StartAsync(managedOptions).GetAwaiter().GetResult(); client.SubscribeAsync("Lestle/topic"); string payload = ""; client.UseApplicationMessageReceivedHandler(e => { try { string topic = e.ApplicationMessage.Topic; if (string.IsNullOrWhiteSpace(topic) == false) { payload = Encoding.UTF8.GetString(e.ApplicationMessage.Payload); } } catch (Exception ex) { Console.WriteLine(ex.Message, ex); } if (payload != "") { var data = (JObject)JsonConvert.DeserializeObject(payload); var towerlights = data["towerlight"].Children(); foreach (var towerlight in towerlights) { ViewBag.Line1 = towerlight["Line1"].Value<string>().ToString(); ViewBag.Line2 = towerlight["Line2"].Value<string>().ToString(); ViewBag.Line3 = towerlight["Line3"].Value<string>().ToString(); ViewBag.Line4 = towerlight["Line4"].Value<string>().ToString(); } RedirectToAction("Index"); } });
Asked
Active
Viewed 117 times
0

hardillb
- 54,545
- 11
- 67
- 105

Yeong Lestle
- 17
- 6