增加mqtt离散输出模式

This commit is contained in:
王海东 2021-12-20 23:38:59 +08:00
parent 3e4119b968
commit e36dd6fc2e
12 changed files with 871 additions and 19 deletions

Binary file not shown.

View File

@ -0,0 +1,797 @@
// <auto-generated />
using System;
using IoTGateway.DataAccess;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace IoTGateway.DataAccess.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20211220151947_disperse")]
partial class disperse
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "5.0.9");
modelBuilder.Entity("IoTGateway.Model.Device", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool>("AutoStart")
.HasColumnType("INTEGER");
b.Property<string>("CreateBy")
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("DeviceName")
.HasColumnType("TEXT");
b.Property<int>("DeviceTypeEnum")
.HasColumnType("INTEGER");
b.Property<Guid?>("DriverId")
.HasColumnType("TEXT");
b.Property<uint>("Index")
.HasColumnType("INTEGER");
b.Property<Guid?>("ParentId")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("DriverId");
b.HasIndex("ParentId");
b.ToTable("Devices");
});
modelBuilder.Entity("IoTGateway.Model.DeviceConfig", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("DeviceConfigName")
.HasColumnType("TEXT");
b.Property<Guid?>("DeviceId")
.HasColumnType("TEXT");
b.Property<string>("EnumInfo")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("DeviceId");
b.ToTable("DeviceConfigs");
});
modelBuilder.Entity("IoTGateway.Model.DeviceVariable", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<int>("DataType")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("DeviceAddress")
.HasColumnType("TEXT");
b.Property<Guid?>("DeviceId")
.HasColumnType("TEXT");
b.Property<string>("Expressions")
.HasColumnType("TEXT");
b.Property<string>("Method")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<int>("ProtectType")
.HasColumnType("INTEGER");
b.HasKey("ID");
b.HasIndex("DeviceId");
b.ToTable("DeviceVariables");
});
modelBuilder.Entity("IoTGateway.Model.Driver", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("AssembleName")
.HasColumnType("TEXT");
b.Property<int>("AuthorizesNum")
.HasColumnType("INTEGER");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("DriverName")
.HasColumnType("TEXT");
b.Property<string>("FileName")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("Drivers");
});
modelBuilder.Entity("IoTGateway.Model.SystemConfig", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<bool>("Disperse")
.HasColumnType("INTEGER");
b.Property<string>("GatewayName")
.HasColumnType("TEXT");
b.Property<string>("MqttIp")
.HasColumnType("TEXT");
b.Property<int>("MqttPort")
.HasColumnType("INTEGER");
b.Property<string>("MqttUName")
.HasColumnType("TEXT");
b.Property<string>("MqttUPwd")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("SystemConfig");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.ActionLog", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ActionName")
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<DateTime>("ActionTime")
.HasColumnType("TEXT");
b.Property<string>("ActionUrl")
.HasMaxLength(250)
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<double>("Duration")
.HasColumnType("REAL");
b.Property<string>("IP")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("ITCode")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int>("LogType")
.HasColumnType("INTEGER");
b.Property<string>("ModuleName")
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<string>("Remark")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("ActionLogs");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.DataPrivilege", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("Domain")
.HasColumnType("TEXT");
b.Property<string>("GroupCode")
.HasColumnType("TEXT");
b.Property<string>("RelateId")
.HasColumnType("TEXT");
b.Property<string>("TableName")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("UserCode")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("DataPrivileges");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FileAttachment", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ExtraInfo")
.HasColumnType("TEXT");
b.Property<byte[]>("FileData")
.HasColumnType("BLOB");
b.Property<string>("FileExt")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("TEXT");
b.Property<string>("FileName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("HandlerInfo")
.HasColumnType("TEXT");
b.Property<long>("Length")
.HasColumnType("INTEGER");
b.Property<string>("Path")
.HasColumnType("TEXT");
b.Property<string>("SaveMode")
.HasColumnType("TEXT");
b.Property<DateTime>("UploadTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FileAttachments");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkGroup", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("GroupCode")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("GroupName")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("GroupRemark")
.HasColumnType("TEXT");
b.Property<string>("TenantCode")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FrameworkGroups");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkMenu", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ActionName")
.HasColumnType("TEXT");
b.Property<string>("ClassName")
.HasColumnType("TEXT");
b.Property<int?>("DisplayOrder")
.IsRequired()
.HasColumnType("INTEGER");
b.Property<string>("Domain")
.HasColumnType("TEXT");
b.Property<bool>("FolderOnly")
.HasColumnType("INTEGER");
b.Property<string>("Icon")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<bool>("IsInherit")
.HasColumnType("INTEGER");
b.Property<bool?>("IsInside")
.IsRequired()
.HasColumnType("INTEGER");
b.Property<bool>("IsPublic")
.HasColumnType("INTEGER");
b.Property<string>("MethodName")
.HasColumnType("TEXT");
b.Property<string>("ModuleName")
.HasColumnType("TEXT");
b.Property<string>("PageName")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<Guid?>("ParentId")
.HasColumnType("TEXT");
b.Property<bool>("ShowOnMenu")
.HasColumnType("INTEGER");
b.Property<string>("Url")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("ParentId");
b.ToTable("FrameworkMenus");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkRole", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("RoleCode")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("RoleName")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("RoleRemark")
.HasColumnType("TEXT");
b.Property<string>("TenantCode")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FrameworkRoles");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkUser", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Address")
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<string>("CellPhone")
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int?>("Gender")
.HasColumnType("INTEGER");
b.Property<string>("HomePhone")
.HasMaxLength(30)
.HasColumnType("TEXT");
b.Property<string>("ITCode")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<bool>("IsValid")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Password")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("TEXT");
b.Property<Guid?>("PhotoId")
.HasColumnType("TEXT");
b.Property<string>("TenantCode")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("ZipCode")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("PhotoId");
b.ToTable("FrameworkUsers");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkUserGroup", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("GroupCode")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("UserCode")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FrameworkUserGroups");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkUserRole", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<string>("RoleCode")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.Property<string>("UserCode")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("FrameworkUserRoles");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FunctionPrivilege", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool?>("Allowed")
.IsRequired()
.HasColumnType("INTEGER");
b.Property<string>("CreateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<Guid>("MenuItemId")
.HasColumnType("TEXT");
b.Property<string>("RoleCode")
.HasColumnType("TEXT");
b.Property<string>("UpdateBy")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<DateTime?>("UpdateTime")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("MenuItemId");
b.ToTable("FunctionPrivileges");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.PersistedGrant", b =>
{
b.Property<Guid>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<DateTime>("CreationTime")
.HasColumnType("TEXT");
b.Property<DateTime>("Expiration")
.HasColumnType("TEXT");
b.Property<string>("RefreshToken")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Type")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("UserCode")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("PersistedGrants");
});
modelBuilder.Entity("IoTGateway.Model.Device", b =>
{
b.HasOne("IoTGateway.Model.Driver", "Driver")
.WithMany()
.HasForeignKey("DriverId");
b.HasOne("IoTGateway.Model.Device", "Parent")
.WithMany("Children")
.HasForeignKey("ParentId");
b.Navigation("Driver");
b.Navigation("Parent");
});
modelBuilder.Entity("IoTGateway.Model.DeviceConfig", b =>
{
b.HasOne("IoTGateway.Model.Device", "Device")
.WithMany("DeviceConfigs")
.HasForeignKey("DeviceId");
b.Navigation("Device");
});
modelBuilder.Entity("IoTGateway.Model.DeviceVariable", b =>
{
b.HasOne("IoTGateway.Model.Device", "Device")
.WithMany("DeviceVariables")
.HasForeignKey("DeviceId");
b.Navigation("Device");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkMenu", b =>
{
b.HasOne("WalkingTec.Mvvm.Core.FrameworkMenu", "Parent")
.WithMany("Children")
.HasForeignKey("ParentId");
b.Navigation("Parent");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkUser", b =>
{
b.HasOne("WalkingTec.Mvvm.Core.FileAttachment", "Photo")
.WithMany()
.HasForeignKey("PhotoId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Photo");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FunctionPrivilege", b =>
{
b.HasOne("WalkingTec.Mvvm.Core.FrameworkMenu", "MenuItem")
.WithMany("Privileges")
.HasForeignKey("MenuItemId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("MenuItem");
});
modelBuilder.Entity("IoTGateway.Model.Device", b =>
{
b.Navigation("Children");
b.Navigation("DeviceConfigs");
b.Navigation("DeviceVariables");
});
modelBuilder.Entity("WalkingTec.Mvvm.Core.FrameworkMenu", b =>
{
b.Navigation("Children");
b.Navigation("Privileges");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace IoTGateway.DataAccess.Migrations
{
public partial class disperse : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "Disperse",
table: "SystemConfig",
type: "INTEGER",
nullable: false,
defaultValue: false);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Disperse",
table: "SystemConfig");
}
}
}

View File

@ -193,6 +193,9 @@ namespace IoTGateway.DataAccess.Migrations
b.Property<DateTime?>("CreateTime")
.HasColumnType("TEXT");
b.Property<bool>("Disperse")
.HasColumnType("INTEGER");
b.Property<string>("GatewayName")
.HasColumnType("TEXT");

View File

@ -15,5 +15,7 @@ namespace IoTGateway.Model
public string MqttUName { get; set; }
[Display(Name = "Mqtt密码")]
public string MqttUPwd { get; set; }
[Display(Name = "离散输出")]
public bool Disperse { get; set; }
}
}

View File

@ -37,6 +37,7 @@ namespace IoTGateway.ViewModel.Config.SystemConfigVMs
this.MakeGridHeader(x => x.MqttPort),
this.MakeGridHeader(x => x.MqttUName),
this.MakeGridHeader(x => x.MqttUPwd),
this.MakeGridHeader(x => x.Disperse),
this.MakeGridHeaderAction(width: 200)
};
}
@ -52,6 +53,7 @@ namespace IoTGateway.ViewModel.Config.SystemConfigVMs
MqttPort = x.MqttPort,
MqttUName = x.MqttUName,
MqttUPwd = x.MqttUPwd,
Disperse = x.Disperse,
})
.OrderBy(x => x.ID);
return query;

View File

@ -2,13 +2,15 @@
@inject IStringLocalizer<Program> Localizer;
<wt:form vm="@Model">
<wt:row items-per-row="ItemsPerRowEnum.Two">
<wt:textbox field="Entity.GatewayName" />
<wt:textbox field="Entity.MqttIp" />
<wt:textbox field="Entity.MqttPort" />
<wt:textbox field="Entity.MqttUName" />
<wt:textbox field="Entity.MqttUPwd" />
</wt:row>
<wt:quote>注意tb只能使用非离散输出模式否则平台无法解析</wt:quote>
<wt:row items-per-row="ItemsPerRowEnum.Two">
<wt:textbox field="Entity.GatewayName" />
<wt:textbox field="Entity.MqttIp" />
<wt:textbox field="Entity.MqttPort" />
<wt:textbox field="Entity.MqttUName" />
<wt:textbox field="Entity.MqttUPwd" />
<wt:switch field="Entity.Disperse" />
</wt:row>
<wt:hidden field="Entity.ID" />
<wt:row align="AlignEnum.Right">
<wt:submitbutton />

View File

@ -2,7 +2,8 @@
@inject IStringLocalizer<Program> Localizer;
<wt:searchpanel vm="@Model" reset-btn="true">
<wt:row items-per-row="ItemsPerRowEnum.Three">
</wt:row>
<wt:row items-per-row="ItemsPerRowEnum.Three">
</wt:row>
</wt:searchpanel>
<wt:grid vm="@Model" url="/Config/SystemConfig/Search"/>
<wt:quote>注意tb只能使用非离散输出模式否则平台无法解析</wt:quote>
<wt:grid vm="@Model" url="/Config/SystemConfig/Search" />

Binary file not shown.

View File

@ -113,7 +113,7 @@ namespace Plugin
{
payLoad.DeviceStatus = DeviceStatusTypeEnum.Good;
sendModel[Device.DeviceName] = new List<PayLoad> { payLoad };
myMqttClient.Publish("v1/gateway/telemetry", sendModel);
myMqttClient.Publish(Device,sendModel);
}
}

View File

@ -21,6 +21,7 @@ namespace Plugin
{
private static IMqttClient _mqttClient = null;
private static MqttClientOptionsBuilder builder = null;
private SystemConfig systemConfig = null;
public MyMqttClient()
{
InitClient();
@ -34,8 +35,8 @@ namespace Plugin
using (var DC = new DataContext(IoTBackgroundService.connnectSetting, IoTBackgroundService.DBType))
{
var systemManage = DC.Set<SystemConfig>().FirstOrDefault();
if (systemManage == null)
systemConfig = DC.Set<SystemConfig>().FirstOrDefault();
if (systemConfig == null)
Console.WriteLine("配置信息错误,无法启动");
else
{
@ -46,9 +47,9 @@ namespace Plugin
builder = new MqttClientOptionsBuilder()
.WithCommunicationTimeout(TimeSpan.FromSeconds(60))
.WithKeepAlivePeriod(TimeSpan.FromSeconds(20))
.WithTcpServer(systemManage.MqttIp, systemManage.MqttPort)
.WithClientId(systemManage.MqttUName + Guid.NewGuid().ToString())
.WithCredentials(systemManage.MqttUName, systemManage.MqttUPwd);
.WithTcpServer(systemConfig.MqttIp, systemConfig.MqttPort)
.WithClientId(systemConfig.MqttUName + Guid.NewGuid().ToString())
.WithCredentials(systemConfig.MqttUName, systemConfig.MqttUPwd);
_mqttClient.ConnectAsync(builder.Build());
}
@ -58,12 +59,32 @@ namespace Plugin
{
}
}
public void Publish(string Topic, Dictionary<string, List<PayLoad>> SendModel)
public void Publish(Device device, Dictionary<string, List<PayLoad>> SendModel)
{
_mqttClient.PublishAsync(Topic, JsonConvert.SerializeObject(SendModel));
try
{
string TopicBase = "v1/gateway/telemetry";
if (!systemConfig.Disperse)
_mqttClient.PublishAsync(TopicBase, JsonConvert.SerializeObject(SendModel));
else
{
foreach (var payload in SendModel[device.DeviceName])
{
foreach (var kv in payload.Values)
{
_mqttClient.PublishAsync($"{TopicBase}/{device.DeviceName}/{kv.Key}", kv.Value.ToString());
}
}
}
}
catch (Exception ex)
{
}
}
private void OnReceived(MqttApplicationMessageReceivedEventArgs obj)