diff --git a/projects/IoTCenter/Controllers/HomeController.cs b/projects/IoTCenter/Controllers/HomeController.cs index da5bec6e..af2159fa 100644 --- a/projects/IoTCenter/Controllers/HomeController.cs +++ b/projects/IoTCenter/Controllers/HomeController.cs @@ -58,6 +58,7 @@ namespace IoTCenter.Controllers #if DEBUG [Route("/license")] + [AllowAnonymous] public IActionResult License(string mac) { return Content(Helper.Instance.MacEncrypt(mac)); diff --git a/projects/IoTDameon/UpdateIoTNodeService.cs b/projects/IoTDameon/UpdateIoTNodeService.cs index 3a9d9e85..7b87a4a7 100644 --- a/projects/IoTDameon/UpdateIoTNodeService.cs +++ b/projects/IoTDameon/UpdateIoTNodeService.cs @@ -215,7 +215,7 @@ namespace IoTDameon this.Log(command.Bash()); this.Log($"修改权限:{updateScript}"); this.Log(updateScript.Bash()); - this.Log($"执行更细脚本:{updateScript}"); + this.Log($"执行更新脚本:{updateScript}"); } //启动更新程序 proxy.startProcess(processName); diff --git a/projects/IoTDameon/Version.cs b/projects/IoTDameon/Version.cs index bb6381a7..e5aaa5db 100644 --- a/projects/IoTDameon/Version.cs +++ b/projects/IoTDameon/Version.cs @@ -1,4 +1,4 @@ using System.Reflection; [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyInformationalVersion("1.0.0.20092701")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("1.0.0.20101601")] \ No newline at end of file diff --git a/projects/IoTNode/Controllers/HomeController.cs b/projects/IoTNode/Controllers/HomeController.cs index 1ebabc36..725f466b 100644 --- a/projects/IoTNode/Controllers/HomeController.cs +++ b/projects/IoTNode/Controllers/HomeController.cs @@ -1,6 +1,7 @@ -using Application.Domain.Entities; +using Application.Domain.Entities; using Infrastructure.Application.Services.Settings; using Infrastructure.Data; +using Infrastructure.Extensions; using Infrastructure.Web; using IoT.Shared.Services; using Microsoft.AspNetCore.Authorization; @@ -60,5 +61,15 @@ namespace IoTNode.Controllers { return Content(this._settingService.GetSetting("notify:host").Value?.Trim()); } + +#if DEBUG + + [AllowAnonymous] + public IActionResult Test(string id) + { + return Content(Helper.Instance.MacEncrypt(id)); + } + +#endif } } \ No newline at end of file diff --git a/projects/IoTNode/DeviceServices/FBee/Controllers/GatewayController.cs b/projects/IoTNode/DeviceServices/FBee/Controllers/GatewayController.cs index 4a71c6ce..c0e9757b 100644 --- a/projects/IoTNode/DeviceServices/FBee/Controllers/GatewayController.cs +++ b/projects/IoTNode/DeviceServices/FBee/Controllers/GatewayController.cs @@ -45,13 +45,13 @@ namespace IoTNode.Controllers }); } - //[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("删除指定设备")] - //public ApiResponse X95([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - //{ - // return this.AsyncAction(() => - // { - // this._deviceService.X95(gateway, number); - // }); - //} + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("删除指定设备")] + public ApiResponse X95([SwaggerParameter("网关编号")] string gateway, [SwaggerParameter("设备编号")] string number) + { + return this.AsyncAction(() => + { + this._deviceService.X95(gateway, number); + }); + } } } \ No newline at end of file diff --git a/projects/IoTNode/DeviceServices/FBee/FBeeService.cs b/projects/IoTNode/DeviceServices/FBee/FBeeService.cs index 4187560a..8c95f81b 100644 --- a/projects/IoTNode/DeviceServices/FBee/FBeeService.cs +++ b/projects/IoTNode/DeviceServices/FBee/FBeeService.cs @@ -335,6 +335,10 @@ namespace IoTNode.DeviceServices.FBee { this.X27(sn, data); } + else if (responseType == ResponseType.x50) + { + this.X50(sn, data); + } else if (responseType == ResponseType.x70) { this.X70(sn, data); @@ -398,6 +402,14 @@ namespace IoTNode.DeviceServices.FBee payload.Add(ep ?? (byte)endPoint); payload.AddRange(command); } + else if (format == 3) + { + payload.Add((byte)(command.Count() + 1 + 2 + 1));//数据总长 + payload.Add(addressType);//地址模式 + payload.AddRange(address); + payload.Add(ep ?? (byte)endPoint); + payload.AddRange(command); + } data.AddRange(payload); } @@ -689,22 +701,22 @@ namespace IoTNode.DeviceServices.FBee var ieee = device.Number; if (new int[] { 0x0002, 0x0009, 0x0081, 0x0202, 0x0220, 0x0051 }.Contains(deviceId)) { - //this.X85(sn, ieee); + //this.X85(sn, ieee);//获取开关状态 } if (deviceId == 0x0210 || deviceId == 0x0220) { - this.X86(sn, ieee); - this.X87(sn, ieee); - this.X88(sn, ieee); - this.XA9(sn, ieee); + this.X86(sn, ieee);//获取亮度 + this.X87(sn, ieee);//获取色调 + this.X88(sn, ieee);//获取饱和度 + this.XA9(sn, ieee);//色温 } else if (deviceId == 0x0163) { - this.XA70080(sn, ieee); + this.XA70080(sn, ieee);//读版本号 } else if (deviceId == 0x0051) { - this.X8D07020000(sn, ieee); + this.X8D0702(sn, ieee);//读取电量 } } catch (Exception ex) @@ -966,12 +978,16 @@ namespace IoTNode.DeviceServices.FBee } /// - /// 0x8d-0x70发送zcl指令,读取簇id为0702属性为0000的电量值 + /// 0x8d-0x70发送zcl指令,读取簇id为0702的电量、电功率 /// - public void X8D07020000(string sn, string ieee) + public void X8D0702(string sn, string ieee) { - this.Write(sn, RequestType.xa7, ieee, new List() { 0x02, 0x07, 0x00, 0x00, 0x00 }, 2); - this.Write(sn, RequestType.xa7, ieee, new List() { 0x02, 0x07, 0x0b, 0x05, 0x00 }, 2); + this.Write(sn, RequestType.x8d, ieee, new List() { 0x02, 0x07, 0x01, 0x03, 0x00 }, 3);//0301电量乘数 + this.Write(sn, RequestType.x8d, ieee, new List() { 0x02, 0x07, 0x02, 0x03, 0x00 }, 3);//0302电量除数 + this.Write(sn, RequestType.x8d, ieee, new List() { 0x04, 0x0b, 0x04, 0x06, 0x00 }, 3);//0604功率乘数 + this.Write(sn, RequestType.x8d, ieee, new List() { 0x04, 0x0b, 0x05, 0x06, 0x00 }, 3);//0605功率除数 + this.Write(sn, RequestType.xa7, ieee, new List() { 0x02, 0x07, 0x00, 0x00, 0x00 }, 2);//0000电量 + this.Write(sn, RequestType.xa7, ieee, new List() { 0x02, 0x07, 0x0b, 0x05, 0x00 }, 2);//050b功率 } // @@ -1204,6 +1220,43 @@ namespace IoTNode.DeviceServices.FBee this.Write(sn, RequestType.xa9, ieee, list); } + public void X50(string sn, byte[] data) + { + try + { + using var ms = new MemoryStream(data); + if (ms.ReadByte() != 0x50) + { + return; + } + var length = ms.ReadByte(); + ms.Seek(10, SeekOrigin.Current); + var success = ms.ReadByte(); + if (success == 0x01) + { + ms.Seek(1, SeekOrigin.Current); + var controlType = ms.ReadByte(); + if (controlType == 0x95) + { + ms.Seek(2, SeekOrigin.Current); + var address = ms.ReadHexStringDesc(2); + using var scope = _applicationServices.CreateScope(); + var deviceRepo = scope.ServiceProvider.GetService>(); + var device = this.GetDeviceByAddress(deviceRepo, sn, address); + if (device != null) + { + deviceRepo.Delete(device); + deviceRepo.SaveChanges(); + } + } + } + } + catch (Exception ex) + { + this._logger.LogError(ex, ex.Message); + } + } + //0xac //0xaf //0xb0 @@ -1455,6 +1508,10 @@ namespace IoTNode.DeviceServices.FBee { foreach (var item in props) { + if (item.Key == 0x0400) + { + Console.WriteLine(item.Value.ToInt()); + } if (item.Key == 0x0000) { var tempBytes = new List(); @@ -1463,8 +1520,14 @@ namespace IoTNode.DeviceServices.FBee tempBytes.Add(0x00); if (tempBytes.Count == 8) { - var electricity = BitConverter.ToInt64(tempBytes.ToArray()) / 10000f; - this.UpdateData(deviceRepo, device, device.CreateData(Keys.Electricity, electricity.ToString("f2"), DeviceDataType.Float, "电量", "kWh", timestamp: timestamp)); + var multiplier = device.Data.FirstOrDefault(o => o.Key == Keys.ElectricityMultiplier)?.Value; + var divisor = device.Data.FirstOrDefault(o => o.Key == Keys.ElectricityDivisor)?.Value; + if (!string.IsNullOrEmpty(multiplier) && !string.IsNullOrEmpty(divisor)) + { + var electricity = BitConverter.ToInt64(tempBytes.ToArray()); + var value = electricity * Convert.ToInt16(multiplier) / Convert.ToSingle(divisor); + this.UpdateData(deviceRepo, device, device.CreateData(Keys.Electricity, value.ToString("f2"), DeviceDataType.Float, "电量", "kWh", timestamp: timestamp)); + } } else { @@ -1473,14 +1536,51 @@ namespace IoTNode.DeviceServices.FBee } else if (item.Key == 0x050b) { - var power = BitConverter.ToUInt16(item.Value.ToArray()); - this.UpdateData(deviceRepo, device, device.CreateData(Keys.Power, power, DeviceDataType.Float, "功率", "W", timestamp: timestamp)); + var multiplier = device.Data.FirstOrDefault(o => o.Key == Keys.PowerMultiplier)?.Value; + var divisor = device.Data.FirstOrDefault(o => o.Key == Keys.PowerDivisor)?.Value; + if (!string.IsNullOrEmpty(multiplier) && !string.IsNullOrEmpty(divisor)) + { + var power = BitConverter.ToUInt16(item.Value.ToArray()); + var value = power * Convert.ToInt16(multiplier) / Convert.ToSingle(divisor); + this.UpdateData(deviceRepo, device, device.CreateData(Keys.Power, value.ToString("f2"), DeviceDataType.Float, "功率", "W", timestamp: timestamp)); + } + } + else if (item.Key == 0x0400)//0x050b + { + var multiplier = device.Data.FirstOrDefault(o => o.Key == Keys.PowerMultiplier)?.Value; + var divisor = device.Data.FirstOrDefault(o => o.Key == Keys.PowerDivisor)?.Value; + if (!string.IsNullOrEmpty(multiplier) && !string.IsNullOrEmpty(divisor)) + { + var power = BitConverter.ToUInt16(item.Value.ToArray()); + var value = power * Convert.ToInt16(multiplier) / Convert.ToSingle(divisor); + this.UpdateData(deviceRepo, device, device.CreateData(Keys.Power, value.ToString("f2"), DeviceDataType.Float, "功率", "W", timestamp: timestamp)); + } + } + else if (item.Key == 0x0301) + { + var value = BitConverter.ToUInt16(item.Value.ToArray()); + this.UpdateData(deviceRepo, device, device.CreateData(Keys.ElectricityMultiplier, value, DeviceDataType.Int, "电功乘数", timestamp: timestamp, hidden: true)); + } + else if (item.Key == 0x0302) + { + var value = BitConverter.ToUInt16(item.Value.ToArray()); + this.UpdateData(deviceRepo, device, device.CreateData(Keys.ElectricityDivisor, value, DeviceDataType.Int, "电功除数", timestamp: timestamp, hidden: true)); + } + else if (item.Key == 0x0604) + { + var value = BitConverter.ToUInt16(item.Value.ToArray()); + this.UpdateData(deviceRepo, device, device.CreateData(Keys.PowerMultiplier, value, DeviceDataType.Int, "电功乘数", timestamp: timestamp, hidden: true)); + } + else if (item.Key == 0x0605) + { + var value = BitConverter.ToUInt16(item.Value.ToArray()); + this.UpdateData(deviceRepo, device, device.CreateData(Keys.PowerDivisor, value, DeviceDataType.Int, "电功除数", timestamp: timestamp, hidden: true)); } } - if (clusterId == ClusterId.SummationDivisor) - { - this.X8D07020000(sn, device.Number); - } + //if (clusterId == ClusterId.SummationDivisor) + //{ + // this.X8D0702(sn, device.Number); + //} } } } diff --git a/projects/IoTNode/DeviceServices/FBee/Keys.cs b/projects/IoTNode/DeviceServices/FBee/Keys.cs index 1243bf40..7f0b4177 100644 --- a/projects/IoTNode/DeviceServices/FBee/Keys.cs +++ b/projects/IoTNode/DeviceServices/FBee/Keys.cs @@ -7,7 +7,11 @@ public const string EndPoint = "EndPoint"; public const string Version = "Version"; public const string Electricity = "Electricity"; + public const string ElectricityMultiplier = "ElectricityMultiplier"; + public const string ElectricityDivisor = "ElectricityDivisor"; public const string Power = "Power"; + public const string PowerMultiplier = "PowerMultiplier"; + public const string PowerDivisor = "PowerDivisor"; public const string KeyPress = "KeyPress"; public const string State = "State"; public const string L1State = "L1State"; diff --git a/projects/IoTNode/DeviceServices/FBee/ResponseType.cs b/projects/IoTNode/DeviceServices/FBee/ResponseType.cs index 2a81d811..2066ef14 100644 --- a/projects/IoTNode/DeviceServices/FBee/ResponseType.cs +++ b/projects/IoTNode/DeviceServices/FBee/ResponseType.cs @@ -8,10 +8,11 @@ public const int x09 = 0x09; public const int x0a = 0x0a; public const int x27 = 0x27; + public const int x50 = 0x50; public const int x70 = 0x70; public const int x75 = 0x75; public const int x72 = 0x72; public const int x15 = 0x15; public const int x29 = 0x29; } -} \ No newline at end of file +} diff --git a/projects/IoTNode/Version.cs b/projects/IoTNode/Version.cs index 60019fca..def643dd 100644 --- a/projects/IoTNode/Version.cs +++ b/projects/IoTNode/Version.cs @@ -1,4 +1,4 @@ using System.Reflection; [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyInformationalVersion("1.0.0.20092801")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("1.0.0.20101901")] \ No newline at end of file diff --git a/projects/IoTNode/Views/Home/Index.cshtml b/projects/IoTNode/Views/Home/Index.cshtml index 0324c1f4..5d809c9f 100644 --- a/projects/IoTNode/Views/Home/Index.cshtml +++ b/projects/IoTNode/Views/Home/Index.cshtml @@ -1,10 +1,8 @@ @model Node -@{ - HtmlTitle = "设备"; - var index = 0; -} -
- @Model.Name:@Model.Number上传数据 +@{ HtmlTitle = "设备"; + var index = 0; } +
+ @Model.Name:@Model.Number上传数据
@@ -18,32 +16,28 @@ @foreach (var item in Model.Devices) { - - - - - - - - - } + + + + + + + +}
@(++index)@item.Product.Number:@item.Product.Name@item.Number:@item.Name@item.DisplayName@Html.DisplayFor(o => item.IsOnline) - @if (item.Product.Number.Contains("fbee") && !item.Product.Number.Contains("gateway")) - { - var values = item.Number.Split('-'); - var gateway = values[0]; - var number = values[1]; - 从网关移除 - } - else if (item.Product.Name == "摄像头") - { - 开始推流 - 停止推流 - } - else if (item.Product.Number.Contains("gateway")) - { - 查询网关设备 - } -
@(++index)@item.Product.Number:@item.Product.Name@item.Number:@item.Name@item.DisplayName@Html.DisplayFor(o => item.IsOnline) + @if (item.Product.Number.Contains("fbee") && !item.Product.Number.Contains("gateway")) + { + var values = item.Number.Split('-'); + var gateway = values[0]; + var number = values[1]; +从网关移除 } + else if (item.Product.Name == "摄像头") + { +开始推流 + 停止推流 } + else if (item.Product.Number.Contains("gateway")) + { + 查询网关设备} +
@section scripts{ diff --git a/projects/Version.cs b/projects/Version.cs index 70945843..e5aaa5db 100644 --- a/projects/Version.cs +++ b/projects/Version.cs @@ -1,4 +1,4 @@ using System.Reflection; [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyInformationalVersion("1.0.0.20092902")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("1.0.0.20101601")] \ No newline at end of file diff --git a/projects/WebMVC/wwwroot/js/config.js b/projects/WebMVC/wwwroot/js/config.js index 2b2830b4..d616d022 100644 --- a/projects/WebMVC/wwwroot/js/config.js +++ b/projects/WebMVC/wwwroot/js/config.js @@ -1,5 +1,5 @@ var config = { - version: '1.0.0.20093001', + version: '1.0.0.20101901', debug: window.location.search.indexOf('debug') > -1, baseUrl: window.location.protocol + '//' + window.location.host, uploadUrl: window.location.protocol + '//' + window.location.host + '/IoTCenter/File/Upload', diff --git a/projects/WebMVC/wwwroot/routes/iot/device.html b/projects/WebMVC/wwwroot/routes/iot/device.html index 953aa409..b33f8ce2 100644 --- a/projects/WebMVC/wwwroot/routes/iot/device.html +++ b/projects/WebMVC/wwwroot/routes/iot/device.html @@ -49,7 +49,8 @@ url: '/IoTCenter/api/v1/device/getDevice?number=' + this.$route.query.number, device: null, events: ['DeviceEntityInserted', 'DeviceEntityUpdated', 'DeviceEntityInserted', - 'DataEntityInserted', 'DataEntityUpdated', 'DataEntityInserted'] + 'DataEntityInserted', 'DataEntityUpdated', 'DataEntityInserted'], + time: '1d' } }, mounted: function () { @@ -79,10 +80,11 @@ return o.type === 10 || o.type === 20; }).toArray(); for (var i = 0; i < dataList.length; i++) { - this.changeTime(dataList[i].key, '1d', dataList[i].name); + this.changeTime(dataList[i].key, this.time, dataList[i].name); } }, tabClick: function (event, key, time, title) { + this.time = time; this.changeTime(key, time, title); var link = $(event.currentTarget); if (!link.hasClass('active')) { diff --git a/publish/src/linux-arm64/publish/50-cloud-init.yaml b/publish/src/linux-arm64/publish/50-cloud-init.yaml index 01a9527d..78f0b42b 100644 --- a/publish/src/linux-arm64/publish/50-cloud-init.yaml +++ b/publish/src/linux-arm64/publish/50-cloud-init.yaml @@ -8,7 +8,7 @@ network: addresses: [192.168.1.4/24] gateway4: 192.168.1.1 nameservers: - addresses: [8.8.8.8,223.5.5.5,119.29.29.29,180.76.76.76] + addresses: [223.5.5.5,119.29.29.29,180.76.76.76] search: [] optional: true version: 2 diff --git a/publish/src/linux-arm64/publish/install.sh b/publish/src/linux-arm64/publish/install.sh index 7406cda6..857c764e 100644 --- a/publish/src/linux-arm64/publish/install.sh +++ b/publish/src/linux-arm64/publish/install.sh @@ -54,6 +54,9 @@ fi if uname -a | grep -q "NanoPC-T4" then echo "nanopc-t4" +# sed -i "s/managed=true/managed=false/g" /etc/NetworkManager/NetworkManager.conf +# cp -f /etc/network/interfaces /etc/network/interfaces.bk +# cp ~/publish/interfaces /etc/network/interfaces nmcli connection modify 'Wired connection 1' connection.autoconnect yes ipv4.method manual ipv4.address 192.168.1.3/24 ipv4.gateway 192.168.1.1 ipv4.dns "223.5.5.5 119.29.29.29 180.76.76.76" nmcli c up 'Wired connection 1' fi \ No newline at end of file