Compare commits

..
17 Commits
Author SHA1 Message Date
BlubbFish 70bcf69b1b [NF] Add Bot-Utils and rewrite code 2018-06-07 20:49:54 +00:00
BlubbFish fc108773d9 [NF] Thread that checks if a MQTT Connection exists and if not reopen it
[NF] ConnectorDataMqtt now supports user and password
2018-06-05 16:46:56 +00:00
BlubbFish 92a6ba2b64 [BF] new try 2018-06-02 19:38:56 +00:00
BlubbFish 57daf12ed4 [BF] new try 2018-06-02 19:36:32 +00:00
BlubbFish cabcce03b3 [BF] new try 2018-06-02 19:32:20 +00:00
BlubbFish a9c77c6614 [BF] Fixing Bug in after installation script 2018-06-02 19:08:05 +00:00
BlubbFish 1c84703ac6 [BF] Making service linux running 2018-06-02 18:41:21 +00:00
BlubbFish 25e1e5165d 2018-06-02 17:14:42 +00:00
BlubbFish a76234f43d 2018-06-01 18:23:30 +00:00
BlubbFish a3afadd5f5 [NF] Move 2018-05-31 18:03:57 +00:00
BlubbFish 002b3cf338 [NF] Logrotate 2018-05-29 20:07:50 +00:00
BlubbFish a7895ef59a 2018-05-29 16:15:17 +00:00
BlubbFish 852a096f1d [NF] Now sould dedect Strg+c on Linux 2018-05-15 20:52:54 +00:00
BlubbFish 69030796f5 [BF] Fixinig installations dpkg script 2018-05-15 19:04:19 +00:00
BlubbFish 19d92c8cac [BF] Fixinig installations dpkg script 2018-05-15 18:59:32 +00:00
BlubbFish c792ea20ad Utils.csproj
[NF] Programmlogger added (v1.1.0)
[NF] Utils fixing tiny issues

Zway-Bot.csproj
[NF] changes Topics without beginning /
[NF] Using programmlogger (v1.4.0)
2018-05-15 18:49:03 +00:00
BlubbFish 611205e78f [BF] Fixing Issue with Math.Abs(l) 2018-05-12 12:36:32 +00:00
66 changed files with 225 additions and 962 deletions
+7 -1
View File
@@ -17,7 +17,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Iot-Interfaces", "..\Utils\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson_4.7.1", "..\Librarys\litjson\litjson\litjson_4.7.1.csproj", "{91A14CD2-2940-4500-8193-56D37EDDDBAA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "M2Mqtt", "..\Librarys\mqtt\M2Mqtt\M2Mqtt_4.7.1.csproj", "{A11AEF5A-B246-4FE8-8330-06DB73CC8074}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "M2Mqtt_4.7.1", "..\Librarys\mqtt\M2Mqtt\M2Mqtt_4.7.1.csproj", "{A11AEF5A-B246-4FE8-8330-06DB73CC8074}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bot-Utils", "..\Utils\Bot-Utils\Bot-Utils.csproj", "{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -57,6 +59,10 @@ Global
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.Build.0 = Release|Any CPU
{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
-81
View File
@@ -1,81 +0,0 @@
using System;
namespace ZwayBot {
public class CronEvent : ModulEventArgs {
public CronEvent() {
}
public CronEvent(String addr, String prop, String value) {
this.Address = addr;
this.Property = prop;
this.Value = value;
this.Source = "Cronjob";
}
}
public class OvertakerEvent : ModulEventArgs {
public OvertakerEvent() {
}
public OvertakerEvent(String addr, String prop, String value) {
this.Address = addr;
this.Property = prop;
this.Value = value;
this.Source = "Overtaker";
}
}
public class Flex4gridEvent : ModulEventArgs {
public Flex4gridEvent() {
}
public Flex4gridEvent(String topic, String text) {
this.Address = topic;
this.Value = text;
this.Source = "Flex4Grid";
}
public override String ToString() {
return this.Source + ": on " + this.Address + " set " + this.Value;
}
}
public class MqttEvent : ModulEventArgs {
public MqttEvent() {
}
public MqttEvent(String topic, String text) {
this.Address = topic;
this.Value = text;
this.Source = "MQTT";
}
public override String ToString() {
return this.Source + ": on " + this.Address + " set " + this.Value;
}
}
public class StatusPollingEvent : ModulEventArgs {
public StatusPollingEvent() {
}
public StatusPollingEvent(String text, String node) {
this.Value = text;
this.Address = node;
this.Source = "POLLING";
}
public override String ToString() {
return this.Source + ": " + this.Value + " on " + this.Address;
}
}
public class ModulEventArgs : EventArgs {
public ModulEventArgs() {
}
public String Address { get; protected set; }
public String Property { get; protected set; }
public String Value { get; protected set; }
public String Source { get; protected set; }
public override String ToString() {
return this.Source + ": " + this.Address + " set " + this.Property + " to " + this.Value;
}
}
}
-82
View File
@@ -1,82 +0,0 @@
using System;
using System.Reflection;
namespace ZwayBot {
static class Helper {
public static void SetProperty(this Object o, String name, String value) {
PropertyInfo prop = o.GetType().GetProperty(name);
if (prop.CanWrite) {
if (prop.PropertyType == typeof(Boolean) && Boolean.TryParse(value, out Boolean vb)) {
prop.SetValue(o, vb);
} else if (prop.PropertyType == typeof(Int32) && Int32.TryParse(value, out Int32 v32)) {
prop.SetValue(o, v32);
} else if (prop.PropertyType == typeof(Single) && Single.TryParse(value, out Single vs)) {
prop.SetValue(o, vs);
} else if (prop.PropertyType == typeof(Double) && Double.TryParse(value, out Double vd)) {
prop.SetValue(o, vd);
} else if (prop.PropertyType == typeof(Int64) && Int64.TryParse(value, out Int64 v64)) {
prop.SetValue(o, v64);
}
}
}
internal static Boolean HasProperty(this Object o, String type) {
Type t = o.GetType();
foreach (PropertyInfo item in t.GetProperties()) {
if (item.Name == type) {
return true;
}
}
return false;
}
internal static Object GetProperty(this Object o, String name) {
PropertyInfo prop = o.GetType().GetProperty(name);
if(prop.CanRead) {
return prop.GetValue(o);
}
return null;
}
internal static Boolean HasAbstract(this Object o, Type type) {
if(o.GetType().BaseType == type) {
return true;
}
return false;
}
internal static Boolean HasInterface(this Type o, String type) {
foreach (Type item in o.GetInterfaces()) {
if(item.Name == type) {
return true;
}
}
return false;
}
internal static Boolean HasInterface(this Object o, Type interf) {
foreach(Type item in o.GetType().GetInterfaces()) {
if(item == interf) {
return true;
}
}
return false;
}
internal static void WriteError(String text) {
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine("ERROR: " + text);
Console.ResetColor();
}
internal static String ToUpperLower(this String s) {
if(s.Length == 0) {
return "";
}
if(s.Length == 1) {
return s.ToUpper();
}
return s[0].ToString().ToUpper() + s.Substring(1).ToLower();
}
}
}
-4
View File
@@ -1,4 +0,0 @@
namespace ZwayBot.Interfaces {
interface IForceLoad {
}
}
-71
View File
@@ -1,71 +0,0 @@
using System;
using System.Collections.Generic;
using BlubbFish.IoT.Zway;
using BlubbFish.Utils;
namespace ZwayBot {
abstract class AModul {
protected ZwayController zw;
private InIReader settings;
protected Dictionary<String, Dictionary<String, String>> config = new Dictionary<String, Dictionary<String, String>>();
public Boolean HasConfig { get; private set; }
public Boolean ConfigPublic { get; private set; }
public delegate void ModulEvent(Object sender, ModulEventArgs e);
public abstract event ModulEvent Update;
public AModul(ZwayController zway, InIReader settings) {
this.HasConfig = false;
this.ConfigPublic = false;
this.zw = zway;
this.settings = settings;
this.ParseConfig();
}
private void ParseConfig() {
if (this.settings != null) {
this.HasConfig = true;
foreach (String item in this.settings.GetSections(false)) {
this.config.Add(item, this.settings.GetSection(item));
}
if(this.config.ContainsKey("modul")) {
this.ConfigPublic = this.config["modul"].ContainsKey("config") && this.config["modul"]["config"].ToLower() == "public";
}
}
}
public Dictionary<String, Dictionary<String, String>> GetConfig() {
if (this.HasConfig && this.ConfigPublic) {
Dictionary<String, Dictionary<String, String>> ret = new Dictionary<String, Dictionary<String, String>>(this.config);
if(ret.ContainsKey("modul")) {
ret.Remove("modul");
}
return ret;
}
return new Dictionary<String, Dictionary<String, String>>();
}
public virtual void Interconnect(Dictionary<String, AModul> moduls) { }
public virtual void SetInterconnection(String param, Action<Object> hook, Object data) { }
public abstract void Dispose();
internal void SetConfig(Dictionary<String, Dictionary<String, String>> newconf) {
if (this.HasConfig && this.ConfigPublic) {
if (newconf.ContainsKey("modul")) {
newconf.Remove("modul");
}
if (this.config.ContainsKey("modul")) {
newconf.Add("modul", this.config["modul"]);
}
this.config = newconf;
this.settings.SetSections(this.config);
this.UpdateConfig();
}
}
protected abstract void UpdateConfig();
}
}
+9 -12
View File
@@ -6,17 +6,20 @@ using System.Threading;
using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils;
using ZwayBot.Interfaces;
using BlubbFish.Utils.IoT.Bots.Moduls;
using BlubbFish.Utils.IoT.Bots.Interfaces;
using BlubbFish.Utils.IoT.Bots.Events;
using BlubbFish.Utils.IoT.Bots;
namespace ZwayBot.Moduls {
internal class CronJob : AModul, IDisposable, IForceLoad {
internal class CronJob : AModul<ZwayController>, IDisposable, IForceLoad {
private DateTime crontime;
private Thread thread;
private List<Tuple<String, Action<Object>, Object>> internalCron = new List<Tuple<String, Action<Object>, Object>>();
private readonly List<Tuple<String, Action<Object>, Object>> internalCron = new List<Tuple<String, Action<Object>, Object>>();
public override event ModulEvent Update;
private Dictionary<String, String> cron_named = new Dictionary<String, String> {
private readonly Dictionary<String, String> cron_named = new Dictionary<String, String> {
{ "@yearly", "0 0 1 1 *" },
{ "@annually", "0 0 1 1 *" },
{ "@monthly", "0 0 1 * *" },
@@ -58,7 +61,7 @@ namespace ZwayBot.Moduls {
String[] items = item.Split(':');
if(items.Length == 2) {
String[] values = items[1].Split('-');
ACommandClass c = this.zw.GetCommandClass(items[0]);
ACommandClass c = this.library.GetCommandClass(items[0]);
if (c != null && values.Length == 2) {
if (c.HasProperty(values[0])) {
c.SetProperty(values[0], values[1]);
@@ -166,19 +169,13 @@ namespace ZwayBot.Moduls {
if (!this.disposedValue) {
if (disposing) {
this.thread.Abort();
while(this.thread.ThreadState != ThreadState.Aborted) { Thread.Sleep(100); }
while(this.thread.ThreadState == ThreadState.Running) { Thread.Sleep(100); }
}
this.thread = null;
this.disposedValue = true;
}
}
~CronJob() {
Dispose(false);
}
public override void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
+42 -83
View File
@@ -1,55 +1,69 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Bots;
using BlubbFish.Utils.IoT.Bots.Events;
using BlubbFish.Utils.IoT.Bots.Moduls;
using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Events;
using BlubbFish.Utils.IoT.Interfaces;
using LitJson;
namespace ZwayBot.Moduls {
class Mqtt : AModul, IDisposable {
private ABackend mqtt;
private Dictionary<String, AModul> modules;
class Mqtt : Mqtt<ZwayController> {
public override event ModulEvent Update;
public Mqtt(ZwayController zway, InIReader settings) : base(zway, settings) {
if (this.config.ContainsKey("settings")) {
this.mqtt = ABackend.GetInstance(this.config["settings"], ABackend.BackendType.Data);
this.mqtt.MessageIncomming += this.Mqtt_MessageIncomming;
this.zw.Update += this.ZwayEvent;
}
public Mqtt(ZwayController zwave, InIReader settings) : base(zwave, settings) { }
#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;
}
private void ZwayEvent(Object sender, DeviceUpdateEvent e) {
protected override void Disconnect() {
if (this.mqtt != null) {
this.mqtt.MessageIncomming -= this.EventInput;
}
this.library.Update -= this.EventOutput;
if (this.mqtt != null) {
this.mqtt.Dispose();
}
this.mqtt = null;
}
#endregion
#region Events
protected virtual void EventOutput(Object sender, DeviceUpdateEvent e) {
String topic = "";
String data = "";
if(e.Parent.HasAbstract(typeof(ACommandClass))) {
ACommandClass sensor = (ACommandClass)e.Parent;
topic = "/zwavebot/devices/" + sensor.MqttTopic();
if (e.Parent.GetType().HasInterface(typeof(IMqtt))) {
IMqtt sensor = (IMqtt)e.Parent;
topic = "zwavebot/devices/" + sensor.MqttTopic();
data = sensor.ToJson();
}
if(topic != "" && data != "") {
if (topic != "" && data != "") {
((ADataBackend)this.mqtt).Send(topic, data);
this.Update?.Invoke(this, new MqttEvent(topic, data));
}
}
private void Mqtt_MessageIncomming(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());
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) {
if (m.Groups[1].Success) {
id = m.Groups[1].Value + "-" + m.Groups[2].Value + "-" + m.Groups[3].Value;
}
if(m.Groups[4].Success) {
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.zw.GetCommandClass(id);
if(c == null) {
ACommandClass c = this.library.GetCommandClass(id);
if (c == null) {
return;
}
if (e.From.ToString().EndsWith("/set")) {
@@ -63,72 +77,17 @@ namespace ZwayBot.Moduls {
}
}
} catch (Exception) { }
} else if(e.From.ToString().EndsWith("/get")) {
} else if (e.From.ToString().EndsWith("/get")) {
c.PollOnce = true;
((ADataBackend)this.mqtt).Send("/zwavebot/devices/" + c.MqttTopic(), c.ToJson());
((ADataBackend)this.mqtt).Send("zwavebot/devices/" + c.MqttTopic(), c.ToJson());
this.Update?.Invoke(this, new MqttEvent(e.From.ToString(), "Dataget"));
}
}
if (e.From.ToString().StartsWith("/zwavebot/config/") && (e.From.ToString().EndsWith("/set") || e.From.ToString().EndsWith("/get"))) {
Match m = new Regex("^/zwavebot/config/(\\w+)/[gs]et$|").Match(e.From.ToString());
if (!m.Groups[1].Success) {
return;
}
AModul modul = null;
foreach (KeyValuePair<String, AModul> item in this.modules) {
if (item.Key.ToLower() == m.Groups[1].Value) {
modul = item.Value;
}
}
if (modul == null) {
return;
}
if(e.From.ToString().EndsWith("/get") && modul.HasConfig && modul.ConfigPublic) {
String topic = "/zwavebot/config/" + m.Groups[1].Value;
String data = JsonMapper.ToJson(modul.GetConfig()).ToString();
((ADataBackend)this.mqtt).Send(topic, data);
this.Update?.Invoke(this, new MqttEvent(topic, data));
}
if (e.From.ToString().EndsWith("/set") && modul.HasConfig && modul.ConfigPublic) {
try {
JsonData a = JsonMapper.ToObject(e.Message);
Dictionary<String, Dictionary<String, String>> newconf = new Dictionary<String, Dictionary<String, String>>();
foreach (String section in a.Keys) {
Dictionary<String, String> sectiondata = new Dictionary<String, String>();
foreach (String item in a[section].Keys) {
sectiondata.Add(item, a[section][item].ToString());
}
newconf.Add(section, sectiondata);
}
modul.SetConfig(newconf);
this.Update?.Invoke(this, new MqttEvent("New Config", "Write"));
} catch (Exception) { }
}
Tuple<Boolean, MqttEvent> cs = this.ChangeConfig(e, "zwavebot/config/");
if (cs.Item1) {
this.Update?.Invoke(this, cs.Item2);
}
}
public override void Interconnect(Dictionary<String, AModul> moduls) {
this.modules = moduls;
}
protected override void UpdateConfig() { }
#region IDisposable Support
private Boolean disposedValue = false;
protected virtual void Dispose(Boolean disposing) {
if (!this.disposedValue) {
if (disposing) {
this.mqtt.Dispose();
}
this.disposedValue = true;
}
}
public override void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}
+8 -9
View File
@@ -4,10 +4,13 @@ using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Bots;
using BlubbFish.Utils.IoT.Bots.Events;
using BlubbFish.Utils.IoT.Bots.Moduls;
namespace ZwayBot.Moduls {
internal class Overtaker : AModul, IDisposable {
private Dictionary<String, Dictionary<String, String>> events = new Dictionary<String, Dictionary<String, String>>();
internal class Overtaker : AModul<ZwayController>, IDisposable {
private readonly Dictionary<String, Dictionary<String, String>> events = new Dictionary<String, Dictionary<String, String>>();
public override event ModulEvent Update;
@@ -21,7 +24,7 @@ namespace ZwayBot.Moduls {
String from = item.Value["from"];
String[] source = from.Split(':');
this.events.Add(source[0], item.Value);
ACommandClass c = this.zw.GetCommandClass(source[0]);
ACommandClass c = this.library.GetCommandClass(source[0]);
if (c != null) {
c.Polling = true;
c.Update += this.ChangedEvent;
@@ -31,7 +34,7 @@ namespace ZwayBot.Moduls {
}
private void ChangedEvent(Object sender, DeviceUpdateEvent e) {
if(sender.HasAbstract(typeof(ACommandClass))) {
if(sender.GetType().HasAbstract(typeof(ACommandClass))) {
if (this.events.ContainsKey(((ACommandClass)sender).Id)) {
this.SetValues(sender, ((ACommandClass)sender).Id, this.events[((ACommandClass)sender).Id]);
}
@@ -62,7 +65,7 @@ namespace ZwayBot.Moduls {
foreach (String to in dictionary["to"].Split(';')) {
String[] target = to.Split(':');
if (target.Length == 2) {
ACommandClass c = this.zw.GetCommandClass(target[0]);
ACommandClass c = this.library.GetCommandClass(target[0]);
if (c != null) {
if (c.HasProperty(target[1])) {
if (c.GetProperty(target[1]).ToString() != source_value) {
@@ -89,10 +92,6 @@ namespace ZwayBot.Moduls {
}
}
~Overtaker() {
Dispose(false);
}
public override void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
+8 -32
View File
@@ -2,63 +2,39 @@
using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Bots;
using BlubbFish.Utils.IoT.Bots.Events;
using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Events;
using BlubbFish.Utils.IoT.Interfaces;
namespace ZwayBot.Moduls {
class Senml : AModul {
class Senml : Mqtt {
public override event ModulEvent Update;
private ABackend mqtt;
private String SenmlGuid;
private readonly String SenmlGuid;
public Senml(ZwayController zway, InIReader settings) : base(zway, settings) {
if (this.config.ContainsKey("settings")) {
this.mqtt = ABackend.GetInstance(this.config["settings"], ABackend.BackendType.Data);
this.mqtt.MessageIncomming += this.EventInput;
this.zw.Update += this.EventOutput;
this.SenmlGuid = this.config["settings"]["guid"];
}
}
#region Events
private void EventOutput(Object sender, DeviceUpdateEvent e) {
protected override void EventOutput(Object sender, DeviceUpdateEvent e) {
String topic = "";
String data = "";
if (e.Parent.HasInterface(typeof(ISenml))) {
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 MqttEvent(topic, data));
this.Update?.Invoke(this, new SenmlEvent(topic, data));
}
}
private void EventInput(Object sender, BackendEvent e) { }
#endregion
#region Config
protected override void UpdateConfig() { }
#endregion
#region IDisposable Support
private Boolean disposedValue = false;
protected virtual void Dispose(Boolean disposing) {
if (!this.disposedValue) {
if (disposing) {
this.mqtt.Dispose();
}
this.disposedValue = true;
}
}
public override void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected override void EventInput(Object sender, BackendEvent e) { }
#endregion
}
}
+10 -8
View File
@@ -4,23 +4,25 @@ using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Devices;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils;
using ZwayBot.Interfaces;
using BlubbFish.Utils.IoT.Bots.Events;
using BlubbFish.Utils.IoT.Bots.Interfaces;
using BlubbFish.Utils.IoT.Bots.Moduls;
namespace ZwayBot.Moduls {
class Statuspolling : AModul, IDisposable, IForceLoad {
class Statuspolling : AModul<ZwayController>, IDisposable, IForceLoad {
public override event ModulEvent Update;
public Statuspolling(ZwayController zway, InIReader settings) : base(zway, settings) { }
public override void Interconnect(Dictionary<String, AModul> moduls) {
foreach (KeyValuePair<String, AModul> item in moduls) {
public override void Interconnect(Dictionary<String, Object> moduls) {
foreach (KeyValuePair<String, Object> item in moduls) {
if (item.Value is CronJob) {
item.Value.SetInterconnection("0 0 * * *", new Action<Object>(this.PollAll), null);
((AModul<ZwayController>)item.Value).SetInterconnection("0 0 * * *", new Action<Object>(this.PollAll), null);
if (this.config.Count != 0) {
foreach (KeyValuePair<String, Dictionary<String, String>> section in this.config) {
if (section.Value.ContainsKey("cron") && section.Value.ContainsKey("devices")) {
item.Value.SetInterconnection(section.Value["cron"], new Action<Object>(this.PollSpecific), section.Value["devices"]);
((AModul<ZwayController>)item.Value).SetInterconnection(section.Value["cron"], new Action<Object>(this.PollSpecific), section.Value["devices"]);
}
}
}
@@ -31,14 +33,14 @@ namespace ZwayBot.Moduls {
private void PollSpecific(Object obj) {
String devices = (String)obj;
foreach (String item in devices.Split(',')) {
ACommandClass c = this.zw.GetCommandClass(item);
ACommandClass c = this.library.GetCommandClass(item);
c.PollOnce = true;
this.Update?.Invoke(this, new StatusPollingEvent("Polling", item));
}
}
private void PollAll(Object o) {
foreach (KeyValuePair<Int32, Device> device in this.zw.Devices) {
foreach (KeyValuePair<Int32, Device> device in this.library.Devices) {
foreach (KeyValuePair<Int32, Instance> instance in device.Value.Instances) {
foreach (KeyValuePair<ACommandClass.Classes, ACommandClass> commandclass in instance.Value.CommandClasses) {
commandclass.Value.PollOnce = true;
+11 -65
View File
@@ -1,16 +1,13 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using BlubbFish.IoT.Zway;
using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Bots;
namespace ZwayBot {
class Program {
class Program : Bot {
static void Main(String[] args) => new Program(args);
private ZwayController zw;
private Dictionary<String, AModul> moduls = new Dictionary<String, AModul>();
public Program(String[] args) {
InIReader.SetSearchPath(new List<String>() { "/etc/zwaybot", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zwaybot" });
Dictionary<String, String> names;
@@ -23,67 +20,16 @@ namespace ZwayBot {
Helper.WriteError("No settings.ini found. Abord!");
return;
}
this.zw = new ZwayController(InIReader.GetInstance("settings").GetSection("zway"), names, false);
this.zw.Update += this.ZwayDataUpate;
this.ModulLoader();
this.ModulInterconnect();
this.ModulEvents();
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.WaitForShutdown();
this.ModulDispose();
}
private void ModulInterconnect() {
foreach (KeyValuePair<String, AModul> item in this.moduls) {
item.Value.Interconnect(this.moduls);
}
}
private void WaitForShutdown() {
while (true) {
System.Threading.Thread.Sleep(100);
if (Console.KeyAvailable) {
String a = Console.ReadLine();
if (a.EndsWith("/exit")) {
break;
}
}
}
}
private void ModulDispose() {
foreach (KeyValuePair<String, AModul> item in this.moduls) {
item.Value.Dispose();
Console.WriteLine("Modul entladen: " + item.Key);
}
this.zw.Dispose();
}
private void ModulEvents() {
foreach (KeyValuePair<String, AModul> item in this.moduls) {
item.Value.Update += this.ModulUpdate;
}
}
private void ModulUpdate(Object sender, ModulEventArgs e) {
Console.WriteLine(e.ToString());
}
private void ModulLoader() {
Assembly asm = Assembly.GetExecutingAssembly();
foreach (Type item in asm.GetTypes()) {
if(item.Namespace == "ZwayBot.Moduls") {
Type t = item;
String name = t.Name;
if (InIReader.ConfigExist(name.ToLower())) {
this.moduls.Add(name, (AModul)t.GetConstructor(new Type[] { typeof(ZwayController), typeof(InIReader) }).Invoke(new Object[] { this.zw, InIReader.GetInstance(name.ToLower()) }));
Console.WriteLine("Load Modul " + name);
} else if(t.HasInterface("IForceLoad")) {
this.moduls.Add(name, (AModul)t.GetConstructor(new Type[] { typeof(ZwayController), typeof(InIReader) }).Invoke(new Object[] { this.zw, null }));
Console.WriteLine("Load Modul Forced " + name);
}
}
}
}
this.ModulDispose<ZwayController>();
zw.Dispose();
}
private void ZwayDataUpate(Object sender, BlubbFish.IoT.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 - 08.05.2018")]
[assembly: AssemblyCopyright("Copyright © 2017 - 05.06.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.3.3")]
[assembly: AssemblyFileVersion("1.3.3")]
[assembly: AssemblyVersion("1.6.1")]
[assembly: AssemblyFileVersion("1.6.1")]
[assembly: NeutralResourcesLanguage("de-DE")]
// “Internet Of Things” icon by By Michael Wohlwend, US, from thenounproject.com.
+15 -42
View File
@@ -12,6 +12,8 @@
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -39,22 +41,9 @@
<ApplicationIcon>Resources\Icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Events.cs" />
<Compile Include="Interfaces\IForceLoad.cs" />
<Compile Include="Moduls\AModul.cs" />
<None Include="dpkg\preinst" />
<None Include="dpkg\postinst" />
<Compile Include="Moduls\CronJob.cs" />
<Compile Include="Helper.cs" />
<Compile Include="Moduls\Mqtt.cs" />
<Compile Include="Moduls\Overtaker.cs" />
<Compile Include="Moduls\Senml.cs" />
@@ -72,6 +61,10 @@
<Project>{91a14cd2-2940-4500-8193-56d37edddbaa}</Project>
<Name>litjson_4.7.1</Name>
</ProjectReference>
<ProjectReference Include="..\..\Utils\Bot-Utils\Bot-Utils.csproj">
<Project>{bb7bfcb5-3db0-49e1-802a-3ce3eecc59f9}</Project>
<Name>Bot-Utils</Name>
</ProjectReference>
<ProjectReference Include="..\..\Utils\IoT\Connector\Data\Mqtt\ConnectorDataMqtt.csproj">
<Project>{ee6c8f68-ed46-4c1c-abdd-cfcdf75104f2}</Project>
<Name>ConnectorDataMqtt</Name>
@@ -94,33 +87,6 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="control\control.sh">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="control\join.sh">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="control\loop.sh">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="control\restart.sh">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="control\settings.cfg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="control\start.sh">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="control\stop.sh">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="control\stuff.sh">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="control\view.sh">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="config-example\cronjob.conf.example">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
@@ -147,6 +113,9 @@
<None Include="dpkg\control" />
<None Include="dpkg\create-Builds.bat" />
<None Include="dpkg\make-deb.sh" />
<None Include="dpkg\prerm" />
<None Include="dpkg\zwaybot-logrotate" />
<None Include="dpkg\zwaybot.service" />
<None Include="Resources\Icon.ico" />
<Content Include="Resources\icon.svg" />
</ItemGroup>
@@ -156,5 +125,9 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
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.
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,4 @@
[modul]
[modul]
config=public
[cold]
@@ -1,4 +1,4 @@
[modul]
[modul]
config=private
[settings]
@@ -1,4 +1,4 @@
[names]
[names]
2-0-37=Kühlschrank Schalter
2-0-49-4=Kühlschrank Leistung
2-0-50-0=Kühlschrank Verbrauch [kWh]
@@ -1,4 +1,4 @@
[hot]
[hot]
from=7-0-67-1:Level
to=8-0-67-1:Level;9-0-67-1:Level
@@ -1,4 +1,4 @@
[modul]
[modul]
config=private
[settings]
@@ -1,4 +1,7 @@
[zway]
[zway]
server=localhost
user=admin
pass=pass
pass=pass
[logging]
path=/var/log/zwaybot.log
@@ -1,3 +1,3 @@
[temp]
[temp]
cron=30 * * * *
devices=7-0-49-1,8-0-49-1,9-0-49-1,10-0-49-1,11-0-49-1
-92
View File
@@ -1,92 +0,0 @@
#!/bin/bash
# Read Settings
DIR=`dirname $0`
source $DIR/settings.cfg
cd $control_root
for(( ; ; ))
do
# Test for Running Servers
servers=$(./view.sh | grep $screen_name)
clear
if [[ -z $servers ]];
then
echo "Zway-Bot not Running!"
echo ""
echo "1) Start Zway-Bot"
else
echo "Zway-Bot is Running :)"
echo ""
echo "2) Stop Zway-Bot"
echo "3) Restart Zway-Bot"
echo "4) Attach to Servers Screen-Session"
echo "5) Put Command to Zway-Bot"
fi
echo "q) Quit"
echo ""
read -p "Choice: " choice
case "$choice" in
q) #Quit
exit 0
;;
1) #Start Server
if [[ -z $servers ]];
then
echo "Starting Zway-Bot..."
./start.sh
else
echo "Zway-Bot Allready started!"
fi
;;
2) #Stop Server
if [[ -z $servers ]];
then
echo "Zway-Bot is not Running!"
else
echo "Stopping Zway-Bot..."
./stop.sh
fi
;;
3) #Restart Server
if [[ -z $servers ]];
then
echo "Zway-Bot is not Running!"
else
echo "Restarting Zway-Bot..."
./restart.sh
fi
;;
4) #Attach to Screen
if [[ -z $servers ]];
then
echo "Zway-Bot is not Running!"
else
./join.sh
fi
;;
5) #Put Command to Server
if [[ -z $servers ]];
then
echo "Zway-Bot is not Running!"
else
read -p "Please enter Zway-Bot-Command: " mc_cmd
./stuff.sh "$mc_cmd"
fi
;;
*) #Invalid Selection
echo "Wrong Selection!"
;;
esac
done
-10
View File
@@ -1,10 +0,0 @@
#!/bin/bash
# Read Settings
DIR=`dirname $0`
source $DIR/settings.cfg
echo Press STRG+A then D to detach from Console
read -p "Press [Enter] to continue..."
screen -R $screen_name
-21
View File
@@ -1,21 +0,0 @@
#!/bin/bash
# Read Settings
DIR=`dirname $0`
source $DIR/settings.cfg
rm $control_root/stop_server.info
for(( ; ; ))
do
if [ ! -e $control_root/stop_server.info ];
then
cd $mc_root
$mc_cmd
else
echo "Stopped Server!"
break
fi
done
rm $control_root/stop_server.info
-28
View File
@@ -1,28 +0,0 @@
#!/bin/bash
# Read Settings
DIR=`dirname $0`
source $DIR/settings.cfg
cd $control_root
# Be Shure theere is no Stop-Info
rm $control_root/stop_server.info
echo "Server will be restarted in 5 Seconds..."
./stuff.sh "/say ReStarting Server in 5 seconds!"
sleep 1
echo "4..."
./stuff.sh "/say 4..."
sleep 1
echo "3..."
./stuff.sh "/say 3..."
sleep 1
echo "2..."
./stuff.sh "/say 2..."
sleep 1
echo "1..."
./stuff.sh "/say 1..."
sleep 1
echo "Restarting Server..."
./stuff.sh "/say Restart Now!"
./stuff.sh "stop"
-23
View File
@@ -1,23 +0,0 @@
#!/bin/bash
# Minecraft Control-Scripts Config-File
# (please remember that there are no spaces allowed around the =-Sign
# in the config-lines)
# Minecraft-Dir & JAR
# Directory where minecraft is in
mc_root="/home/pi/Zway-Bot"
# Root of Control-Scripts
control_root="$mc_root/control"
# MC-Server-Jar (will be executed in mc_root)
mc_jar="$mc_root/Zway-Bot.exe"
# MC-Server Start-Command
mc_cmd="mono $mc_jar"
# Screen
screen_name="Zway-Bot"
-14
View File
@@ -1,14 +0,0 @@
#!/bin/bash
# Read Settings
DIR=`dirname $0`
source $DIR/settings.cfg
# Start Loop in Screen
screen -A -m -d -S $screen_name $control_root/loop.sh
# Allow other users to control this screen-Session!
screen -r $screen_name -X multiuser on
screen -r $screen_name -X addacl www-data
screen -r $screen_name -X addacl mc
screen -r $screen_name -X addacl mw
-13
View File
@@ -1,13 +0,0 @@
#!/bin/bash
# Read Settings
DIR=`dirname $0`
source $DIR/settings.cfg
cd $control_root
# Create Stop-Info!
touch $control_root/stop_server.info
echo "Shuting Down Server..."
./stuff.sh "/exit"
screen -R $screen_name
-10
View File
@@ -1,10 +0,0 @@
#!/bin/bash
# Read Settings
DIR=`dirname $0`
source $DIR/settings.cfg
# screen -r $screen_name -X stuff "$1\n"
screen -p 0 -S $screen_name -X eval "stuff '$1'\015"
# as_user "screen -p 0 -S minecraft -X eval 'stuff \"$command\"\015'"
-3
View File
@@ -1,3 +0,0 @@
#!/bin/bash
screen -ls
Binary file not shown.
+1 -1
View File
@@ -1,4 +1,4 @@
[modul]
[modul]
config=public
[cold]
+1 -1
View File
@@ -1,4 +1,4 @@
[modul]
[modul]
config=private
[settings]
+1 -1
View File
@@ -1,4 +1,4 @@
[names]
[names]
2-0-37=Kühlschrank Schalter
2-0-49-4=Kühlschrank Leistung
2-0-50-0=Kühlschrank Verbrauch [kWh]
@@ -1,4 +1,4 @@
[hot]
[hot]
from=7-0-67-1:Level
to=8-0-67-1:Level;9-0-67-1:Level
+1 -1
View File
@@ -1,4 +1,4 @@
[modul]
[modul]
config=private
[settings]
@@ -1,4 +1,7 @@
[zway]
[zway]
server=localhost
user=admin
pass=pass
pass=pass
[logging]
path=/var/log/zwaybot.log
@@ -1,3 +1,3 @@
[temp]
[temp]
cron=30 * * * *
devices=7-0-49-1,8-0-49-1,9-0-49-1,10-0-49-1,11-0-49-1
-92
View File
@@ -1,92 +0,0 @@
#!/bin/bash
# Read Settings
DIR=`dirname $0`
source $DIR/settings.cfg
cd $control_root
for(( ; ; ))
do
# Test for Running Servers
servers=$(./view.sh | grep $screen_name)
clear
if [[ -z $servers ]];
then
echo "Zway-Bot not Running!"
echo ""
echo "1) Start Zway-Bot"
else
echo "Zway-Bot is Running :)"
echo ""
echo "2) Stop Zway-Bot"
echo "3) Restart Zway-Bot"
echo "4) Attach to Servers Screen-Session"
echo "5) Put Command to Zway-Bot"
fi
echo "q) Quit"
echo ""
read -p "Choice: " choice
case "$choice" in
q) #Quit
exit 0
;;
1) #Start Server
if [[ -z $servers ]];
then
echo "Starting Zway-Bot..."
./start.sh
else
echo "Zway-Bot Allready started!"
fi
;;
2) #Stop Server
if [[ -z $servers ]];
then
echo "Zway-Bot is not Running!"
else
echo "Stopping Zway-Bot..."
./stop.sh
fi
;;
3) #Restart Server
if [[ -z $servers ]];
then
echo "Zway-Bot is not Running!"
else
echo "Restarting Zway-Bot..."
./restart.sh
fi
;;
4) #Attach to Screen
if [[ -z $servers ]];
then
echo "Zway-Bot is not Running!"
else
./join.sh
fi
;;
5) #Put Command to Server
if [[ -z $servers ]];
then
echo "Zway-Bot is not Running!"
else
read -p "Please enter Zway-Bot-Command: " mc_cmd
./stuff.sh "$mc_cmd"
fi
;;
*) #Invalid Selection
echo "Wrong Selection!"
;;
esac
done
-10
View File
@@ -1,10 +0,0 @@
#!/bin/bash
# Read Settings
DIR=`dirname $0`
source $DIR/settings.cfg
echo Press STRG+A then D to detach from Console
read -p "Press [Enter] to continue..."
screen -R $screen_name
-21
View File
@@ -1,21 +0,0 @@
#!/bin/bash
# Read Settings
DIR=`dirname $0`
source $DIR/settings.cfg
rm $control_root/stop_server.info
for(( ; ; ))
do
if [ ! -e $control_root/stop_server.info ];
then
cd $mc_root
$mc_cmd
else
echo "Stopped Server!"
break
fi
done
rm $control_root/stop_server.info
-28
View File
@@ -1,28 +0,0 @@
#!/bin/bash
# Read Settings
DIR=`dirname $0`
source $DIR/settings.cfg
cd $control_root
# Be Shure theere is no Stop-Info
rm $control_root/stop_server.info
echo "Server will be restarted in 5 Seconds..."
./stuff.sh "/say ReStarting Server in 5 seconds!"
sleep 1
echo "4..."
./stuff.sh "/say 4..."
sleep 1
echo "3..."
./stuff.sh "/say 3..."
sleep 1
echo "2..."
./stuff.sh "/say 2..."
sleep 1
echo "1..."
./stuff.sh "/say 1..."
sleep 1
echo "Restarting Server..."
./stuff.sh "/say Restart Now!"
./stuff.sh "stop"
-23
View File
@@ -1,23 +0,0 @@
#!/bin/bash
# Minecraft Control-Scripts Config-File
# (please remember that there are no spaces allowed around the =-Sign
# in the config-lines)
# Minecraft-Dir & JAR
# Directory where minecraft is in
mc_root="/home/pi/Zway-Bot"
# Root of Control-Scripts
control_root="$mc_root/control"
# MC-Server-Jar (will be executed in mc_root)
mc_jar="$mc_root/Zway-Bot.exe"
# MC-Server Start-Command
mc_cmd="mono $mc_jar"
# Screen
screen_name="Zway-Bot"
-14
View File
@@ -1,14 +0,0 @@
#!/bin/bash
# Read Settings
DIR=`dirname $0`
source $DIR/settings.cfg
# Start Loop in Screen
screen -A -m -d -S $screen_name $control_root/loop.sh
# Allow other users to control this screen-Session!
screen -r $screen_name -X multiuser on
screen -r $screen_name -X addacl www-data
screen -r $screen_name -X addacl mc
screen -r $screen_name -X addacl mw
-13
View File
@@ -1,13 +0,0 @@
#!/bin/bash
# Read Settings
DIR=`dirname $0`
source $DIR/settings.cfg
cd $control_root
# Create Stop-Info!
touch $control_root/stop_server.info
echo "Shuting Down Server..."
./stuff.sh "/exit"
screen -R $screen_name
-10
View File
@@ -1,10 +0,0 @@
#!/bin/bash
# Read Settings
DIR=`dirname $0`
source $DIR/settings.cfg
# screen -r $screen_name -X stuff "$1\n"
screen -p 0 -S $screen_name -X eval "stuff '$1'\015"
# as_user "screen -p 0 -S minecraft -X eval 'stuff \"$command\"\015'"
-3
View File
@@ -1,3 +0,0 @@
#!/bin/bash
screen -ls
+10 -10
View File
@@ -1,10 +1,10 @@
Package: zwaybot
Version: x.x-x
Section: base
Priority: optional
Architecture: i386
Depends: mono-complete (>= 5.4.1.6)
Maintainer: BlubbFish <dev@blubbfish.net>
Description: Zway-Bot
Zway-Bot manage a Zwave.me installation
so that it has more features
Package: zwaybot
Version: x.x-x
Section: base
Priority: optional
Architecture: any
Depends: mono-complete (>= 5.4.1.6)
Maintainer: BlubbFish <dev@blubbfish.net>
Description: Zway-Bot
Zway-Bot manage a Zwave.me installation
so that it has more features
+1 -6
View File
@@ -1,6 +1 @@
set /P maj=Enter Major Version:
set /P min=Enter Minor Version:
set /P bui=Enter Build Version:
bash.exe -c "./make-deb.sh %maj% %min% %bui%"
pause
bash.exe -c "./make-deb.sh armhf"
+32 -9
View File
@@ -1,26 +1,49 @@
#!/bin/bash
WORKDIR="/home/blubb"
ROOT="$WORKDIR/deb"
HOMEDIR="/home/blubb"
ROOT="$HOMEDIR/deb"
OUTPUT="../bin/Release"
EXEC="$ROOT/usr/local/bin/zwaybot"
CONFIG="$ROOT/etc/zwaybot"
SYSTEMD="$ROOT/etc/systemd/system"
LOGROTATE="$ROOT/etc/logrotate.d"
DEBIAN="$ROOT/DEBIAN"
VMAJOR=$1
VMINOR=$2
VBUILD=$3
VMAJOR=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 1)
VMINOR=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 2)
VBUILD=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 3)
ARCHT=$1
mkdir -p $EXEC
mkdir -p $CONFIG
mkdir -p $DEBIAN
mkdir -p $SYSTEMD
mkdir -p $LOGROTATE
cp control $DEBIAN
cp preinst $DEBIAN
cp postinst $DEBIAN
cp prerm $DEBIAN
sed -i s/Version:\ x\.x-x/"Version: $VMAJOR.$VMINOR-$VBUILD"/ $DEBIAN/control
sed -i s/Architecture:\ any/"Architecture: $ARCHT"/ $DEBIAN/control
chmod 755 $DEBIAN -R
cp zwaybot.service $SYSTEMD
chmod 644 $SYSTEMD/zwaybot.service
cp $OUTPUT/*.exe $EXEC/
cp $OUTPUT/*.dll $EXEC/
find $OUTPUT -name \*.dll ! -name Mono.Posix.dll -exec cp {} $EXEC/ \;
chmod 644 $EXEC/*
chmod 755 $EXEC
cp $OUTPUT/config-example/* $CONFIG
cp $OUTPUT/control $EXEC/ -r
chmod 644 $CONFIG/*
chmod 755 $CONFIG
cp zwaybot-logrotate $LOGROTATE/zwaybot
chmod 644 $LOGROTATE/*
dpkg-deb --build $ROOT
mv $WORKDIR/deb.deb ../bin/Builds/"zwaybot_$VMAJOR.$VMINOR-$VBUILD.deb"
rm $WORKDIR/deb -r
mv $HOMEDIR/deb.deb ../../../Builds/"$ARCHT-zwaybot_$VMAJOR.$VMINOR-$VBUILD.deb"
rm $HOMEDIR/deb -r
+1
View File
@@ -0,0 +1 @@
Name "Example1"
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
systemctl daemon-reload
if [[ $(systemctl is-active zwaybot || true) == "active" ]]
then
service zwaybot restart
fi
+6
View File
@@ -0,0 +1,6 @@
#!/bin/bash
useradd -M zwaybot
usermod -L zwaybot
groupadd zwaybot
usermod -G zwaybot,adm zwaybot
+3
View File
@@ -0,0 +1,3 @@
#!/bin/bash
service zwaybot stop
+10
View File
@@ -0,0 +1,10 @@
/var/log/zwaybot.log {
compress
copytruncate
daily
delaycompress
missingok
notifempty
rotate 4
size=10M
}
+20
View File
@@ -0,0 +1,20 @@
# If you modify this, please also make sure to edit init.sh
[Unit]
Description=Zway-Bot manage a Zwave.me installation so that it has more features
After=network-online.target
[Service]
User=zwaybot
Group=zwaybot
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
Restart=on-failure
StandardOutput=null
StandardError=syslog
[Install]
WantedBy=multi-user.target
Alias=zwaybot.service