Update for Lorabot

This commit is contained in:
BlubbFish 2018-10-29 22:35:18 +00:00
parent 64cbe250bc
commit 8670c8116f
16 changed files with 122 additions and 95 deletions

View File

@ -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>

View File

@ -32,23 +32,17 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
}
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) {

View File

@ -7,7 +7,7 @@ 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.Trackers;
using Fraunhofer.Fit.Iot.Lora.Events;
using LitJson;
@ -44,34 +44,34 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
}
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"];
@ -81,17 +81,17 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
}
} 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" },

View File

@ -4,7 +4,7 @@ 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.Trackers;
using Fraunhofer.Fit.Iot.Lora.Events;
namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
@ -25,14 +25,13 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
}
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"));

View File

@ -3,12 +3,20 @@ using System.Collections.Generic;
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" });
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;
@ -19,17 +27,32 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot {
this.ModulLoader("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls", lora);
this.ModulInterconnect();
this.ModulEvents();
lora.Update += this.LoraDataUpdate;
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"));
}
}
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());
}
}

View File

@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LoraDisplay")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyCopyright("Copyright © 2018 - 10.10.2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -32,10 +32,15 @@ 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.3.0")]
[assembly: AssemblyFileVersion("1.3.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 not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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 <dev@blubbfish.net>
Description: Lora-Bot
Lora-Bot is a Lora gateway