Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc108773d9 | ||
|
|
92a6ba2b64 | ||
|
|
57daf12ed4 | ||
|
|
cabcce03b3 | ||
|
|
a9c77c6614 | ||
|
|
1c84703ac6 | ||
|
|
25e1e5165d | ||
|
|
a76234f43d | ||
|
|
a3afadd5f5 | ||
|
|
002b3cf338 |
+7
-1
@@ -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
|
||||
|
||||
@@ -6,7 +6,7 @@ using BlubbFish.Utils;
|
||||
namespace ZwayBot {
|
||||
abstract class AModul {
|
||||
protected ZwayController zw;
|
||||
private InIReader settings;
|
||||
private readonly InIReader settings;
|
||||
protected Dictionary<String, Dictionary<String, String>> config = new Dictionary<String, Dictionary<String, String>>();
|
||||
|
||||
public Boolean HasConfig { get; private set; }
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace ZwayBot.Moduls {
|
||||
|
||||
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 * *" },
|
||||
@@ -166,19 +166,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);
|
||||
|
||||
+40
-4
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using BlubbFish.IoT.Zway;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
@@ -12,18 +13,51 @@ using LitJson;
|
||||
namespace ZwayBot.Moduls {
|
||||
class Mqtt : AModul, IDisposable {
|
||||
private ABackend mqtt;
|
||||
private readonly Thread connectionWatcher;
|
||||
private Dictionary<String, AModul> modules;
|
||||
|
||||
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;
|
||||
this.connectionWatcher = new Thread(this.ConnectionWatcherRunner);
|
||||
this.connectionWatcher.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void ConnectionWatcherRunner() {
|
||||
while (true) {
|
||||
try {
|
||||
if (this.mqtt == null || !this.mqtt.IsConnected) {
|
||||
this.Reconnect();
|
||||
}
|
||||
Thread.Sleep(10000);
|
||||
} catch (Exception) { }
|
||||
}
|
||||
}
|
||||
|
||||
private void Reconnect() {
|
||||
this.Disconnect();
|
||||
this.Connect();
|
||||
}
|
||||
|
||||
private void Disconnect() {
|
||||
if (this.mqtt != null) {
|
||||
this.mqtt.MessageIncomming -= this.Mqtt_MessageIncomming;
|
||||
}
|
||||
this.zw.Update -= this.ZwayEvent;
|
||||
if (this.mqtt != null) {
|
||||
this.mqtt.Dispose();
|
||||
}
|
||||
this.mqtt = null;
|
||||
}
|
||||
|
||||
private void Connect() {
|
||||
this.mqtt = ABackend.GetInstance(this.config["settings"], ABackend.BackendType.Data);
|
||||
this.mqtt.MessageIncomming += this.Mqtt_MessageIncomming;
|
||||
this.zw.Update += this.ZwayEvent;
|
||||
}
|
||||
|
||||
private void ZwayEvent(Object sender, DeviceUpdateEvent e) {
|
||||
String topic = "";
|
||||
String data = "";
|
||||
@@ -119,7 +153,9 @@ namespace ZwayBot.Moduls {
|
||||
protected virtual void Dispose(Boolean disposing) {
|
||||
if (!this.disposedValue) {
|
||||
if (disposing) {
|
||||
this.mqtt.Dispose();
|
||||
this.connectionWatcher.Abort();
|
||||
while(this.connectionWatcher.ThreadState == ThreadState.Running) { Thread.Sleep(10); }
|
||||
this.Disconnect();
|
||||
}
|
||||
this.disposedValue = true;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ using BlubbFish.Utils;
|
||||
|
||||
namespace ZwayBot.Moduls {
|
||||
internal class Overtaker : AModul, 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;
|
||||
|
||||
@@ -89,10 +89,6 @@ namespace ZwayBot.Moduls {
|
||||
}
|
||||
}
|
||||
|
||||
~Overtaker() {
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
@@ -9,8 +9,8 @@ using BlubbFish.Utils.IoT.Interfaces;
|
||||
namespace ZwayBot.Moduls {
|
||||
class Senml : AModul {
|
||||
public override event ModulEvent Update;
|
||||
private ABackend mqtt;
|
||||
private String SenmlGuid;
|
||||
private readonly ABackend mqtt;
|
||||
private readonly String SenmlGuid;
|
||||
|
||||
public Senml(ZwayController zway, InIReader settings) : base(zway, settings) {
|
||||
if (this.config.ContainsKey("settings")) {
|
||||
|
||||
+14
-8
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using BlubbFish.IoT.Zway;
|
||||
using BlubbFish.Utils;
|
||||
|
||||
@@ -11,7 +12,7 @@ namespace ZwayBot {
|
||||
private readonly ZwayController zw;
|
||||
private readonly Dictionary<String, AModul> moduls = new Dictionary<String, AModul>();
|
||||
private Boolean RunningProcess = true;
|
||||
private System.Threading.Thread sig_thread;
|
||||
private Thread sig_thread;
|
||||
private readonly ProgramLogger logger = new ProgramLogger();
|
||||
|
||||
public Program(String[] args) {
|
||||
@@ -44,27 +45,32 @@ namespace ZwayBot {
|
||||
|
||||
private void WaitForShutdown() {
|
||||
if (Type.GetType("Mono.Runtime") != null) {
|
||||
this.sig_thread = new System.Threading.Thread(delegate () {
|
||||
this.sig_thread = new Thread(delegate () {
|
||||
Mono.Unix.UnixSignal[] signals = new Mono.Unix.UnixSignal[] {
|
||||
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
|
||||
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGINT)
|
||||
};
|
||||
while (this.RunningProcess) {
|
||||
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
|
||||
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGINT)
|
||||
};
|
||||
Console.WriteLine("Signalhandler Mono attached.");
|
||||
while (true) {
|
||||
Int32 i = Mono.Unix.UnixSignal.WaitAny(signals, -1);
|
||||
this.RunningProcess = false;
|
||||
Console.WriteLine("Signalhandler Mono INT recieved " + i + ".");
|
||||
this.RunningProcess = false; // TODO BUG
|
||||
break;
|
||||
}
|
||||
});
|
||||
this.sig_thread.Start();
|
||||
} else {
|
||||
Console.CancelKeyPress += new ConsoleCancelEventHandler(this.SetupShutdown);
|
||||
Console.WriteLine("Signalhandler Windows attached.");
|
||||
}
|
||||
while (this.RunningProcess) {
|
||||
System.Threading.Thread.Sleep(100);
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupShutdown(Object sender, ConsoleCancelEventArgs e) {
|
||||
e.Cancel = true;
|
||||
Console.WriteLine("Signalhandler Windows INT recieved.");
|
||||
this.RunningProcess = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("BlubbFish")]
|
||||
[assembly: AssemblyProduct("Zway-Bot")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017 - 15.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.5.0")]
|
||||
[assembly: AssemblyFileVersion("1.5.0")]
|
||||
[assembly: AssemblyVersion("1.6.0")]
|
||||
[assembly: AssemblyFileVersion("1.6.0")]
|
||||
[assembly: NeutralResourcesLanguage("de-DE")]
|
||||
|
||||
// “Internet Of Things” icon by By Michael Wohlwend, US, from thenounproject.com.
|
||||
|
||||
@@ -125,6 +125,7 @@
|
||||
<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="packages.config" />
|
||||
<None Include="Resources\Icon.ico" />
|
||||
|
||||
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.
@@ -3,9 +3,12 @@
|
||||
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=$(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)
|
||||
@@ -16,6 +19,7 @@ mkdir -p $EXEC
|
||||
mkdir -p $CONFIG
|
||||
mkdir -p $DEBIAN
|
||||
mkdir -p $SYSTEMD
|
||||
mkdir -p $LOGROTATE
|
||||
|
||||
cp control $DEBIAN
|
||||
cp preinst $DEBIAN
|
||||
@@ -37,6 +41,9 @@ cp $OUTPUT/config-example/* $CONFIG
|
||||
chmod 644 $CONFIG/*
|
||||
chmod 755 $CONFIG
|
||||
|
||||
cp zwaybot-logrotate $LOGROTATE/zwaybot
|
||||
chmod 644 $LOGROTATE/*
|
||||
|
||||
dpkg-deb --build $ROOT
|
||||
mv $HOMEDIR/deb.deb ../../../Builds/$ARCHT/"zwaybot_$VMAJOR.$VMINOR-$VBUILD.deb"
|
||||
mv $HOMEDIR/deb.deb ../../../Builds/"$ARCHT-zwaybot_$VMAJOR.$VMINOR-$VBUILD.deb"
|
||||
rm $HOMEDIR/deb -r
|
||||
@@ -1,4 +1,7 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
systemctl daemon-reload
|
||||
service zwaybot start
|
||||
if [[ $(systemctl is-active zwaybot || true) == "active" ]]
|
||||
then
|
||||
service zwaybot restart
|
||||
fi
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
service zwaybot stop
|
||||
useradd -M zwaybot
|
||||
usermod -L zwaybot
|
||||
groupadd zwaybot
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
/var/log/zwaybot.log {
|
||||
compress
|
||||
copytruncate
|
||||
daily
|
||||
delaycompress
|
||||
missingok
|
||||
notifempty
|
||||
rotate 4
|
||||
size=10M
|
||||
}
|
||||
@@ -8,10 +8,12 @@ After=network-online.target
|
||||
User=zwaybot
|
||||
Group=zwaybot
|
||||
WorkingDirectory=/usr/local/bin/zwaybot
|
||||
ExecStartPre=rm /var/log/zwaybot.log && touch /var/log/zwaybot.log && chown zwaybot:zwaybot /var/log/zwaybot.log && chmod 644 /var/log/zwaybot.log
|
||||
# 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+journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
Reference in New Issue
Block a user