diff --git a/projects/IoTCenter/Controllers/AppController.cs b/projects/IoTCenter/Controllers/AppController.cs index dd5a8a7c..9ea242c9 100644 --- a/projects/IoTCenter/Controllers/AppController.cs +++ b/projects/IoTCenter/Controllers/AppController.cs @@ -256,6 +256,30 @@ namespace IoTCenter.Controllers return Json(ApiResponse.AsyncSuccess()); } + public IActionResult NodeSwitchOn(string connectionId, string node) + { + this.Power(connectionId, new string[] { node }, "On", o => o.Name.Contains("开关")); + return Json(ApiResponse.AsyncSuccess()); + } + + public IActionResult NodeSwitchOff(string connectionId, string node) + { + this.Power(connectionId, new string[] { node }, "Off", o => o.Name.Contains("开关")); + return Json(ApiResponse.AsyncSuccess()); + } + + public IActionResult NodeSocketOn(string connectionId, string node) + { + this.Power(connectionId, new string[] { node }, "On", o => o.Name.Contains("插座")); + return Json(ApiResponse.AsyncSuccess()); + } + + public IActionResult NodeSocketOff(string connectionId, string node) + { + this.Power(connectionId, new string[] { node }, "Off", o => o.Name.Contains("插座")); + return Json(ApiResponse.AsyncSuccess()); + } + private void Power(string connectionId, string[] nodes, string command, Func func) { var devices = this._deviceRepo.ReadOnlyTable() diff --git a/projects/IoTCenter/wwwroot/home.default.html b/projects/IoTCenter/wwwroot/home.default.html index 158255bb..a0564b40 100644 --- a/projects/IoTCenter/wwwroot/home.default.html +++ b/projects/IoTCenter/wwwroot/home.default.html @@ -114,43 +114,6 @@ }); } } - function onMessage() { - connection.on('Connected', function (id) { - connectionId = id; - }); - } - - + + + + +