提交 6293d695 编写于 作者: david10000's avatar david10000

Merge branch 'master' of https://github.com/masterchen/IoTSharp

......@@ -46,15 +46,15 @@ service.interceptors.response.use(
response => {
const res = response.data
// if the custom code is not 20000, it is judged as an error.
if (res.code === 200) {
if (res.code !== 10000) {
Message({
message: res.message || 'Error',
message: res.msg || 'Error',
type: 'error',
duration: 5 * 1000
})
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
if (res.code === 10001 || res.code === 10003 || res.code === 10002) {
// to re-login
MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
confirmButtonText: 'Re-Login',
......@@ -66,7 +66,7 @@ service.interceptors.response.use(
})
})
}
return Promise.reject(new Error(res.message || 'Error'))
return Promise.reject(new Error(res.msg || 'Error'))
} else {
console.log('response = ' + res)
return res
......@@ -75,7 +75,7 @@ service.interceptors.response.use(
error => {
console.log('err' + error) // for debug
Message({
message: error.message,
message: error.msg,
type: 'error',
duration: 5 * 1000
})
......
const customerId = 'b1075b75-7170-437a-aa0a-9787d63ae1f8'
export default customerId
......@@ -75,6 +75,9 @@
<el-button :loading="loading" type="primary" class="item-btn" size="medium" @click.native.prevent="handleRegister">Register</el-button>
<el-button class="item-btn" type="primary" @click="showDialog=true">Getting a tenant?</el-button>
</div>
<div class="block">
<el-button class="thirdparty-button" type="primary" @click="showDialog=true">Getting a tenant?</el-button>
</div>
</div>
</el-form>
<el-dialog title="Getting a tenant?" :visible.sync="showDialog">
......@@ -97,7 +100,7 @@
<script>
// import { validUsername } from '@/utils/validate'
import customerId from '@/utils/test-customer-id'
export default {
name: 'Register',
data() {
......@@ -127,7 +130,7 @@ export default {
registerForm: {
email: '',
phoneNumber: '',
customerId: '',
customerId: customerId,
password: ''
},
loginRules: {
......
......@@ -54,7 +54,7 @@ namespace IoTSharp.Controllers
var uidto = new UserInfoDto()
{
Code = ApiCode.OK,
Code = ApiCode.Success,
Roles = string.Join(',',rooles).ToLower().Contains("admin")?"admin": "admin",//TODO: Permission control
Name = user.UserName,
Email = user.Email,
......@@ -80,7 +80,7 @@ namespace IoTSharp.Controllers
var roles = await _userManager.GetRolesAsync(appUser);
return Ok(new LoginResult()
{
Code = ApiCode.OK,
Code = ApiCode.Success,
Succeeded = result.Succeeded,
Token = token,
UserName = appUser.UserName,
......@@ -152,15 +152,14 @@ namespace IoTSharp.Controllers
else
{
var msg = from e in result.Errors select $"{e.Code}:{e.Description}\r\n";
actionResult = BadRequest(new { code = -3, msg = string.Join(';', msg.ToArray()) });
actionResult = BadRequest(new ApiResult(ApiCode.CreateUserFailed, string.Join(';', msg.ToArray())));
}
}
catch (Exception ex)
{
actionResult = BadRequest(new { code = -2, msg = ex.Message, data = ex });
actionResult = this.ExceptionRequest(ex);
_logger.LogError(ex, ex.Message);
}
return actionResult;
}
......
......@@ -106,6 +106,97 @@ namespace IoTSharp.Controllers
}
return await devid.FirstOrDefaultAsync();
}
/// <summary>
/// Request telemetry values from the server
/// </summary>
/// <param name="deviceId">Which device do you read?</param>
/// <param name="keyName">Specify key name</param>
/// <returns></returns>
[Authorize(Roles = nameof(UserRole.NormalUser))]
[HttpGet("{deviceId}/TelemetryLatest/{keyName}")]
public async Task<ActionResult<object>> GetTelemetryLatest(Guid deviceId, string keyName)
{
var dev = _context.Device.Find(deviceId);
if (dev == null)
{
return NotFound(new ApiResult(ApiCode.NotFoundDeviceIdentity, $"Device's Identity not found "));
}
else
{
var kv = from t in _context.TelemetryLatest where t.Device == dev && t.KeyName == keyName select t;
return (await kv.FirstOrDefaultAsync())?.ToObject();
}
}
/// <summary>
/// Request telemetry values from the server
/// </summary>
/// <param name="deviceId">Which device do you read?</param>
/// <param name="keyName">Specify key name</param>
/// <returns></returns>
[Authorize(Roles = nameof(UserRole.NormalUser))]
[HttpGet("{deviceId}/AttributeLatest/{keyName}")]
public async Task<ActionResult<object>> GetAttributeLatest(Guid deviceId,string keyName)
{
var dev = _context.Device.Find(deviceId);
if (dev == null)
{
return NotFound(new ApiResult(ApiCode.NotFoundDeviceIdentity, $"Device's Identity not found "));
}
else
{
var kv = from t in _context.AttributeLatest where t.Device == dev && t.KeyName == keyName select t;
return (await kv.FirstOrDefaultAsync())?.ToObject();
}
}
/// <summary>
/// Request telemetry values from the server
/// </summary>
/// <param name="deviceId">Which device do you read?</param>
/// <param name="keyName">Specify key name</param>
/// <param name="begin">For example: 2019-06-06 12:24</param>
/// <returns></returns>
[Authorize(Roles = nameof(UserRole.NormalUser))]
[HttpGet("{deviceId}/TelemetryLatest/{keyName}/{begin}")]
public async Task<ActionResult<object[]>> GetTelemetryLatest(Guid deviceId, string keyName, DateTime begin)
{
var dev = _context.Device.Find(deviceId);
if (dev == null)
{
return NotFound(new ApiResult(ApiCode.NotFoundDeviceIdentity, $"Device's Identity not found "));
}
else
{
var kv = from t in _context.TelemetryLatest where t.Device == dev && t.KeyName == keyName && t.DateTime >= begin select t.ToObject();
return await kv.ToArrayAsync();
}
}
/// <summary>
/// Request telemetry values from the server
/// </summary>
/// <param name="deviceId">Which device do you read?</param>
/// <param name="keyName">Specify key name</param>
/// <param name="begin">For example: 2019-06-06 12:24</param>
/// <param name="end">For example: 2019-06-06 12:24</param>
/// <returns></returns>
[Authorize(Roles = nameof(UserRole.NormalUser))]
[HttpGet("{deviceId}/TelemetryLatest/{keyName}/{begin}/{end}")]
public async Task<ActionResult<object>> GetTelemetryLatest(Guid deviceId, string keyName, DateTime begin,DateTime end )
{
var dev = _context.Device.Find(deviceId);
if (dev == null)
{
return NotFound(new ApiResult(ApiCode.NotFoundDeviceIdentity, $"Device's Identity not found "));
}
else
{
var kv = from t in _context.TelemetryLatest where t.Device == dev && t.KeyName == keyName && t.DateTime>=begin && t.DateTime <end select t.ToObject() ;
return await kv.ToArrayAsync();
}
}
/// <summary>
/// Get a device's detail
......
......@@ -17,8 +17,6 @@ namespace IoTSharp.Data
public enum ApiCode : int
{
OK=2000,
NotFound=404,
Success = 10000,
LoginError = 10001,
Exception = 10002,
......@@ -33,6 +31,7 @@ namespace IoTSharp.Data
RPCFailed = 10011,
RPCTimeout = 10012,
CustomerDoesNotHaveDevice = 10013,
CreateUserFailed = 10014,
}
public enum DataCatalog
......
......@@ -10,7 +10,6 @@ namespace IoTSharp.Data
public class TelemetryLatest : DataStorage
{
}
}
......@@ -26,6 +26,8 @@ namespace IoTSharp.Extensions
/// <typeparam name="D">Data</typeparam>
/// <param name="data"></param>
/// <param name="device"></param>
/// <param name="dataSide"></param>
/// <param name="_context"></param>
/// <returns></returns>
internal static async Task<(int ret, Dic exceptions)> SaveAsync<L, D>(this ApplicationDbContext _context, Dictionary<string, object> data, Device device, DataSide dataSide) where L : DataStorage, new() where D : DataStorage, new()
{
......@@ -126,9 +128,11 @@ namespace IoTSharp.Extensions
tdata.Type = DataType.Boolean;
tdata.Value_Boolean = (bool)kp.Value;
break;
case TypeCode.Double:
case TypeCode.Single:
tdata.Type = DataType.Double;
tdata.Value_Double = double.Parse(kp.Value.ToString(), System.Globalization.NumberStyles.Float);
break;
case TypeCode.Double:
case TypeCode.Decimal:
tdata.Type = DataType.Double;
tdata.Value_Double = (double)kp.Value;
......@@ -195,5 +199,45 @@ namespace IoTSharp.Extensions
}
return keyValues;
}
public static object ToObject(this DataStorage kxv)
{
object obj = null;
if (kxv != null)
{
switch (kxv.Type)
{
case DataType.Boolean:
obj = kxv.Value_Boolean;
break;
case DataType.String:
obj = kxv.Value_String;
break;
case DataType.Long:
obj = kxv.Value_Long;
break;
case DataType.Double:
obj = kxv.Value_Double;
break;
case DataType.Json:
obj = kxv.Value_Json;
break;
case DataType.XML:
obj = kxv.Value_XML;
break;
case DataType.Binary:
obj = kxv.Value_Binary;
break;
case DataType.DateTime:
obj = kxv.DateTime;
break;
default:
break;
}
}
return obj;
}
}
}
......@@ -28,7 +28,7 @@ namespace IoTSharp
{
var broker = setting;
if (broker == null) broker = new MqttBrokerSetting();
options.WithDefaultEndpointPort(broker.Port).WithDefaultEndpointBoundIPAddress(System.Net.IPAddress.Parse("127.0.0.1")).WithDefaultEndpoint();
options.WithDefaultEndpointPort(broker.Port).WithDefaultEndpoint();
if (broker.EnableTls)
{
options.WithEncryptedEndpoint();
......
......@@ -277,7 +277,7 @@ namespace IoTSharp.Handlers
Task.Run(() => _serverEx.PublishAsync("$SYS/broker/uptime", uptime.ToString()));
}
}
if (e.TopicFilter.Topic.ToLower().StartsWith("/devices/telemetry"))///devices/attributes
if (e.TopicFilter.Topic.ToLower().StartsWith("/devices/telemetry"))
{
......
......@@ -31,6 +31,12 @@
<PackageTags>IoT</PackageTags>
<PackageIconUrl>https://avatars2.githubusercontent.com/u/44353254?s=200&amp;v=4</PackageIconUrl>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<DocumentationFile>D:\GitHub\IoTSharp\IoTSharp\IoTSharp\IoTSharp.xml</DocumentationFile>
<NoWarn>1701;1702;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<Content Update="appsettings.json">
<LinuxPath>/etc/iotsharp/appsettings.json</LinuxPath>
......
<?xml version="1.0"?>
<doc>
<assembly>
<name>IoTSharp</name>
</assembly>
<members>
<member name="P:IoTSharp.AppSettings.MqttBroker">
<summary>
Broker settings
</summary>
</member>
<member name="P:IoTSharp.AppSettings.MqttClient">
<summary>
mqtt client settings
</summary>
</member>
<member name="P:IoTSharp.MqttClientSetting.MqttBroker">
<summary>
built-in or IP、HostName
</summary>
</member>
<member name="T:IoTSharp.Extensions.RpcClient">
<summary>
https://github.com/chkr1011/MQTTnet/blob/master/Source/MQTTnet.Extensions.Rpc/MqttRpcClient.cs
</summary>
</member>
<member name="M:IoTSharp.Extensions.DataExtension.SaveAsync``2(IoTSharp.Data.ApplicationDbContext,System.Collections.Generic.Dictionary{System.String,System.Object},IoTSharp.Data.Device,IoTSharp.Data.DataSide)">
<summary>
Save Data to Device's <typeparamref name="D"/> and <typeparamref name="L"/>
</summary>
<typeparam name="L">Latest</typeparam>
<typeparam name="D">Data</typeparam>
<param name="data"></param>
<param name="device"></param>
<param name="dataSide"></param>
<param name="_context"></param>
<returns></returns>
</member>
<member name="M:IoTSharp.Extensions.DataExtension.PreparingData``2(IoTSharp.Data.ApplicationDbContext,System.Collections.Generic.Dictionary{System.String,System.Object},IoTSharp.Data.Device,IoTSharp.Data.DataSide)">
<summary>
Preparing Data to Device's <typeparamref name="D"/> and <typeparamref name="L"/>
</summary>
<typeparam name="L"></typeparam>
<typeparam name="D"></typeparam>
<param name="_context"></param>
<param name="data"></param>
<param name="device"></param>
<param name="dataSide"></param>
<returns></returns>
</member>
<member name="M:IoTSharp.Extensions.DeviceExtension.AfterCreateDevice(IoTSharp.Data.ApplicationDbContext,IoTSharp.Data.Device)">
<summary>
When creating a device, all the things that need to be done here are done
</summary>
<param name="_context"></param>
<param name="device"></param>
</member>
<member name="M:IoTSharp.Controllers.AccountController.Register(IoTSharp.Dtos.RegisterDto)">
<summary>
Register a user
</summary>
<param name="model"></param>
<returns ></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.GetDevices(System.Guid)">
<summary>
Get all of the customer's devices.
</summary>
<param name="customerId"></param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.GetIdentity(System.Guid)">
<summary>
Get a device's credentials
</summary>
<param name="deviceId"></param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.GetAttributeLatest(System.Guid)">
<summary>
Request attribute values from the server
</summary>
<param name="deviceId"></param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.GetTelemetryLatest(System.Guid)">
<summary>
Request telemetry values from the server
</summary>
<param name="deviceId"></param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.GetTelemetryLatest(System.Guid,System.String)">
<summary>
Request telemetry values from the server
</summary>
<param name="deviceId">Which device do you read?</param>
<param name="keyName">Specify key name</param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.GetAttributeLatest(System.Guid,System.String)">
<summary>
Request telemetry values from the server
</summary>
<param name="deviceId">Which device do you read?</param>
<param name="keyName">Specify key name</param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.GetTelemetryLatest(System.Guid,System.String,System.DateTime)">
<summary>
Request telemetry values from the server
</summary>
<param name="deviceId">Which device do you read?</param>
<param name="keyName">Specify key name</param>
<param name="begin">For example: 2019-06-06 12:24</param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.GetTelemetryLatest(System.Guid,System.String,System.DateTime,System.DateTime)">
<summary>
Request telemetry values from the server
</summary>
<param name="deviceId">Which device do you read?</param>
<param name="keyName">Specify key name</param>
<param name="begin">For example: 2019-06-06 12:24</param>
<param name="end">For example: 2019-06-06 12:24</param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.GetDevice(System.Guid)">
<summary>
Get a device's detail
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.PutDevice(System.Guid,IoTSharp.Dtos.DevicePutDto)">
<summary>
Modify a device
</summary>
<param name="id"></param>
<param name="device"></param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.PostDevice(IoTSharp.Dtos.DevicePostDto)">
<summary>
Create a new device
</summary>
<param name="device"></param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.Rpc(System.String,System.String,System.Int32,System.Object)">
<summary>
Device rpc
</summary>
<param name="access_token"></param>
<param name="method"></param>
<param name="timeout"></param>
<param name="args"></param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.Telemetry(System.String,System.Collections.Generic.Dictionary{System.String,System.Object})">
<summary>
Upload device telemetry to the server.
</summary>
<param name="access_token">Device 's access token</param>
<param name="telemetrys"></param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.Attributes(System.String,IoTSharp.Data.DataSide,System.String)">
<summary>
Get service-side device attributes from the server.
</summary>
<param name="access_token">Device 's access token </param>
<param name="dataSide">Specifying data side.</param>
<param name="keys">Specifying Attribute's keys</param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.Attributes(System.String,System.Collections.Generic.Dictionary{System.String,System.Object})">
<summary>
Upload client-side device attributes to the server.
</summary>
<param name="access_token">Device 's access token </param>
<param name="attributes">attributes</param>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.TenantsController.GetTenant">
<summary>
Only for SystemAdmin
</summary>
<returns></returns>
</member>
<member name="M:IoTSharp.Controllers.TenantsController.GetTenant(System.Guid)">
<summary>
Normal user can use
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="P:IoTSharp.Data.DeviceIdentity.IdentityId">
<summary>
When <see cref="P:IoTSharp.Data.DeviceIdentity.IdentityType"/> Is <see cref="F:IoTSharp.Data.IdentityType.AccessToken"/> ,this is a Token.
When <see cref="P:IoTSharp.Data.DeviceIdentity.IdentityType"/> Is <see cref="F:IoTSharp.Data.IdentityType.DevicePassword"/> ,this is a device name.
When <see cref="P:IoTSharp.Data.DeviceIdentity.IdentityType"/> Is <see cref="F:IoTSharp.Data.IdentityType.X509Certificate"/> ,this is X509 Certificate' Fingerprint.
</summary>
</member>
<member name="P:IoTSharp.Data.DeviceIdentity.IdentityValue">
<summary>
When <see cref="P:IoTSharp.Data.DeviceIdentity.IdentityType"/> Is <see cref="F:IoTSharp.Data.IdentityType.AccessToken"/> ,this is null.
When <see cref="P:IoTSharp.Data.DeviceIdentity.IdentityType"/> Is <see cref="F:IoTSharp.Data.IdentityType.DevicePassword"/> ,this is a password.
When <see cref="P:IoTSharp.Data.DeviceIdentity.IdentityType"/> Is <see cref="F:IoTSharp.Data.IdentityType.X509Certificate"/> ,this is X509 Certificate' PEM.
</summary>
</member>
<member name="M:IoTSharp.TokenExtension.Gravatar(Microsoft.AspNetCore.Identity.IdentityUser)">
Hashes an email with MD5. Suitable for use with Gravatar profile
image urls
</member>
<member name="T:IoTSharp.Properties.Resources">
<summary>
一个强类型的资源类,用于查找本地化的字符串等。
</summary>
</member>
<member name="P:IoTSharp.Properties.Resources.ResourceManager">
<summary>
返回此类使用的缓存的 ResourceManager 实例。
</summary>
</member>
<member name="P:IoTSharp.Properties.Resources.Culture">
<summary>
重写当前线程的 CurrentUICulture 属性
重写当前线程的 CurrentUICulture 属性。
</summary>
</member>
<member name="P:IoTSharp.Properties.Resources.ShowHelp">
<summary>
查找类似 显示帮助 的本地化字符串。
</summary>
</member>
<member name="P:IoTSharp.Properties.Resources.TheCertificateIsInstalled">
<summary>
查找类似 The certificate is installed 的本地化字符串。
</summary>
</member>
</members>
</doc>
# IoTSharp
<pre>
_ _______ ______ _
| | (_______) / _____)| |
| | ___ _ ( (____ | |__ _____ ____ ____
| | / _ \ | | \____ \ | _ \ (____ | / ___)| _ \
| || |_| | | | _____) )| | | |/ ___ || | | |_| |
|_| \___/ |_| (______/ |_| |_|\_____||_| | __/
|_|
</pre>
[![Build status](https://ci.appveyor.com/api/projects/status/5o23f5vss89ct2lw/branch/master?svg=true)](https://ci.appveyor.com/project/MaiKeBing/iotsharp/branch/master)
![GitHub](https://img.shields.io/github/license/iotsharp/iotsharp.svg)
......@@ -24,7 +33,7 @@ IoTSharp is an open-source IoT platform for data collection, processing, visuali
- C# Client SDK for IoTSharp https://github.com/IoTSharp/IoTSharp.SDKs
![IotSharp Logo](docs/images/iot_sharp_logo.png)
## How to install ?
- mkdir /var/lib/iotsharp/
......@@ -37,3 +46,12 @@ IoTSharp is an open-source IoT platform for data collection, processing, visuali
- http://127.0.0.1:80/
-
## IoTSharp.Edge.RT-Thread
IoTSharp.Edge.RT-Thread (STM32L4 + Wi-Fi, sensor, lcd, audio etc)
https://github.com/IoTSharp/IoTSharp.Edge.RT-Thread
![20190615010003.jpg](docs/images/20190615010003.jpg)
![20190615010115.jpg](docs/images/20190615010115.jpg)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册