diff --git a/Lora-Bot/Lora-Bot.csproj b/Lora-Bot/Lora-Bot.csproj index 1575b1b..7221bfe 100644 --- a/Lora-Bot/Lora-Bot.csproj +++ b/Lora-Bot/Lora-Bot.csproj @@ -111,9 +111,6 @@ PreserveNewest - - PreserveNewest - \ No newline at end of file diff --git a/Lora-Bot/Moduls/Mqtt.cs b/Lora-Bot/Moduls/Mqtt.cs index aa2883e..35ca207 100644 --- a/Lora-Bot/Moduls/Mqtt.cs +++ b/Lora-Bot/Moduls/Mqtt.cs @@ -18,7 +18,7 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { protected override void Connect() { this.mqtt = ABackend.GetInstance(this.config["settings"], ABackend.BackendType.Data); - Console.WriteLine("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Mqtt.Connect()"); + Console.WriteLine("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Mqtt.Connect"); this.mqttconnect = true; } @@ -28,7 +28,7 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { this.mqtt.Dispose(); } this.mqtt = null; - Console.WriteLine("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Mqtt.Disconnect()"); + Console.WriteLine("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Mqtt.Disconnect"); } public override void EventLibSetter() { @@ -46,14 +46,14 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { topic = "lora/" + sensor.MqttTopic(); data = sensor.ToJson(); } - Console.WriteLine(topic); - Console.WriteLine(data); if (topic != "" && data != "") { ((ADataBackend)this.mqtt).Send(topic, data); this.Update?.Invoke(this, new MqttEvent(topic, data)); } } - } catch { } + } catch (Exception e) { + Helper.WriteError("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Mqtt.LibUpadteThread: " + e.Message); + } } } } diff --git a/Lora-Bot/Moduls/Scral.cs b/Lora-Bot/Moduls/Scral.cs index 7c8fbbc..c61e69d 100644 --- a/Lora-Bot/Moduls/Scral.cs +++ b/Lora-Bot/Moduls/Scral.cs @@ -16,8 +16,32 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { private readonly List nodes = new List(); public override event ModulEvent Update; private readonly Object getLock = new Object(); - private readonly String server = "https://portal.monica-cloud.eu/"; - public Scral(LoraController lib, InIReader settings) : base(lib, settings) { } + public Scral(LoraController lib, InIReader settings) : base(lib, settings) { + if(!this.config.ContainsKey("general")) { + throw new ArgumentException("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Scral: Config section [general] not exist"); + } + if(!this.config["general"].ContainsKey("server")) { + throw new ArgumentException("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Scral: In config section [general] value server not exist"); + } + if (!this.config.ContainsKey("update")) { + throw new ArgumentException("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Scral: Config section [update] not exist"); + } + if (!this.config["update"].ContainsKey("addr")) { + throw new ArgumentException("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Scral: In config section [update] value addr not exist"); + } + if (!this.config["update"].ContainsKey("method")) { + throw new ArgumentException("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Scral: In config section [update] value method not exist"); + } + if (!this.config.ContainsKey("register")) { + throw new ArgumentException("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Scral: Config section [register] not exist"); + } + if (!this.config["register"].ContainsKey("addr")) { + throw new ArgumentException("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Scral: In config section [register] value addr not exist"); + } + if (!this.config["register"].ContainsKey("method")) { + throw new ArgumentException("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Scral: In config section [register] value method not exist"); + } + } public override void EventLibSetter() { this.library.Update += this.HandleLibUpdate; @@ -28,11 +52,13 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { DeviceUpdateEvent e = state as DeviceUpdateEvent; LoraClient l = (LoraClient)e.Parent; if (!this.nodes.Contains(l.Name)) { - this.Register(l); + this.SendRegister(l); this.nodes.Add(l.Name); } this.SendUpdate(l); - } catch { } + } catch (Exception e) { + Helper.WriteError("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Scral.LibUpadteThread: " + e.Message); + } } private void SendUpdate(LoraClient l) { @@ -47,14 +73,20 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { { "herr", l.Gps.Hdop }, { "battery_level", l.Snr } }; - if(this.RequestString("scral/puetz/dexels/wearable/localization", JsonMapper.ToJson(d), false, RequestMethod.PUT) == null) { - this.Register(l); + try { + String addr = this.config["update"]["addr"]; + if (Enum.TryParse(this.config["update"]["method"], true, out RequestMethod meth)) { + this.RequestString(addr, JsonMapper.ToJson(d), false, meth); + this.Update?.Invoke(this, new BlubbFish.Utils.IoT.Bots.Events.ModulEventArgs(addr, meth.ToString(), JsonMapper.ToJson(d), "SCRAL")); + } + } catch (Exception e) { + Helper.WriteError("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Scral.SendUpdate: " + e.Message); + this.SendRegister(l); } - this.Update?.Invoke(this, new BlubbFish.Utils.IoT.Bots.Events.ModulEventArgs("scral/puetz/dexels/wearable/localization", "PUT", JsonMapper.ToJson(d), "SCRAL")); } } - private void Register(LoraClient l) { + private void SendRegister(LoraClient l) { Dictionary d = new Dictionary { { "device", "wearable" }, { "sensor", "tag" }, @@ -65,8 +97,15 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { { "observationType", "propietary" }, { "state", "active" } }; - this.RequestString("scral/puetz/dexels/wearable", JsonMapper.ToJson(d), false, RequestMethod.POST); - this.Update?.Invoke(this, new BlubbFish.Utils.IoT.Bots.Events.ModulEventArgs("scral/puetz/dexels/wearable", "POST", JsonMapper.ToJson(d), "SCRAL")); + try { + String addr = this.config["register"]["addr"]; + if (Enum.TryParse(this.config["register"]["method"], true, out RequestMethod meth)) { + this.RequestString(addr, JsonMapper.ToJson(d), false, meth); + this.Update?.Invoke(this, new BlubbFish.Utils.IoT.Bots.Events.ModulEventArgs(addr, meth.ToString(), JsonMapper.ToJson(d), "SCRAL")); + } + } catch (Exception e) { + Helper.WriteError("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Scral.SendRegister: " + e.Message); + } } public override void Dispose() { } @@ -77,8 +116,8 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { private String RequestString(String address, String json = "", Boolean withoutput = true, RequestMethod method = RequestMethod.GET) { String ret = null; lock (this.getLock) { - HttpWebRequest request = WebRequest.CreateHttp(this.server + address); - request.Timeout = 5000; + HttpWebRequest request = WebRequest.CreateHttp(this.config["general"]["server"] + address); + request.Timeout = 2000; if (method == RequestMethod.POST || method == RequestMethod.PUT) { Byte[] requestdata = Encoding.ASCII.GetBytes(json); request.ContentLength = requestdata.Length; @@ -100,9 +139,7 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { } } } catch (Exception e) { - Helper.WriteError("Konnte keine Verbindung zum Razzbery Server herstellen. Resource: \"" + this.server + address + "\" Fehler: " + e.Message); - return null; - //throw new Exceptions.ConnectionException("Konnte keine Verbindung zum Razzbery Server herstellen: " + e.Message); + throw new WebException("Error while uploading to Scal. Resource: \"" + this.config["general"]["server"] + address + "\" Method: " + method + " Data: " + json + " Fehler: " + e.Message); } } return ret; diff --git a/Lora-Bot/Moduls/Txtout.cs b/Lora-Bot/Moduls/Txtout.cs index ee8490d..d412182 100644 --- a/Lora-Bot/Moduls/Txtout.cs +++ b/Lora-Bot/Moduls/Txtout.cs @@ -1,26 +1,29 @@ -using System; -using System.IO; -using BlubbFish.Utils; -using BlubbFish.Utils.IoT.Bots.Events; -using BlubbFish.Utils.IoT.Bots.Moduls; -using Fraunhofer.Fit.Iot.Lora; -using Fraunhofer.Fit.Iot.Lora.Devices; -using Fraunhofer.Fit.Iot.Lora.Events; - -namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { - public class Txtout : AModul { - public override event ModulEvent Update; - - private readonly String filename; - private readonly StreamWriter file; - - public Txtout(LoraController lib, InIReader settings) : base(lib, settings) { - if (this.config.ContainsKey("general") && this.config["general"].ContainsKey("path")) { - this.filename = this.config["general"]["path"]; - this.file = new StreamWriter(this.filename, true); - } - } - +using System; +using System.IO; +using BlubbFish.Utils; +using BlubbFish.Utils.IoT.Bots.Events; +using BlubbFish.Utils.IoT.Bots.Moduls; +using Fraunhofer.Fit.Iot.Lora; +using Fraunhofer.Fit.Iot.Lora.Devices; +using Fraunhofer.Fit.Iot.Lora.Events; + +namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { + public class Txtout : AModul { + public override event ModulEvent Update; + + private readonly String filename; + private readonly StreamWriter file; + + public Txtout(LoraController lib, InIReader settings) : base(lib, settings) { + if (this.config.ContainsKey("general") && this.config["general"].ContainsKey("path")) { + this.filename = this.config["general"]["path"]; + this.file = new StreamWriter(this.filename, true); + } else { + throw new ArgumentException("Setting section [general] is missing or its value path"); + } + + } + public override void EventLibSetter() { this.library.Update += this.HandleLibUpdate; } @@ -35,13 +38,13 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { this.Update?.Invoke(this, new ModulEventArgs(this.filename, "Line", s, "TXTOUT")); } } catch { } - } - - public override void Dispose() { - this.file.Flush(); - this.file.Close(); - } - - protected override void UpdateConfig() {} - } + } + + public override void Dispose() { + this.file.Flush(); + this.file.Close(); + } + + protected override void UpdateConfig() {} + } } \ No newline at end of file diff --git a/Lora-Bot/Program.cs b/Lora-Bot/Program.cs index 64724c8..14f34b0 100644 --- a/Lora-Bot/Program.cs +++ b/Lora-Bot/Program.cs @@ -29,7 +29,7 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot { } private void LoraDataUpdate(Object sender, Iot.Lora.Events.DeviceUpdateEvent e) { - Console.WriteLine("-> Lora [" + e.UpdateTime + "]: " + e.Parent.ToString()); + Console.WriteLine("-> Lora " + e.Parent.ToString()); } } diff --git a/Lora-Bot/Properties/AssemblyInfo.cs b/Lora-Bot/Properties/AssemblyInfo.cs index 61d396e..3a9a3eb 100644 --- a/Lora-Bot/Properties/AssemblyInfo.cs +++ b/Lora-Bot/Properties/AssemblyInfo.cs @@ -32,9 +32,10 @@ using System.Runtime.InteropServices; // 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.2.0")] -[assembly: AssemblyFileVersion("1.2.0")] +[assembly: AssemblyVersion("1.3.0")] +[assembly: AssemblyFileVersion("1.3.0")] /* * 1.1.0 Update Scral addresses * 1.2.0 Run Module Events in threads so that one Module can not block others, TXTOut now appends to the logfile - */ \ No newline at end of file + * 1.3.0 Scral now get its config from configfile, lora now want to get battery as [0-9].[0-9]{2} value + */ diff --git a/Lora-Bot/bin/Release/Bot-Utils.dll b/Lora-Bot/bin/Release/Bot-Utils.dll index caf4664..eb7fd4b 100644 Binary files a/Lora-Bot/bin/Release/Bot-Utils.dll and b/Lora-Bot/bin/Release/Bot-Utils.dll differ diff --git a/Lora-Bot/bin/Release/ConnectorDataMqtt.dll b/Lora-Bot/bin/Release/ConnectorDataMqtt.dll index 03c5d80..cceb8e3 100644 Binary files a/Lora-Bot/bin/Release/ConnectorDataMqtt.dll and b/Lora-Bot/bin/Release/ConnectorDataMqtt.dll differ diff --git a/Lora-Bot/bin/Release/Iot-Interfaces.dll b/Lora-Bot/bin/Release/Iot-Interfaces.dll index 41ce76e..54db89b 100644 Binary files a/Lora-Bot/bin/Release/Iot-Interfaces.dll and b/Lora-Bot/bin/Release/Iot-Interfaces.dll differ diff --git a/Lora-Bot/bin/Release/Lora-Bot.exe b/Lora-Bot/bin/Release/Lora-Bot.exe index fe58cbf..2331adc 100644 Binary files a/Lora-Bot/bin/Release/Lora-Bot.exe and b/Lora-Bot/bin/Release/Lora-Bot.exe differ diff --git a/Lora-Bot/bin/Release/Lora.dll b/Lora-Bot/bin/Release/Lora.dll index 4ed71a7..c03e526 100644 Binary files a/Lora-Bot/bin/Release/Lora.dll and b/Lora-Bot/bin/Release/Lora.dll differ diff --git a/Lora-Bot/bin/Release/M2Mqtt.dll b/Lora-Bot/bin/Release/M2Mqtt.dll index d1a6c32..3f67f8c 100644 Binary files a/Lora-Bot/bin/Release/M2Mqtt.dll and b/Lora-Bot/bin/Release/M2Mqtt.dll differ diff --git a/Lora-Bot/bin/Release/Utils-IoT.dll b/Lora-Bot/bin/Release/Utils-IoT.dll index 454c6c6..2cd403e 100644 Binary files a/Lora-Bot/bin/Release/Utils-IoT.dll and b/Lora-Bot/bin/Release/Utils-IoT.dll differ diff --git a/Lora-Bot/bin/Release/Utils.dll b/Lora-Bot/bin/Release/Utils.dll index 39a51a9..f8b51d3 100644 Binary files a/Lora-Bot/bin/Release/Utils.dll and b/Lora-Bot/bin/Release/Utils.dll differ diff --git a/Lora-Bot/bin/Release/config-example/mqtt.conf.example b/Lora-Bot/bin/Release/config-example/mqtt.conf.example index 5477ead..7fdb045 100644 --- a/Lora-Bot/bin/Release/config-example/mqtt.conf.example +++ b/Lora-Bot/bin/Release/config-example/mqtt.conf.example @@ -1,4 +1,4 @@ -[modul] +[modul] config=private [settings] diff --git a/Lora-Bot/bin/Release/config-example/scral.conf.example b/Lora-Bot/bin/Release/config-example/scral.conf.example index 5477ead..63d4d9c 100644 --- a/Lora-Bot/bin/Release/config-example/scral.conf.example +++ b/Lora-Bot/bin/Release/config-example/scral.conf.example @@ -1,6 +1,13 @@ -[modul] +[modul] config=private -[settings] -type=mqtt -server=localhost +[general] +server=https://portal.monica-cloud.eu/ + +[update] +addr=scral/puetz/dexels/wearable/localization +method=put + +[register] +addr=scral/puetz/dexels/wearable +method=post diff --git a/Lora-Bot/bin/Release/config-example/settings.conf.example b/Lora-Bot/bin/Release/config-example/settings.conf.example index 9ee7bb3..e90da3f 100644 --- a/Lora-Bot/bin/Release/config-example/settings.conf.example +++ b/Lora-Bot/bin/Release/config-example/settings.conf.example @@ -1,8 +1,8 @@ -[logging] +[logging] path=/var/log/lorabot.log [lora] frequency=868100000 spreadingfactor=8 signalbandwith=125000 -codingrate=6 \ No newline at end of file +codingrate=6 diff --git a/Lora-Bot/bin/Release/config-example/txtout.conf.example b/Lora-Bot/bin/Release/config-example/txtout.conf.example index 5a41aad..89df7bf 100644 --- a/Lora-Bot/bin/Release/config-example/txtout.conf.example +++ b/Lora-Bot/bin/Release/config-example/txtout.conf.example @@ -1,2 +1,2 @@ -[general] -path=/home/pi/coords.txt \ No newline at end of file +[general] +path=/home/pi/coords.txt diff --git a/Lora-Bot/bin/Release/litjson.dll b/Lora-Bot/bin/Release/litjson.dll index 6fbbc76..693061f 100644 Binary files a/Lora-Bot/bin/Release/litjson.dll and b/Lora-Bot/bin/Release/litjson.dll differ diff --git a/Lora-Bot/bin/Release/lora.sh b/Lora-Bot/bin/Release/lora.sh deleted file mode 100644 index 394f67e..0000000 --- a/Lora-Bot/bin/Release/lora.sh +++ /dev/null @@ -1,5 +0,0 @@ -for(( ; ; )) -do - sudo mono --debug Lora-Bot.exe -done - \ No newline at end of file diff --git a/Lora-Bot/config-example/mqtt.conf.example b/Lora-Bot/config-example/mqtt.conf.example index 5477ead..7fdb045 100644 --- a/Lora-Bot/config-example/mqtt.conf.example +++ b/Lora-Bot/config-example/mqtt.conf.example @@ -1,4 +1,4 @@ -[modul] +[modul] config=private [settings] diff --git a/Lora-Bot/config-example/scral.conf.example b/Lora-Bot/config-example/scral.conf.example index 358a3ae..63d4d9c 100644 --- a/Lora-Bot/config-example/scral.conf.example +++ b/Lora-Bot/config-example/scral.conf.example @@ -1,2 +1,13 @@ -[modul] +[modul] config=private + +[general] +server=https://portal.monica-cloud.eu/ + +[update] +addr=scral/puetz/dexels/wearable/localization +method=put + +[register] +addr=scral/puetz/dexels/wearable +method=post diff --git a/Lora-Bot/config-example/settings.conf.example b/Lora-Bot/config-example/settings.conf.example index 9ee7bb3..e90da3f 100644 --- a/Lora-Bot/config-example/settings.conf.example +++ b/Lora-Bot/config-example/settings.conf.example @@ -1,8 +1,8 @@ -[logging] +[logging] path=/var/log/lorabot.log [lora] frequency=868100000 spreadingfactor=8 signalbandwith=125000 -codingrate=6 \ No newline at end of file +codingrate=6 diff --git a/Lora-Bot/config-example/txtout.conf.example b/Lora-Bot/config-example/txtout.conf.example index 5a41aad..89df7bf 100644 --- a/Lora-Bot/config-example/txtout.conf.example +++ b/Lora-Bot/config-example/txtout.conf.example @@ -1,2 +1,2 @@ -[general] -path=/home/pi/coords.txt \ No newline at end of file +[general] +path=/home/pi/coords.txt diff --git a/Lora-Bot/lora.sh b/Lora-Bot/lora.sh deleted file mode 100644 index 394f67e..0000000 --- a/Lora-Bot/lora.sh +++ /dev/null @@ -1,5 +0,0 @@ -for(( ; ; )) -do - sudo mono --debug Lora-Bot.exe -done - \ No newline at end of file