Skip to content

Commit

Permalink
Update for Lorabot
Browse files Browse the repository at this point in the history
  • Loading branch information
blubbfish committed Oct 29, 2018
1 parent 64cbe25 commit 8670c81
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 95 deletions.
6 changes: 6 additions & 0 deletions Lora-Bot/Lora-Bot.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartArguments>-freq 868100000 -sp 8 -bw 62500 -cr 6</StartArguments>
</PropertyGroup>
</Project>
18 changes: 6 additions & 12 deletions Lora-Bot/Moduls/Mqtt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,17 @@ protected override void Disconnect() {
}

public override void EventLibSetter() {
this.library.Update += this.HandleLibUpdate;
this.library.DataUpdate += this.HandleLibUpdate;
this.library.StatusUpdate += this.HandleLibUpdate;
}

protected override void LibUpadteThread(Object state) {
try {
if (this.mqttconnect) {
DeviceUpdateEvent e = state as DeviceUpdateEvent;
String topic = "";
String data = "";
if (e.Parent.GetType().HasInterface(typeof(IMqtt))) {
IMqtt sensor = (IMqtt)e.Parent;
topic = "lora/" + sensor.MqttTopic();
data = sensor.ToJson();
}
if (topic != "" && data != "") {
((ADataBackend)this.mqtt).Send(topic, data);
this.Update?.Invoke(this, new MqttEvent(topic, data));
if(state.GetType().HasInterface(typeof(IMqtt))) {
IMqtt sensor = state as IMqtt;
((ADataBackend)this.mqtt).Send("lora/" + sensor.MqttTopic(), sensor.ToJson());
this.Update?.Invoke(this, new MqttEvent("lora/" + sensor.MqttTopic(), sensor.ToJson()));
}
}
} catch (Exception e) {
Expand Down
38 changes: 19 additions & 19 deletions Lora-Bot/Moduls/Scral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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.Trackers;
using Fraunhofer.Fit.Iot.Lora.Events;
using LitJson;

Expand Down Expand Up @@ -44,34 +44,34 @@ public Scral(LoraController lib, InIReader settings) : base(lib, settings) {
}

public override void EventLibSetter() {
this.library.Update += this.HandleLibUpdate;
this.library.DataUpdate += this.HandleLibUpdate;
}

protected override void LibUpadteThread(Object state) {
try {
DeviceUpdateEvent e = state as DeviceUpdateEvent;
LoraClient l = (LoraClient)e.Parent;
if (!this.nodes.Contains(l.Name)) {
this.SendRegister(l);
this.nodes.Add(l.Name);
if (state is DataUpdateEvent data) {
if (!this.nodes.Contains(data.Name)) {
this.SendRegister(data);
this.nodes.Add(data.Name);
}
this.SendUpdate(data);
}
this.SendUpdate(l);
} catch (Exception e) {
Helper.WriteError("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Scral.LibUpadteThread: " + e.Message);
}
}

private void SendUpdate(LoraClient l) {
if (l.Gps.Fix) {
private void SendUpdate(DataUpdateEvent data) {
if (data.Gps.Fix) {
Dictionary<String, Object> d = new Dictionary<String, Object> {
{ "type", "uwb" },
{ "tagId", l.Name },
{ "tagId", data.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 }
{ "lat", data.Gps.Latitude },
{ "lon", data.Gps.Longitude },
{ "bearing", data.Rssi },
{ "herr", data.Gps.Hdop },
{ "battery_level", data.Snr }
};
try {
String addr = this.config["update"]["addr"];
Expand All @@ -81,17 +81,17 @@ private void SendUpdate(LoraClient l) {
}
} catch (Exception e) {
Helper.WriteError("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Scral.SendUpdate: " + e.Message);
this.SendRegister(l);
this.SendRegister(data);
}
}
}

private void SendRegister(LoraClient l) {
private void SendRegister(DataUpdateEvent data) {
Dictionary<String, Object> d = new Dictionary<String, Object> {
{ "device", "wearable" },
{ "sensor", "tag" },
{ "type", "uwb" },
{ "tagId", l.Name },
{ "tagId", data.Name },
{ "timestamp", DateTime.Now.ToString("o") },
{ "unitOfMeasurements", "meters" },
{ "observationType", "propietary" },
Expand Down
9 changes: 4 additions & 5 deletions Lora-Bot/Moduls/Txtout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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.Trackers;
using Fraunhofer.Fit.Iot.Lora.Events;

namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
Expand All @@ -25,14 +25,13 @@ public Txtout(LoraController lib, InIReader settings) : base(lib, settings) {
}

public override void EventLibSetter() {
this.library.Update += this.HandleLibUpdate;
this.library.DataUpdate += this.HandleLibUpdate;
}

protected override void LibUpadteThread(Object state) {
try {
DeviceUpdateEvent e = state as DeviceUpdateEvent;
if (e.Parent is LoraClient l) {
String s = l.Name + "," + l.Receivedtime.ToString("o") + "," + l.Gps.Latitude + "," + l.Gps.Longitude + ",https://www.google.de/maps?q=" + l.Gps.Latitude + "%2C" + l.Gps.Longitude + "," + l.Rssi + "," + l.PacketRssi + "," + l.Snr;
if(state is DataUpdateEvent data) {
String s = data.Name + "," + data.Receivedtime.ToString("o") + "," + data.Gps.Latitude + "," + data.Gps.Longitude + "," + data.Rssi + "," + data.PacketRssi + "," + data.Snr + ",https://www.google.de/maps?q=" + data.Gps.Latitude + "%2C" + data.Gps.Longitude;
this.file.WriteLine(s);
this.file.Flush();
this.Update?.Invoke(this, new ModulEventArgs(this.filename, "Line", s, "TXTOUT"));
Expand Down
59 changes: 41 additions & 18 deletions Lora-Bot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,56 @@
using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Bots;
using Fraunhofer.Fit.Iot.Lora;
using Fraunhofer.Fit.Iot.Lora.Events;

namespace Fraunhofer.Fit.IoT.Bots.LoraBot {
class Program : Bot<LoraController> {
static void Main(String[] args) => new Program(args);
public Program(String[] args) {
InIReader.SetSearchPath(new List<String>() { "/etc/lorabot", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\lorabot" });
if (!InIReader.ConfigExist("settings")) {
Helper.WriteError("No settings.ini found. Abord!");
return;
CmdArgs.Instance.SetArguments(new Dictionary<String, CmdArgs.VaildArguments>() {
{ "-freq", new CmdArgs.VaildArguments(CmdArgs.ArgLength.Touple) },
{ "-bw", new CmdArgs.VaildArguments(CmdArgs.ArgLength.Touple) },
{ "-sp", new CmdArgs.VaildArguments(CmdArgs.ArgLength.Touple) },
{ "-cr", new CmdArgs.VaildArguments(CmdArgs.ArgLength.Touple) },
}, args);
if (!CmdArgs.Instance.HasArgumentType("-freq") && !CmdArgs.Instance.HasArgumentType("-bw") && !CmdArgs.Instance.HasArgumentType("-sp") && !CmdArgs.Instance.HasArgumentType("-cr")) {
if (!InIReader.ConfigExist("settings")) {
Helper.WriteError("No settings.ini found. Abord!");
return;
}
InIReader settings = InIReader.GetInstance("settings");
this.logger.SetPath(settings.GetValue("logging", "path"));
LoraController lora = new LoraController(settings.GetSection("lora"));
this.ModulLoader("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls", lora);
this.ModulInterconnect();
this.ModulEvents();
lora.DataUpdate += this.LoraDataUpdate;
lora.StatusUpdate += this.LoraStatusUpdate;
this.WaitForShutdown();
Console.WriteLine("after wait");
this.ModulDispose();
Console.WriteLine("after dispose");
lora.Dispose();
Console.WriteLine("after loradisp");
} else if(CmdArgs.Instance.HasArgumentType("-freq") && CmdArgs.Instance.HasArgumentType("-bw") && CmdArgs.Instance.HasArgumentType("-sp") && CmdArgs.Instance.HasArgumentType("-cr")) {
LoraController lora = new LoraController(new Dictionary<String, String>() {
{ "frequency", CmdArgs.Instance.GetArgumentData("-freq") },
{ "signalbandwith", CmdArgs.Instance.GetArgumentData("-bw") },
{ "spreadingfactor", CmdArgs.Instance.GetArgumentData("-sp") },
{ "codingrate", CmdArgs.Instance.GetArgumentData("-cr") }
}, false);
} else {
Helper.WriteError("Usage for Debug:\n" + CmdArgs.Instance.GetUsageList("Lora-Bot"));
}
InIReader settings = InIReader.GetInstance("settings");
this.logger.SetPath(settings.GetValue("logging", "path"));
LoraController lora = new LoraController(settings.GetSection("lora"));
this.ModulLoader("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls", lora);
this.ModulInterconnect();
this.ModulEvents();
lora.Update += this.LoraDataUpdate;
this.WaitForShutdown();
Console.WriteLine("after wait");
this.ModulDispose();
Console.WriteLine("after dispose");
lora.Dispose();
Console.WriteLine("after loradisp");
}

private void LoraDataUpdate(Object sender, Iot.Lora.Events.DeviceUpdateEvent e) {
Console.WriteLine("-> Lora " + e.Parent.ToString());
private void LoraStatusUpdate(Object sender, StatusUpdateEvent e) {
Console.WriteLine("-> Lora-Status: " + e.ToString());
}

private void LoraDataUpdate(Object sender, DataUpdateEvent e) {
Console.WriteLine("-> Lora-Data: " + e.ToString());
}

}
Expand Down
85 changes: 45 additions & 40 deletions Lora-Bot/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
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("LoraDisplay")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LoraDisplay")]
[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("fb11b997-af4d-427f-96fd-4c84143057cf")]

// 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.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
* 1.3.0 Scral now get its config from configfile, lora now want to get battery as [0-9].[0-9]{2} value
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("LoraDisplay")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LoraDisplay")]
[assembly: AssemblyCopyright("Copyright © 2018 - 10.10.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("fb11b997-af4d-427f-96fd-4c84143057cf")]

// 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.6.0")]
[assembly: AssemblyFileVersion("1.6.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
* 1.3.0 Scral now get its config from configfile, lora now want to get battery as [0-9].[0-9]{2} value
* 1.4.0 Adding Debugmode for finetuning Lora-Trackers
* 1.4.1 Remove old Wirelesscode and Rename some Classes
* 1.5.0 Send over Mqtt the new status items and refactoring
* 1.5.1 Dependencies in debian Packet cleaned
* 1.6.0 Implement Height in LoraBot
*/
Binary file modified Lora-Bot/bin/Release/Bot-Utils.dll
Binary file not shown.
Binary file modified Lora-Bot/bin/Release/ConnectorDataMqtt.dll
Binary file not shown.
Binary file modified Lora-Bot/bin/Release/Iot-Interfaces.dll
Binary file not shown.
Binary file modified Lora-Bot/bin/Release/Lora-Bot.exe
Binary file not shown.
Binary file modified Lora-Bot/bin/Release/Lora.dll
Binary file not shown.
Binary file modified Lora-Bot/bin/Release/M2Mqtt.dll
Binary file not shown.
Binary file modified Lora-Bot/bin/Release/Utils-IoT.dll
Binary file not shown.
Binary file modified Lora-Bot/bin/Release/Utils.dll
Binary file not shown.
Binary file modified Lora-Bot/bin/Release/litjson.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Lora-Bot/dpkg/control
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Version: x.x-x
Section: base
Priority: optional
Architecture: any
Depends: mono-complete (>= 5.4.1.6)
Depends: mono-runtime (>= 5.16.0)
Maintainer: BlubbFish <[email protected]>
Description: Lora-Bot
Lora-Bot is a Lora gateway

0 comments on commit 8670c81

Please sign in to comment.