From 3b98e1878c3168459474e7efb3dac0f2e088d2c4 Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Tue, 29 Jan 2019 17:09:45 +0000 Subject: [PATCH] [v1.7.0] Add support for IC880A Board --- mqtt-map/Googlelocation.cs | 64 ++----------------- mqtt-map/Model/Botclient.cs | 56 ++++++++++++++++ mqtt-map/Program.cs | 5 +- mqtt-map/config-example/requests.conf.example | 5 +- mqtt-map/config-example/settings.conf.example | 3 +- mqtt-map/mqtt-map.csproj | 5 +- mqtt-map/resources/js/nav.js | 19 +++--- 7 files changed, 82 insertions(+), 75 deletions(-) create mode 100644 mqtt-map/Model/Botclient.cs diff --git a/mqtt-map/Googlelocation.cs b/mqtt-map/Googlelocation.cs index d4eba0d..319f1bb 100644 --- a/mqtt-map/Googlelocation.cs +++ b/mqtt-map/Googlelocation.cs @@ -1,70 +1,20 @@ 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; using BlubbFish.Utils.IoT.Bots; using BlubbFish.Utils.IoT.Connector; using BlubbFish.Utils.IoT.Events; +using Fraunhofer.Fit.IoT.MqttMap.Model; using LitJson; -namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls_broken { - class Botclient { +namespace Fraunhofer.Fit.IoT.MqttMap { - public Botclient(Int32 paketrssi, Int32 rssi, Double snr, String updatetime, Double lat, Double lon, Double hdop, Int32 battery, Boolean fix) { - this.PacketRssi = paketrssi; - this.Rssi = rssi; - this.Snr = snr; - this.Upatedtime = updatetime; - this.Latitude = lat; - this.Longitude = lon; - this.Hdop = hdop; - this.Battery = battery; - 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 Battery { 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 : Webserver { - private readonly Dictionary> locations = new Dictionary>(); + private readonly Dictionary locations = new Dictionary(); public Googlelocation(ADataBackend backend, Dictionary settings, InIReader requests) : base(backend, settings, requests) { } @@ -75,7 +25,7 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls_broken { && d.ContainsKey("Rssi") && d["Rssi"].IsInt && d.ContainsKey("Snr") && d["Snr"].IsDouble && d.ContainsKey("Receivedtime") && d["Receivedtime"].IsString - && d.ContainsKey("BatteryLevel") && d["BatteryLevel"].IsInt + && d.ContainsKey("BatteryLevel") && d["BatteryLevel"].IsDouble && d.ContainsKey("Gps") && d["Gps"].IsObject && d["Gps"].ContainsKey("Latitude") && d["Gps"]["Latitude"].IsDouble && d["Gps"].ContainsKey("Longitude") && d["Gps"]["Longitude"].IsDouble @@ -83,12 +33,12 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls_broken { && 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["Receivedtime"], (Double)d["Gps"]["Latitude"], (Double)d["Gps"]["Longitude"], (Double)d["Gps"]["Hdop"], (Int32)d["BatteryLevel"], (Boolean)d["Gps"]["Fix"]); + Botclient b = new Botclient((Int32)d["PacketRssi"], (Int32)d["Rssi"], (Double)d["Snr"], (String)d["Receivedtime"], (Double)d["Gps"]["Latitude"], (Double)d["Gps"]["Longitude"], (Double)d["Gps"]["Hdop"], (Double)d["BatteryLevel"], (Boolean)d["Gps"]["Fix"]); if (b.Fix) { if (this.locations.ContainsKey(name)) { - this.locations[name].Add(b); + this.locations[name] = b; } else { - this.locations.Add(name, new List { b }); + this.locations.Add(name,b); } Console.WriteLine("Koodinate erhalten!"); } else { diff --git a/mqtt-map/Model/Botclient.cs b/mqtt-map/Model/Botclient.cs new file mode 100644 index 0000000..eaee44e --- /dev/null +++ b/mqtt-map/Model/Botclient.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using BlubbFish.Utils; + +namespace Fraunhofer.Fit.IoT.MqttMap.Model { + class Botclient { + + public Botclient(Int32 paketrssi, Int32 rssi, Double snr, String updatetime, Double lat, Double lon, Double hdop, Double battery, Boolean fix) { + this.PacketRssi = paketrssi; + this.Rssi = rssi; + this.Snr = snr; + this.Upatedtime = updatetime; + this.Latitude = lat; + this.Longitude = lon; + this.Hdop = hdop; + this.Battery = battery; + 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 Double Battery { 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; + } + } +} diff --git a/mqtt-map/Program.cs b/mqtt-map/Program.cs index 0530400..9b60231 100644 --- a/mqtt-map/Program.cs +++ b/mqtt-map/Program.cs @@ -2,9 +2,8 @@ using System.Collections.Generic; using BlubbFish.Utils; using BlubbFish.Utils.IoT.Connector; -using Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls_broken; -namespace mqtt_map { +namespace Fraunhofer.Fit.IoT.MqttMap { class Program { static void Main(String[] args) { InIReader.SetSearchPath(new List() { "/etc/mqttmap", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mqttmap" }); @@ -20,7 +19,7 @@ namespace mqtt_map { } InIReader ini = InIReader.GetInstance("settings"); ADataBackend b = (ADataBackend)ABackend.GetInstance(ini.GetSection("mqtt"), ABackend.BackendType.Data); - new Googlelocation(b, ini.GetSection("google"), InIReader.GetInstance("requests")); + new Googlelocation(b, ini.GetSection("webserver"), InIReader.GetInstance("requests")); while(true) { System.Threading.Thread.Sleep(1000); } diff --git a/mqtt-map/config-example/requests.conf.example b/mqtt-map/config-example/requests.conf.example index b6ddc7c..9769295 100644 --- a/mqtt-map/config-example/requests.conf.example +++ b/mqtt-map/config-example/requests.conf.example @@ -1,2 +1,3 @@ -[index.html] -your_api_key=abc \ No newline at end of file +[js/nav.js] +your_api_key=abc +start_location=50.7, 7.2 \ No newline at end of file diff --git a/mqtt-map/config-example/settings.conf.example b/mqtt-map/config-example/settings.conf.example index f5ceafe..39be6d5 100644 --- a/mqtt-map/config-example/settings.conf.example +++ b/mqtt-map/config-example/settings.conf.example @@ -2,6 +2,5 @@ type=mqtt server=127.0.0.1 -[google] -api_key=abc +[webserver] prefix=http://+:8080/ \ No newline at end of file diff --git a/mqtt-map/mqtt-map.csproj b/mqtt-map/mqtt-map.csproj index c1bc6cb..e32d60e 100644 --- a/mqtt-map/mqtt-map.csproj +++ b/mqtt-map/mqtt-map.csproj @@ -6,8 +6,8 @@ AnyCPU {95D6F48A-9488-42A6-A973-941B45B26DB8} Exe - mqtt_map - mqtt-map + Fraunhofer.Fit.IoT.MqttMap + mqttmap v4.7.1 512 true @@ -46,6 +46,7 @@ + diff --git a/mqtt-map/resources/js/nav.js b/mqtt-map/resources/js/nav.js index 766b79d..a4c99a9 100644 --- a/mqtt-map/resources/js/nav.js +++ b/mqtt-map/resources/js/nav.js @@ -1,4 +1,4 @@ -var mymap = L.map('bigmap').setView([51.396851, 12.401617], 15); +var mymap = L.map('bigmap').setView([{%START_LOCATION%}], 14); L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', { attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox', @@ -16,16 +16,17 @@ function datarunner() { xhttp.open("GET", "http://{%REQUEST_URL_HOST%}:8080/loc", true); xhttp.send(); } - +//https://leafletjs.com/reference-1.4.0.html#marker function parsedata() { if (this.readyState == 4 && this.status == 200) { - var obj = JSON.parse(this.responseText); - for (var names in obj) { - if (obj.hasOwnProperty(names)) { - var markeritem = obj[names]; - - if (!markers.hasOwnProperty(names)) { - markers[names] = L.marker([51.396851, 12.401617]).addTo(mymap); + var items = JSON.parse(this.responseText); + for (var key in items) { + if (items.hasOwnProperty(key)) { + var markeritem = items[key]; + if (!markers.hasOwnProperty(key)) { + markers[key] = L.marker([markeritem['Latitude'], markeritem['Longitude']]).addTo(mymap); + } else { + markers[key].setLatLng([markeritem['Latitude'], markeritem['Longitude']]); } } }