[BF] Fixing Senml

[NF] Senml now has a configure option to setup the guid
[NF] Zway-Bot now listen on /exit
[NF] Implment searchpath for Zway-Bot (/etc/zwaybot and %appdata%/zwaybot)
This commit is contained in:
BlubbFish 2018-05-07 16:52:24 +00:00
parent a1009b5293
commit 04f43b95ff
30 changed files with 190 additions and 67 deletions

View File

@ -17,7 +17,7 @@ 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.csproj", "{A11AEF5A-B246-4FE8-8330-06DB73CC8074}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "M2Mqtt", "..\Librarys\mqtt\M2Mqtt\M2Mqtt_4.7.1.csproj", "{A11AEF5A-B246-4FE8-8330-06DB73CC8074}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -6,18 +6,19 @@ 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.Connector; using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Events;
using LitJson; using LitJson;
namespace ZwayBot.Moduls { namespace ZwayBot.Moduls {
class Mqtt : AModul, IDisposable { class Mqtt : AModul, IDisposable {
private ADataBackend mqtt; private ABackend mqtt;
private Dictionary<String, AModul> modules; 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 zway, InIReader settings) : base(zway, settings) {
if (this.config.ContainsKey("settings")) { if (this.config.ContainsKey("settings")) {
this.mqtt = ADataBackend.GetInstance(this.config["settings"]); this.mqtt = ABackend.GetInstance(this.config["settings"], ABackend.BackendType.Data);
this.mqtt.MessageIncomming += this.Mqtt_MessageIncomming; this.mqtt.MessageIncomming += this.Mqtt_MessageIncomming;
this.zw.Update += this.ZwayEvent; this.zw.Update += this.ZwayEvent;
} }
@ -32,14 +33,14 @@ namespace ZwayBot.Moduls {
data = sensor.ToJson(); data = sensor.ToJson();
} }
if(topic != "" && data != "") { if(topic != "" && data != "") {
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, MqttEventArgs e) { private void Mqtt_MessageIncomming(Object sender, BackendEvent e) {
if (e.Topic.StartsWith("/zwavebot/devices/") && (e.Topic.EndsWith("/set") || e.Topic.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.Topic); 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;
@ -51,7 +52,7 @@ namespace ZwayBot.Moduls {
if(c == null) { if(c == null) {
return; return;
} }
if (e.Topic.EndsWith("/set")) { if (e.From.ToString().EndsWith("/set")) {
try { try {
JsonData a = JsonMapper.ToObject(e.Message); JsonData a = JsonMapper.ToObject(e.Message);
foreach (String item in a.Keys) { foreach (String item in a.Keys) {
@ -62,14 +63,14 @@ namespace ZwayBot.Moduls {
} }
} }
} catch (Exception) { } } catch (Exception) { }
} else if(e.Topic.EndsWith("/get")) { } else if(e.From.ToString().EndsWith("/get")) {
c.PollOnce = true; c.PollOnce = true;
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.Topic, "Dataget")); this.Update?.Invoke(this, new MqttEvent(e.From.ToString(), "Dataget"));
} }
} }
if (e.Topic.StartsWith("/zwavebot/config/") && (e.Topic.EndsWith("/set") || e.Topic.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.Topic); 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;
} }
@ -82,13 +83,13 @@ namespace ZwayBot.Moduls {
if (modul == null) { if (modul == null) {
return; return;
} }
if(e.Topic.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();
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));
} }
if (e.Topic.EndsWith("/set") && modul.HasConfig && modul.ConfigPublic) { if (e.From.ToString().EndsWith("/set") && modul.HasConfig && modul.ConfigPublic) {
try { try {
JsonData a = JsonMapper.ToObject(e.Message); JsonData a = JsonMapper.ToObject(e.Message);
Dictionary<String, Dictionary<String, String>> newconf = new Dictionary<String, Dictionary<String, String>>(); Dictionary<String, Dictionary<String, String>> newconf = new Dictionary<String, Dictionary<String, String>>();

View File

@ -3,20 +3,21 @@ using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.Utils; using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Connector; using BlubbFish.Utils.IoT.Connector;
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 : AModul {
public override event ModulEvent Update; public override event ModulEvent Update;
private ADataBackend mqtt; private ABackend mqtt;
private 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 = ADataBackend.GetInstance(this.config["settings"]); this.mqtt = ABackend.GetInstance(this.config["settings"], ABackend.BackendType.Data);
this.mqtt.MessageIncomming += this.EventInput; this.mqtt.MessageIncomming += this.EventInput;
this.zw.Update += this.EventOutput; this.zw.Update += this.EventOutput;
this.SenmlGuid = Guid.NewGuid().ToString(); this.SenmlGuid = this.config["settings"]["guid"];
} }
} }
@ -30,12 +31,12 @@ namespace ZwayBot.Moduls {
data = sensor.ToSenml(); data = sensor.ToSenml();
} }
if (topic != "" && data != null && data != "") { if (topic != "" && data != null && data != "") {
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 EventInput(Object sender, MqttEventArgs e) { } private void EventInput(Object sender, BackendEvent e) { }
#endregion #endregion
#region Config #region Config

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Reflection; using System.Reflection;
using BlubbFish.IoT.Zway; using BlubbFish.IoT.Zway;
using BlubbFish.Utils; using BlubbFish.Utils;
@ -13,17 +12,18 @@ namespace ZwayBot {
private Dictionary<String, AModul> moduls = new Dictionary<String, AModul>(); private Dictionary<String, AModul> moduls = new Dictionary<String, AModul>();
public Program(String[] args) { public Program(String[] args) {
InIReader.SetSearchPath(new List<String>() { "/etc/zwaybot", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zwaybot" });
Dictionary<String, String> names; Dictionary<String, String> names;
if(File.Exists("names.ini")) { if(InIReader.ConfigExist("names")) {
names = InIReader.GetInstance("names.ini").GetSection("names"); names = InIReader.GetInstance("names").GetSection("names");
} else { } else {
names = new Dictionary<String, String>(); names = new Dictionary<String, String>();
} }
if(!File.Exists("settings.ini")) { if(!InIReader.ConfigExist("settings")) {
Helper.WriteError("No settings.ini found. Abord!"); Helper.WriteError("No settings.ini found. Abord!");
return; return;
} }
this.zw = new ZwayController(InIReader.GetInstance("settings.ini").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();
this.ModulInterconnect(); this.ModulInterconnect();
@ -42,8 +42,8 @@ namespace ZwayBot {
while (true) { while (true) {
System.Threading.Thread.Sleep(100); System.Threading.Thread.Sleep(100);
if (Console.KeyAvailable) { if (Console.KeyAvailable) {
ConsoleKeyInfo key = Console.ReadKey(false); String a = Console.ReadLine();
if (key.Key == ConsoleKey.Escape) { if (a.EndsWith("/exit")) {
break; break;
} }
} }
@ -74,8 +74,8 @@ namespace ZwayBot {
if(item.Namespace == "ZwayBot.Moduls") { if(item.Namespace == "ZwayBot.Moduls") {
Type t = item; Type t = item;
String name = t.Name; String name = t.Name;
if (File.Exists(name.ToLower() + ".ini")) { 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() + ".ini") })); 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); Console.WriteLine("Load Modul " + name);
} else if(t.HasInterface("IForceLoad")) { } else if(t.HasInterface("IForceLoad")) {
this.moduls.Add(name, (AModul)t.GetConstructor(new Type[] { typeof(ZwayController), typeof(InIReader) }).Invoke(new Object[] { this.zw, null })); this.moduls.Add(name, (AModul)t.GetConstructor(new Type[] { typeof(ZwayController), typeof(InIReader) }).Invoke(new Object[] { this.zw, null }));

View File

@ -32,8 +32,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.0.0")] [assembly: AssemblyVersion("1.3.1.0")]
[assembly: AssemblyFileVersion("1.3.0.0")] [assembly: AssemblyFileVersion("1.3.1.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

@ -121,8 +121,29 @@
<None Include="control\view.sh"> <None Include="control\view.sh">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="config-example\cronjob.conf.example">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="config-example\names.conf.example">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="config-example\senml.conf.example">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="config-example\settings.conf.example">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="config-example\statuspolling.conf.example">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="config-example\mqtt.conf.example">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="config-example\overtaker.conf.example">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<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.

View File

@ -0,0 +1,10 @@
[modul]
config=public
[cold]
cron=0 23 * * 0-4
set=7-0-67-2:Level-19;7-0-112-8:Level-2
[hot]
cron=0 16 * * 1-5
set=7-0-67-1:Level-22;7-0-112-8:Level-1

View File

@ -0,0 +1,6 @@
[modul]
config=private
[settings]
type=mqtt
server=localhost

View File

@ -0,0 +1,24 @@
[names]
2-0-37=Kühlschrank Schalter
2-0-49-4=Kühlschrank Leistung
2-0-50-0=Kühlschrank Verbrauch [kWh]
2-0-50-2=Kühlschrank Verbrauch [Wh]
2-0-112-1=Kühlschrank Config (Immer AN)
2-0-112-16=Kühlschrank Config (Zurück zu altem Status nach Stromausfall)
2-0-112-34=Kühlschrank Config (Reaktion auf Alarm)
2-0-112-35=Kühlschrank Config (Antwort auf Alarmmeldung)
2-0-112-39=Kühlschrank Config (Alarm Dauer)
2-0-112-40=Kühlschrank Config (Sofortiger Bericht über Stromverbrauch)
2-0-112-42=Kühlschrank Config (Änderung der Leistung zum Generieren eines Reports)
2-0-112-43=Kühlschrank Config (Regelmäßiges Senden eines Reports über die Stromaufnahme)
2-0-112-45=Kühlschrank Config (Automatisches Senden eines Reportes über Stromverbrauch bei Verbrauchsänderung)
2-0-112-47=Kühlschrank Config (Zeitinterval zum Senden eines Reportes ohne Änderung im Verbrauch)
2-0-112-49=Kühlschrank Config (Messen des Eigenstromverbrauches)
2-0-112-50=Kühlschrank Config (unterer Leistungsschwellwert)
2-0-112-51=Kühlschrank Config (oberer Leistungsschwellwert)
2-0-112-52=Kühlschrank Config (Aktion bei Erreichen des definierten Schwellwertes (Parameter 50/51))
2-0-112-60=Kühlschrank Config (Leistungsschwellwert für violettes Blinken)
2-0-112-61=Kühlschrank Config (LED Ring Farbe im Einschaltzustand)
2-0-112-62=Kühlschrank Config (LED Ring Farbe im Ausschaltzustand)
2-0-112-63=Kühlschrank Config (LED Ring Farbe bei Z-Wave Alarmmeldungen)
2-0-112-70=Kühlschrank Config (Überlastabschaltung)

View File

@ -0,0 +1,12 @@
[hot]
from=7-0-67-1:Level
to=8-0-67-1:Level;9-0-67-1:Level
[cold]
from=7-0-67-2:Level
to=8-0-67-11:Level;9-0-67-11:Level
[mode]
from=7-0-112-8:Level
to=8-0-64:Level;9-0-64:Level
convert=1-1;2-11

View File

@ -0,0 +1,7 @@
[modul]
config=private
[settings]
type=mqtt
server=localhost
guid=linksmart-zwaybot

View File

@ -0,0 +1,4 @@
[zway]
server=localhost
user=admin
pass=pass

View File

@ -0,0 +1,3 @@
[temp]
cron=30 * * * *
devices=7-0-49-1,8-0-49-1,9-0-49-1,10-0-49-1,11-0-49-1

View File

@ -8,22 +8,6 @@ cd $control_root
# Create Stop-Info! # Create Stop-Info!
touch $control_root/stop_server.info touch $control_root/stop_server.info
echo "Shutting Down Server in 5 Seconds!"
./stuff.sh "/say Shutting Down 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 "Shuting Down Server..." echo "Shuting Down Server..."
./stuff.sh "/say Shutdown Now!" ./stuff.sh "/exit"
./stuff.sh "stop"
screen -R $screen_name screen -R $screen_name

Binary file not shown.

View File

@ -0,0 +1,10 @@
[modul]
config=public
[cold]
cron=0 23 * * 0-4
set=7-0-67-2:Level-19;7-0-112-8:Level-2
[hot]
cron=0 16 * * 1-5
set=7-0-67-1:Level-22;7-0-112-8:Level-1

View File

@ -0,0 +1,6 @@
[modul]
config=private
[settings]
type=mqtt
server=localhost

View File

@ -0,0 +1,24 @@
[names]
2-0-37=Kühlschrank Schalter
2-0-49-4=Kühlschrank Leistung
2-0-50-0=Kühlschrank Verbrauch [kWh]
2-0-50-2=Kühlschrank Verbrauch [Wh]
2-0-112-1=Kühlschrank Config (Immer AN)
2-0-112-16=Kühlschrank Config (Zurück zu altem Status nach Stromausfall)
2-0-112-34=Kühlschrank Config (Reaktion auf Alarm)
2-0-112-35=Kühlschrank Config (Antwort auf Alarmmeldung)
2-0-112-39=Kühlschrank Config (Alarm Dauer)
2-0-112-40=Kühlschrank Config (Sofortiger Bericht über Stromverbrauch)
2-0-112-42=Kühlschrank Config (Änderung der Leistung zum Generieren eines Reports)
2-0-112-43=Kühlschrank Config (Regelmäßiges Senden eines Reports über die Stromaufnahme)
2-0-112-45=Kühlschrank Config (Automatisches Senden eines Reportes über Stromverbrauch bei Verbrauchsänderung)
2-0-112-47=Kühlschrank Config (Zeitinterval zum Senden eines Reportes ohne Änderung im Verbrauch)
2-0-112-49=Kühlschrank Config (Messen des Eigenstromverbrauches)
2-0-112-50=Kühlschrank Config (unterer Leistungsschwellwert)
2-0-112-51=Kühlschrank Config (oberer Leistungsschwellwert)
2-0-112-52=Kühlschrank Config (Aktion bei Erreichen des definierten Schwellwertes (Parameter 50/51))
2-0-112-60=Kühlschrank Config (Leistungsschwellwert für violettes Blinken)
2-0-112-61=Kühlschrank Config (LED Ring Farbe im Einschaltzustand)
2-0-112-62=Kühlschrank Config (LED Ring Farbe im Ausschaltzustand)
2-0-112-63=Kühlschrank Config (LED Ring Farbe bei Z-Wave Alarmmeldungen)
2-0-112-70=Kühlschrank Config (Überlastabschaltung)

View File

@ -0,0 +1,12 @@
[hot]
from=7-0-67-1:Level
to=8-0-67-1:Level;9-0-67-1:Level
[cold]
from=7-0-67-2:Level
to=8-0-67-11:Level;9-0-67-11:Level
[mode]
from=7-0-112-8:Level
to=8-0-64:Level;9-0-64:Level
convert=1-1;2-11

View File

@ -0,0 +1,7 @@
[modul]
config=private
[settings]
type=mqtt
server=localhost
guid=linksmart-zwaybot

View File

@ -0,0 +1,4 @@
[zway]
server=localhost
user=admin
pass=pass

View File

@ -0,0 +1,3 @@
[temp]
cron=30 * * * *
devices=7-0-49-1,8-0-49-1,9-0-49-1,10-0-49-1,11-0-49-1

View File

@ -8,22 +8,6 @@ cd $control_root
# Create Stop-Info! # Create Stop-Info!
touch $control_root/stop_server.info touch $control_root/stop_server.info
echo "Shutting Down Server in 5 Seconds!"
./stuff.sh "/say Shutting Down 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 "Shuting Down Server..." echo "Shuting Down Server..."
./stuff.sh "/say Shutdown Now!" ./stuff.sh "/exit"
./stuff.sh "stop"
screen -R $screen_name screen -R $screen_name