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)
This commit is contained in:
BlubbFish 2018-05-15 18:49:03 +00:00
parent 611205e78f
commit c792ea20ad
19 changed files with 65 additions and 21 deletions

View File

@ -29,7 +29,7 @@ namespace ZwayBot.Moduls {
String data = ""; String data = "";
if(e.Parent.HasAbstract(typeof(ACommandClass))) { if(e.Parent.HasAbstract(typeof(ACommandClass))) {
ACommandClass sensor = (ACommandClass)e.Parent; ACommandClass sensor = (ACommandClass)e.Parent;
topic = "/zwavebot/devices/" + sensor.MqttTopic(); topic = "zwavebot/devices/" + sensor.MqttTopic();
data = sensor.ToJson(); data = sensor.ToJson();
} }
if(topic != "" && data != "") { if(topic != "" && data != "") {
@ -39,8 +39,8 @@ namespace ZwayBot.Moduls {
} }
private void Mqtt_MessageIncomming(Object sender, BackendEvent e) { 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"))) { 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;
@ -65,12 +65,12 @@ 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"))) { 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()); Match m = new Regex("^zwavebot/config/(\\w+)/[gs]et$|").Match(e.From.ToString());
if (!m.Groups[1].Success) { if (!m.Groups[1].Success) {
return; return;
} }
@ -84,7 +84,7 @@ namespace ZwayBot.Moduls {
return; return;
} }
if(e.From.ToString().EndsWith("/get") && modul.HasConfig && modul.ConfigPublic) { if(e.From.ToString().EndsWith("/get") && modul.HasConfig && modul.ConfigPublic) {
String topic = "/zwavebot/config/" + m.Groups[1].Value; String topic = "zwavebot/config/" + m.Groups[1].Value;
String data = JsonMapper.ToJson(modul.GetConfig()).ToString(); String data = JsonMapper.ToJson(modul.GetConfig()).ToString();
((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));

View File

@ -8,8 +8,10 @@ namespace ZwayBot {
class Program { class Program {
static void Main(String[] args) => new Program(args); static void Main(String[] args) => new Program(args);
private ZwayController zw; private readonly ZwayController zw;
private Dictionary<String, AModul> moduls = new Dictionary<String, AModul>(); 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" });
@ -23,6 +25,7 @@ namespace ZwayBot {
Helper.WriteError("No settings.ini found. Abord!"); Helper.WriteError("No settings.ini found. Abord!");
return; return;
} }
this.logger.SetPath(InIReader.GetInstance("settings").GetValue("logging", "path"));
this.zw = new ZwayController(InIReader.GetInstance("settings").GetSection("zway"), names, false); this.zw = new ZwayController(InIReader.GetInstance("settings").GetSection("zway"), names, false);
this.zw.Update += this.ZwayDataUpate; this.zw.Update += this.ZwayDataUpate;
this.ModulLoader(); this.ModulLoader();
@ -39,17 +42,17 @@ namespace ZwayBot {
} }
private void WaitForShutdown() { private void WaitForShutdown() {
while (true) { Console.CancelKeyPress += new ConsoleCancelEventHandler(this.SetupShutdown);
while (this.RunningProcess) {
System.Threading.Thread.Sleep(100); System.Threading.Thread.Sleep(100);
if (Console.KeyAvailable) {
String a = Console.ReadLine();
if (a.EndsWith("/exit")) {
break;
}
}
} }
} }
private void SetupShutdown(Object sender, ConsoleCancelEventArgs e) {
e.Cancel = true;
this.RunningProcess = false;
}
private void ModulDispose() { private void ModulDispose() {
foreach (KeyValuePair<String, AModul> item in this.moduls) { foreach (KeyValuePair<String, AModul> item in this.moduls) {
item.Value.Dispose(); item.Value.Dispose();

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 - 08.05.2018")] [assembly: AssemblyCopyright("Copyright © 2017 - 15.05.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.3.4")] [assembly: AssemblyVersion("1.4.0")]
[assembly: AssemblyFileVersion("1.3.4")] [assembly: AssemblyFileVersion("1.4.0")]
[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.

View File

@ -50,6 +50,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="dpkg\preinst" />
<Compile Include="Events.cs" /> <Compile Include="Events.cs" />
<Compile Include="Interfaces\IForceLoad.cs" /> <Compile Include="Interfaces\IForceLoad.cs" />
<Compile Include="Moduls\AModul.cs" /> <Compile Include="Moduls\AModul.cs" />
@ -147,6 +148,8 @@
<None Include="dpkg\control" /> <None Include="dpkg\control" />
<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\zwaybot.service" />
<None Include="Resources\Icon.ico" /> <None Include="Resources\Icon.ico" />
<Content Include="Resources\icon.svg" /> <Content Include="Resources\icon.svg" />
</ItemGroup> </ItemGroup>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,7 @@
[zway] [zway]
server=localhost server=localhost
user=admin user=admin
pass=pass pass=pass
[logging]
path=/var/log/zwaybot.log

Binary file not shown.

View File

@ -1,4 +1,7 @@
[zway] [zway]
server=localhost server=localhost
user=admin user=admin
pass=pass pass=pass
[logging]
path=/var/log/zwaybot.log

View File

@ -4,6 +4,7 @@ ROOT="$WORKDIR/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"
DEBIAN="$ROOT/DEBIAN" DEBIAN="$ROOT/DEBIAN"
VMAJOR=$1 VMAJOR=$1
VMINOR=$2 VMINOR=$2
@ -12,10 +13,17 @@ VBUILD=$3
mkdir -p $EXEC mkdir -p $EXEC
mkdir -p $CONFIG mkdir -p $CONFIG
mkdir -p $DEBIAN mkdir -p $DEBIAN
mkdir -p $SYSTEMD
cp control $DEBIAN cp control $DEBIAN
cp preinst $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
chmod 755 $DEBIAN -R chmod 755 $DEBIAN -R
cp zwaybot.service $SYSTEMD
chmod 755 $SYSTEMD -R
cp $OUTPUT/*.exe $EXEC/ cp $OUTPUT/*.exe $EXEC/
cp $OUTPUT/*.dll $EXEC/ cp $OUTPUT/*.dll $EXEC/
cp $OUTPUT/config-example/* $CONFIG cp $OUTPUT/config-example/* $CONFIG

4
Zway-Bot/dpkg/preinst Normal file
View File

@ -0,0 +1,4 @@
#!/bin/sh
service zwaybot stop
adduser --system zwaybot

3
Zway-Bot/dpkg/prerm Normal file
View File

@ -0,0 +1,3 @@
#!/bin/bash
service zwaybot stop

View File

@ -0,0 +1,17 @@
# 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
ExecStart=/usr/bin/mono /usr/local/bin/zwaybot/Zway-Bot.exe
KillMode=control-group
Restart=on-failure
[Install]
WantedBy=multi-user.target
Alias=zwaybot.service