Init of Snips
This commit is contained in:
parent
56a562bdc6
commit
e5957b47b8
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/.vs
|
||||
/Snips/bin
|
||||
/Snips/obj
|
61
Snips.sln
Normal file
61
Snips.sln
Normal file
@ -0,0 +1,61 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.28307.645
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Snips", "Snips\Snips.csproj", "{E32A1FC4-CF86-4DEA-8868-AC14BA4D1A85}"
|
||||
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
|
||||
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}") = "Mono.Posix", "..\Librarys\Mono.Posix\Mono.Posix\Mono.Posix.csproj", "{E2CA132E-E85C-40AD-BE94-B138AA68772B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils\Utils-IoT\Utils-IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "..\Utils\ConnectorDataMqtt\ConnectorDataMqtt\ConnectorDataMqtt.csproj", "{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{E32A1FC4-CF86-4DEA-8868-AC14BA4D1A85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E32A1FC4-CF86-4DEA-8868-AC14BA4D1A85}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E32A1FC4-CF86-4DEA-8868-AC14BA4D1A85}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E32A1FC4-CF86-4DEA-8868-AC14BA4D1A85}.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
|
||||
{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
|
||||
{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
|
||||
{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
|
||||
{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
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {3E7374AD-D5E2-4BD3-A37C-0BB057D34C25}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
28
Snips/DataInputs/EnvEsp8266.cs
Normal file
28
Snips/DataInputs/EnvEsp8266.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.Iot.Snips.DataInputs {
|
||||
public class EnvEsp8266 {
|
||||
public Double Humidity { get; private set; }
|
||||
public Double Lux { get; private set; }
|
||||
public Double Pressure { get; private set; }
|
||||
public Double Temperature { get; private set; }
|
||||
public String Name { get; private set; }
|
||||
|
||||
public EnvEsp8266(JsonData data) {
|
||||
this.Name = GetID(data);
|
||||
this.Update(data);
|
||||
}
|
||||
|
||||
internal static String GetID(JsonData data) => data["Name"].ToString();
|
||||
|
||||
internal void Update(JsonData data) {
|
||||
this.Humidity = (Double)data["Humidity"];
|
||||
this.Lux = (Double)data["Lux"];
|
||||
this.Pressure = (Double)data["Pressure"];
|
||||
this.Temperature = (Double)data["Temperature"];
|
||||
}
|
||||
|
||||
public override String ToString() => this.Name + " " + this.Temperature + "°C " + this.Humidity + "% " + this.Pressure + " mhP " + this.Lux + " Lux";
|
||||
}
|
||||
}
|
71
Snips/Helper/Texthelper.cs
Normal file
71
Snips/Helper/Texthelper.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlubbFish.Iot.Snips.Helper {
|
||||
public class Texthelper {
|
||||
public static Int32 ComputeLevenshteinDistance(String source, String target) {
|
||||
if((source == null) || (target == null)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if((source.Length == 0) || (target.Length == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(source == target) {
|
||||
return source.Length;
|
||||
}
|
||||
|
||||
Int32 sourceWordCount = source.Length;
|
||||
Int32 targetWordCount = target.Length;
|
||||
|
||||
// Step 1
|
||||
if(sourceWordCount == 0) {
|
||||
return targetWordCount;
|
||||
}
|
||||
|
||||
if(targetWordCount == 0) {
|
||||
return sourceWordCount;
|
||||
}
|
||||
|
||||
Int32[,] distance = new Int32[sourceWordCount + 1, targetWordCount + 1];
|
||||
|
||||
// Step 2
|
||||
for(Int32 i = 0; i <= sourceWordCount; distance[i, 0] = i++) { }
|
||||
|
||||
for(Int32 j = 0; j <= targetWordCount; distance[0, j] = j++) { }
|
||||
|
||||
for(Int32 i = 1; i <= sourceWordCount; i++) {
|
||||
for(Int32 j = 1; j <= targetWordCount; j++) {
|
||||
// Step 3
|
||||
Int32 cost = (target[j - 1] == source[i - 1]) ? 0 : 1;
|
||||
|
||||
// Step 4
|
||||
distance[i, j] = Math.Min(Math.Min(distance[i - 1, j] + 1, distance[i, j - 1] + 1), distance[i - 1, j - 1] + cost);
|
||||
}
|
||||
}
|
||||
|
||||
return distance[sourceWordCount, targetWordCount];
|
||||
}
|
||||
|
||||
public static Double CalculateSimilarity(String source, String target) {
|
||||
if((source == null) || (target == null)) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if((source.Length == 0) || (target.Length == 0)) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if(source == target) {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
Int32 stepsToSame = ComputeLevenshteinDistance(source, target);
|
||||
return (1.0 - (stepsToSame / (Double)Math.Max(source.Length, target.Length)));
|
||||
}
|
||||
}
|
||||
}
|
33
Snips/Intents/AEspIntent.cs
Normal file
33
Snips/Intents/AEspIntent.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BlubbFish.Iot.Snips.DataInputs;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.Iot.Snips.Intents {
|
||||
abstract public class AEspIntent : AIntent {
|
||||
protected readonly Dictionary<String, EnvEsp8266> esps;
|
||||
protected String espid = null;
|
||||
|
||||
protected AEspIntent(JsonData data, ABackend snips, Dictionary<String, EnvEsp8266> esps) : base(data, snips) => this.esps = esps;
|
||||
|
||||
public override void Parse() {
|
||||
String ort = this.slots["ort"];
|
||||
String mort = "ESP8266-" + ort;
|
||||
Dictionary<String, Double> goal = new Dictionary<String, Double>();
|
||||
foreach(KeyValuePair<String, EnvEsp8266> item in this.esps) {
|
||||
goal.Add(item.Key, Helper.Texthelper.CalculateSimilarity(mort.ToLower(), item.Key.ToLower()));
|
||||
}
|
||||
if(goal.Count > 0) {
|
||||
KeyValuePair<String, Double> t = goal.First();
|
||||
foreach(KeyValuePair<String, Double> move in goal) {
|
||||
if(move.Value > t.Value) {
|
||||
t = move;
|
||||
}
|
||||
}
|
||||
this.espid = t.Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
49
Snips/Intents/AIntent.cs
Normal file
49
Snips/Intents/AIntent.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.Iot.Snips.Intents {
|
||||
public abstract class AIntent {
|
||||
protected readonly JsonData data;
|
||||
private readonly ABackend snips;
|
||||
protected readonly Dictionary<String, String> slots = new Dictionary<String, String>();
|
||||
|
||||
protected AIntent(JsonData data, ABackend snips) {
|
||||
this.data = data;
|
||||
this.snips = snips;
|
||||
this.ParseSlots();
|
||||
}
|
||||
|
||||
private void ParseSlots() {
|
||||
foreach(JsonData item in this.data["slots"]) {
|
||||
this.slots.Add(item["slotName"].ToString(), item["value"]["value"].ToString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void SnipsSay(String text) => ((ADataBackend)this.snips).Send("hermes/tts/say",
|
||||
JsonMapper.ToJson(
|
||||
new Dictionary<String, Object> {
|
||||
{ "id",this.data["id"].ToString() },
|
||||
{ "lang","de" },
|
||||
{ "sessionId", this.data["sessionId"].ToString() },
|
||||
{ "siteId","default" },
|
||||
{ "text",text }
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
protected void SnipsEndSpeak() => ((ADataBackend)this.snips).Send("hermes/tts/sayFinished",
|
||||
JsonMapper.ToJson(
|
||||
new Dictionary<String, Object> {
|
||||
{ "id", this.data["id"].ToString() },
|
||||
{ "sessionId", this.data["sessionId"].ToString() }
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
public abstract void Parse();
|
||||
|
||||
public abstract void Answer();
|
||||
}
|
||||
}
|
21
Snips/Intents/GetHum.cs
Normal file
21
Snips/Intents/GetHum.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.Iot.Snips.DataInputs;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.Iot.Snips.Intents {
|
||||
public class GetHum : AEspIntent {
|
||||
public GetHum(JsonData data, ABackend snips, Dictionary<String, EnvEsp8266> esps) : base(data, snips, esps) {
|
||||
}
|
||||
|
||||
public override void Answer() {
|
||||
if(this.espid != null) {
|
||||
this.SnipsSay("Die Luftfeuchtigkeit beträgt " + this.esps[this.espid].Humidity + " Prozent relative Luftfeuchtigkeit im " + this.slots["ort"] + " !");
|
||||
} else {
|
||||
this.SnipsSay("Ich habe bisher keine Sensordaten erhalten!");
|
||||
}
|
||||
this.SnipsEndSpeak();
|
||||
}
|
||||
}
|
||||
}
|
21
Snips/Intents/GetTemp.cs
Normal file
21
Snips/Intents/GetTemp.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.Iot.Snips.DataInputs;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.Iot.Snips.Intents {
|
||||
class GetTemp : AEspIntent {
|
||||
public GetTemp(JsonData data, ABackend snips, Dictionary<String, EnvEsp8266> esps) : base(data, snips, esps) {
|
||||
}
|
||||
|
||||
public override void Answer() {
|
||||
if(this.espid != null) {
|
||||
this.SnipsSay("Im " + this.slots["ort"] + " ist es " + this.esps[this.espid].Temperature + " Grad "+this.slots["feel"]+"!");
|
||||
} else {
|
||||
this.SnipsSay("Ich habe bisher keine Sensordaten erhalten!");
|
||||
}
|
||||
this.SnipsEndSpeak();
|
||||
}
|
||||
}
|
||||
}
|
65
Snips/Intents/Wetter.cs
Normal file
65
Snips/Intents/Wetter.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.Iot.Snips.Intents {
|
||||
public class Wetter : AIntent {
|
||||
private String wetterText;
|
||||
|
||||
public Wetter(JsonData data, ABackend snips) : base(data, snips) {
|
||||
}
|
||||
|
||||
public override void Answer() {
|
||||
this.SnipsSay("Die Wettervorhersage für NRW Lautet:");
|
||||
this.SnipsSay(this.wetterText);
|
||||
this.SnipsEndSpeak();
|
||||
}
|
||||
public override void Parse() {
|
||||
String html = null;
|
||||
String url = "https://opendata.dwd.de/weather/text_forecasts/txt/";
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
|
||||
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
|
||||
using(Stream stream = response.GetResponseStream())
|
||||
using(StreamReader reader = new StreamReader(stream)) {
|
||||
html = reader.ReadToEnd();
|
||||
}
|
||||
if(html != null) {
|
||||
String file = null;
|
||||
MatchCollection m = new Regex("\"(.*VHDL13_DWEH_([0-9]{6}).*)\"").Matches(html);
|
||||
if(m.Count > 1) {
|
||||
Int32 d = Int32.Parse(m[0].Groups[2].Value);
|
||||
file = m[0].Groups[1].Value;
|
||||
foreach(Match item in m) {
|
||||
if(d < Int32.Parse(item.Groups[2].Value)) {
|
||||
file = item.Groups[1].Value;
|
||||
}
|
||||
}
|
||||
} else if(m.Count == 1) {
|
||||
file = m[0].Groups[1].Value;
|
||||
}
|
||||
String wetter = null;
|
||||
String urlw = "https://opendata.dwd.de/weather/text_forecasts/txt/"+ file;
|
||||
|
||||
HttpWebRequest requestw = (HttpWebRequest)WebRequest.Create(urlw);
|
||||
Byte[] buffer;
|
||||
using(HttpWebResponse response = (HttpWebResponse)requestw.GetResponse())
|
||||
using(Stream stream = response.GetResponseStream())
|
||||
using(MemoryStream memstream = new MemoryStream()) {
|
||||
stream.CopyTo(memstream);
|
||||
buffer = memstream.ToArray();
|
||||
}
|
||||
wetter = Encoding.UTF8.GetString(Encoding.Convert(Encoding.GetEncoding(1252), Encoding.UTF8, buffer));
|
||||
wetter = wetter.Replace("\r\r\n", "\n");
|
||||
Int32 start = wetter.IndexOf("\n\n")+2;
|
||||
Int32 end = wetter.IndexOf("Detaillierter Wetterablauf") - start;
|
||||
this.wetterText = wetter.Substring(start, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
18
Snips/Program.cs
Normal file
18
Snips/Program.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
|
||||
namespace BlubbFish.Iot.Snips {
|
||||
class Program {
|
||||
public Program(String[] args) {
|
||||
Dictionary<String, ABackend> sources = new Dictionary<String, ABackend> {
|
||||
{ "snips", ABackend.GetInstance(new Dictionary<String, String> { { "type", "mqtt" }, { "server", "10.100.0.34" }, { "topic", "hermes/nlu/intentParsed" } }, ABackend.BackendType.Data) },
|
||||
{ "iot", ABackend.GetInstance(new Dictionary<String, String> { { "type", "mqtt" }, { "server", "iot.blubbfish.net" }, { "topic", "esp8266/sensor/+" } }, ABackend.BackendType.Data) }
|
||||
};
|
||||
SnipsBot s = new SnipsBot(sources, new Dictionary<String, String> { { "logger", "out.log" } });
|
||||
s.Dispose();
|
||||
}
|
||||
|
||||
static void Main(String[] args) => new Program(args);
|
||||
}
|
||||
}
|
36
Snips/Properties/AssemblyInfo.cs
Normal file
36
Snips/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die einer Assembly zugeordnet sind.
|
||||
[assembly: AssemblyTitle("Snips")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Snips")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("e32a1fc4-cf86-4dea-8868-ac14ba4d1a85")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
81
Snips/Snips.csproj
Normal file
81
Snips/Snips.csproj
Normal file
@ -0,0 +1,81 @@
|
||||
<?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>{E32A1FC4-CF86-4DEA-8868-AC14BA4D1A85}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>BlubbFish.Iot.Snips</RootNamespace>
|
||||
<AssemblyName>Snips</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<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' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DataInputs\EnvEsp8266.cs" />
|
||||
<Compile Include="Helper\Texthelper.cs" />
|
||||
<Compile Include="Intents\AEspIntent.cs" />
|
||||
<Compile Include="Intents\AIntent.cs" />
|
||||
<Compile Include="Intents\GetHum.cs" />
|
||||
<Compile Include="Intents\GetTemp.cs" />
|
||||
<Compile Include="Intents\Wetter.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SnipsBot.cs" />
|
||||
</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\mqtt\M2Mqtt\M2Mqtt_4.7.1.csproj">
|
||||
<Project>{A11AEF5A-B246-4FE8-8330-06DB73CC8074}</Project>
|
||||
<Name>M2Mqtt_4.7.1</Name>
|
||||
</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\Utils-IoT\Utils-IoT\Utils-IoT.csproj">
|
||||
<Project>{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}</Project>
|
||||
<Name>Utils-IoT</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
61
Snips/SnipsBot.cs
Normal file
61
Snips/SnipsBot.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.Iot.Snips.DataInputs;
|
||||
using BlubbFish.Iot.Snips.Intents;
|
||||
using BlubbFish.Utils.IoT.Bots;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using BlubbFish.Utils.IoT.Events;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.Iot.Snips {
|
||||
class SnipsBot : MultiSourceBot {
|
||||
private readonly Boolean debug = true;
|
||||
private readonly Dictionary<String, EnvEsp8266> esps = new Dictionary<String, EnvEsp8266>();
|
||||
|
||||
public SnipsBot(Dictionary<String, ABackend> sources, Dictionary<String, String> settings) : base(sources, settings) {
|
||||
this.sources["snips"].MessageIncomming += this.IntentWorker;
|
||||
this.sources["iot"].MessageIncomming += this.GetEspData;
|
||||
this.WaitForShutdown();
|
||||
}
|
||||
|
||||
private void IntentWorker(Object sender, BackendEvent e) {
|
||||
try {
|
||||
JsonData data = JsonMapper.ToObject(e.Message);
|
||||
AIntent intent = null;
|
||||
if(data["intent"]["intentName"].ToString() == "blubbfish:GetTemp") {
|
||||
intent = new GetTemp(data, this.sources["snips"], this.esps);
|
||||
} else if(data["intent"]["intentName"].ToString() == "blubbfish:GetHum") {
|
||||
intent = new GetHum(data, this.sources["snips"], this.esps);
|
||||
} else if(data["intent"]["intentName"].ToString() == "blubbfish:Wetter") {
|
||||
intent = new Wetter(data, this.sources["snips"]);
|
||||
}
|
||||
if(intent != null) {
|
||||
intent.Parse();
|
||||
intent.Answer();
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
|
||||
private void GetEspData(Object sender, BackendEvent e) {
|
||||
try {
|
||||
JsonData data = JsonMapper.ToObject(e.Message);
|
||||
String name = EnvEsp8266.GetID(data);
|
||||
if(this.esps.ContainsKey(name)) {
|
||||
this.esps[name].Update(data);
|
||||
} else {
|
||||
this.esps.Add(name, new EnvEsp8266(data));
|
||||
}
|
||||
if(this.debug) {
|
||||
Console.WriteLine("Get data: " + this.esps[name]);
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
foreach(KeyValuePair<String, ABackend> item in this.sources) {
|
||||
item.Value.Dispose();
|
||||
}
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user