Lora-Bot 1.3.0 Scral now get its config from configfile, make the GW more stable

Lora 1.1.0 Now awaiing Battery as Double and fix the sending twise issue
This commit is contained in:
BlubbFish 2018-09-13 22:02:07 +00:00
parent c3ab7b897b
commit 64cbe250bc
25 changed files with 130 additions and 84 deletions

View File

@ -111,9 +111,6 @@
<None Include="libwiringPi.so.2.44">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="lora.sh">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -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);
}
}
}
}

View File

@ -16,8 +16,32 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
private readonly List<String> nodes = new List<String>();
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<String, Object> d = new Dictionary<String, Object> {
{ "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;

View File

@ -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<LoraController> {
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<LoraController> {
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() {}
}
}

View File

@ -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());
}
}

View File

@ -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
*/
* 1.3.0 Scral now get its config from configfile, lora now want to get battery as [0-9].[0-9]{2} value
*/

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

@ -1,4 +1,4 @@
[modul]
[modul]
config=private
[settings]

View File

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

View File

@ -1,8 +1,8 @@
[logging]
[logging]
path=/var/log/lorabot.log
[lora]
frequency=868100000
spreadingfactor=8
signalbandwith=125000
codingrate=6
codingrate=6

View File

@ -1,2 +1,2 @@
[general]
path=/home/pi/coords.txt
[general]
path=/home/pi/coords.txt

Binary file not shown.

View File

@ -1,5 +0,0 @@
for(( ; ; ))
do
sudo mono --debug Lora-Bot.exe
done

View File

@ -1,4 +1,4 @@
[modul]
[modul]
config=private
[settings]

View File

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

View File

@ -1,8 +1,8 @@
[logging]
[logging]
path=/var/log/lorabot.log
[lora]
frequency=868100000
spreadingfactor=8
signalbandwith=125000
codingrate=6
codingrate=6

View File

@ -1,2 +1,2 @@
[general]
path=/home/pi/coords.txt
[general]
path=/home/pi/coords.txt

View File

@ -1,5 +0,0 @@
for(( ; ; ))
do
sudo mono --debug Lora-Bot.exe
done