支持ThingsCloud
This commit is contained in:
parent
184288a64e
commit
ecd6827295
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -31,7 +31,8 @@ namespace IoTGateway.Model
|
|||||||
[Display(Name = "百度物联网通信")]
|
[Display(Name = "百度物联网通信")]
|
||||||
BaiduIoTCore =4,
|
BaiduIoTCore =4,
|
||||||
[Display(Name = "中移OneNet")]
|
[Display(Name = "中移OneNet")]
|
||||||
OneNET =5
|
OneNET = 5,
|
||||||
|
[Display(Name = "ThingsCloud")]
|
||||||
|
ThingsCloud = 6
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,5 +5,5 @@
|
|||||||
<wt:row items-per-row="ItemsPerRowEnum.Three">
|
<wt:row items-per-row="ItemsPerRowEnum.Three">
|
||||||
</wt:row>
|
</wt:row>
|
||||||
</wt:searchpanel>
|
</wt:searchpanel>
|
||||||
<wt:quote>注意:目前实现了iotsharp和tb的遥测、属性上传以及RPC功能</wt:quote>
|
<wt:quote>注意:目前实现了iotsharp、thingsboard、thingscloud的遥测、属性上传以及RPC功能</wt:quote>
|
||||||
<wt:grid vm="@Model" url="/Config/SystemConfig/Search" />
|
<wt:grid vm="@Model" url="/Config/SystemConfig/Search" />
|
||||||
|
Binary file not shown.
@ -258,8 +258,8 @@ namespace Plugin
|
|||||||
if (task != null)
|
if (task != null)
|
||||||
{
|
{
|
||||||
_myMqttClient.OnExcRpc -= MyMqttClient_OnExcRpc;
|
_myMqttClient.OnExcRpc -= MyMqttClient_OnExcRpc;
|
||||||
_driver.Close();
|
|
||||||
tokenSource.Cancel();
|
tokenSource.Cancel();
|
||||||
|
_driver.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,6 +120,13 @@ namespace Plugin
|
|||||||
//Message: {"device": "Device A", "data": {"attribute1": "value1", "attribute2": 42}}
|
//Message: {"device": "Device A", "data": {"attribute1": "value1", "attribute2": 42}}
|
||||||
Client.SubscribeAsync("devices/+/attributes/response/+", MqttQualityOfServiceLevel.ExactlyOnce);
|
Client.SubscribeAsync("devices/+/attributes/response/+", MqttQualityOfServiceLevel.ExactlyOnce);
|
||||||
break;
|
break;
|
||||||
|
case IoTPlatformType.ThingsCloud:
|
||||||
|
Client.SubscribeAsync("gateway/attributes/response", MqttQualityOfServiceLevel.ExactlyOnce);
|
||||||
|
Client.SubscribeAsync("gateway/attributes/get/response", MqttQualityOfServiceLevel.ExactlyOnce);
|
||||||
|
Client.SubscribeAsync("gateway/attributes/push", MqttQualityOfServiceLevel.ExactlyOnce);
|
||||||
|
Client.SubscribeAsync("gateway/event/response", MqttQualityOfServiceLevel.ExactlyOnce);
|
||||||
|
Client.SubscribeAsync("gateway/command/send", MqttQualityOfServiceLevel.ExactlyOnce);
|
||||||
|
break;
|
||||||
case IoTPlatformType.AliCloudIoT:
|
case IoTPlatformType.AliCloudIoT:
|
||||||
break;
|
break;
|
||||||
case IoTPlatformType.TencentIoTHub:
|
case IoTPlatformType.TencentIoTHub:
|
||||||
@ -149,6 +156,9 @@ namespace Plugin
|
|||||||
else if (e.ApplicationMessage.Topic.StartsWith($"devices/") && e.ApplicationMessage.Topic.Contains("/rpc/request/"))
|
else if (e.ApplicationMessage.Topic.StartsWith($"devices/") && e.ApplicationMessage.Topic.Contains("/rpc/request/"))
|
||||||
{
|
{
|
||||||
ReceiveIsRpc(e);
|
ReceiveIsRpc(e);
|
||||||
|
}else if(e.ApplicationMessage.Topic== "gateway/command/send")
|
||||||
|
{
|
||||||
|
ReceiveTcRpc(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -158,6 +168,10 @@ namespace Plugin
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// thingsboard rpc
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e"></param>
|
||||||
private void ReceiveTbRpc(MqttApplicationMessageReceivedEventArgs e)
|
private void ReceiveTbRpc(MqttApplicationMessageReceivedEventArgs e)
|
||||||
{
|
{
|
||||||
TBRpcRequest tBRpcRequest;
|
TBRpcRequest tBRpcRequest;
|
||||||
@ -179,6 +193,30 @@ namespace Plugin
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// thingscloud rpc
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ReceiveTcRpc(MqttApplicationMessageReceivedEventArgs e)
|
||||||
|
{
|
||||||
|
TCRpcRequest tCRpcRequest;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tCRpcRequest = JsonConvert.DeserializeObject<TCRpcRequest>(e.ApplicationMessage.ConvertPayloadToString());
|
||||||
|
OnExcRpc?.Invoke(Client, new RpcRequest()
|
||||||
|
{
|
||||||
|
Method = tCRpcRequest.RequestData.Method,
|
||||||
|
DeviceName = tCRpcRequest.DeviceName,
|
||||||
|
RequestId = tCRpcRequest.RequestData.RequestId,
|
||||||
|
Params = tCRpcRequest.RequestData.Params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError($"ReceiveTbRpc:Topic:{e.ApplicationMessage.Topic},Payload:{e.ApplicationMessage.ConvertPayloadToString()}", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
private void ReceiveIsRpc(MqttApplicationMessageReceivedEventArgs e)
|
private void ReceiveIsRpc(MqttApplicationMessageReceivedEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -217,6 +255,15 @@ namespace Plugin
|
|||||||
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce).Build());
|
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce).Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task ResponseTCRpc(TCRpcRequest tCRpcResponse)
|
||||||
|
{
|
||||||
|
string topic = $"command/reply/{tCRpcResponse.RequestData.RequestId}";
|
||||||
|
return Client.PublishAsync(new MqttApplicationMessageBuilder()
|
||||||
|
.WithTopic(topic)
|
||||||
|
.WithPayload(JsonConvert.SerializeObject(tCRpcResponse))
|
||||||
|
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce).Build());
|
||||||
|
}
|
||||||
|
|
||||||
private Task ResponseISRpc(ISRpcResponse rpcResult)
|
private Task ResponseISRpc(ISRpcResponse rpcResult)
|
||||||
{
|
{
|
||||||
///IoTSharp/Clients/RpcClient.cs#L65 var responseTopic = $"/devices/{deviceid}/rpc/response/{methodName}/{rpcid}";
|
///IoTSharp/Clients/RpcClient.cs#L65 var responseTopic = $"/devices/{deviceid}/rpc/response/{methodName}/{rpcid}";
|
||||||
@ -269,11 +316,16 @@ namespace Plugin
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task UploadTelemetryDataAsync(string _devicename, object obj)
|
public Task UploadISTelemetryDataAsync(string _devicename, object obj)
|
||||||
{
|
{
|
||||||
return Client.PublishAsync(new MqttApplicationMessageBuilder().WithTopic($"devices/{_devicename}/telemetry").WithPayload(Newtonsoft.Json.JsonConvert.SerializeObject(obj)).Build());
|
return Client.PublishAsync(new MqttApplicationMessageBuilder().WithTopic($"devices/{_devicename}/telemetry").WithPayload(Newtonsoft.Json.JsonConvert.SerializeObject(obj)).Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task UploadTCTelemetryDataAsync(string _devicename, object obj)
|
||||||
|
{
|
||||||
|
var toSend = new Dictionary<string, object> { { _devicename, obj } };
|
||||||
|
return Client.PublishAsync("gateway/attributes", JsonConvert.SerializeObject(toSend));
|
||||||
|
}
|
||||||
public void ResponseRpc(RpcResponse rpcResponse)
|
public void ResponseRpc(RpcResponse rpcResponse)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -298,6 +350,9 @@ namespace Plugin
|
|||||||
Data = JsonConvert.SerializeObject(new Dictionary<string, object> { { "success", rpcResponse.IsSuccess }, { "description", rpcResponse.Description } })
|
Data = JsonConvert.SerializeObject(new Dictionary<string, object> { { "success", rpcResponse.IsSuccess }, { "description", rpcResponse.Description } })
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case IoTPlatformType.ThingsCloud:
|
||||||
|
//官网API不需要回复的
|
||||||
|
break;
|
||||||
case IoTPlatformType.AliCloudIoT:
|
case IoTPlatformType.AliCloudIoT:
|
||||||
break;
|
break;
|
||||||
case IoTPlatformType.TencentIoTHub:
|
case IoTPlatformType.TencentIoTHub:
|
||||||
@ -372,7 +427,13 @@ namespace Plugin
|
|||||||
case IoTPlatformType.IoTSharp:
|
case IoTPlatformType.IoTSharp:
|
||||||
foreach (var payload in SendModel[device.DeviceName])
|
foreach (var payload in SendModel[device.DeviceName])
|
||||||
{
|
{
|
||||||
UploadTelemetryDataAsync(device.DeviceName, payload.Values);
|
UploadISTelemetryDataAsync(device.DeviceName, payload.Values);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case IoTPlatformType.ThingsCloud:
|
||||||
|
foreach (var payload in SendModel[device.DeviceName])
|
||||||
|
{
|
||||||
|
UploadTCTelemetryDataAsync(device.DeviceName, payload.Values);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IoTPlatformType.AliCloudIoT:
|
case IoTPlatformType.AliCloudIoT:
|
||||||
@ -418,6 +479,9 @@ namespace Plugin
|
|||||||
break;
|
break;
|
||||||
case IoTPlatformType.OneNET:
|
case IoTPlatformType.OneNET:
|
||||||
break;
|
break;
|
||||||
|
case IoTPlatformType.ThingsCloud:
|
||||||
|
await Client.PublishAsync("gateway/connect", JsonConvert.SerializeObject(new Dictionary<string, string> { { "device", DeviceName } }));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -446,6 +510,9 @@ namespace Plugin
|
|||||||
break;
|
break;
|
||||||
case IoTPlatformType.OneNET:
|
case IoTPlatformType.OneNET:
|
||||||
break;
|
break;
|
||||||
|
case IoTPlatformType.ThingsCloud:
|
||||||
|
await Client.PublishAsync("gateway/disconnect", JsonConvert.SerializeObject(new Dictionary<string, string> { { "device", DeviceName } }));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
26
Plugins/PluginInterface/ThingsCloud/TCRpcRequest.cs
Normal file
26
Plugins/PluginInterface/ThingsCloud/TCRpcRequest.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PluginInterface.ThingsBoard
|
||||||
|
{
|
||||||
|
public class TCRpcRequest
|
||||||
|
{
|
||||||
|
[JsonProperty(PropertyName = "device")]
|
||||||
|
public string DeviceName { get; set; }
|
||||||
|
[JsonProperty(PropertyName = "command")]
|
||||||
|
public TBRpcData RequestData { get; set; }
|
||||||
|
}
|
||||||
|
public class TCRpcData
|
||||||
|
{
|
||||||
|
[JsonProperty(PropertyName = "id")]
|
||||||
|
public string RequestId { get; set; }
|
||||||
|
[JsonProperty(PropertyName = "method")]
|
||||||
|
public string Method { get; set; }
|
||||||
|
[JsonProperty(PropertyName = "params")]
|
||||||
|
public Dictionary<string, object> Params { get; set; }
|
||||||
|
}
|
||||||
|
}
|
BIN
iotgateway.db
BIN
iotgateway.db
Binary file not shown.
Loading…
Reference in New Issue
Block a user