Compare commits

..
15 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
67 changed files with 181 additions and 963 deletions
+7 -1
View File
@@ -17,7 +17,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Iot-Interfaces", "..\Utils\
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson_4.7.1", "..\Librarys\litjson\litjson\litjson_4.7.1.csproj", "{91A14CD2-2940-4500-8193-56D37EDDDBAA}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson_4.7.1", "..\Librarys\litjson\litjson\litjson_4.7.1.csproj", "{91A14CD2-2940-4500-8193-56D37EDDDBAA}"
EndProject 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution 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}.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.ActiveCfg = Release|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE 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;
using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils; 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 { namespace ZwayBot.Moduls {
internal class CronJob : AModul, IDisposable, IForceLoad { internal class CronJob : AModul<ZwayController>, IDisposable, IForceLoad {
private DateTime crontime; private DateTime crontime;
private Thread thread; 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; 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 *" }, { "@yearly", "0 0 1 1 *" },
{ "@annually", "0 0 1 1 *" }, { "@annually", "0 0 1 1 *" },
{ "@monthly", "0 0 1 * *" }, { "@monthly", "0 0 1 * *" },
@@ -58,7 +61,7 @@ namespace ZwayBot.Moduls {
String[] items = item.Split(':'); String[] items = item.Split(':');
if(items.Length == 2) { if(items.Length == 2) {
String[] values = items[1].Split('-'); 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 != null && values.Length == 2) {
if (c.HasProperty(values[0])) { if (c.HasProperty(values[0])) {
c.SetProperty(values[0], values[1]); c.SetProperty(values[0], values[1]);
@@ -166,19 +169,13 @@ namespace ZwayBot.Moduls {
if (!this.disposedValue) { if (!this.disposedValue) {
if (disposing) { if (disposing) {
this.thread.Abort(); 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.thread = null;
this.disposedValue = true; this.disposedValue = true;
} }
} }
~CronJob() {
Dispose(false);
}
public override void Dispose() { public override void Dispose() {
Dispose(true); Dispose(true);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
+37 -78
View File
@@ -1,55 +1,69 @@
using System; using System;
using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway; using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils; 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.Connector;
using BlubbFish.Utils.IoT.Events; using BlubbFish.Utils.IoT.Events;
using BlubbFish.Utils.IoT.Interfaces;
using LitJson; using LitJson;
namespace ZwayBot.Moduls { namespace ZwayBot.Moduls {
class Mqtt : AModul, IDisposable { class Mqtt : Mqtt<ZwayController> {
private ABackend mqtt;
private Dictionary<String, AModul> modules;
public override event ModulEvent Update; public override event ModulEvent Update;
public Mqtt(ZwayController zway, InIReader settings) : base(zway, settings) { public Mqtt(ZwayController zwave, InIReader settings) : base(zwave, settings) { }
if (this.config.ContainsKey("settings")) {
#region Mqtt
protected override void Connect() {
this.mqtt = ABackend.GetInstance(this.config["settings"], ABackend.BackendType.Data); this.mqtt = ABackend.GetInstance(this.config["settings"], ABackend.BackendType.Data);
this.mqtt.MessageIncomming += this.Mqtt_MessageIncomming; this.mqtt.MessageIncomming += this.EventInput;
this.zw.Update += this.ZwayEvent; 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 topic = "";
String data = ""; String data = "";
if(e.Parent.HasAbstract(typeof(ACommandClass))) { if (e.Parent.GetType().HasInterface(typeof(IMqtt))) {
ACommandClass sensor = (ACommandClass)e.Parent; IMqtt sensor = (IMqtt)e.Parent;
topic = "zwavebot/devices/" + sensor.MqttTopic(); topic = "zwavebot/devices/" + sensor.MqttTopic();
data = sensor.ToJson(); data = sensor.ToJson();
} }
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));
} }
} }
private void Mqtt_MessageIncomming(Object sender, BackendEvent e) { 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"))) { 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()); 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 = ""; 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; 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; id = m.Groups[4].Value + "-" + m.Groups[5].Value + "-" + m.Groups[6].Value + "-" + m.Groups[7].Value;
} }
ACommandClass c = this.zw.GetCommandClass(id); ACommandClass c = this.library.GetCommandClass(id);
if(c == null) { if (c == null) {
return; return;
} }
if (e.From.ToString().EndsWith("/set")) { if (e.From.ToString().EndsWith("/set")) {
@@ -63,71 +77,16 @@ namespace ZwayBot.Moduls {
} }
} }
} catch (Exception) { } } catch (Exception) { }
} else if(e.From.ToString().EndsWith("/get")) { } else if (e.From.ToString().EndsWith("/get")) {
c.PollOnce = true; 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")); 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"))) { Tuple<Boolean, MqttEvent> cs = this.ChangeConfig(e, "zwavebot/config/");
Match m = new Regex("^zwavebot/config/(\\w+)/[gs]et$|").Match(e.From.ToString()); if (cs.Item1) {
if (!m.Groups[1].Success) { this.Update?.Invoke(this, cs.Item2);
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) { }
}
}
}
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 #endregion
} }
+8 -9
View File
@@ -4,10 +4,13 @@ using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils; using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Bots;
using BlubbFish.Utils.IoT.Bots.Events;
using BlubbFish.Utils.IoT.Bots.Moduls;
namespace ZwayBot.Moduls { namespace ZwayBot.Moduls {
internal class Overtaker : AModul, IDisposable { internal class Overtaker : AModul<ZwayController>, IDisposable {
private Dictionary<String, Dictionary<String, String>> events = new Dictionary<String, Dictionary<String, String>>(); private readonly Dictionary<String, Dictionary<String, String>> events = new Dictionary<String, Dictionary<String, String>>();
public override event ModulEvent Update; public override event ModulEvent Update;
@@ -21,7 +24,7 @@ namespace ZwayBot.Moduls {
String from = item.Value["from"]; String from = item.Value["from"];
String[] source = from.Split(':'); String[] source = from.Split(':');
this.events.Add(source[0], item.Value); this.events.Add(source[0], item.Value);
ACommandClass c = this.zw.GetCommandClass(source[0]); ACommandClass c = this.library.GetCommandClass(source[0]);
if (c != null) { if (c != null) {
c.Polling = true; c.Polling = true;
c.Update += this.ChangedEvent; c.Update += this.ChangedEvent;
@@ -31,7 +34,7 @@ namespace ZwayBot.Moduls {
} }
private void ChangedEvent(Object sender, DeviceUpdateEvent e) { 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)) { if (this.events.ContainsKey(((ACommandClass)sender).Id)) {
this.SetValues(sender, ((ACommandClass)sender).Id, this.events[((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(';')) { foreach (String to in dictionary["to"].Split(';')) {
String[] target = to.Split(':'); String[] target = to.Split(':');
if (target.Length == 2) { if (target.Length == 2) {
ACommandClass c = this.zw.GetCommandClass(target[0]); ACommandClass c = this.library.GetCommandClass(target[0]);
if (c != null) { if (c != null) {
if (c.HasProperty(target[1])) { if (c.HasProperty(target[1])) {
if (c.GetProperty(target[1]).ToString() != source_value) { if (c.GetProperty(target[1]).ToString() != source_value) {
@@ -89,10 +92,6 @@ namespace ZwayBot.Moduls {
} }
} }
~Overtaker() {
Dispose(false);
}
public override void Dispose() { public override void Dispose() {
Dispose(true); Dispose(true);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
+8 -32
View File
@@ -2,63 +2,39 @@
using BlubbFish.IoT.Zway; using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.Utils; using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Bots;
using BlubbFish.Utils.IoT.Bots.Events;
using BlubbFish.Utils.IoT.Connector; using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Events; using BlubbFish.Utils.IoT.Events;
using BlubbFish.Utils.IoT.Interfaces; using BlubbFish.Utils.IoT.Interfaces;
namespace ZwayBot.Moduls { namespace ZwayBot.Moduls {
class Senml : AModul { class Senml : Mqtt {
public override event ModulEvent Update; public override event ModulEvent Update;
private ABackend mqtt; private readonly String SenmlGuid;
private String SenmlGuid;
public Senml(ZwayController zway, InIReader settings) : base(zway, settings) { public Senml(ZwayController zway, InIReader settings) : base(zway, settings) {
if (this.config.ContainsKey("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"]; this.SenmlGuid = this.config["settings"]["guid"];
} }
} }
#region Events #region Events
private void EventOutput(Object sender, DeviceUpdateEvent e) { protected override void EventOutput(Object sender, DeviceUpdateEvent e) {
String topic = ""; String topic = "";
String data = ""; String data = "";
if (e.Parent.HasInterface(typeof(ISenml))) { if (e.Parent.GetType().HasInterface(typeof(ISenml))) {
ISenml sensor = (ISenml)e.Parent; ISenml sensor = (ISenml)e.Parent;
topic = sensor.SenmlTopic() + this.SenmlGuid+ "/senml"; topic = sensor.SenmlTopic() + this.SenmlGuid+ "/senml";
data = sensor.ToSenml(); data = sensor.ToSenml();
} }
if (topic != "" && data != null && data != "") { if (topic != "" && data != null && 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 SenmlEvent(topic, data));
} }
} }
private void EventInput(Object sender, BackendEvent e) { } protected override 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);
}
#endregion #endregion
} }
} }
+10 -8
View File
@@ -4,23 +4,25 @@ using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Devices; using BlubbFish.IoT.Zway.Devices;
using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils; 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 { namespace ZwayBot.Moduls {
class Statuspolling : AModul, IDisposable, IForceLoad { class Statuspolling : AModul<ZwayController>, IDisposable, IForceLoad {
public override event ModulEvent Update; public override event ModulEvent Update;
public Statuspolling(ZwayController zway, InIReader settings) : base(zway, settings) { } public Statuspolling(ZwayController zway, InIReader settings) : base(zway, settings) { }
public override void Interconnect(Dictionary<String, AModul> moduls) { public override void Interconnect(Dictionary<String, Object> moduls) {
foreach (KeyValuePair<String, AModul> item in moduls) { foreach (KeyValuePair<String, Object> item in moduls) {
if (item.Value is CronJob) { 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) { if (this.config.Count != 0) {
foreach (KeyValuePair<String, Dictionary<String, String>> section in this.config) { foreach (KeyValuePair<String, Dictionary<String, String>> section in this.config) {
if (section.Value.ContainsKey("cron") && section.Value.ContainsKey("devices")) { 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) { private void PollSpecific(Object obj) {
String devices = (String)obj; String devices = (String)obj;
foreach (String item in devices.Split(',')) { foreach (String item in devices.Split(',')) {
ACommandClass c = this.zw.GetCommandClass(item); ACommandClass c = this.library.GetCommandClass(item);
c.PollOnce = true; c.PollOnce = true;
this.Update?.Invoke(this, new StatusPollingEvent("Polling", item)); this.Update?.Invoke(this, new StatusPollingEvent("Polling", item));
} }
} }
private void PollAll(Object o) { 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<Int32, Instance> instance in device.Value.Instances) {
foreach (KeyValuePair<ACommandClass.Classes, ACommandClass> commandclass in instance.Value.CommandClasses) { foreach (KeyValuePair<ACommandClass.Classes, ACommandClass> commandclass in instance.Value.CommandClasses) {
commandclass.Value.PollOnce = true; commandclass.Value.PollOnce = true;
+9 -66
View File
@@ -1,18 +1,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection;
using BlubbFish.IoT.Zway; using BlubbFish.IoT.Zway;
using BlubbFish.Utils; using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Bots;
namespace ZwayBot { namespace ZwayBot {
class Program { class Program : Bot {
static void Main(String[] args) => new Program(args); static void Main(String[] args) => new Program(args);
private readonly ZwayController zw;
private readonly Dictionary<String, AModul> moduls = new Dictionary<String, AModul>();
private Boolean RunningProcess = true;
private readonly ProgramLogger logger = new ProgramLogger();
public Program(String[] args) { public Program(String[] args) {
InIReader.SetSearchPath(new List<String>() { "/etc/zwaybot", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zwaybot" }); InIReader.SetSearchPath(new List<String>() { "/etc/zwaybot", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zwaybot" });
Dictionary<String, String> names; Dictionary<String, String> names;
@@ -26,66 +21,14 @@ namespace ZwayBot {
return; return;
} }
this.logger.SetPath(InIReader.GetInstance("settings").GetValue("logging", "path")); this.logger.SetPath(InIReader.GetInstance("settings").GetValue("logging", "path"));
this.zw = new ZwayController(InIReader.GetInstance("settings").GetSection("zway"), names, false); ZwayController zw = new ZwayController(InIReader.GetInstance("settings").GetSection("zway"), names, false);
this.zw.Update += this.ZwayDataUpate; zw.Update += this.ZwayDataUpate;
this.ModulLoader(); this.ModulLoader<ZwayController>("ZwayBot.Moduls", zw);
this.ModulInterconnect(); this.ModulInterconnect<ZwayController>();
this.ModulEvents(); this.ModulEvents<ZwayController>();
this.WaitForShutdown(); this.WaitForShutdown();
this.ModulDispose(); this.ModulDispose<ZwayController>();
} zw.Dispose();
private void ModulInterconnect() {
foreach (KeyValuePair<String, AModul> item in this.moduls) {
item.Value.Interconnect(this.moduls);
}
}
private void WaitForShutdown() {
Console.CancelKeyPress += new ConsoleCancelEventHandler(this.SetupShutdown);
while (this.RunningProcess) {
System.Threading.Thread.Sleep(100);
}
}
private void SetupShutdown(Object sender, ConsoleCancelEventArgs e) {
e.Cancel = true;
this.RunningProcess = false;
}
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);
}
}
}
} }
private void ZwayDataUpate(Object sender, BlubbFish.IoT.Zway.Events.DeviceUpdateEvent e) { private void ZwayDataUpate(Object sender, BlubbFish.IoT.Zway.Events.DeviceUpdateEvent e) {
+3 -3
View File
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("BlubbFish")] [assembly: AssemblyCompany("BlubbFish")]
[assembly: AssemblyProduct("Zway-Bot")] [assembly: AssemblyProduct("Zway-Bot")]
[assembly: AssemblyCopyright("Copyright © 2017 - 15.05.2018")] [assembly: AssemblyCopyright("Copyright © 2017 - 05.06.2018")]
[assembly: AssemblyTrademark("BlubbFish")] [assembly: AssemblyTrademark("BlubbFish")]
[assembly: AssemblyCulture("")] [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, // 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.4.0")] [assembly: AssemblyVersion("1.6.1")]
[assembly: AssemblyFileVersion("1.4.0")] [assembly: AssemblyFileVersion("1.6.1")]
[assembly: NeutralResourcesLanguage("de-DE")] [assembly: NeutralResourcesLanguage("de-DE")]
// “Internet Of Things” icon by By Michael Wohlwend, US, from thenounproject.com. // “Internet Of Things” icon by By Michael Wohlwend, US, from thenounproject.com.
+12 -42
View File
@@ -12,6 +12,8 @@
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
@@ -38,24 +40,10 @@
<PropertyGroup> <PropertyGroup>
<ApplicationIcon>Resources\Icon.ico</ApplicationIcon> <ApplicationIcon>Resources\Icon.ico</ApplicationIcon>
</PropertyGroup> </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> <ItemGroup>
<None Include="dpkg\preinst" /> <None Include="dpkg\preinst" />
<Compile Include="Events.cs" /> <None Include="dpkg\postinst" />
<Compile Include="Interfaces\IForceLoad.cs" />
<Compile Include="Moduls\AModul.cs" />
<Compile Include="Moduls\CronJob.cs" /> <Compile Include="Moduls\CronJob.cs" />
<Compile Include="Helper.cs" />
<Compile Include="Moduls\Mqtt.cs" /> <Compile Include="Moduls\Mqtt.cs" />
<Compile Include="Moduls\Overtaker.cs" /> <Compile Include="Moduls\Overtaker.cs" />
<Compile Include="Moduls\Senml.cs" /> <Compile Include="Moduls\Senml.cs" />
@@ -73,6 +61,10 @@
<Project>{91a14cd2-2940-4500-8193-56d37edddbaa}</Project> <Project>{91a14cd2-2940-4500-8193-56d37edddbaa}</Project>
<Name>litjson_4.7.1</Name> <Name>litjson_4.7.1</Name>
</ProjectReference> </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"> <ProjectReference Include="..\..\Utils\IoT\Connector\Data\Mqtt\ConnectorDataMqtt.csproj">
<Project>{ee6c8f68-ed46-4c1c-abdd-cfcdf75104f2}</Project> <Project>{ee6c8f68-ed46-4c1c-abdd-cfcdf75104f2}</Project>
<Name>ConnectorDataMqtt</Name> <Name>ConnectorDataMqtt</Name>
@@ -95,33 +87,6 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<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"> <None Include="config-example\cronjob.conf.example">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
@@ -149,6 +114,7 @@
<None Include="dpkg\create-Builds.bat" /> <None Include="dpkg\create-Builds.bat" />
<None Include="dpkg\make-deb.sh" /> <None Include="dpkg\make-deb.sh" />
<None Include="dpkg\prerm" /> <None Include="dpkg\prerm" />
<None Include="dpkg\zwaybot-logrotate" />
<None Include="dpkg\zwaybot.service" /> <None Include="dpkg\zwaybot.service" />
<None Include="Resources\Icon.ico" /> <None Include="Resources\Icon.ico" />
<Content Include="Resources\icon.svg" /> <Content Include="Resources\icon.svg" />
@@ -159,5 +125,9 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </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.
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,4 @@
[modul] [modul]
config=public config=public
[cold] [cold]
@@ -1,4 +1,4 @@
[modul] [modul]
config=private config=private
[settings] [settings]
@@ -1,4 +1,4 @@
[names] [names]
2-0-37=Kühlschrank Schalter 2-0-37=Kühlschrank Schalter
2-0-49-4=Kühlschrank Leistung 2-0-49-4=Kühlschrank Leistung
2-0-50-0=Kühlschrank Verbrauch [kWh] 2-0-50-0=Kühlschrank Verbrauch [kWh]
@@ -1,4 +1,4 @@
[hot] [hot]
from=7-0-67-1:Level from=7-0-67-1:Level
to=8-0-67-1:Level;9-0-67-1:Level to=8-0-67-1:Level;9-0-67-1:Level
@@ -1,4 +1,4 @@
[modul] [modul]
config=private config=private
[settings] [settings]
@@ -1,4 +1,4 @@
[zway] [zway]
server=localhost server=localhost
user=admin user=admin
pass=pass pass=pass
@@ -1,3 +1,3 @@
[temp] [temp]
cron=30 * * * * cron=30 * * * *
devices=7-0-49-1,8-0-49-1,9-0-49-1,10-0-49-1,11-0-49-1 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 config=public
[cold] [cold]
+1 -1
View File
@@ -1,4 +1,4 @@
[modul] [modul]
config=private config=private
[settings] [settings]
+1 -1
View File
@@ -1,4 +1,4 @@
[names] [names]
2-0-37=Kühlschrank Schalter 2-0-37=Kühlschrank Schalter
2-0-49-4=Kühlschrank Leistung 2-0-49-4=Kühlschrank Leistung
2-0-50-0=Kühlschrank Verbrauch [kWh] 2-0-50-0=Kühlschrank Verbrauch [kWh]
@@ -1,4 +1,4 @@
[hot] [hot]
from=7-0-67-1:Level from=7-0-67-1:Level
to=8-0-67-1:Level;9-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 config=private
[settings] [settings]
@@ -1,4 +1,4 @@
[zway] [zway]
server=localhost server=localhost
user=admin user=admin
pass=pass pass=pass
@@ -1,3 +1,3 @@
[temp] [temp]
cron=30 * * * * cron=30 * * * *
devices=7-0-49-1,8-0-49-1,9-0-49-1,10-0-49-1,11-0-49-1 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
+1 -1
View File
@@ -2,7 +2,7 @@ Package: zwaybot
Version: x.x-x Version: x.x-x
Section: base Section: base
Priority: optional Priority: optional
Architecture: i386 Architecture: any
Depends: mono-complete (>= 5.4.1.6) Depends: mono-complete (>= 5.4.1.6)
Maintainer: BlubbFish <dev@blubbfish.net> Maintainer: BlubbFish <dev@blubbfish.net>
Description: Zway-Bot Description: Zway-Bot
+1 -6
View File
@@ -1,6 +1 @@
set /P maj=Enter Major Version: bash.exe -c "./make-deb.sh armhf"
set /P min=Enter Minor Version:
set /P bui=Enter Build Version:
bash.exe -c "./make-deb.sh %maj% %min% %bui%"
pause
+25 -10
View File
@@ -1,34 +1,49 @@
#!/bin/bash #!/bin/bash
WORKDIR="/home/blubb"
ROOT="$WORKDIR/deb" HOMEDIR="/home/blubb"
ROOT="$HOMEDIR/deb"
OUTPUT="../bin/Release" OUTPUT="../bin/Release"
EXEC="$ROOT/usr/local/bin/zwaybot" EXEC="$ROOT/usr/local/bin/zwaybot"
CONFIG="$ROOT/etc/zwaybot" CONFIG="$ROOT/etc/zwaybot"
SYSTEMD="$ROOT/etc/systemd/system" SYSTEMD="$ROOT/etc/systemd/system"
LOGROTATE="$ROOT/etc/logrotate.d"
DEBIAN="$ROOT/DEBIAN" DEBIAN="$ROOT/DEBIAN"
VMAJOR=$1 VMAJOR=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 1)
VMINOR=$2 VMINOR=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 2)
VBUILD=$3 VBUILD=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 3)
ARCHT=$1
mkdir -p $EXEC mkdir -p $EXEC
mkdir -p $CONFIG mkdir -p $CONFIG
mkdir -p $DEBIAN mkdir -p $DEBIAN
mkdir -p $SYSTEMD mkdir -p $SYSTEMD
mkdir -p $LOGROTATE
cp control $DEBIAN cp control $DEBIAN
cp preinst $DEBIAN cp preinst $DEBIAN
cp postinst $DEBIAN
cp prerm $DEBIAN cp prerm $DEBIAN
sed -i s/Version:\ x\.x-x/"Version: $VMAJOR.$VMINOR-$VBUILD"/ $DEBIAN/control 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 chmod 755 $DEBIAN -R
cp zwaybot.service $SYSTEMD cp zwaybot.service $SYSTEMD
chmod 755 $SYSTEMD -R chmod 644 $SYSTEMD/zwaybot.service
cp $OUTPUT/*.exe $EXEC/ 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/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 dpkg-deb --build $ROOT
mv $WORKDIR/deb.deb ../bin/Builds/"zwaybot_$VMAJOR.$VMINOR-$VBUILD.deb" mv $HOMEDIR/deb.deb ../../../Builds/"$ARCHT-zwaybot_$VMAJOR.$VMINOR-$VBUILD.deb"
rm $WORKDIR/deb -r rm $HOMEDIR/deb -r
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
systemctl daemon-reload
if [[ $(systemctl is-active zwaybot || true) == "active" ]]
then
service zwaybot restart
fi
+5 -3
View File
@@ -1,4 +1,6 @@
#!/bin/sh #!/bin/bash
service zwaybot stop useradd -M zwaybot
adduser --system zwaybot usermod -L zwaybot
groupadd zwaybot
usermod -G zwaybot,adm zwaybot
+10
View File
@@ -0,0 +1,10 @@
/var/log/zwaybot.log {
compress
copytruncate
daily
delaycompress
missingok
notifempty
rotate 4
size=10M
}
+3
View File
@@ -8,9 +8,12 @@ After=network-online.target
User=zwaybot User=zwaybot
Group=zwaybot Group=zwaybot
WorkingDirectory=/usr/local/bin/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 ExecStart=/usr/bin/mono /usr/local/bin/zwaybot/Zway-Bot.exe
KillMode=control-group KillMode=control-group
Restart=on-failure Restart=on-failure
StandardOutput=null
StandardError=syslog
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target