public async Task <JsonResult> PostAsync([FromBody] UserRequest operation) { if (operation.dev == "Mote") { await _mqttService.PublishAsync("/iot/zolertia/cmd", operation.opr); if (operation.opr == "off") { StorageSingleton.Instance.DeviceData.IsEnabled = false; } else { StorageSingleton.Instance.DeviceData.IsEnabled = true; } } else { if (operation.opr == "on") { await _mqttService.PublishAsync("/iot/sensor/cmd", "ACTIVATETEMPSEN"); } else { await _mqttService.PublishAsync("/iot/sensor/cmd", "DEACTIVATETEMPSEN"); } } return(new JsonResult(operation)); }
public async Task <IActionResult> Post([FromBody] object data) { if (data != null) { _messageEngine.Process(data.ToString(), new RestChannelContext(HttpContext)); await _mqttSvc.PublishAsync("RawMessage", data.ToString()); } return(Ok("ok")); }
public async Task <ActionResult> OnPostPostOperationAsync([FromBody] UserRequest operation) { if (operation.dev == "Mote") { await _mqttService.PublishAsync("/iot/zolertia/cmd", operation.opr); } else { if (operation.opr == "on") { await _mqttService.PublishAsync("/iot/sensor/cmd", "ACTIVATETEMPSEN"); } else { await _mqttService.PublishAsync("/iot/sensor/cmd", "DEACTIVATETEMPSEN"); } } return(new JsonResult("Ok")); }
public async Task MqttService() { await _mqttService.StartAsync(); int count = 1; do { await _mqttService.PublishAsync("hello", $"test message {count++}"); }while (Console.ReadKey().KeyChar != 'q'); //while (Console.KeyAvailable); }