7 Commits
Author SHA1 Message Date
BlubbFish e5eb4c8740 [1.4.0] Cleanup 2022-01-09 14:02:35 +01:00
BlubbFish 9a94ff97d2 make mirror on github.com
also remove a disconnet on the first start
2021-08-22 00:41:55 +02:00
BlubbFish 51bfd52095 newer c# lang 2021-04-10 01:02:20 +02:00
BlubbFish d7f2ccd4af Make netcore as default, also using 3.1 now 2021-01-09 00:13:14 +01:00
BlubbFish 47cdef0959 Thread Abort in netcore is not working 2019-12-01 17:53:57 +01:00
BlubbFish 35ba2b8135 change to netcore 2019-11-29 14:45:10 +01:00
BlubbFish 8381edd133 Refactoring and add netcore 2019-11-28 17:42:21 +01:00
8 changed files with 268 additions and 109 deletions
+37
View File
@@ -0,0 +1,37 @@
# Changelog
## 1.4.0 - 2022-01-09 - Cleanup
### New Features
* On first startup, not try to disconnect first
### Bugfixes
* Fixing nullpointer exception
### Changes
* Cleanup project and fixes version numbers
## 1.3.0 - 2021-01-09 - Default netcore
### New Features
* Create toString, so in logfiles the used Server is visible
* add changelog.md
### Bugfixes
### Changes
* Netcore is now the default projekt
## 1.2.0 - 2019-11-28 - Add netcore
### New Features
* add Licence, readme.md and contribute.md
* add netcore version
### Bugfixes
### Changes
* Using newer C# language version
## 1.1.0 - 2019-05-27 - Rewrite Module to reconnect itselfs, so you dont need to watch over the the state of the connection
### New Features
* Keep the connection alive and reconnect internally
### Bugfixes
### Changes
## 1.0.0.0 - 2019-02-14 - Init
### New Features
* Init release
### Bugfixes
### Changes
+43
View File
@@ -0,0 +1,43 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "ConnectorDataMqtt\ConnectorDataMqtt-4.7.1.csproj", "{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils-IoT\Utils-IoT\Utils-IoT-4.7.1.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "M2Mqtt_4.7.1", "..\..\Librarys\mqtt\M2Mqtt\M2Mqtt_4.7.1.csproj", "{A11AEF5A-B246-4FE8-8330-06DB73CC8074}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson_4.7.1", "..\..\Librarys\litjson\litjson\litjson_4.7.1.csproj", "{91A14CD2-2940-4500-8193-56D37EDDDBAA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Release|Any CPU.Build.0 = Release|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.Build.0 = Release|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.Build.0 = Release|Any CPU
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B90F7B1F-FDD8-4B59-AAA5-218655C2716C}
EndGlobalSection
EndGlobal
+29 -23
View File
@@ -1,15 +1,17 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.136
# Visual Studio Version 16
VisualStudioVersion = 16.0.29519.87
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "ConnectorDataMqtt\ConnectorDataMqtt.csproj", "{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConnectorDataMqtt", "ConnectorDataMqtt\ConnectorDataMqtt.csproj", "{5D7A8892-6687-4FE2-85D1-12B49782EDF0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils-IoT\Utils-IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Utils-IoT", "..\Utils-IoT\Utils-IoT\Utils-IoT.csproj", "{45837342-5906-4906-AB49-971767D9E180}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "M2Mqtt_4.7.1", "..\..\Librarys\mqtt\M2Mqtt\M2Mqtt_4.7.1.csproj", "{A11AEF5A-B246-4FE8-8330-06DB73CC8074}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "M2Mqtt", "..\..\Librarys\mqtt\M2Mqtt\M2Mqtt.csproj", "{05B829EF-6F4F-496D-8936-35D7F2179DF0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson_4.7.1", "..\..\Librarys\litjson\litjson\litjson_4.7.1.csproj", "{91A14CD2-2940-4500-8193-56D37EDDDBAA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "litjson", "..\..\Librarys\litjson\litjson\litjson.csproj", "{CA22D3E9-4195-453D-9CE0-3EBC672E6D06}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Utils", "..\Utils\Utils\Utils.csproj", "{19424C4A-D024-484A-BE65-09C7C529A2C4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -17,27 +19,31 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Release|Any CPU.Build.0 = Release|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.Build.0 = Release|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.Build.0 = Release|Any CPU
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.Build.0 = Release|Any CPU
{5D7A8892-6687-4FE2-85D1-12B49782EDF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D7A8892-6687-4FE2-85D1-12B49782EDF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D7A8892-6687-4FE2-85D1-12B49782EDF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D7A8892-6687-4FE2-85D1-12B49782EDF0}.Release|Any CPU.Build.0 = Release|Any CPU
{45837342-5906-4906-AB49-971767D9E180}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45837342-5906-4906-AB49-971767D9E180}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45837342-5906-4906-AB49-971767D9E180}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45837342-5906-4906-AB49-971767D9E180}.Release|Any CPU.Build.0 = Release|Any CPU
{05B829EF-6F4F-496D-8936-35D7F2179DF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{05B829EF-6F4F-496D-8936-35D7F2179DF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{05B829EF-6F4F-496D-8936-35D7F2179DF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{05B829EF-6F4F-496D-8936-35D7F2179DF0}.Release|Any CPU.Build.0 = Release|Any CPU
{CA22D3E9-4195-453D-9CE0-3EBC672E6D06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA22D3E9-4195-453D-9CE0-3EBC672E6D06}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA22D3E9-4195-453D-9CE0-3EBC672E6D06}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA22D3E9-4195-453D-9CE0-3EBC672E6D06}.Release|Any CPU.Build.0 = Release|Any CPU
{19424C4A-D024-484A-BE65-09C7C529A2C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19424C4A-D024-484A-BE65-09C7C529A2C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19424C4A-D024-484A-BE65-09C7C529A2C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19424C4A-D024-484A-BE65-09C7C529A2C4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B90F7B1F-FDD8-4B59-AAA5-218655C2716C}
SolutionGuid = {92985FD1-A967-4AE1-B2E0-5E938C0A7D6A}
EndGlobalSection
EndGlobal
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BlubbFish.Utils.IoT.Connector.Data</RootNamespace>
<AssemblyName>ConnectorDataMqtt</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Mqtt.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="..\CHANGELOG.md" />
<Content Include="..\CONTRIBUTING.md" />
<Content Include="..\LICENSE" />
<Content Include="..\README.md" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Librarys\mqtt\M2Mqtt\M2Mqtt_4.7.1.csproj">
<Project>{a11aef5a-b246-4fe8-8330-06db73cc8074}</Project>
<Name>M2Mqtt_4.7.1</Name>
</ProjectReference>
<ProjectReference Include="..\..\Utils-IoT\Utils-IoT\Utils-IoT.csproj">
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
<Name>Utils-IoT</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+35 -40
View File
@@ -1,51 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>BlubbFish.Utils.IoT.Connector.Data</RootNamespace>
<AssemblyName>ConnectorDataMqtt</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Company>BlubbFish</Company>
<Authors>BlubbFish</Authors>
<Version>1.4.0</Version>
<Copyright>Copyright © BlubbFish 2017 - 09.01.2022</Copyright>
<Description>ADataBackend Connector that connects to mqtt using M2Mqtt</Description>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageProjectUrl>http://git.blubbfish.net/vs_utils/ConnectorDataMqtt</PackageProjectUrl>
<RepositoryUrl>http://git.blubbfish.net/vs_utils/ConnectorDataMqtt.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>
1.4.0 Cleanup
1.3.0 Default netcore
1.2.0 Add netcore
1.1.0 Rewrite Module to reconnect itselfs, so you dont need to watch over the the state of the connection
1.0.0.0 Init
</PackageReleaseNotes>
<NeutralLanguage>de-DE</NeutralLanguage>
<PackageId>Mqtt.Data.Connector.IoT.Utils.BlubbFish</PackageId>
</PropertyGroup>
<ItemGroup>
<Compile Include="Mqtt.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<ProjectReference Include="..\..\..\Librarys\mqtt\M2Mqtt\M2Mqtt.csproj" />
<ProjectReference Include="..\..\Utils-IoT\Utils-IoT\Utils-IoT.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Librarys\mqtt\M2Mqtt\M2Mqtt_4.7.1.csproj">
<Project>{a11aef5a-b246-4fe8-8330-06db73cc8074}</Project>
<Name>M2Mqtt_4.7.1</Name>
</ProjectReference>
<ProjectReference Include="..\..\Utils-IoT\Utils-IoT\Utils-IoT.csproj">
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
<Name>Utils-IoT</Name>
</ProjectReference>
<Content Include="../CHANGELOG.md" />
<Content Include="../CONTRIBUTING.md" />
<Content Include="../LICENSE" />
<Content Include="../README.md" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<None Include="..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+58 -41
View File
@@ -11,9 +11,11 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
public class Mqtt : ADataBackend, IDisposable {
private MqttClient client;
private Thread connectionWatcher;
private Boolean connectionWatcherRunning;
private Boolean firstStart = true;
public Mqtt(Dictionary<String, String> settings) : base(settings) {
Console.WriteLine("BlubbFish.Utils.IoT.Connector.Data.Mqtt.Mqtt()");
Console.WriteLine("BlubbFish.Utils.IoT.Connector.Data.Mqtt(" + this.ToString()+")");
Int32 port = 1883;
if(this.settings.ContainsKey("port")) {
port = Int32.Parse(this.settings["port"]);
@@ -22,35 +24,59 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
this.ConnectionWatcher();
}
public override String ToString() {
String ret = "mqtt://";
if (this.settings.ContainsKey("user")) {
ret += this.settings["user"];
if (this.settings.ContainsKey("pass")) {
ret += ":" + this.settings["pass"];
}
ret += "@";
}
ret += this.settings["server"];
if (this.settings.ContainsKey("port")) {
ret += ":" + this.settings["port"];
}
if (this.settings.ContainsKey("topic")) {
ret += "/" + this.settings["topic"];
}
return ret;
}
#region ConectionManage
private void ConnectionWatcher() {
this.connectionWatcher = new Thread(this.ConnectionWatcherRunner);
this.connectionWatcherRunning = true;
this.connectionWatcher.Start();
}
private void ConnectionWatcherRunner() {
while(true) {
while(this.connectionWatcherRunning) {
try {
if(!this.IsConnected) {
this.Reconnect();
Thread.Sleep(1000);
}
Thread.Sleep(500);
Thread.Sleep(10);
} catch(Exception) { }
}
}
private void Reconnect() {
Console.WriteLine("BlubbFish.Utils.IoT.Connector.Data.Mqtt.Reconnect()");
if(this.IsConnected) {
this.Disconnect(true);
if(!this.firstStart) {
if(this.IsConnected) {
this.Disconnect(true);
} else {
this.Disconnect(false);
}
} else {
this.Disconnect(false);
this.firstStart = false;
}
this.Connect();
}
private void Disconnect(Boolean complete) {
Console.WriteLine("BlubbFish.Utils.IoT.Connector.Data.Mqtt.Disconnect()");
Console.WriteLine("BlubbFish.Utils.IoT.Connector.Data.Disconnect(" + this.ToString() + ")");
this.client.MqttMsgPublishReceived -= this.Client_MqttMsgPublishReceived;
this.Unsubscripe();
if(complete) {
@@ -59,25 +85,19 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
}
private void Connect() {
Console.WriteLine("BlubbFish.Utils.IoT.Connector.Data.Mqtt.Connect()");
Console.WriteLine("BlubbFish.Utils.IoT.Connector.Data.Connect(" + this.ToString() + ")");
this.client.MqttMsgPublishReceived += this.Client_MqttMsgPublishReceived;
if (this.settings.ContainsKey("user") && this.settings.ContainsKey("pass")) {
this.client.Connect(Guid.NewGuid().ToString(), this.settings["user"], this.settings["pass"]);
} else {
this.client.Connect(Guid.NewGuid().ToString());
}
_ = this.settings.ContainsKey("user") && this.settings.ContainsKey("pass")
? this.client.Connect(Guid.NewGuid().ToString(), this.settings["user"], this.settings["pass"])
: this.client.Connect(Guid.NewGuid().ToString());
this.Subscripe();
}
#endregion
#region Subscription
private void Unsubscripe() {
if(this.settings.ContainsKey("topic")) {
this.client.Unsubscribe(this.settings["topic"].Split(';'));
} else {
this.client.Unsubscribe(new String[] { "#" });
}
}
private void Unsubscripe() => _ = this.settings.ContainsKey("topic")
? this.client.Unsubscribe(this.settings["topic"].Split(';'))
: this.client.Unsubscribe(new String[] { "#" });
private void Subscripe() {
if(this.settings.ContainsKey("topic")) {
@@ -86,42 +106,39 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
for(Int32 i = 0; i < qos.Length; i++) {
qos[i] = MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE;
}
this.client.Subscribe(this.settings["topic"].Split(';'), qos);
_ = this.client.Subscribe(this.settings["topic"].Split(';'), qos);
} else {
this.client.Subscribe(new String[] { "#" }, new Byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
_ = this.client.Subscribe(new String[] { "#" }, new Byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
}
}
#endregion
private async void Client_MqttMsgPublishReceived(Object sender, MqttMsgPublishEventArgs e) => await Task.Run(() => {
this.NotifyClientIncomming(new DataEvent(Encoding.UTF8.GetString(e.Message), e.Topic, DateTime.Now));
});
private async void Client_MqttMsgPublishReceived(Object sender, MqttMsgPublishEventArgs e) => await Task.Run(() => this.NotifyClientIncomming(new DataEvent(Encoding.UTF8.GetString(e.Message), e.Topic, DateTime.Now)));
public override void Send(String topic, String data) {
this.client.Publish(topic, Encoding.UTF8.GetBytes(data));
_ = this.client.Publish(topic, Encoding.UTF8.GetBytes(data));
this.NotifyClientSending(new DataEvent(data, topic, DateTime.Now));
}
public void Send(String topic, Byte[] data) {
_ = this.client.Publish(topic, data);
this.NotifyClientSending(new DataEvent(Encoding.UTF8.GetString(data), topic, DateTime.Now));
}
#region IDisposable Support
private Boolean disposedValue = false;
public override Boolean IsConnected {
get {
if(this.client != null) {
return this.client.IsConnected;
} else {
return false;
}
}
}
public override Boolean IsConnected => this.client != null && this.client.IsConnected;
protected virtual void Dispose(Boolean disposing) {
if(!this.disposedValue) {
if(disposing) {try {
try {
this.connectionWatcher.Abort();
this.connectionWatcher = null;
} catch { }
if(disposing) {
try {
this.connectionWatcherRunning = false;
while(this.connectionWatcher != null && this.connectionWatcher.IsAlive) {
Thread.Sleep(10);
}
this.connectionWatcher = null;
this.Disconnect(true);
} catch (Exception) { }
}
+4 -2
View File
@@ -1,4 +1,5 @@
using System.Reflection;
#if !NETCOREAPP
using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices;
@@ -10,7 +11,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("BlubbFish")]
[assembly: AssemblyProduct("ConnectorDataMqtt")]
[assembly: AssemblyCopyright("Copyright © 2017 - 27.05.2019")]
[assembly: AssemblyCopyright("Copyright © BlubbFish 2017 - 27.05.2019")]
[assembly: AssemblyTrademark("© BlubbFish")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("de-DE")]
@@ -35,6 +36,7 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0")]
[assembly: AssemblyFileVersion("1.1.0")]
#endif
/*
* 1.1.0 Rewrite Module to reconnect itselfs, so you dont need to watch over the the state of the connection
+3 -1
View File
@@ -1,9 +1,11 @@
# BlubbFish.Utils.IoT.Connector.Data.Mqtt (ConnectorDataMqtt)
Library that connects to Mqtt using M2Mqtt
Maybe you find this Repo on Github. This is a mirror from [here](https://git.blubbfish.net/vs_utils/ConnectorDataMqtt).
## Linking to
### Internal
* BlubbFish.Utils.IoT ([Utils-IoT](http://git.blubbfish.net/vs_utils/Utils-IoT))
### External
* M2Mqtt
* M2Mqtt ([Used Fork](https://github.com/blubbfish/mqtt), [Original](https://github.com/eclipse/paho.mqtt.m2mqtt))