diff --git a/projects/IoT.Shared/Application/Domain/Entities/Device.cs b/projects/IoT.Shared/Application/Domain/Entities/Device.cs index 167f34f3..528dd0ca 100644 --- a/projects/IoT.Shared/Application/Domain/Entities/Device.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/Device.cs @@ -94,7 +94,9 @@ namespace Application.Domain.Entities } else { + oldData.Name = data.Name; oldData.Value = data.Value; + oldData.Unit = data.Unit; oldData.Description = data.Description; } return oldData; diff --git a/projects/IoTCenter/Controllers/AppController.cs b/projects/IoTCenter/Controllers/AppController.cs index 84b91f40..425c5e65 100644 --- a/projects/IoTCenter/Controllers/AppController.cs +++ b/projects/IoTCenter/Controllers/AppController.cs @@ -185,25 +185,32 @@ namespace IoTCenter.Controllers var dbName = "iot"; var measurementName = "data"; var list = new List(); + var labels = new List(); using (var client = new InfluxClient(new Uri(url), usr, pwd)) { var fileds = String.Join(',', device.Data.Where(o => o.Type == DeviceDataType.Int || o.Type == DeviceDataType.Float).Select(o => o.Key)); - var query = $"select {fileds} from {measurementName} where time>now()-{time} and DeviceNumber = '{device.Number}' limit 10000"; - var result = client.ReadAsync(dbName, query).Result; - var rows = result.Results.FirstOrDefault()? - .Series.FirstOrDefault()? - .Rows; - foreach (var data in device.Data.Where(o => o.Type == DeviceDataType.Int || o.Type == DeviceDataType.Float)) + if (!string.IsNullOrEmpty(fileds)) { - list.Add(new + var query = $"select {fileds} from {measurementName} where time>now()-{time} and DeviceNumber = '{device.Number}' limit 10000"; + var result = client.ReadAsync(dbName, query).Result; + var rows = result.Results.FirstOrDefault()? + .Series.FirstOrDefault()? + .Rows; + foreach (var data in device.Data.Where(o => o.Type == DeviceDataType.Int || o.Type == DeviceDataType.Float)) { - label = data.Name, - data = rows != null ? rows.Where(o => o.Fields.ContainsKey(data.Key)).Select(o => o.GetField(data.Key)).ToList() : new List(), - backgroundColor = this.GetColor(data.Key), - fill = false - }); + list.Add(new + { + label = data.Name, + data = rows != null ? rows.Where(o => o.Fields.ContainsKey(data.Key)).Select(o => o.GetField(data.Key)).ToList() : new List(), + backgroundColor = this.GetColor(data.Key), + fill = false + }); + } + if (rows != null) + { + labels = rows.Select(o => o.Timestamp.Value).Select(o => o.ToString("MM-dd HH:mm")).Distinct().ToList(); + } } - var labels = rows != null ? rows.Select(o => o.Timestamp.Value).Select(o => o.ToString("MM-dd HH:mm")).ToList().Distinct() : new List(); var model = new { datasets = list, diff --git a/projects/IoTCenter/Views/Home/Node.cshtml b/projects/IoTCenter/Views/Home/Node.cshtml index 30ab3093..c80c02b2 100644 --- a/projects/IoTCenter/Views/Home/Node.cshtml +++ b/projects/IoTCenter/Views/Home/Node.cshtml @@ -701,7 +701,7 @@
-
+
{{device.DisplayName}} diff --git a/projects/IoTCenter/iotcenter.db b/projects/IoTCenter/iotcenter.db index 406d81fd..f96bd030 100644 Binary files a/projects/IoTCenter/iotcenter.db and b/projects/IoTCenter/iotcenter.db differ diff --git a/projects/IoTNode/DeviceServices/FBee/FBeeService.cs b/projects/IoTNode/DeviceServices/FBee/FBeeService.cs index 484fc701..6db66d41 100644 --- a/projects/IoTNode/DeviceServices/FBee/FBeeService.cs +++ b/projects/IoTNode/DeviceServices/FBee/FBeeService.cs @@ -513,6 +513,9 @@ namespace IoTNode.DeviceServices.FBee device.AddorUpdateData(device.CreateData(Keys.Battery, battery, DeviceDataType.Int, Keys.Battery, hidden: true)); var epCount = ms.ReadByte(); device.AddorUpdateData(device.CreateData(Keys.EndPointCount, battery, DeviceDataType.Int, Keys.EndPointCount, hidden: true)); + if (device.Name == "光强检测器") + { + } var historyData = ms.ReadHexString(4); device.AddorUpdateData(device.CreateData(Keys.Data, historyData, DeviceDataType.String, Keys.Data, hidden: true)); device.AddorUpdateData(device.CreateData(Keys.ZoneType, zoneType, DeviceDataType.String, Keys.ZoneType, hidden: true)); @@ -1245,7 +1248,7 @@ namespace IoTNode.DeviceServices.FBee } else if (clusterId == ClusterId.voltage) { - var data1 = device.CreateData(Keys.Voltage, props[0x21][0] / 2f, DeviceDataType.Float, "电量"); + var data1 = device.CreateData(Keys.Voltage, props[0x21][0] / 2f, DeviceDataType.Float, "电量", hidden: true); device.AddorUpdateData(data1); var dto1 = data1.To(); dataList.Add(dto1); diff --git a/projects/IoTNode/Services/IoTNodeEventHandler.cs b/projects/IoTNode/Services/IoTNodeEventHandler.cs index 996cd6ee..822088e5 100644 --- a/projects/IoTNode/Services/IoTNodeEventHandler.cs +++ b/projects/IoTNode/Services/IoTNodeEventHandler.cs @@ -12,8 +12,10 @@ using System.Linq; namespace IoTNode.Services { public class IoTNodeEventHandler : + IEventHander>, IEventHander>, IEventHander>, + IEventHander>, IEventHander>, IEventHander>, IEventHander> @@ -26,6 +28,11 @@ namespace IoTNode.Services this._sp = sp; } + public void Handle(EntityInsertedEvent message) + { + RecurringJob.AddOrUpdate(message.Data.Id.ToString(), o => o.TimerHanle(message.Data.Id), message.Data.Cron); + } + public void Handle(EntityUpdatedEvent message) { RecurringJob.AddOrUpdate(message.Data.Id.ToString(), o => o.TimerHanle(message.Data.Id), message.Data.Cron); @@ -36,6 +43,11 @@ namespace IoTNode.Services RecurringJob.RemoveIfExists(message.Data.Id.ToString()); } + public void Handle(EntityInsertedEvent message) + { + Tiggers.TryAdd(message.Data.Id, message.Data); + } + public void Handle(EntityUpdatedEvent message) { Tiggers.TryRemove(message.Data.Id, out IoTTigger tigger); diff --git a/projects/IoTNode/iotnode.db b/projects/IoTNode/iotnode.db index 395f24e6..e976ace5 100644 Binary files a/projects/IoTNode/iotnode.db and b/projects/IoTNode/iotnode.db differ