Compare commits

...
4 Commits
Author SHA1 Message Date
BlubbFish 26a0688dae Zway-Bot [v1.7.1] Tiny fix for nullpointer exception 2018-09-29 18:13:17 +00:00
BlubbFish 6807cd35ad Zway [v1.5.0] Throw Exception if 3 times failed to connect to Raspberry server, add 3 new commandlcasses to IgnoredClasses
Zway-Bot [v1.7.0] rewrite to Threaded Modules, edit service file for systemd
2018-09-29 12:15:37 +00:00
BlubbFish 877bce4d1a Rewrite of Eventhandleing, Threaded 2018-09-11 12:04:43 +00:00
BlubbFish 55f7b609b1 To new Structure 2018-08-02 21:49:22 +00:00
21 changed files with 123 additions and 89 deletions
+5 -1
View File
@@ -6,7 +6,7 @@ using BlubbFish.Utils.IoT.Bots;
using BlubbFish.Utils.IoT.Bots.Events;
using BlubbFish.Utils.IoT.Bots.Moduls;
namespace ZwayBot.Moduls {
namespace BlubbFish.IoT.Bots.ZwayBot.Moduls {
internal class CronJob : CronJob<ZwayController> {
public override event ModulEvent Update;
@@ -27,5 +27,9 @@ namespace ZwayBot.Moduls {
}
}
}
public override void EventLibSetter() { }
protected override void LibUpadteThread(Object state) { }
}
}
+63 -49
View File
@@ -12,8 +12,9 @@ using BlubbFish.Utils.IoT.Events;
using BlubbFish.Utils.IoT.Interfaces;
using LitJson;
namespace ZwayBot.Moduls {
namespace BlubbFish.IoT.Bots.ZwayBot.Moduls {
class Mqtt : Mqtt<ZwayController> {
protected Boolean mqttConnect = false;
public override event ModulEvent Update;
public Mqtt(ZwayController zwave, InIReader settings) : base(zwave, settings) { }
@@ -21,15 +22,15 @@ namespace ZwayBot.Moduls {
#region Mqtt
protected override void Connect() {
this.mqtt = ABackend.GetInstance(this.config["settings"], ABackend.BackendType.Data);
this.mqtt.MessageIncomming += this.EventInput;
this.library.Update += this.EventOutput;
this.mqtt.MessageIncomming += this.MqttUpdate;
this.mqttConnect = true;
}
protected override void Disconnect() {
this.mqttConnect = false;
if (this.mqtt != null) {
this.mqtt.MessageIncomming -= this.EventInput;
this.mqtt.MessageIncomming -= this.MqttUpdate;
}
this.library.Update -= this.EventOutput;
if (this.mqtt != null) {
this.mqtt.Dispose();
}
@@ -38,55 +39,68 @@ namespace ZwayBot.Moduls {
#endregion
#region Events
protected virtual void EventOutput(Object sender, DeviceUpdateEvent e) {
String topic = "";
String data = "";
if (e.Parent.GetType().HasInterface(typeof(IMqtt))) {
IMqtt sensor = (IMqtt)e.Parent;
topic = "zwavebot/devices/" + sensor.MqttTopic();
data = sensor.ToJson();
}
if (topic != "" && data != "") {
((ADataBackend)this.mqtt).Send(topic, data);
this.Update?.Invoke(this, new MqttEvent(topic, data));
}
public override void EventLibSetter() {
this.library.Update += this.HandleLibUpdate;
}
protected virtual void EventInput(Object sender, BackendEvent e) {
if (e.From.ToString().StartsWith("zwavebot/devices/") && (e.From.ToString().EndsWith("/set") || e.From.ToString().EndsWith("/get"))) {
Match m = new Regex("^zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/[gs]et$|^zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/(\\d+)/[gs]et$").Match(e.From.ToString());
String id = "";
if (m.Groups[1].Success) {
id = m.Groups[1].Value + "-" + m.Groups[2].Value + "-" + m.Groups[3].Value;
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 = "zwavebot/devices/" + sensor.MqttTopic();
data = sensor.ToJson();
}
if (topic != "" && data != "") {
((ADataBackend)this.mqtt).Send(topic, data);
this.Update?.Invoke(this, new MqttEvent(topic, data));
}
}
if (m.Groups[4].Success) {
id = m.Groups[4].Value + "-" + m.Groups[5].Value + "-" + m.Groups[6].Value + "-" + m.Groups[7].Value;
}
ACommandClass c = this.library.GetCommandClass(id);
if (c == null) {
return;
}
if (e.From.ToString().EndsWith("/set")) {
try {
JsonData a = JsonMapper.ToObject(e.Message);
foreach (String item in a.Keys) {
String key = item.ToUpperLower();
if (c.HasProperty(key)) {
c.SetProperty(key, a[item].ToString());
this.Update?.Invoke(this, new MqttEvent(c.Id, a[item].ToString()));
}
} catch { }
}
protected virtual void MqttUpdate(Object sender, BackendEvent e) {
try {
if (this.mqttConnect) {
if (e.From.ToString().StartsWith("zwavebot/devices/") && (e.From.ToString().EndsWith("/set") || e.From.ToString().EndsWith("/get"))) {
Match m = new Regex("^zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/[gs]et$|^zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/(\\d+)/[gs]et$").Match(e.From.ToString());
String id = "";
if (m.Groups[1].Success) {
id = m.Groups[1].Value + "-" + m.Groups[2].Value + "-" + m.Groups[3].Value;
}
} catch (Exception) { }
} else if (e.From.ToString().EndsWith("/get")) {
c.PollOnce = true;
((ADataBackend)this.mqtt).Send("zwavebot/devices/" + c.MqttTopic(), c.ToJson());
this.Update?.Invoke(this, new MqttEvent(e.From.ToString(), "Dataget"));
if (m.Groups[4].Success) {
id = m.Groups[4].Value + "-" + m.Groups[5].Value + "-" + m.Groups[6].Value + "-" + m.Groups[7].Value;
}
ACommandClass c = this.library.GetCommandClass(id);
if (c == null) {
return;
}
if (e.From.ToString().EndsWith("/set")) {
try {
JsonData a = JsonMapper.ToObject(e.Message);
foreach (String item in a.Keys) {
String key = item.ToUpperLower();
if (c.HasProperty(key)) {
c.SetProperty(key, a[item].ToString());
this.Update?.Invoke(this, new MqttEvent(c.Id, a[item].ToString()));
}
}
} catch (Exception) { }
} else if (e.From.ToString().EndsWith("/get")) {
c.PollOnce = true;
((ADataBackend)this.mqtt).Send("zwavebot/devices/" + c.MqttTopic(), c.ToJson());
this.Update?.Invoke(this, new MqttEvent(e.From.ToString(), "Dataget"));
}
}
Tuple<Boolean, MqttEvent> cs = this.ChangeConfig(e, "zwavebot/config/");
if (cs.Item1) {
this.Update?.Invoke(this, cs.Item2);
}
}
}
Tuple<Boolean, MqttEvent> cs = this.ChangeConfig(e, "zwavebot/config/");
if (cs.Item1) {
this.Update?.Invoke(this, cs.Item2);
}
} catch { }
}
#endregion
}
+13 -8
View File
@@ -8,7 +8,7 @@ using BlubbFish.Utils.IoT.Bots;
using BlubbFish.Utils.IoT.Bots.Events;
using BlubbFish.Utils.IoT.Bots.Moduls;
namespace ZwayBot.Moduls {
namespace BlubbFish.IoT.Bots.ZwayBot.Moduls {
internal class Overtaker : Overtaker<ZwayController> {
private readonly Dictionary<String, ACommandClass> overtakeritems = new Dictionary<String, ACommandClass>();
public override event ModulEvent Update;
@@ -19,23 +19,26 @@ namespace ZwayBot.Moduls {
protected override void LibraryUpdateHook(String id) {
foreach (KeyValuePair<String, ACommandClass> item in this.overtakeritems) {
item.Value.Polling = false;
item.Value.Update -= this.ChangedEvent;
item.Value.Update -= this.HandleLibUpdate;
}
this.overtakeritems.Clear();
ACommandClass c = this.library.GetCommandClass(id);
if (c != null) {
this.overtakeritems.Add(id, c);
c.Polling = true;
c.Update += this.ChangedEvent;
c.Update += this.HandleLibUpdate;
}
}
private void ChangedEvent(Object sender, DeviceUpdateEvent e) {
if(sender.GetType().HasAbstract(typeof(ACommandClass))) {
if (this.events.ContainsKey(((ACommandClass)sender).Id)) {
this.SetValues(sender, ((ACommandClass)sender).Id, this.events[((ACommandClass)sender).Id]);
protected override void LibUpadteThread(Object state) {
try {
DeviceUpdateEvent e = state as DeviceUpdateEvent;
if (e.Parent.GetType().HasAbstract(typeof(ACommandClass))) {
if (this.events.ContainsKey(((ACommandClass)e.Parent).Id)) {
this.SetValues(e.Parent, ((ACommandClass)e.Parent).Id, this.events[((ACommandClass)e.Parent).Id]);
}
}
}
} catch { }
}
protected override void SetValueHook(String id, String prop, String value) {
@@ -49,5 +52,7 @@ namespace ZwayBot.Moduls {
}
}
}
public override void EventLibSetter() { }
}
}
+19 -14
View File
@@ -8,7 +8,7 @@ using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Events;
using BlubbFish.Utils.IoT.Interfaces;
namespace ZwayBot.Moduls {
namespace BlubbFish.IoT.Bots.ZwayBot.Moduls {
class Senml : Mqtt {
public override event ModulEvent Update;
private readonly String SenmlGuid;
@@ -20,21 +20,26 @@ namespace ZwayBot.Moduls {
}
#region Events
protected override void EventOutput(Object sender, DeviceUpdateEvent e) {
String topic = "";
String data = "";
if (e.Parent.GetType().HasInterface(typeof(ISenml))) {
ISenml sensor = (ISenml)e.Parent;
topic = sensor.SenmlTopic() + this.SenmlGuid+ "/senml";
data = sensor.ToSenml();
}
if (topic != "" && data != null && data != "") {
((ADataBackend)this.mqtt).Send(topic, data);
this.Update?.Invoke(this, new SenmlEvent(topic, data));
}
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(ISenml))) {
ISenml sensor = (ISenml)e.Parent;
topic = sensor.SenmlTopic() + this.SenmlGuid + "/senml";
data = sensor.ToSenml();
}
if (topic != "" && data != null && data != "") {
((ADataBackend)this.mqtt).Send(topic, data);
this.Update?.Invoke(this, new SenmlEvent(topic, data));
}
}
} catch { }
}
protected override void EventInput(Object sender, BackendEvent e) { }
protected override void MqttUpdate(Object sender, BackendEvent e) { }
#endregion
}
}
+5 -1
View File
@@ -7,7 +7,7 @@ using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Bots.Events;
using BlubbFish.Utils.IoT.Bots.Moduls;
namespace ZwayBot.Moduls {
namespace BlubbFish.IoT.Bots.ZwayBot.Moduls {
class Statuspolling : Statuspolling<ZwayController> {
public override event ModulEvent Update;
@@ -37,5 +37,9 @@ namespace ZwayBot.Moduls {
}
this.Update?.Invoke(this, new StatusPollingEvent("Polling", "all nodes"));
}
public override void EventLibSetter() { }
protected override void LibUpadteThread(Object state) { }
}
}
+7 -7
View File
@@ -4,8 +4,8 @@ using BlubbFish.IoT.Zway;
using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Bots;
namespace ZwayBot {
class Program : Bot {
namespace BlubbFish.IoT.Bots.ZwayBot {
class Program : Bot<ZwayController> {
static void Main(String[] args) => new Program(args);
public Program(String[] args) {
@@ -23,15 +23,15 @@ namespace ZwayBot {
this.logger.SetPath(InIReader.GetInstance("settings").GetValue("logging", "path"));
ZwayController zw = new ZwayController(InIReader.GetInstance("settings").GetSection("zway"), names, false);
zw.Update += this.ZwayDataUpate;
this.ModulLoader<ZwayController>("ZwayBot.Moduls", zw);
this.ModulInterconnect<ZwayController>();
this.ModulEvents<ZwayController>();
this.ModulLoader("BlubbFish.IoT.Bots.ZwayBot.Moduls", zw);
this.ModulInterconnect();
this.ModulEvents();
this.WaitForShutdown();
this.ModulDispose<ZwayController>();
this.ModulDispose();
zw.Dispose();
}
private void ZwayDataUpate(Object sender, BlubbFish.IoT.Zway.Events.DeviceUpdateEvent e) {
private void ZwayDataUpate(Object sender, Zway.Events.DeviceUpdateEvent e) {
Console.WriteLine("-> ZW [" + e.UpdateTime + "]: " + e.Parent.ToString());
}
}
+3 -3
View File
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("BlubbFish")]
[assembly: AssemblyProduct("Zway-Bot")]
[assembly: AssemblyCopyright("Copyright © 2017 - 05.06.2018")]
[assembly: AssemblyCopyright("Copyright © 2017 - 29.09.2018")]
[assembly: AssemblyTrademark("BlubbFish")]
[assembly: AssemblyCulture("")]
@@ -31,8 +31,8 @@ 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.6.2")]
[assembly: AssemblyFileVersion("1.6.2")]
[assembly: AssemblyVersion("1.7.1")]
[assembly: AssemblyFileVersion("1.7.1")]
[assembly: NeutralResourcesLanguage("de-DE")]
// “Internet Of Things” icon by By Michael Wohlwend, US, from thenounproject.com.
+2 -2
View File
@@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace ZwayBot.Properties {
namespace BlubbFish.IoT.Bots.ZwayBot.Properties {
using System;
@@ -39,7 +39,7 @@ namespace ZwayBot.Properties {
public static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ZwayBot.Properties.Resources", typeof(Resources).Assembly);
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BlubbFish.IoT.Bots.ZwayBot.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
+2 -2
View File
@@ -6,7 +6,7 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AEF8059F-8AEF-45C7-85C4-318C8F797900}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ZwayBot</RootNamespace>
<RootNamespace>BlubbFish.IoT.Bots.ZwayBot</RootNamespace>
<AssemblyName>Zway-Bot</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
@@ -35,7 +35,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject>ZwayBot.Program</StartupObject>
<StartupObject>BlubbFish.IoT.Bots.ZwayBot.Program</StartupObject>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\Icon.ico</ApplicationIcon>
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.
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -6,7 +6,7 @@ OUTPUT="../bin/Release"
EXEC="$ROOT/usr/local/bin/zwaybot"
CONFIG="$ROOT/etc/zwaybot"
SYSTEMD="$ROOT/etc/systemd/system"
SYSTEMD="$ROOT/lib/systemd/system"
LOGROTATE="$ROOT/etc/logrotate.d"
DEBIAN="$ROOT/DEBIAN"
+1
View File
@@ -1,5 +1,6 @@
#!/bin/bash
systemctl enable zwaybot
systemctl daemon-reload
if [[ $(systemctl is-active zwaybot || true) == "active" ]]
then
+1
View File
@@ -11,6 +11,7 @@ WorkingDirectory=/usr/local/bin/zwaybot
# ExecStartPre=/bin/rm /var/log/zwaybot.log && /bin/touch /var/log/zwaybot.log && /bin/chown zwaybot:zwaybot /var/log/zwaybot.log && /bin/chmod 644 /var/log/zwaybot.log
ExecStart=/usr/bin/mono /usr/local/bin/zwaybot/Zway-Bot.exe
KillMode=control-group
TimeoutStopSec=5
Restart=on-failure
StandardOutput=null
StandardError=syslog