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"> <None Include="libwiringPi.so.2.44">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="lora.sh">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -18,7 +18,7 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
protected override void Connect() { protected override void Connect() {
this.mqtt = ABackend.GetInstance(this.config["settings"], ABackend.BackendType.Data); 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; this.mqttconnect = true;
} }
@ -28,7 +28,7 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
this.mqtt.Dispose(); this.mqtt.Dispose();
} }
this.mqtt = null; 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() { public override void EventLibSetter() {
@ -46,14 +46,14 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
topic = "lora/" + sensor.MqttTopic(); topic = "lora/" + sensor.MqttTopic();
data = sensor.ToJson(); data = sensor.ToJson();
} }
Console.WriteLine(topic);
Console.WriteLine(data);
if (topic != "" && data != "") { if (topic != "" && data != "") {
((ADataBackend)this.mqtt).Send(topic, data); ((ADataBackend)this.mqtt).Send(topic, data);
this.Update?.Invoke(this, new MqttEvent(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>(); private readonly List<String> nodes = new List<String>();
public override event ModulEvent Update; public override event ModulEvent Update;
private readonly Object getLock = new Object(); 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() { public override void EventLibSetter() {
this.library.Update += this.HandleLibUpdate; this.library.Update += this.HandleLibUpdate;
@ -28,11 +52,13 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
DeviceUpdateEvent e = state as DeviceUpdateEvent; DeviceUpdateEvent e = state as DeviceUpdateEvent;
LoraClient l = (LoraClient)e.Parent; LoraClient l = (LoraClient)e.Parent;
if (!this.nodes.Contains(l.Name)) { if (!this.nodes.Contains(l.Name)) {
this.Register(l); this.SendRegister(l);
this.nodes.Add(l.Name); this.nodes.Add(l.Name);
} }
this.SendUpdate(l); this.SendUpdate(l);
} catch { } } catch (Exception e) {
Helper.WriteError("Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls.Scral.LibUpadteThread: " + e.Message);
}
} }
private void SendUpdate(LoraClient l) { private void SendUpdate(LoraClient l) {
@ -47,14 +73,20 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
{ "herr", l.Gps.Hdop }, { "herr", l.Gps.Hdop },
{ "battery_level", l.Snr } { "battery_level", l.Snr }
}; };
if(this.RequestString("scral/puetz/dexels/wearable/localization", JsonMapper.ToJson(d), false, RequestMethod.PUT) == null) { try {
this.Register(l); 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> { Dictionary<String, Object> d = new Dictionary<String, Object> {
{ "device", "wearable" }, { "device", "wearable" },
{ "sensor", "tag" }, { "sensor", "tag" },
@ -65,8 +97,15 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
{ "observationType", "propietary" }, { "observationType", "propietary" },
{ "state", "active" } { "state", "active" }
}; };
this.RequestString("scral/puetz/dexels/wearable", JsonMapper.ToJson(d), false, RequestMethod.POST); try {
this.Update?.Invoke(this, new BlubbFish.Utils.IoT.Bots.Events.ModulEventArgs("scral/puetz/dexels/wearable", "POST", JsonMapper.ToJson(d), "SCRAL")); 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() { } 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) { private String RequestString(String address, String json = "", Boolean withoutput = true, RequestMethod method = RequestMethod.GET) {
String ret = null; String ret = null;
lock (this.getLock) { lock (this.getLock) {
HttpWebRequest request = WebRequest.CreateHttp(this.server + address); HttpWebRequest request = WebRequest.CreateHttp(this.config["general"]["server"] + address);
request.Timeout = 5000; request.Timeout = 2000;
if (method == RequestMethod.POST || method == RequestMethod.PUT) { if (method == RequestMethod.POST || method == RequestMethod.PUT) {
Byte[] requestdata = Encoding.ASCII.GetBytes(json); Byte[] requestdata = Encoding.ASCII.GetBytes(json);
request.ContentLength = requestdata.Length; request.ContentLength = requestdata.Length;
@ -100,9 +139,7 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
} }
} }
} catch (Exception e) { } catch (Exception e) {
Helper.WriteError("Konnte keine Verbindung zum Razzbery Server herstellen. Resource: \"" + this.server + address + "\" Fehler: " + e.Message); throw new WebException("Error while uploading to Scal. Resource: \"" + this.config["general"]["server"] + address + "\" Method: " + method + " Data: " + json + " Fehler: " + e.Message);
return null;
//throw new Exceptions.ConnectionException("Konnte keine Verbindung zum Razzbery Server herstellen: " + e.Message);
} }
} }
return ret; return ret;

View File

@ -18,7 +18,10 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot.Moduls {
if (this.config.ContainsKey("general") && this.config["general"].ContainsKey("path")) { if (this.config.ContainsKey("general") && this.config["general"].ContainsKey("path")) {
this.filename = this.config["general"]["path"]; this.filename = this.config["general"]["path"];
this.file = new StreamWriter(this.filename, true); this.file = new StreamWriter(this.filename, true);
} else {
throw new ArgumentException("Setting section [general] is missing or its value path");
} }
} }
public override void EventLibSetter() { public override void EventLibSetter() {

View File

@ -29,7 +29,7 @@ namespace Fraunhofer.Fit.IoT.Bots.LoraBot {
} }
private void LoraDataUpdate(Object sender, Iot.Lora.Events.DeviceUpdateEvent e) { 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, // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben: // übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0")] [assembly: AssemblyVersion("1.3.0")]
[assembly: AssemblyFileVersion("1.2.0")] [assembly: AssemblyFileVersion("1.3.0")]
/* /*
* 1.1.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 * 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 config=private
[settings] [settings]

View File

@ -1,6 +1,13 @@
[modul] [modul]
config=private config=private
[settings] [general]
type=mqtt server=https://portal.monica-cloud.eu/
server=localhost
[update]
addr=scral/puetz/dexels/wearable/localization
method=put
[register]
addr=scral/puetz/dexels/wearable
method=post

View File

@ -1,4 +1,4 @@
[logging] [logging]
path=/var/log/lorabot.log path=/var/log/lorabot.log
[lora] [lora]

View File

@ -1,2 +1,2 @@
[general] [general]
path=/home/pi/coords.txt 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 config=private
[settings] [settings]

View File

@ -1,2 +1,13 @@
[modul] [modul]
config=private 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,4 +1,4 @@
[logging] [logging]
path=/var/log/lorabot.log path=/var/log/lorabot.log
[lora] [lora]

View File

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

View File

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