[NF] Umbenennung zu IoTBot Namespace
This commit is contained in:
parent
ceef3daf21
commit
8d80a132dc
3
.gitignore
vendored
3
.gitignore
vendored
@ -87,3 +87,6 @@
|
||||
/IoT-Bot/IoT-Bot/Connector/.svn
|
||||
/IoT-Bot/IoT-Bot/obj/Debug
|
||||
/IoT-Bot/IoT-Bot/Sensor/.svn
|
||||
/Mqtt-Dashboard/Mqtt-Dashboard/Connector/.svn
|
||||
/Mqtt-Dashboard/Mqtt-Dashboard/Sensor/.svn
|
||||
/IoT-Bot/IoT-Bot/bin/Debug
|
||||
|
@ -1,32 +1,37 @@
|
||||
using Dashboard.Sensor;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using IoTBot.Connector;
|
||||
using IoTBot.Sensor;
|
||||
|
||||
namespace MqttToTelegram.Condition {
|
||||
namespace IoTBot.Condition {
|
||||
abstract class ACondition {
|
||||
protected ASensor sensor;
|
||||
protected Dictionary<String, String> settings;
|
||||
|
||||
public ACondition(Dictionary<String, String> settings) {
|
||||
public ACondition(Dictionary<String, String> settings, ADataBackend backend) {
|
||||
this.settings = settings;
|
||||
Dictionary<String, String> l = new Dictionary<string, string>();
|
||||
l.Add("topic", this.settings["sensor_topic"]);
|
||||
l.Add("polling", this.settings["sensor_polling"]);
|
||||
this.sensor = ASensor.GetInstance(this.settings["sensor"],l);
|
||||
this.sensor.Update += Sensor_Update;
|
||||
Dictionary<String, String> l = new Dictionary<String, String> {
|
||||
{ "topic", this.settings["sensor_topic"] },
|
||||
{ "type", this.settings["sensor"] }
|
||||
};
|
||||
if(settings.ContainsKey("sensor_polling")) {
|
||||
l.Add("polling", this.settings["sensor_polling"]);
|
||||
}
|
||||
this.sensor = ASensor.GetInstance(backend, l, "testSensor");
|
||||
this.sensor.Update += this.Sensor_Update;
|
||||
}
|
||||
|
||||
protected abstract void Sensor_Update(Object sender, EventArgs e);
|
||||
|
||||
public static ACondition GetInstance(String v, Dictionary<String, String> dictionary) {
|
||||
string object_condition = "MqttToTelegram.Condition." + char.ToUpper(v[0]) + v.Substring(1).ToLower();
|
||||
public static ACondition GetInstance(Dictionary<String, String> settings, ADataBackend backend) {
|
||||
String object_condition = "IoTBot.Condition." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
|
||||
Type t = null;
|
||||
try {
|
||||
t = Type.GetType(object_condition, true);
|
||||
} catch(TypeLoadException) {
|
||||
throw new ArgumentException("condition.ini: " + v + " is not a Sensor");
|
||||
throw new ArgumentException("condition.ini: " + settings["type"] + " is not a Sensor");
|
||||
}
|
||||
return (ACondition)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>) }).Invoke(new object[] { dictionary });
|
||||
return (ACondition)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>), typeof(ADataBackend) }).Invoke(new Object[] { settings, backend });
|
||||
}
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
using BlubbFish.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Dashboard.Connector;
|
||||
|
||||
namespace MqttToTelegram.Condition {
|
||||
class ConditionWorker {
|
||||
private InIReader ini;
|
||||
private static ConditionWorker instance;
|
||||
private List<ACondition> conditions;
|
||||
private Telegram telegram;
|
||||
|
||||
public static ConditionWorker Instance {
|
||||
get {
|
||||
if(instance == null) {
|
||||
instance = new ConditionWorker();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
internal void Run(Telegram telegram) {
|
||||
this.telegram = telegram;
|
||||
}
|
||||
|
||||
private ConditionWorker() {
|
||||
this.ini = InIReader.GetInstance("condition.ini");
|
||||
this.conditions = new List<ACondition>();
|
||||
List<String> sections = this.ini.GetSections();
|
||||
foreach(String section in sections) {
|
||||
this.conditions.Add(ACondition.GetInstance(this.ini.GetValue(section,"type"), this.ini.GetSection(section)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using IoTBot.Connector;
|
||||
using IoTBot.Sensor;
|
||||
|
||||
namespace MqttToTelegram.Condition {
|
||||
namespace IoTBot.Condition {
|
||||
class Edge : ACondition {
|
||||
private Boolean histBool;
|
||||
|
||||
public Edge(Dictionary<String, String> settings) : base(settings) {
|
||||
public Edge(Dictionary<String, String> settings, ADataBackend backend) : base(settings, backend) {
|
||||
|
||||
}
|
||||
|
||||
protected override void Sensor_Update(Object sender, EventArgs e) {
|
||||
if(this.sensor.Datatypes == Dashboard.Sensor.ASensor.Types.Bool) {
|
||||
if(this.sensor.Datatypes == ASensor.Types.Bool) {
|
||||
if(this.sensor.GetBool == Boolean.Parse(this.settings["sensor_value"]) && this.histBool != this.sensor.GetBool) {
|
||||
this.histBool = this.sensor.GetBool;
|
||||
Telegram.Instance.Send("Jemand ist DA!");
|
||||
IoTBot.Connector.Telegram.Instance.Send("Jemand ist DA!");
|
||||
} else {
|
||||
this.histBool = this.sensor.GetBool;
|
||||
}
|
||||
|
34
IoT-Bot/IoT-Bot/ConditionWorker.cs
Normal file
34
IoT-Bot/IoT-Bot/ConditionWorker.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.Utils;
|
||||
using IoTBot.Condition;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace IoTBot {
|
||||
class ConditionWorker {
|
||||
private InIReader ini;
|
||||
private static ConditionWorker instance;
|
||||
private List<ACondition> conditions;
|
||||
private Connector.Telegram telegram;
|
||||
|
||||
public static ConditionWorker GetInstance(ADataBackend backend) {
|
||||
if (instance == null) {
|
||||
instance = new ConditionWorker(backend);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
internal void Run(Connector.Telegram telegram) {
|
||||
this.telegram = telegram;
|
||||
}
|
||||
|
||||
private ConditionWorker(ADataBackend backend) {
|
||||
this.ini = InIReader.GetInstance("condition.ini");
|
||||
this.conditions = new List<ACondition>();
|
||||
List<String> sections = this.ini.GetSections();
|
||||
foreach(String section in sections) {
|
||||
this.conditions.Add(ACondition.GetInstance(this.ini.GetSection(section), backend));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Dashboard.Connector {
|
||||
namespace IoTBot.Connector {
|
||||
public abstract class ADataBackend {
|
||||
|
||||
public abstract event MqttMessage MessageIncomming;
|
||||
public abstract event MqttMessage MessageSending;
|
||||
public delegate void MqttMessage(Object sender, MqttEventArgs e);
|
||||
public delegate void MqttMessage(ADataBackend sender, MqttEventArgs e);
|
||||
|
||||
public static ADataBackend GetInstance(Dictionary<String, String> dictionary) {
|
||||
String object_sensor = "Dashboard.Connector." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
|
||||
String object_sensor = "IoTBot.Connector." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
|
||||
Type t = null;
|
||||
try {
|
||||
t = Type.GetType(object_sensor, true);
|
||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Dashboard.Connector {
|
||||
namespace IoTBot.Connector {
|
||||
class Mosquitto : ADataBackend, IDisposable {
|
||||
private Process p;
|
||||
private String message;
|
||||
|
@ -4,7 +4,7 @@ using System.Text;
|
||||
using uPLibrary.Networking.M2Mqtt;
|
||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||
|
||||
namespace Dashboard.Connector {
|
||||
namespace IoTBot.Connector {
|
||||
class Mqtt : ADataBackend, IDisposable {
|
||||
private MqttClient client;
|
||||
|
||||
|
@ -5,7 +5,7 @@ using Telegram.Bot.Args;
|
||||
using Telegram.Bot.Exceptions;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace MqttToTelegram {
|
||||
namespace IoTBot.Connector {
|
||||
class Telegram {
|
||||
private static Telegram instance;
|
||||
private TelegramBotClient bot;
|
||||
@ -17,8 +17,8 @@ namespace MqttToTelegram {
|
||||
public event TelegramMessage MessageSending;
|
||||
|
||||
private Telegram() {
|
||||
bot = new TelegramBotClient(InIReader.GetInstance("settings.ini").GetValue("general", "telegram-key"));
|
||||
bot.OnMessage += Bot_OnMessage;
|
||||
this.bot = new TelegramBotClient(InIReader.GetInstance("settings.ini").GetValue("general", "telegram-key"));
|
||||
this.bot.OnMessage += this.Bot_OnMessage;
|
||||
this.Connect();
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ namespace MqttToTelegram {
|
||||
}
|
||||
|
||||
private void Connect() {
|
||||
bot.StartReceiving();
|
||||
this.bot.StartReceiving();
|
||||
this.chat = new ChatId(InIReader.GetInstance("settings.ini").GetValue("general", "chatid"));
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Condition\ConditionWorker.cs" />
|
||||
<Compile Include="ConditionWorker.cs" />
|
||||
<Compile Include="Condition\ACondition.cs" />
|
||||
<Compile Include="Condition\Edge.cs" />
|
||||
<Compile Include="Connector\ADataBackend.cs" />
|
||||
@ -79,6 +79,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="condition.ini.example" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="settings.ini.example" />
|
||||
</ItemGroup>
|
||||
|
@ -1,25 +1,24 @@
|
||||
using Dashboard.Connector;
|
||||
using MqttToTelegram.Condition;
|
||||
using System;
|
||||
using System.Text;
|
||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||
using System;
|
||||
using BlubbFish.Utils;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace MqttToTelegram {
|
||||
namespace IoTBot {
|
||||
class Program {
|
||||
static void Main(string[] args) {
|
||||
ConditionWorker.Instance.Run(Telegram.Instance);
|
||||
Mqtt.Instance.MessageIncomming += Mqtt_MessageIncomming;
|
||||
Mqtt.Instance.MessageSending += Mqtt_MessageSending;
|
||||
Telegram.Instance.MessageIncomming += Telegram_MessageIncomming;
|
||||
Telegram.Instance.MessageSending += Telegram_MessageSending;
|
||||
static void Main(String[] args) {
|
||||
ADataBackend mqtt = ADataBackend.GetInstance(InIReader.GetInstance("settings.ini").GetSection("mqtt"));
|
||||
ConditionWorker.GetInstance(mqtt).Run(Connector.Telegram.Instance);
|
||||
mqtt.MessageIncomming += Mqtt_MessageIncomming;
|
||||
mqtt.MessageSending += Mqtt_MessageSending;
|
||||
Connector.Telegram.Instance.MessageIncomming += Telegram_MessageIncomming;
|
||||
Connector.Telegram.Instance.MessageSending += Telegram_MessageSending;
|
||||
|
||||
while(true) {
|
||||
System.Threading.Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Mqtt_MessageSending(Object sender, MqttMsgPublishEventArgs e) {
|
||||
Console.WriteLine("-> [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + Encoding.UTF8.GetString(e.Message) + " on " + e.Topic);
|
||||
private static void Mqtt_MessageSending(ADataBackend sender, MqttEventArgs e) {
|
||||
Console.WriteLine("-> [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + e.Message + " on " + e.Topic);
|
||||
}
|
||||
|
||||
private static void Telegram_MessageSending(Object sender, global::Telegram.Bot.Types.Message e) {
|
||||
@ -30,8 +29,8 @@ namespace MqttToTelegram {
|
||||
Console.WriteLine("<- [" + e.Date.ToUniversalTime() + "] Telegram: " + e.Text + " on " + e.Chat.Id);
|
||||
}
|
||||
|
||||
private static void Mqtt_MessageIncomming(Object sender, MqttMsgPublishEventArgs e) {
|
||||
Console.WriteLine("<- [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + Encoding.UTF8.GetString(e.Message) + " on " + e.Topic);
|
||||
private static void Mqtt_MessageIncomming(ADataBackend sender, MqttEventArgs e) {
|
||||
Console.WriteLine("<- [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + e.Message + " on " + e.Topic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
using Dashboard.Connector;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
public abstract class ASensor : IDisposable {
|
||||
protected String topic;
|
||||
protected Int32 pollcount;
|
||||
@ -50,7 +50,7 @@ namespace Dashboard.Sensor {
|
||||
}
|
||||
|
||||
internal static ASensor GetInstance(ADataBackend backend, Dictionary<String, String> dictionary, String name) {
|
||||
String object_sensor = "Dashboard.Sensor." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
|
||||
String object_sensor = "IoTBot.Sensor." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
|
||||
Type t = null;
|
||||
try {
|
||||
t = Type.GetType(object_sensor, true);
|
||||
|
@ -2,10 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using Dashboard.Connector;
|
||||
using IoTBot.Connector;
|
||||
using LitJson;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
class Flex4gridswitch : ASensor {
|
||||
private String id;
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Dashboard.Connector;
|
||||
using IoTBot.Connector;
|
||||
using LitJson;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
class Flex4gridpower : ASensor {
|
||||
private String id;
|
||||
|
||||
|
@ -1,20 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
class Luminanz : ASensor {
|
||||
public Luminanz(Dictionary<String, String> settings) : base(settings) {
|
||||
public Luminanz(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
||||
this.GetBool = true;
|
||||
this.GetFloat = 0.0f;
|
||||
this.GetInt = 0;
|
||||
this.Datatypes = Types.Int;
|
||||
}
|
||||
|
||||
protected override void UpdateValue(MqttMsgPublishEventArgs e) {
|
||||
this.GetInt = Int32.Parse(Encoding.UTF8.GetString(e.Message), new CultureInfo("en-US"));
|
||||
protected override Boolean UpdateValue(MqttEventArgs e) {
|
||||
this.GetInt = Int32.Parse(e.Message, new CultureInfo("en-US"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
class Pir : ASensor {
|
||||
public Pir(Dictionary<String, String> settings) : base(settings) {
|
||||
public Pir(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
||||
this.Datatypes = Types.Bool;
|
||||
}
|
||||
|
||||
protected override void UpdateValue(MqttMsgPublishEventArgs e) {
|
||||
this.GetBool = (Encoding.UTF8.GetString(e.Message).ToLower() == "on") ? true : false;
|
||||
protected override Boolean UpdateValue(MqttEventArgs e) {
|
||||
this.GetBool = (e.Message.ToLower() == "on") ? true : false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Dashboard.Connector;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
class Power : ASensor {
|
||||
public Power(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
||||
this.GetBool = true;
|
||||
|
@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Dashboard.Connector;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
class Switch : ASensor {
|
||||
public Switch(Dictionary<System.String, System.String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
||||
this.Datatypes = Types.Bool;
|
||||
|
@ -1,20 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
class Temperatur : ASensor {
|
||||
public Temperatur(Dictionary<String, String> settings) : base(settings) {
|
||||
public Temperatur(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
||||
this.GetBool = true;
|
||||
this.GetFloat = 0.0f;
|
||||
this.GetInt = 0;
|
||||
this.Datatypes = Types.Float;
|
||||
}
|
||||
|
||||
protected override void UpdateValue(MqttMsgPublishEventArgs e) {
|
||||
this.GetFloat = Single.Parse(Encoding.UTF8.GetString(e.Message), new CultureInfo("en-US"));
|
||||
protected override Boolean UpdateValue(MqttEventArgs e) {
|
||||
this.GetFloat = Single.Parse(e.Message, new CultureInfo("en-US"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
4
IoT-Bot/IoT-Bot/condition.ini.example
Normal file
4
IoT-Bot/IoT-Bot/condition.ini.example
Normal file
@ -0,0 +1,4 @@
|
||||
[test]
|
||||
type=Edge
|
||||
sensor=Power
|
||||
sensor_topic=/test/powersensor
|
@ -1,4 +1,7 @@
|
||||
[general]
|
||||
mqtt-server=localhost
|
||||
telegram-key=ABCDEFGH
|
||||
chatid=1234
|
||||
chatid=1234
|
||||
|
||||
[mqtt]
|
||||
server=localhost
|
||||
type=mqtt
|
@ -1,15 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Dashboard.Connector {
|
||||
namespace IoTBot.Connector {
|
||||
public abstract class ADataBackend {
|
||||
|
||||
public abstract event MqttMessage MessageIncomming;
|
||||
public abstract event MqttMessage MessageSending;
|
||||
public delegate void MqttMessage(Object sender, MqttEventArgs e);
|
||||
public delegate void MqttMessage(ADataBackend sender, MqttEventArgs e);
|
||||
|
||||
public static ADataBackend GetInstance(Dictionary<String, String> dictionary) {
|
||||
String object_sensor = "Dashboard.Connector." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
|
||||
String object_sensor = "IoTBot.Connector." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
|
||||
Type t = null;
|
||||
try {
|
||||
t = Type.GetType(object_sensor, true);
|
||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Dashboard.Connector {
|
||||
namespace IoTBot.Connector {
|
||||
class Mosquitto : ADataBackend, IDisposable {
|
||||
private Process p;
|
||||
private String message;
|
||||
|
@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using BlubbFish.Utils;
|
||||
using uPLibrary.Networking.M2Mqtt;
|
||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||
|
||||
namespace Dashboard.Connector {
|
||||
namespace IoTBot.Connector {
|
||||
class Mqtt : ADataBackend, IDisposable {
|
||||
private MqttClient client;
|
||||
|
||||
|
@ -5,7 +5,7 @@ using Telegram.Bot.Args;
|
||||
using Telegram.Bot.Exceptions;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace MqttToTelegram {
|
||||
namespace IoTBot.Connector {
|
||||
class Telegram {
|
||||
private static Telegram instance;
|
||||
private TelegramBotClient bot;
|
||||
@ -17,8 +17,8 @@ namespace MqttToTelegram {
|
||||
public event TelegramMessage MessageSending;
|
||||
|
||||
private Telegram() {
|
||||
bot = new TelegramBotClient(InIReader.GetInstance("settings.ini").GetValue("general", "telegram-key"));
|
||||
bot.OnMessage += Bot_OnMessage;
|
||||
this.bot = new TelegramBotClient(InIReader.GetInstance("settings.ini").GetValue("general", "telegram-key"));
|
||||
this.bot.OnMessage += this.Bot_OnMessage;
|
||||
this.Connect();
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ namespace MqttToTelegram {
|
||||
}
|
||||
|
||||
private void Connect() {
|
||||
bot.StartReceiving();
|
||||
this.bot.StartReceiving();
|
||||
this.chat = new ChatId(InIReader.GetInstance("settings.ini").GetValue("general", "chatid"));
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using BlubbFish.Utils;
|
||||
using Dashboard.Connector;
|
||||
using Dashboard.Sensor;
|
||||
using IoTBot.Connector;
|
||||
using IoTBot.Sensor;
|
||||
using Dashboard.Tracings;
|
||||
|
||||
namespace Dashboard {
|
||||
|
@ -1,11 +1,11 @@
|
||||
using Dashboard.Connector;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
public abstract class ASensor : IDisposable {
|
||||
protected String topic;
|
||||
protected Int32 pollcount;
|
||||
@ -50,7 +50,7 @@ namespace Dashboard.Sensor {
|
||||
}
|
||||
|
||||
internal static ASensor GetInstance(ADataBackend backend, Dictionary<String, String> dictionary, String name) {
|
||||
String object_sensor = "Dashboard.Sensor." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
|
||||
String object_sensor = "IoTBot.Sensor." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
|
||||
Type t = null;
|
||||
try {
|
||||
t = Type.GetType(object_sensor, true);
|
||||
|
@ -2,10 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using Dashboard.Connector;
|
||||
using IoTBot.Connector;
|
||||
using LitJson;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
class Flex4gridswitch : ASensor {
|
||||
private String id;
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Dashboard.Connector;
|
||||
using IoTBot.Connector;
|
||||
using LitJson;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
class Flex4gridpower : ASensor {
|
||||
private String id;
|
||||
|
||||
|
@ -1,20 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
class Luminanz : ASensor {
|
||||
public Luminanz(Dictionary<String, String> settings) : base(settings) {
|
||||
public Luminanz(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
||||
this.GetBool = true;
|
||||
this.GetFloat = 0.0f;
|
||||
this.GetInt = 0;
|
||||
this.Datatypes = Types.Int;
|
||||
}
|
||||
|
||||
protected override void UpdateValue(MqttMsgPublishEventArgs e) {
|
||||
this.GetInt = Int32.Parse(Encoding.UTF8.GetString(e.Message), new CultureInfo("en-US"));
|
||||
protected override Boolean UpdateValue(MqttEventArgs e) {
|
||||
this.GetInt = Int32.Parse(e.Message, new CultureInfo("en-US"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
class Pir : ASensor {
|
||||
public Pir(Dictionary<String, String> settings) : base(settings) {
|
||||
public Pir(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
||||
this.Datatypes = Types.Bool;
|
||||
}
|
||||
|
||||
protected override void UpdateValue(MqttMsgPublishEventArgs e) {
|
||||
this.GetBool = (Encoding.UTF8.GetString(e.Message).ToLower() == "on") ? true : false;
|
||||
protected override Boolean UpdateValue(MqttEventArgs e) {
|
||||
this.GetBool = (e.Message.ToLower() == "on") ? true : false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Dashboard.Connector;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
class Power : ASensor {
|
||||
public Power(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
||||
this.GetBool = true;
|
||||
|
@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Dashboard.Connector;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
class Switch : ASensor {
|
||||
public Switch(Dictionary<System.String, System.String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
||||
this.Datatypes = Types.Bool;
|
||||
|
@ -1,20 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace Dashboard.Sensor {
|
||||
namespace IoTBot.Sensor {
|
||||
class Temperatur : ASensor {
|
||||
public Temperatur(Dictionary<String, String> settings) : base(settings) {
|
||||
public Temperatur(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
||||
this.GetBool = true;
|
||||
this.GetFloat = 0.0f;
|
||||
this.GetInt = 0;
|
||||
this.Datatypes = Types.Float;
|
||||
}
|
||||
|
||||
protected override void UpdateValue(MqttMsgPublishEventArgs e) {
|
||||
this.GetFloat = Single.Parse(Encoding.UTF8.GetString(e.Message), new CultureInfo("en-US"));
|
||||
protected override Boolean UpdateValue(MqttEventArgs e) {
|
||||
this.GetFloat = Single.Parse(e.Message, new CultureInfo("en-US"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using Dashboard.Sensor;
|
||||
using IoTBot.Sensor;
|
||||
|
||||
namespace Dashboard.Tracings {
|
||||
public abstract class ATracings {
|
||||
|
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using Dashboard.Sensor;
|
||||
using IoTBot.Sensor;
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Series;
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Dashboard.Sensor;
|
||||
using IoTBot.Sensor;
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using System.Linq;
|
||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using Dashboard.Sensor;
|
||||
using IoTBot.Sensor;
|
||||
|
||||
namespace Dashboard.Tracings {
|
||||
class Powermeter : Meter {
|
||||
|
@ -2,8 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Windows.Forms;
|
||||
using Dashboard.Connector;
|
||||
using Dashboard.Sensor;
|
||||
using IoTBot.Connector;
|
||||
using IoTBot.Sensor;
|
||||
|
||||
namespace Dashboard.Tracings {
|
||||
class Switcher : ATracings {
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,15 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Dashboard.Connector {
|
||||
namespace IoTBot.Connector {
|
||||
public abstract class ADataBackend {
|
||||
|
||||
public abstract event MqttMessage MessageIncomming;
|
||||
public abstract event MqttMessage MessageSending;
|
||||
public delegate void MqttMessage(Object sender, MqttEventArgs e);
|
||||
public delegate void MqttMessage(ADataBackend sender, MqttEventArgs e);
|
||||
|
||||
public static ADataBackend GetInstance(Dictionary<String, String> dictionary) {
|
||||
String object_sensor = "Dashboard.Connector." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
|
||||
String object_sensor = "IoTBot.Connector." + Char.ToUpper(dictionary["type"][0]) + dictionary["type"].Substring(1).ToLower();
|
||||
Type t = null;
|
||||
try {
|
||||
t = Type.GetType(object_sensor, true);
|
||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Dashboard.Connector {
|
||||
namespace IoTBot.Connector {
|
||||
class Mosquitto : ADataBackend, IDisposable {
|
||||
private Process p;
|
||||
private String message;
|
||||
|
@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using BlubbFish.Utils;
|
||||
using uPLibrary.Networking.M2Mqtt;
|
||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||
|
||||
namespace Dashboard.Connector {
|
||||
namespace IoTBot.Connector {
|
||||
class Mqtt : ADataBackend, IDisposable {
|
||||
private MqttClient client;
|
||||
|
||||
|
@ -5,7 +5,7 @@ using Telegram.Bot.Args;
|
||||
using Telegram.Bot.Exceptions;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace MqttToTelegram {
|
||||
namespace IoTBot.Connector {
|
||||
class Telegram {
|
||||
private static Telegram instance;
|
||||
private TelegramBotClient bot;
|
||||
@ -17,8 +17,8 @@ namespace MqttToTelegram {
|
||||
public event TelegramMessage MessageSending;
|
||||
|
||||
private Telegram() {
|
||||
bot = new TelegramBotClient(InIReader.GetInstance("settings.ini").GetValue("general", "telegram-key"));
|
||||
bot.OnMessage += Bot_OnMessage;
|
||||
this.bot = new TelegramBotClient(InIReader.GetInstance("settings.ini").GetValue("general", "telegram-key"));
|
||||
this.bot.OnMessage += this.Bot_OnMessage;
|
||||
this.Connect();
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ namespace MqttToTelegram {
|
||||
}
|
||||
|
||||
private void Connect() {
|
||||
bot.StartReceiving();
|
||||
this.bot.StartReceiving();
|
||||
this.chat = new ChatId(InIReader.GetInstance("settings.ini").GetValue("general", "chatid"));
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using Dashboard.Connector;
|
||||
using IoTBot.Connector;
|
||||
|
||||
namespace Mqtt_SWB_Dashboard {
|
||||
/// <summary>
|
||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Dashboard.Connector;
|
||||
using IoTBot.Connector;
|
||||
using LitJson;
|
||||
using Mqtt_SWB_Dashboard.Helper;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user