[NF] Umbenennung zu IoTBot Namespace

This commit is contained in:
BlubbFish 2017-10-02 00:49:44 +02:00
parent ceef3daf21
commit 8d80a132dc
47 changed files with 186 additions and 175 deletions

3
.gitignore vendored
View File

@ -87,3 +87,6 @@
/IoT-Bot/IoT-Bot/Connector/.svn /IoT-Bot/IoT-Bot/Connector/.svn
/IoT-Bot/IoT-Bot/obj/Debug /IoT-Bot/IoT-Bot/obj/Debug
/IoT-Bot/IoT-Bot/Sensor/.svn /IoT-Bot/IoT-Bot/Sensor/.svn
/Mqtt-Dashboard/Mqtt-Dashboard/Connector/.svn
/Mqtt-Dashboard/Mqtt-Dashboard/Sensor/.svn
/IoT-Bot/IoT-Bot/bin/Debug

View File

@ -1,32 +1,37 @@
using Dashboard.Sensor; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using IoTBot.Connector;
using IoTBot.Sensor;
namespace MqttToTelegram.Condition { namespace IoTBot.Condition {
abstract class ACondition { abstract class ACondition {
protected ASensor sensor; protected ASensor sensor;
protected Dictionary<String, String> settings; protected Dictionary<String, String> settings;
public ACondition(Dictionary<String, String> settings) { public ACondition(Dictionary<String, String> settings, ADataBackend backend) {
this.settings = settings; this.settings = settings;
Dictionary<String, String> l = new Dictionary<string, string>(); Dictionary<String, String> l = new Dictionary<String, String> {
l.Add("topic", this.settings["sensor_topic"]); { "topic", this.settings["sensor_topic"] },
l.Add("polling", this.settings["sensor_polling"]); { "type", this.settings["sensor"] }
this.sensor = ASensor.GetInstance(this.settings["sensor"],l); };
this.sensor.Update += Sensor_Update; 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); protected abstract void Sensor_Update(Object sender, EventArgs e);
public static ACondition GetInstance(String v, Dictionary<String, String> dictionary) { public static ACondition GetInstance(Dictionary<String, String> settings, ADataBackend backend) {
string object_condition = "MqttToTelegram.Condition." + char.ToUpper(v[0]) + v.Substring(1).ToLower(); String object_condition = "IoTBot.Condition." + Char.ToUpper(settings["type"][0]) + settings["type"].Substring(1).ToLower();
Type t = null; Type t = null;
try { try {
t = Type.GetType(object_condition, true); t = Type.GetType(object_condition, true);
} catch(TypeLoadException) { } 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 });
} }
} }
} }

View File

@ -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)));
}
}
}
}

View File

@ -1,22 +1,21 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using IoTBot.Connector;
using System.Text; using IoTBot.Sensor;
using System.Threading.Tasks;
namespace MqttToTelegram.Condition { namespace IoTBot.Condition {
class Edge : ACondition { class Edge : ACondition {
private Boolean histBool; 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) { 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) { if(this.sensor.GetBool == Boolean.Parse(this.settings["sensor_value"]) && this.histBool != this.sensor.GetBool) {
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 { } else {
this.histBool = this.sensor.GetBool; this.histBool = this.sensor.GetBool;
} }

View 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));
}
}
}
}

View File

@ -1,15 +1,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Dashboard.Connector { namespace IoTBot.Connector {
public abstract class ADataBackend { public abstract class ADataBackend {
public abstract event MqttMessage MessageIncomming; public abstract event MqttMessage MessageIncomming;
public abstract event MqttMessage MessageSending; 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) { 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; Type t = null;
try { try {
t = Type.GetType(object_sensor, true); t = Type.GetType(object_sensor, true);

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Dashboard.Connector { namespace IoTBot.Connector {
class Mosquitto : ADataBackend, IDisposable { class Mosquitto : ADataBackend, IDisposable {
private Process p; private Process p;
private String message; private String message;

View File

@ -4,7 +4,7 @@ using System.Text;
using uPLibrary.Networking.M2Mqtt; using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages; using uPLibrary.Networking.M2Mqtt.Messages;
namespace Dashboard.Connector { namespace IoTBot.Connector {
class Mqtt : ADataBackend, IDisposable { class Mqtt : ADataBackend, IDisposable {
private MqttClient client; private MqttClient client;

View File

@ -5,7 +5,7 @@ using Telegram.Bot.Args;
using Telegram.Bot.Exceptions; using Telegram.Bot.Exceptions;
using Telegram.Bot.Types; using Telegram.Bot.Types;
namespace MqttToTelegram { namespace IoTBot.Connector {
class Telegram { class Telegram {
private static Telegram instance; private static Telegram instance;
private TelegramBotClient bot; private TelegramBotClient bot;
@ -17,8 +17,8 @@ namespace MqttToTelegram {
public event TelegramMessage MessageSending; public event TelegramMessage MessageSending;
private Telegram() { private Telegram() {
bot = new TelegramBotClient(InIReader.GetInstance("settings.ini").GetValue("general", "telegram-key")); this.bot = new TelegramBotClient(InIReader.GetInstance("settings.ini").GetValue("general", "telegram-key"));
bot.OnMessage += Bot_OnMessage; this.bot.OnMessage += this.Bot_OnMessage;
this.Connect(); this.Connect();
} }
@ -36,7 +36,7 @@ namespace MqttToTelegram {
} }
private void Connect() { private void Connect() {
bot.StartReceiving(); this.bot.StartReceiving();
this.chat = new ChatId(InIReader.GetInstance("settings.ini").GetValue("general", "chatid")); this.chat = new ChatId(InIReader.GetInstance("settings.ini").GetValue("general", "chatid"));
} }

View File

@ -62,7 +62,7 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Condition\ConditionWorker.cs" /> <Compile Include="ConditionWorker.cs" />
<Compile Include="Condition\ACondition.cs" /> <Compile Include="Condition\ACondition.cs" />
<Compile Include="Condition\Edge.cs" /> <Compile Include="Condition\Edge.cs" />
<Compile Include="Connector\ADataBackend.cs" /> <Compile Include="Connector\ADataBackend.cs" />
@ -79,6 +79,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
<None Include="condition.ini.example" />
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="settings.ini.example" /> <None Include="settings.ini.example" />
</ItemGroup> </ItemGroup>

View File

@ -1,25 +1,24 @@
using Dashboard.Connector; using System;
using MqttToTelegram.Condition; using BlubbFish.Utils;
using System; using IoTBot.Connector;
using System.Text;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace MqttToTelegram { namespace IoTBot {
class Program { class Program {
static void Main(string[] args) { static void Main(String[] args) {
ConditionWorker.Instance.Run(Telegram.Instance); ADataBackend mqtt = ADataBackend.GetInstance(InIReader.GetInstance("settings.ini").GetSection("mqtt"));
Mqtt.Instance.MessageIncomming += Mqtt_MessageIncomming; ConditionWorker.GetInstance(mqtt).Run(Connector.Telegram.Instance);
Mqtt.Instance.MessageSending += Mqtt_MessageSending; mqtt.MessageIncomming += Mqtt_MessageIncomming;
Telegram.Instance.MessageIncomming += Telegram_MessageIncomming; mqtt.MessageSending += Mqtt_MessageSending;
Telegram.Instance.MessageSending += Telegram_MessageSending; Connector.Telegram.Instance.MessageIncomming += Telegram_MessageIncomming;
Connector.Telegram.Instance.MessageSending += Telegram_MessageSending;
while(true) { while(true) {
System.Threading.Thread.Sleep(100); System.Threading.Thread.Sleep(100);
} }
} }
private static void Mqtt_MessageSending(Object sender, MqttMsgPublishEventArgs e) { private static void Mqtt_MessageSending(ADataBackend sender, MqttEventArgs e) {
Console.WriteLine("-> [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + Encoding.UTF8.GetString(e.Message) + " on " + e.Topic); Console.WriteLine("-> [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + e.Message + " on " + e.Topic);
} }
private static void Telegram_MessageSending(Object sender, global::Telegram.Bot.Types.Message e) { 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); Console.WriteLine("<- [" + e.Date.ToUniversalTime() + "] Telegram: " + e.Text + " on " + e.Chat.Id);
} }
private static void Mqtt_MessageIncomming(Object sender, MqttMsgPublishEventArgs e) { private static void Mqtt_MessageIncomming(ADataBackend sender, MqttEventArgs e) {
Console.WriteLine("<- [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + Encoding.UTF8.GetString(e.Message) + " on " + e.Topic); Console.WriteLine("<- [" + DateTime.Now.ToUniversalTime() + "] MQTT: " + e.Message + " on " + e.Topic);
} }
} }
} }

View File

@ -1,11 +1,11 @@
using Dashboard.Connector; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading;
using IoTBot.Connector;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
public abstract class ASensor : IDisposable { public abstract class ASensor : IDisposable {
protected String topic; protected String topic;
protected Int32 pollcount; protected Int32 pollcount;
@ -50,7 +50,7 @@ namespace Dashboard.Sensor {
} }
internal static ASensor GetInstance(ADataBackend backend, Dictionary<String, String> dictionary, String name) { 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; Type t = null;
try { try {
t = Type.GetType(object_sensor, true); t = Type.GetType(object_sensor, true);

View File

@ -2,10 +2,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Dashboard.Connector; using IoTBot.Connector;
using LitJson; using LitJson;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
class Flex4gridswitch : ASensor { class Flex4gridswitch : ASensor {
private String id; private String id;

View File

@ -1,10 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Dashboard.Connector; using IoTBot.Connector;
using LitJson; using LitJson;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
class Flex4gridpower : ASensor { class Flex4gridpower : ASensor {
private String id; private String id;

View File

@ -1,20 +1,20 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Text; using IoTBot.Connector;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
class Luminanz : ASensor { 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.GetBool = true;
this.GetFloat = 0.0f; this.GetFloat = 0.0f;
this.GetInt = 0; this.GetInt = 0;
this.Datatypes = Types.Int; this.Datatypes = Types.Int;
} }
protected override void UpdateValue(MqttMsgPublishEventArgs e) { protected override Boolean UpdateValue(MqttEventArgs e) {
this.GetInt = Int32.Parse(Encoding.UTF8.GetString(e.Message), new CultureInfo("en-US")); this.GetInt = Int32.Parse(e.Message, new CultureInfo("en-US"));
return true;
} }
} }
} }

View File

@ -1,16 +1,16 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using IoTBot.Connector;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
class Pir : ASensor { 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; this.Datatypes = Types.Bool;
} }
protected override void UpdateValue(MqttMsgPublishEventArgs e) { protected override Boolean UpdateValue(MqttEventArgs e) {
this.GetBool = (Encoding.UTF8.GetString(e.Message).ToLower() == "on") ? true : false; this.GetBool = (e.Message.ToLower() == "on") ? true : false;
return true;
} }
} }
} }

View File

@ -1,9 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Dashboard.Connector; using IoTBot.Connector;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
class Power : ASensor { class Power : ASensor {
public Power(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) { public Power(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
this.GetBool = true; this.GetBool = true;

View File

@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Dashboard.Connector; using IoTBot.Connector;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
class Switch : ASensor { class Switch : ASensor {
public Switch(Dictionary<System.String, System.String> settings, String name, ADataBackend backend) : base(settings, name, backend) { public Switch(Dictionary<System.String, System.String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
this.Datatypes = Types.Bool; this.Datatypes = Types.Bool;

View File

@ -1,20 +1,20 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Text; using IoTBot.Connector;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
class Temperatur : ASensor { 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.GetBool = true;
this.GetFloat = 0.0f; this.GetFloat = 0.0f;
this.GetInt = 0; this.GetInt = 0;
this.Datatypes = Types.Float; this.Datatypes = Types.Float;
} }
protected override void UpdateValue(MqttMsgPublishEventArgs e) { protected override Boolean UpdateValue(MqttEventArgs e) {
this.GetFloat = Single.Parse(Encoding.UTF8.GetString(e.Message), new CultureInfo("en-US")); this.GetFloat = Single.Parse(e.Message, new CultureInfo("en-US"));
return true;
} }
} }
} }

View File

@ -0,0 +1,4 @@
[test]
type=Edge
sensor=Power
sensor_topic=/test/powersensor

View File

@ -1,4 +1,7 @@
[general] [general]
mqtt-server=localhost
telegram-key=ABCDEFGH telegram-key=ABCDEFGH
chatid=1234 chatid=1234
[mqtt]
server=localhost
type=mqtt

View File

@ -1,15 +1,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Dashboard.Connector { namespace IoTBot.Connector {
public abstract class ADataBackend { public abstract class ADataBackend {
public abstract event MqttMessage MessageIncomming; public abstract event MqttMessage MessageIncomming;
public abstract event MqttMessage MessageSending; 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) { 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; Type t = null;
try { try {
t = Type.GetType(object_sensor, true); t = Type.GetType(object_sensor, true);

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Dashboard.Connector { namespace IoTBot.Connector {
class Mosquitto : ADataBackend, IDisposable { class Mosquitto : ADataBackend, IDisposable {
private Process p; private Process p;
private String message; private String message;

View File

@ -1,11 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using BlubbFish.Utils;
using uPLibrary.Networking.M2Mqtt; using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages; using uPLibrary.Networking.M2Mqtt.Messages;
namespace Dashboard.Connector { namespace IoTBot.Connector {
class Mqtt : ADataBackend, IDisposable { class Mqtt : ADataBackend, IDisposable {
private MqttClient client; private MqttClient client;

View File

@ -5,7 +5,7 @@ using Telegram.Bot.Args;
using Telegram.Bot.Exceptions; using Telegram.Bot.Exceptions;
using Telegram.Bot.Types; using Telegram.Bot.Types;
namespace MqttToTelegram { namespace IoTBot.Connector {
class Telegram { class Telegram {
private static Telegram instance; private static Telegram instance;
private TelegramBotClient bot; private TelegramBotClient bot;
@ -17,8 +17,8 @@ namespace MqttToTelegram {
public event TelegramMessage MessageSending; public event TelegramMessage MessageSending;
private Telegram() { private Telegram() {
bot = new TelegramBotClient(InIReader.GetInstance("settings.ini").GetValue("general", "telegram-key")); this.bot = new TelegramBotClient(InIReader.GetInstance("settings.ini").GetValue("general", "telegram-key"));
bot.OnMessage += Bot_OnMessage; this.bot.OnMessage += this.Bot_OnMessage;
this.Connect(); this.Connect();
} }
@ -36,7 +36,7 @@ namespace MqttToTelegram {
} }
private void Connect() { private void Connect() {
bot.StartReceiving(); this.bot.StartReceiving();
this.chat = new ChatId(InIReader.GetInstance("settings.ini").GetValue("general", "chatid")); this.chat = new ChatId(InIReader.GetInstance("settings.ini").GetValue("general", "chatid"));
} }

View File

@ -2,8 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms; using System.Windows.Forms;
using BlubbFish.Utils; using BlubbFish.Utils;
using Dashboard.Connector; using IoTBot.Connector;
using Dashboard.Sensor; using IoTBot.Sensor;
using Dashboard.Tracings; using Dashboard.Tracings;
namespace Dashboard { namespace Dashboard {

View File

@ -1,11 +1,11 @@
using Dashboard.Connector; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading;
using IoTBot.Connector;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
public abstract class ASensor : IDisposable { public abstract class ASensor : IDisposable {
protected String topic; protected String topic;
protected Int32 pollcount; protected Int32 pollcount;
@ -50,7 +50,7 @@ namespace Dashboard.Sensor {
} }
internal static ASensor GetInstance(ADataBackend backend, Dictionary<String, String> dictionary, String name) { 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; Type t = null;
try { try {
t = Type.GetType(object_sensor, true); t = Type.GetType(object_sensor, true);

View File

@ -2,10 +2,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Dashboard.Connector; using IoTBot.Connector;
using LitJson; using LitJson;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
class Flex4gridswitch : ASensor { class Flex4gridswitch : ASensor {
private String id; private String id;

View File

@ -1,10 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Dashboard.Connector; using IoTBot.Connector;
using LitJson; using LitJson;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
class Flex4gridpower : ASensor { class Flex4gridpower : ASensor {
private String id; private String id;

View File

@ -1,20 +1,20 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Text; using IoTBot.Connector;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
class Luminanz : ASensor { 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.GetBool = true;
this.GetFloat = 0.0f; this.GetFloat = 0.0f;
this.GetInt = 0; this.GetInt = 0;
this.Datatypes = Types.Int; this.Datatypes = Types.Int;
} }
protected override void UpdateValue(MqttMsgPublishEventArgs e) { protected override Boolean UpdateValue(MqttEventArgs e) {
this.GetInt = Int32.Parse(Encoding.UTF8.GetString(e.Message), new CultureInfo("en-US")); this.GetInt = Int32.Parse(e.Message, new CultureInfo("en-US"));
return true;
} }
} }
} }

View File

@ -1,16 +1,16 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using IoTBot.Connector;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
class Pir : ASensor { 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; this.Datatypes = Types.Bool;
} }
protected override void UpdateValue(MqttMsgPublishEventArgs e) { protected override Boolean UpdateValue(MqttEventArgs e) {
this.GetBool = (Encoding.UTF8.GetString(e.Message).ToLower() == "on") ? true : false; this.GetBool = (e.Message.ToLower() == "on") ? true : false;
return true;
} }
} }
} }

View File

@ -1,9 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Dashboard.Connector; using IoTBot.Connector;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
class Power : ASensor { class Power : ASensor {
public Power(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) { public Power(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
this.GetBool = true; this.GetBool = true;

View File

@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Dashboard.Connector; using IoTBot.Connector;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
class Switch : ASensor { class Switch : ASensor {
public Switch(Dictionary<System.String, System.String> settings, String name, ADataBackend backend) : base(settings, name, backend) { public Switch(Dictionary<System.String, System.String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
this.Datatypes = Types.Bool; this.Datatypes = Types.Bool;

View File

@ -1,20 +1,20 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Text; using IoTBot.Connector;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace Dashboard.Sensor { namespace IoTBot.Sensor {
class Temperatur : ASensor { 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.GetBool = true;
this.GetFloat = 0.0f; this.GetFloat = 0.0f;
this.GetInt = 0; this.GetInt = 0;
this.Datatypes = Types.Float; this.Datatypes = Types.Float;
} }
protected override void UpdateValue(MqttMsgPublishEventArgs e) { protected override Boolean UpdateValue(MqttEventArgs e) {
this.GetFloat = Single.Parse(Encoding.UTF8.GetString(e.Message), new CultureInfo("en-US")); this.GetFloat = Single.Parse(e.Message, new CultureInfo("en-US"));
return true;
} }
} }
} }

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms; using System.Windows.Forms;
using Dashboard.Sensor; using IoTBot.Sensor;
namespace Dashboard.Tracings { namespace Dashboard.Tracings {
public abstract class ATracings { public abstract class ATracings {

View File

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using Dashboard.Sensor; using IoTBot.Sensor;
using OxyPlot; using OxyPlot;
using OxyPlot.Axes; using OxyPlot.Axes;
using OxyPlot.Series; using OxyPlot.Series;

View File

@ -1,5 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using Dashboard.Sensor; using IoTBot.Sensor;
using System; using System;
using System.Windows.Forms; using System.Windows.Forms;
using System.Linq; using System.Linq;

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using Dashboard.Sensor; using IoTBot.Sensor;
namespace Dashboard.Tracings { namespace Dashboard.Tracings {
class Powermeter : Meter { class Powermeter : Meter {

View File

@ -2,8 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Windows.Forms; using System.Windows.Forms;
using Dashboard.Connector; using IoTBot.Connector;
using Dashboard.Sensor; using IoTBot.Sensor;
namespace Dashboard.Tracings { namespace Dashboard.Tracings {
class Switcher : ATracings { class Switcher : ATracings {

View File

@ -1,15 +1,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Dashboard.Connector { namespace IoTBot.Connector {
public abstract class ADataBackend { public abstract class ADataBackend {
public abstract event MqttMessage MessageIncomming; public abstract event MqttMessage MessageIncomming;
public abstract event MqttMessage MessageSending; 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) { 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; Type t = null;
try { try {
t = Type.GetType(object_sensor, true); t = Type.GetType(object_sensor, true);

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Dashboard.Connector { namespace IoTBot.Connector {
class Mosquitto : ADataBackend, IDisposable { class Mosquitto : ADataBackend, IDisposable {
private Process p; private Process p;
private String message; private String message;

View File

@ -1,11 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using BlubbFish.Utils;
using uPLibrary.Networking.M2Mqtt; using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages; using uPLibrary.Networking.M2Mqtt.Messages;
namespace Dashboard.Connector { namespace IoTBot.Connector {
class Mqtt : ADataBackend, IDisposable { class Mqtt : ADataBackend, IDisposable {
private MqttClient client; private MqttClient client;

View File

@ -5,7 +5,7 @@ using Telegram.Bot.Args;
using Telegram.Bot.Exceptions; using Telegram.Bot.Exceptions;
using Telegram.Bot.Types; using Telegram.Bot.Types;
namespace MqttToTelegram { namespace IoTBot.Connector {
class Telegram { class Telegram {
private static Telegram instance; private static Telegram instance;
private TelegramBotClient bot; private TelegramBotClient bot;
@ -17,8 +17,8 @@ namespace MqttToTelegram {
public event TelegramMessage MessageSending; public event TelegramMessage MessageSending;
private Telegram() { private Telegram() {
bot = new TelegramBotClient(InIReader.GetInstance("settings.ini").GetValue("general", "telegram-key")); this.bot = new TelegramBotClient(InIReader.GetInstance("settings.ini").GetValue("general", "telegram-key"));
bot.OnMessage += Bot_OnMessage; this.bot.OnMessage += this.Bot_OnMessage;
this.Connect(); this.Connect();
} }
@ -36,7 +36,7 @@ namespace MqttToTelegram {
} }
private void Connect() { private void Connect() {
bot.StartReceiving(); this.bot.StartReceiving();
this.chat = new ChatId(InIReader.GetInstance("settings.ini").GetValue("general", "chatid")); this.chat = new ChatId(InIReader.GetInstance("settings.ini").GetValue("general", "chatid"));
} }

View File

@ -2,7 +2,7 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.Windows; using System.Windows;
using Dashboard.Connector; using IoTBot.Connector;
namespace Mqtt_SWB_Dashboard { namespace Mqtt_SWB_Dashboard {
/// <summary> /// <summary>

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Dashboard.Connector; using IoTBot.Connector;
using LitJson; using LitJson;
using Mqtt_SWB_Dashboard.Helper; using Mqtt_SWB_Dashboard.Helper;