[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:
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BlubbFish.Utils.IoT.Events;
|
||||
|
||||
namespace BlubbFish.Utils.IoT.Connector {
|
||||
public abstract class ABackend {
|
||||
public enum BackendType {
|
||||
Data,
|
||||
User
|
||||
}
|
||||
public event BackendMessage MessageIncomming;
|
||||
public event BackendMessage MessageSending;
|
||||
public delegate void BackendMessage(Object sender, BackendEvent e);
|
||||
|
||||
protected Dictionary<String, String> settings;
|
||||
|
||||
public ABackend(Dictionary<String, String> settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public static ABackend GetInstance(Dictionary<String, String> settings, BackendType ty) {
|
||||
if (settings.Count == 0) {
|
||||
return null;
|
||||
}
|
||||
String object_sensor = "BlubbFish.Utils.IoT.Connector." + ty.ToString() + "." + settings["type"].ToUpperLower() + ", " + "Connector" + ty.ToString() + settings["type"].ToUpperLower();
|
||||
Type t = null;
|
||||
try {
|
||||
t = Type.GetType(object_sensor, true);
|
||||
} catch (TypeLoadException) {
|
||||
Console.Error.WriteLine("Configuration: " + settings["type"] + " is not a " + ty.ToString() + "Backend");
|
||||
return null;
|
||||
} catch (System.IO.FileNotFoundException) {
|
||||
Console.Error.WriteLine("Driver " + object_sensor + " could not load!");
|
||||
return null;
|
||||
}
|
||||
return (ABackend)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>) }).Invoke(new Object[] { settings });
|
||||
}
|
||||
|
||||
protected void NotifyClientIncomming(BackendEvent value) {
|
||||
this.MessageIncomming?.Invoke(this, value);
|
||||
}
|
||||
|
||||
protected void NotifyClientSending(BackendEvent value) {
|
||||
this.MessageSending?.Invoke(this, value);
|
||||
}
|
||||
|
||||
public abstract void Dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.Utils.IoT.Events;
|
||||
|
||||
namespace BlubbFish.Utils.IoT.Connector {
|
||||
public abstract class ADataBackend {
|
||||
|
||||
public abstract event MqttMessage MessageIncomming;
|
||||
public abstract event MqttMessage MessageSending;
|
||||
public delegate void MqttMessage(Object sender, MqttEventArgs e);
|
||||
|
||||
public static ADataBackend GetInstance(Dictionary<String, String> settings) {
|
||||
if(settings.Count == 0) {
|
||||
return null;
|
||||
}
|
||||
String object_sensor = "BlubbFish.Utils.IoT.Connector.Data." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower()+", "+ "ConnectorData" + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
|
||||
Type t = null;
|
||||
try {
|
||||
t = Type.GetType(object_sensor, true);
|
||||
} catch (TypeLoadException) {
|
||||
Console.Error.WriteLine("settings.ini: " + settings["type"] + " is not a DataBackend");
|
||||
return null;
|
||||
} catch(System.IO.FileNotFoundException) {
|
||||
Console.Error.WriteLine("Driver " + settings["type"] + " could not load!");
|
||||
return null;
|
||||
}
|
||||
return (ADataBackend)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>) }).Invoke(new Object[] { settings });
|
||||
}
|
||||
|
||||
public abstract class ADataBackend : ABackend {
|
||||
public ADataBackend(Dictionary<String, String> settings) : base(settings) { }
|
||||
public abstract void Send(String topic, String data);
|
||||
|
||||
public abstract void Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.Utils.IoT.Events;
|
||||
|
||||
namespace BlubbFish.Utils.IoT.Connector {
|
||||
public abstract class AUserBackend {
|
||||
protected Dictionary<String, String> settings;
|
||||
|
||||
public abstract event TelegramMessage MessageIncomming;
|
||||
public abstract event TelegramMessage MessageSending;
|
||||
public delegate void TelegramMessage(Object sender, UserMessageEventArgs e);
|
||||
|
||||
public AUserBackend(Dictionary<String, String> settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public static AUserBackend GetInstance(Dictionary<String, String> settings) {
|
||||
String object_sensor = "BlubbFish.Utils.IoT.Connector.User." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower()+", "+ "ConnectorUser" + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
|
||||
Type t = null;
|
||||
try {
|
||||
t = Type.GetType(object_sensor, true);
|
||||
} catch (TypeLoadException) {
|
||||
throw new ArgumentException("settings.ini: " + settings["type"] + " is not a UserBackend");
|
||||
}
|
||||
return (AUserBackend)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>) }).Invoke(new Object[] { settings });
|
||||
}
|
||||
|
||||
public abstract class AUserBackend : ABackend {
|
||||
public AUserBackend(Dictionary<String, String> settings) : base(settings) {}
|
||||
public abstract void Send(String message);
|
||||
public abstract void Send(String message, String[] buttons);
|
||||
|
||||
public abstract void Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\..\Librarys\mqtt\M2Mqtt\M2Mqtt.csproj">
|
||||
<ProjectReference Include="..\..\..\..\..\Librarys\mqtt\M2Mqtt\M2Mqtt_4.7.1.csproj">
|
||||
<Project>{a11aef5a-b246-4fe8-8330-06db73cc8074}</Project>
|
||||
<Name>M2Mqtt</Name>
|
||||
</ProjectReference>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using BlubbFish.Utils.IoT.Events;
|
||||
using uPLibrary.Networking.M2Mqtt;
|
||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||
|
||||
@@ -8,10 +9,7 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
|
||||
public class Mqtt : ADataBackend, IDisposable {
|
||||
private MqttClient client;
|
||||
|
||||
public override event MqttMessage MessageIncomming;
|
||||
public override event MqttMessage MessageSending;
|
||||
|
||||
public Mqtt(Dictionary<String, String> settings) {
|
||||
public Mqtt(Dictionary<String, String> settings) : base(settings) {
|
||||
if(settings.ContainsKey("port")) {
|
||||
this.client = new MqttClient(settings["server"], Int32.Parse(settings["port"]), false, null, null, MqttSslProtocols.None);
|
||||
} else {
|
||||
@@ -27,12 +25,12 @@ namespace BlubbFish.Utils.IoT.Connector.Data {
|
||||
}
|
||||
|
||||
private void Client_MqttMsgPublishReceived(Object sender, MqttMsgPublishEventArgs e) {
|
||||
this.MessageIncomming?.Invoke(this, new MqttEventArgs(Encoding.UTF8.GetString(e.Message), e.Topic));
|
||||
this.NotifyClientIncomming(new DataEvent(Encoding.UTF8.GetString(e.Message), e.Topic, DateTime.Now));
|
||||
}
|
||||
|
||||
public override void Send(String topic, String data) {
|
||||
this.client.Publish(topic, Encoding.UTF8.GetBytes(data));
|
||||
this.MessageSending?.Invoke(this, new MqttEventArgs(data, topic));
|
||||
this.NotifyClientSending(new DataEvent(data, topic, DateTime.Now));
|
||||
}
|
||||
|
||||
#region IDisposable Support
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user