commit 3a1d3f27cc579ab0e2df70acba6c76956adc3b58 Author: BlubbFish Date: Sat Aug 11 23:10:30 2018 +0000 mqtt-map added diff --git a/mqtt-map.sln b/mqtt-map.sln new file mode 100644 index 0000000..acbfcb1 --- /dev/null +++ b/mqtt-map.sln @@ -0,0 +1,61 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27703.2026 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mqtt-map", "mqtt-map\mqtt-map.csproj", "{95D6F48A-9488-42A6-A973-941B45B26DB8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils\IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "..\Utils\IoT\Connector\Data\Mqtt\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}") = "M2Mqtt_4.7.1", "..\Librarys\mqtt\M2Mqtt\M2Mqtt_4.7.1.csproj", "{A11AEF5A-B246-4FE8-8330-06DB73CC8074}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bot-Utils", "..\Utils\Bot-Utils\Bot-Utils.csproj", "{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {95D6F48A-9488-42A6-A973-941B45B26DB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {95D6F48A-9488-42A6-A973-941B45B26DB8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {95D6F48A-9488-42A6-A973-941B45B26DB8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {95D6F48A-9488-42A6-A973-941B45B26DB8}.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 + {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 + {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 + {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 + {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.ActiveCfg = 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.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1534B636-9FC8-49BB-BB14-FC403ECDF889} + EndGlobalSection +EndGlobal diff --git a/mqtt-map/App.config b/mqtt-map/App.config new file mode 100644 index 0000000..4bba09a --- /dev/null +++ b/mqtt-map/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/mqtt-map/Googlelocation.cs b/mqtt-map/Googlelocation.cs new file mode 100644 index 0000000..b4539d5 --- /dev/null +++ b/mqtt-map/Googlelocation.cs @@ -0,0 +1,183 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Reflection; +using System.Text; +using System.Threading; +using BlubbFish.Utils.IoT.Bots; +using BlubbFish.Utils.IoT.Connector; +using BlubbFish.Utils.IoT.Events; +using LitJson; + +namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls_broken { + class Botclient { + + public Botclient(Int32 paketrssi, Int32 rssi, Double snr, String updatetime, Double lat, Double lon, Double hdop, Int32 sat, Boolean fix) { + this.PacketRssi = paketrssi; + this.Rssi = rssi; + this.Snr = snr; + this.Upatedtime = updatetime; + this.Latitude = lat; + this.Longitude = lon; + this.Hdop = hdop; + this.Satelites = sat; + this.Fix = fix; + } + + public Int32 PacketRssi { get; private set; } + public Int32 Rssi { get; private set; } + public Double Snr { get; private set; } + public String Upatedtime { get; private set; } + public Double Latitude { get; private set; } + public Double Longitude { get; private set; } + public Double Hdop { get; private set; } + public Int32 Satelites { get; private set; } + public Boolean Fix { get; private set; } + + public virtual Dictionary ToDictionary() { + Dictionary dictionary = new Dictionary(); + foreach (PropertyInfo item in this.GetType().GetProperties()) { + if (item.CanRead && item.GetValue(this) != null) { + if (item.GetValue(this).GetType().GetMethod("ToDictionary") != null) { + dictionary.Add(item.Name, item.GetValue(this).GetType().GetMethod("ToDictionary").Invoke(item.GetValue(this), null)); + } else if (item.GetValue(this).GetType().HasInterface(typeof(IDictionary))) { + Dictionary subdict = new Dictionary(); + foreach (DictionaryEntry subitem in (IDictionary)item.GetValue(this)) { + if (subitem.Value.GetType().GetMethod("ToDictionary") != null) { + subdict.Add(subitem.Key.ToString(), subitem.Value.GetType().GetMethod("ToDictionary").Invoke(subitem.Value, null)); + } + } + dictionary.Add(item.Name, subdict); + } else if (item.GetValue(this).GetType().BaseType == typeof(Enum)) { + dictionary.Add(item.Name, Helper.GetEnumDescription((Enum)item.GetValue(this))); + } else { + dictionary.Add(item.Name, item.GetValue(this)); + } + } + } + return dictionary; + } + } + + class Googlelocation { + private readonly HttpListener _listener = new HttpListener(); + private readonly Dictionary> locations = new Dictionary>(); + private readonly Dictionary config; + + public Googlelocation(ADataBackend backend, Dictionary settings) { + this.config = settings; + backend.MessageIncomming += this.Backend_MessageIncomming; + this._listener.Prefixes.Add("http://"+ this.config["prefix"] + ":8080/"); + this._listener.Start(); + this.Run(); + } + + private void Backend_MessageIncomming(Object sender, BackendEvent e) { + try { + JsonData d = JsonMapper.ToObject(e.Message); + if (d.ContainsKey("PacketRssi") && d["PacketRssi"].IsInt + && d.ContainsKey("Rssi") && d["Rssi"].IsInt + && d.ContainsKey("Snr") && d["Snr"].IsDouble + && d.ContainsKey("Upatedtime") && d["Upatedtime"].IsString + && d.ContainsKey("Gps") && d["Gps"].IsObject + && d["Gps"].ContainsKey("Breitengrad") && d["Gps"]["Breitengrad"].IsDouble + && d["Gps"].ContainsKey("Laengengrad") && d["Gps"]["Laengengrad"].IsDouble + && d["Gps"].ContainsKey("Hdop") && d["Gps"]["Hdop"].IsDouble + && d["Gps"].ContainsKey("Satelites") && d["Gps"]["Satelites"].IsInt + && d["Gps"].ContainsKey("Fix") && d["Gps"]["Fix"].IsBoolean + && d.ContainsKey("Name") && d["Name"].IsString) { + String name = (String)d["Name"]; + Botclient b = new Botclient((Int32)d["PacketRssi"], (Int32)d["Rssi"], (Double)d["Snr"], (String)d["Upatedtime"], (Double)d["Gps"]["Breitengrad"], (Double)d["Gps"]["Laengengrad"], (Double)d["Gps"]["Hdop"], (Int32)d["Gps"]["Satelites"], (Boolean)d["Gps"]["Fix"]); + if (b.Fix) { + if (this.locations.ContainsKey(name)) { + this.locations[name].Add(b); + } else { + this.locations.Add(name, new List { b }); + } + Console.WriteLine("Koodinate erhalten!"); + } else { + Console.WriteLine("Daten erhalten! (Kein Fix)"); + } + } + } catch { } + } + + private void Run() { + ThreadPool.QueueUserWorkItem((o) => { + Console.WriteLine("Webserver is Running..."); + try { + while(this._listener.IsListening) { + ThreadPool.QueueUserWorkItem((c) => { + HttpListenerContext ctx = c as HttpListenerContext; + try { + String rstr = this.SendResponse(ctx.Request); + Byte[] buf = Encoding.UTF8.GetBytes(rstr); + ctx.Response.ContentLength64 = buf.Length; + ctx.Response.OutputStream.Write(buf, 0, buf.Length); + } + catch { } + finally { + ctx.Response.OutputStream.Close(); + } + }, this._listener.GetContext()); + } + } + catch { }; + }); + } + + private String SendResponse(HttpListenerRequest request) { + if(request.Url.PathAndQuery == "/") { + if(File.Exists("resources/google.html")) { + try { + String file = File.ReadAllText("resources/google.html"); + file = file.Replace("{%YOUR_API_KEY%}", this.config["api_key"]); + file = file.Replace("{%REQUEST-PAGE%}", request.Url.Host); + return file; + } + catch { return "500"; } + } + return "404"; + } + if (request.Url.PathAndQuery.StartsWith("/loc?i=")) { + try { + String requeststrings = request.Url.PathAndQuery.Substring(7); + Dictionary requestquerys = new Dictionary(); + if (requeststrings.Length != 0) { + foreach (String requeststring in requeststrings.Split(';')) { + String[] item = requeststring.Split(':'); + requestquerys.Add(item[0], Int32.Parse(item[1])); + + } + } + Dictionary ret = new Dictionary(); + foreach (KeyValuePair> devices in this.locations) { + if(!requestquerys.ContainsKey(devices.Key) || (requestquerys.ContainsKey(devices.Key) && devices.Value.Count > requestquerys[devices.Key])) { + Int32 qindex = requestquerys.ContainsKey(devices.Key)?requestquerys[devices.Key]:0; + Dictionary subret = new Dictionary(); + Int32 i = 0; + List sub = devices.Value.GetRange(qindex, devices.Value.Count - qindex); + foreach (Botclient item in sub) { + subret.Add(i++.ToString(), item); + } + ret.Add(devices.Key, subret); + } + } + Console.WriteLine("Koordiante abgefragt!"); + return JsonMapper.ToJson(ret); + } catch { + return "{}"; + } + } + return "

Works

"+ request.Url.PathAndQuery; + } + + public void Dispose() { + this._listener.Stop(); + this._listener.Close(); + } + + } +} \ No newline at end of file diff --git a/mqtt-map/Program.cs b/mqtt-map/Program.cs new file mode 100644 index 0000000..5a29aa5 --- /dev/null +++ b/mqtt-map/Program.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using BlubbFish.Utils; +using BlubbFish.Utils.IoT.Connector; +using Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls_broken; + +namespace mqtt_map { + class Program { + static void Main(String[] args) { + if(!InIReader.ConfigExist("settings")) { + Console.WriteLine("settings.ini not found!"); + Console.ReadLine(); + return; + } + InIReader ini = InIReader.GetInstance("settings"); + ADataBackend b = (ADataBackend)ABackend.GetInstance(ini.GetSection("mqtt"), ABackend.BackendType.Data); + new Googlelocation(b, ini.GetSection("google")); + while(true) { + System.Threading.Thread.Sleep(1000); + } + } + } +} diff --git a/mqtt-map/Properties/AssemblyInfo.cs b/mqtt-map/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4eb317c --- /dev/null +++ b/mqtt-map/Properties/AssemblyInfo.cs @@ -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("mqtt-map")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("mqtt-map")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[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("95d6f48a-9488-42a6-a973-941b45b26db8")] + +// 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")] diff --git a/mqtt-map/app.manifest b/mqtt-map/app.manifest new file mode 100644 index 0000000..f21a980 --- /dev/null +++ b/mqtt-map/app.manifest @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mqtt-map/mqtt-map.csproj b/mqtt-map/mqtt-map.csproj new file mode 100644 index 0000000..1c26088 --- /dev/null +++ b/mqtt-map/mqtt-map.csproj @@ -0,0 +1,91 @@ + + + + + Debug + AnyCPU + {95D6F48A-9488-42A6-A973-941B45B26DB8} + Exe + mqtt_map + mqtt-map + v4.7.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + app.manifest + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + + + PreserveNewest + + + + + {91a14cd2-2940-4500-8193-56d37edddbaa} + litjson_4.7.1 + + + {a11aef5a-b246-4fe8-8330-06db73cc8074} + M2Mqtt_4.7.1 + + + {bb7bfcb5-3db0-49e1-802a-3ce3eecc59f9} + Bot-Utils + + + {ee6c8f68-ed46-4c1c-abdd-cfcdf75104f2} + ConnectorDataMqtt + + + {b870e4d5-6806-4a0b-b233-8907eedc5afc} + Utils-IoT + + + {fac8ce64-bf13-4ece-8097-aeb5dd060098} + Utils + + + + \ No newline at end of file diff --git a/mqtt-map/resources/google.html b/mqtt-map/resources/google.html new file mode 100644 index 0000000..9875956 --- /dev/null +++ b/mqtt-map/resources/google.html @@ -0,0 +1,102 @@ + + + + + + Google Map + + + +

Google Map

+
+ + + + + \ No newline at end of file diff --git a/mqtt-map/settings.conf.example b/mqtt-map/settings.conf.example new file mode 100644 index 0000000..eeed973 --- /dev/null +++ b/mqtt-map/settings.conf.example @@ -0,0 +1,7 @@ +[mqtt] +type=mqtt +server=127.0.0.1 + +[google] +api_key=abc +prefix=localhost \ No newline at end of file