Change stuff
This commit is contained in:
parent
505ef0e627
commit
e4de8509a0
@ -13,6 +13,20 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unosquare.Swan.Lite", "..\L
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bot-Utils", "..\Utils\Bot-Utils\Bot-Utils\Bot-Utils.csproj", "{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Iot-Interfaces", "..\Utils\Iot-Interfaces\Iot-Interfaces\Iot-Interfaces.csproj", "{4DAADA29-C600-4CF3-8AD3-9C97C8D7F632}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "..\Utils\ConnectorDataMqtt\ConnectorDataMqtt\ConnectorDataMqtt.csproj", "{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}"
|
||||||
|
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
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Posix", "..\Librarys\Mono.Posix\Mono.Posix\Mono.Posix.csproj", "{E2CA132E-E85C-40AD-BE94-B138AA68772B}"
|
||||||
|
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}") = "Utils-IoT", "..\Utils\Utils-IoT\Utils-IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -39,6 +53,34 @@ Global
|
|||||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.Build.0 = Release|Any CPU
|
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{4DAADA29-C600-4CF3-8AD3-9C97C8D7F632}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4DAADA29-C600-4CF3-8AD3-9C97C8D7F632}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4DAADA29-C600-4CF3-8AD3-9C97C8D7F632}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4DAADA29-C600-4CF3-8AD3-9C97C8D7F632}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{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
|
||||||
|
{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
|
||||||
|
{E2CA132E-E85C-40AD-BE94-B138AA68772B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{E2CA132E-E85C-40AD-BE94-B138AA68772B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{E2CA132E-E85C-40AD-BE94-B138AA68772B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{E2CA132E-E85C-40AD-BE94-B138AA68772B}.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
|
||||||
|
{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
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Librarys\Rainbowdruino.cs" />
|
<Compile Include="Librarys\Rainbowdruino.cs" />
|
||||||
|
<Compile Include="Models\Measurings.cs" />
|
||||||
<Compile Include="System\ATwi.cs" />
|
<Compile Include="System\ATwi.cs" />
|
||||||
<Compile Include="Librarys\Bme280.cs" />
|
<Compile Include="Librarys\Bme280.cs" />
|
||||||
<Compile Include="Librarys\TSL2591.cs" />
|
<Compile Include="Librarys\TSL2591.cs" />
|
||||||
@ -51,6 +52,18 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\Librarys\litjson\litjson\litjson_4.7.1.csproj">
|
||||||
|
<Project>{91A14CD2-2940-4500-8193-56D37EDDDBAA}</Project>
|
||||||
|
<Name>litjson_4.7.1</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\..\Librarys\Mono.Posix\Mono.Posix\Mono.Posix.csproj">
|
||||||
|
<Project>{e2ca132e-e85c-40ad-be94-b138aa68772b}</Project>
|
||||||
|
<Name>Mono.Posix</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<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="..\..\Librarys\RaspberryIO\Unosquare.RaspberryIO\Unosquare.RaspberryIO.csproj">
|
<ProjectReference Include="..\..\Librarys\RaspberryIO\Unosquare.RaspberryIO\Unosquare.RaspberryIO.csproj">
|
||||||
<Project>{8C5D4DE9-377F-4EC8-873D-6EEF15F43516}</Project>
|
<Project>{8C5D4DE9-377F-4EC8-873D-6EEF15F43516}</Project>
|
||||||
<Name>Unosquare.RaspberryIO</Name>
|
<Name>Unosquare.RaspberryIO</Name>
|
||||||
@ -63,6 +76,22 @@
|
|||||||
<Project>{2ea5e3e4-f8c8-4742-8c78-4b070afcfb73}</Project>
|
<Project>{2ea5e3e4-f8c8-4742-8c78-4b070afcfb73}</Project>
|
||||||
<Name>Unosquare.Swan</Name>
|
<Name>Unosquare.Swan</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\..\Utils\Bot-Utils\Bot-Utils\Bot-Utils.csproj">
|
||||||
|
<Project>{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}</Project>
|
||||||
|
<Name>Bot-Utils</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\..\Utils\ConnectorDataMqtt\ConnectorDataMqtt\ConnectorDataMqtt.csproj">
|
||||||
|
<Project>{ee6c8f68-ed46-4c1c-abdd-cfcdf75104f2}</Project>
|
||||||
|
<Name>ConnectorDataMqtt</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\..\Utils\Iot-Interfaces\Iot-Interfaces\Iot-Interfaces.csproj">
|
||||||
|
<Project>{4DAADA29-C600-4CF3-8AD3-9C97C8D7F632}</Project>
|
||||||
|
<Name>Iot-Interfaces</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\..\Utils\Utils-IoT\Utils-IoT\Utils-IoT.csproj">
|
||||||
|
<Project>{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}</Project>
|
||||||
|
<Name>Utils-IoT</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\..\Utils\Utils\Utils\Utils.csproj">
|
<ProjectReference Include="..\..\Utils\Utils\Utils\Utils.csproj">
|
||||||
<Project>{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}</Project>
|
<Project>{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}</Project>
|
||||||
<Name>Utils</Name>
|
<Name>Utils</Name>
|
||||||
|
@ -42,6 +42,8 @@ namespace BlubbFish.Iot.Thermometer.Librarys {
|
|||||||
this.CalcHum(humidity);
|
this.CalcHum(humidity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose() => this.init = false;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Calculation
|
#region Calculation
|
||||||
|
@ -6,6 +6,7 @@ namespace BlubbFish.Iot.Thermometer.Librarys {
|
|||||||
class Rainbowdruino {
|
class Rainbowdruino {
|
||||||
private readonly SerialPort serial;
|
private readonly SerialPort serial;
|
||||||
private readonly UInt32[,] zbuffer = new UInt32[8, 16];
|
private readonly UInt32[,] zbuffer = new UInt32[8, 16];
|
||||||
|
private Boolean init = false;
|
||||||
|
|
||||||
private struct Digets {
|
private struct Digets {
|
||||||
public static readonly Boolean[][] Null = {
|
public static readonly Boolean[][] Null = {
|
||||||
@ -80,9 +81,20 @@ namespace BlubbFish.Iot.Thermometer.Librarys {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rainbowdruino(String com) {
|
|
||||||
this.serial = new SerialPort(com, 19200);
|
|
||||||
|
public Rainbowdruino(String com) => this.serial = new SerialPort(com, 19200);
|
||||||
|
|
||||||
|
public void Begin() {
|
||||||
|
if(!this.init) {
|
||||||
this.serial.Open();
|
this.serial.Open();
|
||||||
|
this.init = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
this.serial.Close();
|
||||||
|
this.init = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawDigets(String number, UInt32 color) {
|
public void DrawDigets(String number, UInt32 color) {
|
||||||
@ -125,6 +137,7 @@ namespace BlubbFish.Iot.Thermometer.Librarys {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Write() {
|
public void Write() {
|
||||||
|
if(this.init) {
|
||||||
this.Clear();
|
this.Clear();
|
||||||
List<UInt32> colors = this.GetAllColors();
|
List<UInt32> colors = this.GetAllColors();
|
||||||
foreach(UInt32 item in colors) {
|
foreach(UInt32 item in colors) {
|
||||||
@ -132,8 +145,13 @@ namespace BlubbFish.Iot.Thermometer.Librarys {
|
|||||||
}
|
}
|
||||||
this.ClearZbuffer();
|
this.ClearZbuffer();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Clear() => this.serial.Write("clear\n");
|
public void Clear() {
|
||||||
|
if(this.init) {
|
||||||
|
this.serial.Write("clear\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ClearZbuffer() {
|
private void ClearZbuffer() {
|
||||||
for(Int32 i = 0; i < 8; i++) {
|
for(Int32 i = 0; i < 8; i++) {
|
||||||
|
@ -31,6 +31,10 @@ namespace BlubbFish.Iot.Thermometer.Librarys {
|
|||||||
this.CalcLux(this.GetLumAdv(this.IntegrationAmplifier));
|
this.CalcLux(this.GetLumAdv(this.IntegrationAmplifier));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void Dispose() {
|
||||||
|
this.Disable();
|
||||||
|
this.init = false;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Calculation
|
#region Calculation
|
||||||
|
122
IotThermometer/Models/Measurings.cs
Normal file
122
IotThermometer/Models/Measurings.cs
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using BlubbFish.Utils.IoT.Interfaces;
|
||||||
|
using LitJson;
|
||||||
|
|
||||||
|
namespace BlubbFish.Iot.Thermometer.Models {
|
||||||
|
class Measurings : ISenml {
|
||||||
|
private Int32 updateCount = 0;
|
||||||
|
|
||||||
|
public delegate void UpdateDataEvent(Object sender, EventArgs e);
|
||||||
|
public event UpdateDataEvent DataUpdate;
|
||||||
|
|
||||||
|
public Double Temperatur { get; private set; }
|
||||||
|
public Double Humidity { get; private set; }
|
||||||
|
public Double Pressure { get; private set; }
|
||||||
|
public Double Lumiosity { get; private set; }
|
||||||
|
|
||||||
|
public String SenmlTopic() => "LS/v2/ZGW/linksmart-iot/senml";
|
||||||
|
public String ToSenml() {
|
||||||
|
Object[] json = new Object[] {new Dictionary<String, Object> {
|
||||||
|
{ "e", new Dictionary<String, Object>() {
|
||||||
|
{ "n", "temperatur" },
|
||||||
|
{ "u", "Cel" },
|
||||||
|
{ "t", 0 },
|
||||||
|
{ "v", this.Temperatur } } },
|
||||||
|
{ "bn", "iot" },
|
||||||
|
{ "bt", ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds() }
|
||||||
|
},new Dictionary<String, Object> {
|
||||||
|
{ "e", new Dictionary<String, Object>() {
|
||||||
|
{ "n", "humidity" },
|
||||||
|
{ "u", "%RH" },
|
||||||
|
{ "t", 0 },
|
||||||
|
{ "v", this.Humidity } } },
|
||||||
|
{ "bn", "iot" },
|
||||||
|
{ "bt", ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds() }
|
||||||
|
},new Dictionary<String, Object> {
|
||||||
|
{ "e", new Dictionary<String, Object>() {
|
||||||
|
{ "n", "pressure" },
|
||||||
|
{ "u", "Pa" },
|
||||||
|
{ "t", 0 },
|
||||||
|
{ "v", this.Pressure*100 } } },
|
||||||
|
{ "bn", "iot" },
|
||||||
|
{ "bt", ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds() }
|
||||||
|
},new Dictionary<String, Object> {
|
||||||
|
{ "e", new Dictionary<String, Object>() {
|
||||||
|
{ "n", "luminace" },
|
||||||
|
{ "u", "lx" },
|
||||||
|
{ "t", 0 },
|
||||||
|
{ "v", this.Temperatur } } },
|
||||||
|
{ "bn", "iot" },
|
||||||
|
{ "bt", ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds() }
|
||||||
|
} };
|
||||||
|
return JsonMapper.ToJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(Double temperatur, Double humidity, Double pressure, Double luminosity) {
|
||||||
|
this.updateCount++;
|
||||||
|
this.CheckTemp(temperatur);
|
||||||
|
this.CheckHum(humidity);
|
||||||
|
this.CheckPress(pressure);
|
||||||
|
this.CheckLumi(luminosity);
|
||||||
|
this.Temperatur = temperatur;
|
||||||
|
this.Humidity = humidity;
|
||||||
|
this.Pressure = pressure;
|
||||||
|
this.Lumiosity = luminosity;
|
||||||
|
if(this.updateCount > 60) {
|
||||||
|
this.updateCount = 0;
|
||||||
|
this.DataUpdate?.Invoke(this, new EventArgs());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckLumi(Double luminosity) {
|
||||||
|
Double diff = 0.5;
|
||||||
|
if(luminosity < 100 && this.Lumiosity < 100) {
|
||||||
|
diff = 1;
|
||||||
|
}
|
||||||
|
if(luminosity < 20 && this.Lumiosity < 20) {
|
||||||
|
diff = 2;
|
||||||
|
}
|
||||||
|
if(luminosity < 5 && this.Lumiosity < 5) {
|
||||||
|
diff = 4;
|
||||||
|
}
|
||||||
|
if(luminosity < 1 && this.Lumiosity < 1) {
|
||||||
|
diff = 10;
|
||||||
|
}
|
||||||
|
if(luminosity < 0.1 && this.Lumiosity < 0.1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(luminosity < this.Lumiosity && (100 - ((luminosity / this.Lumiosity) * 100)) > diff) {
|
||||||
|
this.updateCount = Int32.MaxValue;
|
||||||
|
}
|
||||||
|
if(luminosity > this.Lumiosity && (100 - ((this.Lumiosity / luminosity) * 100)) > diff) {
|
||||||
|
this.updateCount = Int32.MaxValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckPress(Double pressure) {
|
||||||
|
if(Math.Abs(this.Pressure - pressure) > 0.1) {
|
||||||
|
this.updateCount = Int32.MaxValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckHum(Double humidity) {
|
||||||
|
if(Math.Abs(this.Humidity - humidity) > 1) {
|
||||||
|
this.updateCount = Int32.MaxValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckTemp(Double temperatur) {
|
||||||
|
if(Math.Abs(this.Temperatur - temperatur) > 0.02) {
|
||||||
|
this.updateCount = Int32.MaxValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,38 +1,96 @@
|
|||||||
using System;
|
using System;
|
||||||
using BlubbFish.Iot.Thermometer.Librarys;
|
using BlubbFish.Iot.Thermometer.Librarys;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using BlubbFish.Utils.IoT.Bots;
|
||||||
|
using BlubbFish.Iot.Thermometer.Models;
|
||||||
|
using BlubbFish.Utils.IoT.Interfaces;
|
||||||
|
using BlubbFish.Utils.IoT.Connector;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace BlubbFish.Iot.Thermometer {
|
namespace BlubbFish.Iot.Thermometer {
|
||||||
class Program {
|
class Program : ABot {
|
||||||
private readonly TSL2591 tls;
|
private readonly TSL2591 tls = new TSL2591(0x29);
|
||||||
private readonly Bme280 bme;
|
private readonly Bme280 bme = new Bme280(0x76);
|
||||||
private readonly Rainbowdruino disp;
|
private readonly Rainbowdruino disp = new Rainbowdruino("/dev/ttyUSB0");
|
||||||
|
private readonly Measurings measurings = new Measurings();
|
||||||
|
private Thread measureThread;
|
||||||
|
private Thread displayThread;
|
||||||
|
private ADataBackend mqtt;
|
||||||
|
|
||||||
public Program(String[] args) {
|
public Program(String[] args) {
|
||||||
this.tls = new TSL2591(0x29);
|
this.Startup();
|
||||||
this.bme = new Bme280(0x76);
|
this.StartThreads();
|
||||||
this.disp = new Rainbowdruino("/dev/ttyUSB0");
|
this.WaitForShutdown();
|
||||||
this.tls.Begin();
|
this.Shutdown();
|
||||||
this.bme.Begin();
|
}
|
||||||
|
|
||||||
|
private void MeasureRunner() {
|
||||||
|
Console.WriteLine("Start Measure Runner...");
|
||||||
while(true) {
|
while(true) {
|
||||||
this.tls.Measure();
|
this.tls.Measure();
|
||||||
this.bme.Measure();
|
this.bme.Measure();
|
||||||
|
this.measurings.Update(this.bme.Temperatur, this.bme.Humidity, this.bme.Pressure, this.tls.Luminosity);
|
||||||
|
Thread.Sleep(780);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DispayRunner() {
|
||||||
|
Console.WriteLine("Start Display Runner...");
|
||||||
|
while(true) {
|
||||||
this.DrawDisp(this.bme.Temperatur, 0x110000);
|
this.DrawDisp(this.bme.Temperatur, 0x110000);
|
||||||
Thread.Sleep(5000);
|
Thread.Sleep(10000);
|
||||||
|
this.DrawDisp(this.bme.Temperatur, 0x110000);
|
||||||
|
Thread.Sleep(10000);
|
||||||
|
this.DrawDisp(this.bme.Temperatur, 0x110000);
|
||||||
|
Thread.Sleep(10000);
|
||||||
|
this.DrawDisp(this.bme.Temperatur, 0x110000);
|
||||||
|
Thread.Sleep(10000);
|
||||||
this.DrawDisp(this.bme.Humidity, 0x001100);
|
this.DrawDisp(this.bme.Humidity, 0x001100);
|
||||||
Thread.Sleep(2000);
|
Thread.Sleep(10000);
|
||||||
this.DrawDisp(this.bme.Pressure, 0x111100);
|
this.DrawDisp(this.bme.Pressure, 0x111100);
|
||||||
Thread.Sleep(2000);
|
Thread.Sleep(5000);
|
||||||
this.DrawDisp(this.tls.Luminosity, 0x000011);
|
this.DrawDisp(this.tls.Luminosity, 0x000011);
|
||||||
Thread.Sleep(2000);
|
Thread.Sleep(5000);
|
||||||
Console.WriteLine(this.tls.Luminosity.ToString("F5") + " lux");
|
Console.WriteLine(this.tls.Luminosity.ToString("F5") + " lux");
|
||||||
Console.WriteLine(this.bme.Temperatur.ToString("F2") + " °C");
|
Console.WriteLine(this.bme.Temperatur.ToString("F2") + " °C");
|
||||||
Console.WriteLine(this.bme.Pressure.ToString("F2") + " mbHp");
|
Console.WriteLine(this.bme.Pressure.ToString("F2") + " mbHp");
|
||||||
Console.WriteLine(this.bme.Humidity.ToString("F3") + " Hm%");
|
Console.WriteLine(this.bme.Humidity.ToString("F3") + " Hm%");
|
||||||
Console.WriteLine();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Shutdown() {
|
||||||
|
this.measureThread.Abort();
|
||||||
|
this.displayThread.Abort();
|
||||||
|
this.tls.Dispose();
|
||||||
|
this.bme.Dispose();
|
||||||
|
this.disp.Dispose();
|
||||||
|
this.measurings.Dispose();
|
||||||
|
base.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Startup() {
|
||||||
|
this.measurings.DataUpdate += this.SendSenml;
|
||||||
|
this.mqtt = (ADataBackend)ABackend.GetInstance(new Dictionary<String, String>() { { "type", "mqtt" }, { "server", "iot.blubbfish.net" } }, ABackend.BackendType.Data);
|
||||||
|
this.tls.Begin();
|
||||||
|
this.bme.Begin();
|
||||||
|
this.disp.Begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SendSenml(Object sender, EventArgs e) {
|
||||||
|
ISenml s = sender as ISenml;
|
||||||
|
String topic = s.SenmlTopic();
|
||||||
|
String data = s.ToSenml();
|
||||||
|
Console.WriteLine("MQTT: " + topic + " " + data);
|
||||||
|
this.mqtt.Send(topic, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartThreads() {
|
||||||
|
this.measureThread = new Thread(this.MeasureRunner);
|
||||||
|
this.measureThread.Start();
|
||||||
|
this.displayThread = new Thread(this.DispayRunner);
|
||||||
|
this.displayThread.Start();
|
||||||
|
}
|
||||||
|
|
||||||
private void DrawDisp(Double c, UInt32 color) {
|
private void DrawDisp(Double c, UInt32 color) {
|
||||||
this.disp.DrawDigets(c.ToString().Replace(",", "."), color);
|
this.disp.DrawDigets(c.ToString().Replace(",", "."), color);
|
||||||
this.disp.DrawLineX(0, 0, 16, color);
|
this.disp.DrawLineX(0, 0, 16, color);
|
||||||
|
Loading…
Reference in New Issue
Block a user