Compare commits

...
5 Commits
Author SHA1 Message Date
BlubbFish 83cb131efe Zway-Bot [v1.7.2] Add Logging to some Modules, fixing a bug in overtaker (now it not removes every time all events, so only the latest event are watched)
[Utils] Fixing a bug if more than one argument with params
2018-10-02 14:53:59 +00:00
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 146 additions and 95 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) { }
}
}
+65 -49
View File
@@ -12,24 +12,27 @@ 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) { }
#region Mqtt
protected override void Connect() {
Console.WriteLine("BlubbFish.IoT.Bots.ZwayBot.Moduls.Mqtt.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() {
Console.WriteLine("BlubbFish.IoT.Bots.ZwayBot.Moduls.Mqtt.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 +41,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
}
+24 -14
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;
@@ -16,26 +16,34 @@ namespace ZwayBot.Moduls {
public Overtaker(ZwayController zway, InIReader settings) : base(zway, settings) { }
protected override void LibraryUpdateHook(String id) {
foreach (KeyValuePair<String, ACommandClass> item in this.overtakeritems) {
item.Value.Polling = false;
item.Value.Update -= this.ChangedEvent;
}
this.overtakeritems.Clear();
protected override void AddLibraryUpdateHook(String id) {
ACommandClass c = this.library.GetCommandClass(id);
if (c != null) {
Console.WriteLine("BlubbFish.IoT.Bots.ZwayBot.Moduls.Overtaker.LibraryUpdateHook: Add Watcher to " + c.Name + " [" + c.Id + "]");
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 RemoveLibraryUpdateHooks() {
foreach (KeyValuePair<String, ACommandClass> item in this.overtakeritems) {
Console.WriteLine("BlubbFish.IoT.Bots.ZwayBot.Moduls.Overtaker.LibraryUpdateHook: Remove Watcher to " + item.Value.Name + " [" + item.Value.Id + "]");
item.Value.Polling = false;
item.Value.Update -= this.HandleLibUpdate;
}
this.overtakeritems.Clear();
}
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 +57,7 @@ namespace ZwayBot.Moduls {
}
}
}
public override void EventLibSetter() { }
}
}
+30 -15
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;
@@ -19,22 +19,37 @@ 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 Connect() {
Console.WriteLine("BlubbFish.IoT.Bots.ZwayBot.Moduls.Senml.Connect()");
base.Connect();
}
protected override void EventInput(Object sender, BackendEvent e) { }
protected override void Disconnect() {
Console.WriteLine("BlubbFish.IoT.Bots.ZwayBot.Moduls.Senml.Disconnect()");
base.Disconnect();
}
#region Events
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 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 - 02.10.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.2")]
[assembly: AssemblyFileVersion("1.7.2")]
[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