diff --git a/projects/IoT.Shared/Controllers/AjaxBaseController.cs b/projects/IoT.Shared/Controllers/AjaxBaseController.cs index 38b5b6a7..a0afc7c1 100644 --- a/projects/IoT.Shared/Controllers/AjaxBaseController.cs +++ b/projects/IoT.Shared/Controllers/AjaxBaseController.cs @@ -79,7 +79,9 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls var repo = scope.ServiceProvider.GetRequiredService>(); var list = repo.ReadOnlyTable() .Where(o => o.IoTGatewayId == parentId) - .Select(o => new { o.Id, o.Name }) + .Select(o => new { o.Id,o.Name, o.DisplayName }) + .ToList() + .Select(o=>new { o.Id,Name=o.DisplayName??o.Name}) .ToList(); return new JsonResult(new SelectList(list, "Id", "Name", selected)); } diff --git a/projects/IoTNode/DeviceServices/FBee/FBeeService.cs b/projects/IoTNode/DeviceServices/FBee/FBeeService.cs index 57935b8e..d825bf60 100644 --- a/projects/IoTNode/DeviceServices/FBee/FBeeService.cs +++ b/projects/IoTNode/DeviceServices/FBee/FBeeService.cs @@ -569,10 +569,11 @@ namespace IoTNode.DeviceServices.FBee } else if (clusterId == ClusterId.socket) { - if (props.Keys.Contains(0x0000)) + byte[] item; + if (props.TryGetValue(0x0000, out item))//总量 { var tempBytes = new List(); - tempBytes.AddRange(props[0x00]); + tempBytes.AddRange(item); tempBytes.Add(0x00); tempBytes.Add(0x00); if (tempBytes.Count == 8) @@ -586,6 +587,20 @@ namespace IoTNode.DeviceServices.FBee this.UpdateIoTData(device.Id, DataKeys.Electricity, value); } } + else + { + this._logger.LogError($"data length must be 8 but now is {tempBytes.Count}"); + } + } + else if (props.TryGetValue(0x0301, out item))//总量乘数 + { + var value = BitConverter.ToUInt16(item); + this.UpdateIoTData(device.Id, DataKeys.ElectricityMultiplier, value); + } + else if (props.TryGetValue(0x0302, out item))//总量除数 + { + var value = BitConverter.ToUInt16(item); + this.UpdateIoTData(device.Id, DataKeys.ElectricityDivisor, value); } } else if (clusterId == ClusterId.doorlock) @@ -726,7 +741,7 @@ namespace IoTNode.DeviceServices.FBee } } else if (clusterId == ClusterId.ElectricityMeasurement) - { + {//505-605 var clusterIdValueX = clusterIdValue.ToString("x2"); var deviceName = device.Name; var PropKey = props.First().Key.ToString("x2"); @@ -734,39 +749,8 @@ namespace IoTNode.DeviceServices.FBee var FbeeDeviceId = fbeeDeviceId.ToString("x2"); Console.WriteLine(deviceName); byte[] item; - if (props.TryGetValue(0x0000, out item))//总量 - { - var tempBytes = new List(); - tempBytes.AddRange(item); - tempBytes.Add(0x00); - tempBytes.Add(0x00); - if (tempBytes.Count == 8) - { - var multiplier = this.GetIoTDataValue(device.Id, DataKeys.ElectricityMultiplier); - var divisor = this.GetIoTDataValue(device.Id, DataKeys.ElectricityDivisor); - if (!string.IsNullOrEmpty(multiplier) && !string.IsNullOrEmpty(divisor)) - { - var electricity = BitConverter.ToInt64(tempBytes.ToArray()); - var value = electricity * Convert.ToInt16(multiplier) / Convert.ToSingle(divisor); - this.UpdateIoTData(device.Id, DataKeys.Electricity, value); - } - } - else - { - this._logger.LogError($"data length must be 8 but now is {tempBytes.Count}"); - } - } - else if (props.TryGetValue(0x0301, out item))//总量乘数 - { - var value = BitConverter.ToUInt16(item); - this.UpdateIoTData(device.Id, DataKeys.ElectricityMultiplier, value); - } - else if (props.TryGetValue(0x0302, out item))//总量除数 - { - var value = BitConverter.ToUInt16(item); - this.UpdateIoTData(device.Id, DataKeys.ElectricityDivisor, value); - } - else if (props.TryGetValue(0x0505, out item))//电压 + + if (props.TryGetValue(0x0505, out item))//电压 { var value = BitConverter.ToUInt16(item); } @@ -835,62 +819,6 @@ namespace IoTNode.DeviceServices.FBee var FbeeDeviceId = fbeeDeviceId.ToString("x2"); Console.WriteLine(deviceName); } - if (fbeeDeviceId == 0x0163) - { - //if (props.ContainsKey(0x400a)) - //{ - // var irdata = props[0x400a]; - // if (irdata.Length == 10) - // { - // //var irVersion = BitConverter.ToString((props[0x400a].Skip(3).Take(6).ToArray())).Replace("-", "").ToLower(); - // //if (!string.IsNullOrEmpty(irVersion)) - // //{ - // // this.UpdateIoTData(device.Id, DataKeys.IrVersion, irVersion); - // //} - // } - // else - // { - // var irtype = BitConverter.ToInt16(irdata.Skip(9).Take(2).ToArray()); - // if (irtype == 0x0082) - // { - // var irDeviceType = irdata.Skip(11).First(); - // if (irDeviceType == 0x01) - // { - // var keyCode = BitConverter.ToInt16(irdata.Skip(12).Take(2).ToArray()); - // this.UpdateIoTData(device.Id, DataKeys.KeyPress, keyCode); - // } - // } - // } - //} - //else - //{ - //} - } - else if (fbeeDeviceId == 0x0051) - { - foreach (var item in props) - { - if (item.Key == 0x0400) - { - Console.WriteLine(item.Value.ToInt()); - } - else if (item.Key == 0x0400)//0x050b - { - var multiplier = this.GetIoTDataValue(device.Id, DataKeys.PowerMultiplier); - var divisor = this.GetIoTDataValue(device.Id, DataKeys.PowerDivisor); - if (!string.IsNullOrEmpty(multiplier) && !string.IsNullOrEmpty(divisor)) - { - var power = BitConverter.ToUInt16(item.Value.ToArray()); - var value = power * Convert.ToInt16(multiplier) / Convert.ToSingle(divisor); - this.UpdateIoTData(device.Id, DataKeys.Power, value); - } - } - } - //if (clusterId == ClusterId.SummationDivisor) - //{ - // this.X8D0702(sn, device.Number); - //} - } } } @@ -1055,12 +983,9 @@ namespace IoTNode.DeviceServices.FBee if (device != null) { var switchState = ms.ReadInt(); - if(device.Name.Contains("电机")) - { - - } if (endpoint == 0x01) { + //插座 this.UpdateIoTData(device.Id, DataKeys.PowerState, switchState); } else if(endpoint==0x0b) @@ -1075,7 +1000,15 @@ namespace IoTNode.DeviceServices.FBee } else if (endpoint == 0x10) { - this.UpdateIoTData(device.Id, DataKeys.L1State, switchState); + //开关 + if (device.Name.Contains("二路") || device.Name.Contains("三路")) + { + this.UpdateIoTData(device.Id, DataKeys.L1State, switchState); + } + else + { + this.UpdateIoTData(device.Id, DataKeys.PowerState, switchState); + } } else if (endpoint == 0x11) { diff --git a/projects/Platform/wwwroot/components/devices/door.html b/projects/Platform/wwwroot/components/devices/door.html new file mode 100644 index 00000000..2a754d2f --- /dev/null +++ b/projects/Platform/wwwroot/components/devices/door.html @@ -0,0 +1,64 @@ + + diff --git a/projects/Platform/wwwroot/components/devices/gateway.html b/projects/Platform/wwwroot/components/devices/gateway.html new file mode 100644 index 00000000..bd6c43ae --- /dev/null +++ b/projects/Platform/wwwroot/components/devices/gateway.html @@ -0,0 +1,43 @@ + + \ No newline at end of file diff --git a/projects/Platform/wwwroot/components/devices/humiture.html b/projects/Platform/wwwroot/components/devices/humiture.html new file mode 100644 index 00000000..d0b22370 --- /dev/null +++ b/projects/Platform/wwwroot/components/devices/humiture.html @@ -0,0 +1,31 @@ + + \ No newline at end of file diff --git a/projects/Platform/wwwroot/components/devices/switch1.html b/projects/Platform/wwwroot/components/devices/switch1.html new file mode 100644 index 00000000..f6bec527 --- /dev/null +++ b/projects/Platform/wwwroot/components/devices/switch1.html @@ -0,0 +1,47 @@ + + \ No newline at end of file diff --git a/projects/Platform/wwwroot/js/app.js b/projects/Platform/wwwroot/js/app.js index 07d13130..c6bebbcd 100644 --- a/projects/Platform/wwwroot/js/app.js +++ b/projects/Platform/wwwroot/js/app.js @@ -60,6 +60,13 @@ function addVueComponents(config) { } } //获取设备数据 +function getIoTData(device,name) { + var data = Enumerable.from(device.data).where(o => o.name === name).firstOrDefault(); + if (data) { + return data['value'] + ' ' + data['unit'] + ' ' + data['description']; + } + return null; +} function getIoTDataValue(device, name) { var data = Enumerable.from(device.data).where(o => o.name === name).firstOrDefault(); if (data) { diff --git a/projects/Platform/wwwroot/js/main.js b/projects/Platform/wwwroot/js/main.js index 992bf9f5..0980fb2b 100644 --- a/projects/Platform/wwwroot/js/main.js +++ b/projects/Platform/wwwroot/js/main.js @@ -19,11 +19,15 @@ addVueComponents({ addVueComponents({ prefix: "/components/devices/", list: [ + 'gateway', + 'humiture', 'light', 'infrared', 'smoke', + 'switch1', 'socket', - 'curtain' + 'curtain', + 'door', ] });