diff --git a/Lora-Bot/Lora-Bot.csproj b/Lora-Bot/Lora-Bot.csproj index dc41609..1575b1b 100644 --- a/Lora-Bot/Lora-Bot.csproj +++ b/Lora-Bot/Lora-Bot.csproj @@ -45,7 +45,6 @@ - @@ -86,6 +85,9 @@ Designer + + PreserveNewest + PreserveNewest @@ -95,6 +97,14 @@ PreserveNewest + + + + + + + + PreserveNewest @@ -105,9 +115,5 @@ PreserveNewest - - - - \ No newline at end of file diff --git a/Lora-Bot/Moduls/Googlelocation.cs b/Lora-Bot/Moduls/Googlelocation.cs deleted file mode 100644 index c463338..0000000 --- a/Lora-Bot/Moduls/Googlelocation.cs +++ /dev/null @@ -1,87 +0,0 @@ -/*using System; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Text; -using System.Threading; -using BlubbFish.Utils; -using BlubbFish.Utils.IoT.Bots.Moduls; -using Fraunhofer.Fit.Iot.Lora; -using Fraunhofer.Fit.Iot.Lora.Devices; -using LitJson; - -namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls_broken { - class Googlelocation : AModul { - private readonly HttpListener _listener = new HttpListener(); - private readonly Dictionary> locations = new Dictionary>(); - - public override event ModulEvent Update; - - public Googlelocation(LoraController lib, InIReader settings) : base(lib, settings) { - this._listener.Prefixes.Add("http://+:8080/"); - this._listener.Start(); - this.Run(); - } - - 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["google"]["api_key"]); - return file; - } - catch { return "500"; } - } - return "404"; - } - if(request.Url.PathAndQuery == "/loc") { - Dictionary ret = new Dictionary(); - foreach (KeyValuePair> devices in this.locations) { - Dictionary subret = new Dictionary(); - Int32 i = 0; - foreach (LoraClient item in devices.Value) { - subret.Add(i++.ToString(), item.ToDictionary()); - } - ret.Add(devices.Key, subret); - } - return JsonMapper.ToJson(ret); - } - return "

Works

"+ request.Url.PathAndQuery; - } - - public override void Dispose() { - this._listener.Stop(); - this._listener.Close(); - } - - protected override void UpdateConfig() { - } - - } -} -*/ \ No newline at end of file diff --git a/Lora-Bot/Moduls/Scral.cs b/Lora-Bot/Moduls/Scral.cs index e26ba80..7c8fbbc 100644 --- a/Lora-Bot/Moduls/Scral.cs +++ b/Lora-Bot/Moduls/Scral.cs @@ -1,16 +1,16 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Text; -using BlubbFish.Utils; -using BlubbFish.Utils.IoT.Bots; -using BlubbFish.Utils.IoT.Bots.Moduls; -using Fraunhofer.Fit.Iot.Lora; -using Fraunhofer.Fit.Iot.Lora.Devices; +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Text; +using BlubbFish.Utils; +using BlubbFish.Utils.IoT.Bots; +using BlubbFish.Utils.IoT.Bots.Moduls; +using Fraunhofer.Fit.Iot.Lora; +using Fraunhofer.Fit.Iot.Lora.Devices; using Fraunhofer.Fit.Iot.Lora.Events; -using LitJson; - +using LitJson; + namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { public class Scral : AModul { private readonly List nodes = new List(); @@ -33,40 +33,40 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { } this.SendUpdate(l); } catch { } - } - - private void SendUpdate(LoraClient l) { - if (l.Gps.Fix) { - Dictionary d = new Dictionary { - { "type", "uwb" }, - { "tagId", l.Name }, - { "timestamp", DateTime.Now.ToString("o") }, - { "lat", l.Gps.Latitude }, - { "lon", l.Gps.Longitude }, - { "bearing", l.Rssi }, - { "herr", l.Gps.Hdop }, - { "battery_level", l.Snr } - }; + } + + private void SendUpdate(LoraClient l) { + if (l.Gps.Fix) { + Dictionary d = new Dictionary { + { "type", "uwb" }, + { "tagId", l.Name }, + { "timestamp", DateTime.Now.ToString("o") }, + { "lat", l.Gps.Latitude }, + { "lon", l.Gps.Longitude }, + { "bearing", l.Rssi }, + { "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); - } - 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) { - Dictionary d = new Dictionary { - { "device", "wearable" }, - { "sensor", "tag" }, - { "type", "uwb" }, - { "tagId", l.Name }, - { "timestamp", DateTime.Now.ToString("o") }, - { "unitOfMeasurements", "meters" }, - { "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")); + } + 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) { + Dictionary d = new Dictionary { + { "device", "wearable" }, + { "sensor", "tag" }, + { "type", "uwb" }, + { "tagId", l.Name }, + { "timestamp", DateTime.Now.ToString("o") }, + { "unitOfMeasurements", "meters" }, + { "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")); } public override void Dispose() { } @@ -114,5 +114,5 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls { PUT } #endregion - } -} + } +} diff --git a/Lora-Bot/Properties/AssemblyInfo.cs b/Lora-Bot/Properties/AssemblyInfo.cs index 07f824a..61d396e 100644 --- a/Lora-Bot/Properties/AssemblyInfo.cs +++ b/Lora-Bot/Properties/AssemblyInfo.cs @@ -32,8 +32,9 @@ 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.1.0.0")] -[assembly: AssemblyFileVersion("1.1.0.0")] +[assembly: AssemblyVersion("1.2.0")] +[assembly: AssemblyFileVersion("1.2.0")] /* - * 1.1.0.0 Update Scral addresses + * 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 diff --git a/Lora-Bot/bin/Release/Bot-Utils.dll b/Lora-Bot/bin/Release/Bot-Utils.dll index 3bd46d5..caf4664 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 6779a24..03c5d80 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 1172216..41ce76e 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 1b8e182..fe58cbf 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 20afb71..4ed71a7 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 4d872de..d1a6c32 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 6d3a46e..454c6c6 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 3193878..39a51a9 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/scral.conf.example b/Lora-Bot/bin/Release/config-example/scral.conf.example new file mode 100644 index 0000000..5477ead --- /dev/null +++ b/Lora-Bot/bin/Release/config-example/scral.conf.example @@ -0,0 +1,6 @@ +[modul] +config=private + +[settings] +type=mqtt +server=localhost diff --git a/Lora-Bot/bin/Release/litjson.dll b/Lora-Bot/bin/Release/litjson.dll index fec89ca..6fbbc76 100644 Binary files a/Lora-Bot/bin/Release/litjson.dll and b/Lora-Bot/bin/Release/litjson.dll differ diff --git a/Lora-Bot/config-example/googlelocation.conf.example b/Lora-Bot/config-example/googlelocation.conf.example deleted file mode 100644 index d19d33a..0000000 --- a/Lora-Bot/config-example/googlelocation.conf.example +++ /dev/null @@ -1,2 +0,0 @@ -[google] -api_key = 12345345345673645 \ No newline at end of file diff --git a/Lora-Bot/config-example/scral.conf.example b/Lora-Bot/config-example/scral.conf.example new file mode 100644 index 0000000..358a3ae --- /dev/null +++ b/Lora-Bot/config-example/scral.conf.example @@ -0,0 +1,2 @@ +[modul] +config=private diff --git a/Lora-Bot/dpkg/control b/Lora-Bot/dpkg/control new file mode 100644 index 0000000..701aac3 --- /dev/null +++ b/Lora-Bot/dpkg/control @@ -0,0 +1,9 @@ +Package: lorabot +Version: x.x-x +Section: base +Priority: optional +Architecture: any +Depends: mono-complete (>= 5.4.1.6) +Maintainer: BlubbFish +Description: Lora-Bot + Lora-Bot is a Lora gateway diff --git a/Lora-Bot/dpkg/create-Builds.bat b/Lora-Bot/dpkg/create-Builds.bat new file mode 100644 index 0000000..9cc5846 --- /dev/null +++ b/Lora-Bot/dpkg/create-Builds.bat @@ -0,0 +1,2 @@ +bash.exe -c "./make-deb.sh armhf" +pause \ No newline at end of file diff --git a/Lora-Bot/dpkg/lorabot-logrotate b/Lora-Bot/dpkg/lorabot-logrotate new file mode 100644 index 0000000..6a70643 --- /dev/null +++ b/Lora-Bot/dpkg/lorabot-logrotate @@ -0,0 +1,10 @@ +/var/log/lorabot.log { + compress + copytruncate + daily + delaycompress + missingok + notifempty + rotate 4 + size=10M +} \ No newline at end of file diff --git a/Lora-Bot/dpkg/lorabot.service b/Lora-Bot/dpkg/lorabot.service new file mode 100644 index 0000000..d9e1000 --- /dev/null +++ b/Lora-Bot/dpkg/lorabot.service @@ -0,0 +1,20 @@ +# If you modify this, please also make sure to edit init.sh + +[Unit] +Description=Lora-Bot +After=network-online.target + +[Service] +User=root +Group=root +WorkingDirectory=/usr/local/bin/lorabot +ExecStart=/usr/bin/mono /usr/local/bin/lorabot/Lora-Bot.exe +KillMode=control-group +TimeoutStopSec=5 +Restart=on-failure +StandardOutput=null +StandardError=syslog + +[Install] +WantedBy=multi-user.target +Alias=lorabot.service diff --git a/Lora-Bot/dpkg/make-deb.sh b/Lora-Bot/dpkg/make-deb.sh new file mode 100644 index 0000000..15ae06b --- /dev/null +++ b/Lora-Bot/dpkg/make-deb.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +HOMEDIR="/home/blubb" +ROOT="$HOMEDIR/deb" +OUTPUT="../bin/Release" + +EXEC="$ROOT/usr/local/bin/lorabot" +CONFIG="$ROOT/etc/lorabot" +SYSTEMD="$ROOT/lib/systemd/system" +LOGROTATE="$ROOT/etc/logrotate.d" + +DEBIAN="$ROOT/DEBIAN" +VMAJOR=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 1) +VMINOR=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 2) +VBUILD=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 3) +ARCHT=$1 + +mkdir -p $EXEC +mkdir -p $CONFIG +mkdir -p $DEBIAN +mkdir -p $SYSTEMD +mkdir -p $LOGROTATE + +cp control $DEBIAN +cp preinst $DEBIAN +cp postinst $DEBIAN +cp prerm $DEBIAN +sed -i s/Version:\ x\.x-x/"Version: $VMAJOR.$VMINOR-$VBUILD"/ $DEBIAN/control +sed -i s/Architecture:\ any/"Architecture: $ARCHT"/ $DEBIAN/control +chmod 755 $DEBIAN -R + +cp lorabot.service $SYSTEMD +chmod 644 $SYSTEMD/lorabot.service + +cp $OUTPUT/*.exe $EXEC/ +cp $OUTPUT/gpio.2.44 $EXEC/ +cp $OUTPUT/libwiringPi.so.2.44 $EXEC/ +find $OUTPUT -name \*.dll ! -name Mono.Posix.dll -exec cp {} $EXEC/ \; +chmod 644 $EXEC/* +chmod 755 $EXEC + +cp $OUTPUT/config-example/* $CONFIG +chmod 644 $CONFIG/* +chmod 755 $CONFIG + +cp lorabot-logrotate $LOGROTATE/lorabot +chmod 644 $LOGROTATE/* + +dpkg-deb --build $ROOT +mv $HOMEDIR/deb.deb ../../../Builds/"$ARCHT-lorabot_$VMAJOR.$VMINOR-$VBUILD.deb" +rm $HOMEDIR/deb -r \ No newline at end of file diff --git a/Lora-Bot/dpkg/postinst b/Lora-Bot/dpkg/postinst new file mode 100644 index 0000000..6c792d0 --- /dev/null +++ b/Lora-Bot/dpkg/postinst @@ -0,0 +1,8 @@ +#!/bin/bash + +systemctl enable lorabot +systemctl daemon-reload +if [[ $(systemctl is-active lorabot || true) == "active" ]] +then + service lorabot restart +fi diff --git a/Lora-Bot/dpkg/preinst b/Lora-Bot/dpkg/preinst new file mode 100644 index 0000000..05a7907 --- /dev/null +++ b/Lora-Bot/dpkg/preinst @@ -0,0 +1,2 @@ +#!/bin/bash + diff --git a/Lora-Bot/dpkg/prerm b/Lora-Bot/dpkg/prerm new file mode 100644 index 0000000..886ae8b --- /dev/null +++ b/Lora-Bot/dpkg/prerm @@ -0,0 +1,3 @@ +#!/bin/bash + +service lorabot stop diff --git a/Lora-Bot/resources/google.html b/Lora-Bot/resources/google.html deleted file mode 100644 index 918ca16..0000000 --- a/Lora-Bot/resources/google.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - Google Map - - - -

Google Map

-
- - - - \ No newline at end of file