[DW] Flex4Grid deleted

[NF] BosMon Mqtt Plugin created
This commit is contained in:
BlubbFish 2018-03-31 20:42:28 +00:00
parent 307f03c7c0
commit acf5cea593
9 changed files with 0 additions and 204 deletions

View File

@ -11,8 +11,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Uti
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils\IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMosquitto", "..\Utils\IoT\Connector\Data\Mosquitto\ConnectorDataMosquitto.csproj", "{39235FAD-BA9D-4B51-82FC-6969967BEAE9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "..\Utils\IoT\Connector\Data\Mqtt\ConnectorDataMqtt.csproj", "{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}"
EndProject
Global
@ -37,10 +35,6 @@ Global
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.Build.0 = Release|Any CPU
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Release|Any CPU.Build.0 = Release|Any CPU
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Release|Any CPU.ActiveCfg = Release|Any CPU

View File

@ -1,193 +0,0 @@
using System;
using System.Collections.Generic;
using System.Net;
using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Devices;
using BlubbFish.IoT.Zway.Devices.CommandClasses;
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Connector;
using LitJson;
namespace ZwayBot.Moduls {
class Flex4Grid : AModul, IDisposable {
private ADataBackend mqtt;
private String household = "";
private Object requestalivelock = new Object();
public override event ModulEvent Update;
public Flex4Grid(ZwayController zway, InIReader settings) : base(zway, settings) {
if (this.config.ContainsKey("settings")) {
this.mqtt = ADataBackend.GetInstance(this.config["settings"]);
this.ParseIni();
this.mqtt.MessageIncomming += this.Mqtt_MessageIncomming;
}
}
private void ParseIni() {
if (this.config.ContainsKey("zway") && this.config["zway"].ContainsKey("devices")) {
foreach (String device in this.config["zway"]["devices"].Split(',')) {
Int32 deviceid = Int32.Parse(device);
if (this.zw.Devices.ContainsKey(deviceid) && this.zw.Devices[deviceid].Instances.ContainsKey(0)) {
this.zw.Devices[deviceid].Instances[0].Update += this.DeviceUpdate;
}
}
}
if(this.config.ContainsKey("f4g") && this.config["f4g"].ContainsKey("household")) {
this.household = this.config["f4g"]["household"];
}
}
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
Instance instance = (Instance)sender;
if(e.Parent.GetType() == typeof(Switchbinary)) {
if (instance.CommandClasses.ContainsKey(ACommandClass.Classes.SwitchBinary)) {
String topic = "/flex4grid/v1/households/" + this.household + "/device/state";
String text = JsonMapper.ToJson(new Dictionary<String, String>() {
{ "status", ((Switchbinary)instance.CommandClasses[ACommandClass.Classes.SwitchBinary]).State?"active":"idle" },
{ "timestamp", DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'") },
{ "type", ((Switchbinary)instance.CommandClasses[ACommandClass.Classes.SwitchBinary]).Name },
{ "id", instance.DeviceId.ToString() }
}).ToString();
this.mqtt.Send(topic, text);
this.Update?.Invoke(this, new Flex4gridEvent(topic, text));
}
} else if(e.Parent.GetType() == typeof(Sensormultilevelsub) || e.Parent.GetType() == typeof(Metersub)) {
if (instance.CommandClasses.ContainsKey(ACommandClass.Classes.SensorMultilevel) &&
((Sensormultilevel)instance.CommandClasses[ACommandClass.Classes.SensorMultilevel]).Sub.ContainsKey(4) &&
instance.CommandClasses.ContainsKey(ACommandClass.Classes.Meter) && ((Meter)instance.CommandClasses[ACommandClass.Classes.Meter]).Sub.ContainsKey(0)) {
String topic = "/flex4grid/v1/households/" + this.household + "/device/consumption";
String text = JsonMapper.ToJson(new Dictionary<String, String>() {
{ "timestamp", DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'") },
{ "id", instance.DeviceId.ToString() },
{ "power", Math.Round(((Sensormultilevelsub)((Sensormultilevel)instance.CommandClasses[ACommandClass.Classes.SensorMultilevel]).Sub[4]).Level).ToString("F0") },
{ "energyCumul", ((Metersub)((Meter)instance.CommandClasses[ACommandClass.Classes.Meter]).Sub[0]).Level.ToString() }
}).ToString();
this.mqtt.Send(topic, text);
this.Update?.Invoke(this, new Flex4gridEvent(topic, text));
}
}
}
private void Mqtt_MessageIncomming(Object sender, MqttEventArgs e) {
JsonData message;
String topic = e.Topic;
try {
if (e.Message.StartsWith("{")) {
message = JsonMapper.ToObject(e.Message);
} else {
return;
}
} catch (Exception) {
return;
}
if(topic == "/flex4grid/v1/households/" + this.household + "/device/actuate") {
if(message.Keys.Contains("deviceId") && message.Keys.Contains("command")) {
String device = message["deviceId"].ToString();
if(this.config.ContainsKey("zway") && this.config["zway"].ContainsKey("devices")) {
foreach (String item in this.config["zway"]["devices"].Split(',')) {
if (item == device) {
Int32 deviceid = Int32.Parse(device);
if (this.zw.Devices.ContainsKey(deviceid) && this.zw.Devices[deviceid].Instances.ContainsKey(0) &&
this.zw.Devices[deviceid].Instances[0].CommandClasses.ContainsKey(ACommandClass.Classes.SwitchBinary)) {
((Switchbinary)this.zw.Devices[deviceid].Instances[0].CommandClasses[ACommandClass.Classes.SwitchBinary]).State = message["command"].ToString() == "ON";
}
}
}
}
}
}
if (topic == "/flex4grid/v1/households/" + this.household + "/devices/state/request") {
if (this.config.ContainsKey("zway") && this.config["zway"].ContainsKey("devices")) {
Dictionary<String, String> response = new Dictionary<String, String>();
foreach (String device in this.config["zway"]["devices"].Split(',')) {
Int32 deviceid = Int32.Parse(device);
if (this.zw.Devices.ContainsKey(deviceid) && this.zw.Devices[deviceid].Instances.ContainsKey(0)) {
if (this.zw.Devices[deviceid].Instances[0].CommandClasses.ContainsKey(ACommandClass.Classes.SwitchBinary)) {
Switchbinary sw = ((Switchbinary)this.zw.Devices[deviceid].Instances[0].CommandClasses[ACommandClass.Classes.SwitchBinary]);
response.Add(sw.DeviceId.ToString(), sw.State ? "active" : "idle");
}
}
}
if(response.Count != 0) {
response.Add("timestamp", DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'"));
String rtopic = "/flex4grid/v1/households/" + this.household + "/devices/state/response";
String rtext = JsonMapper.ToJson(response).ToString();
}
}
}
}
private void RequestAlive(Object o) {
if (this.config.ContainsKey("f4g") && this.config["f4g"].ContainsKey("raspi")) {
String raspi = this.config["f4g"]["raspi"];
lock (this.requestalivelock) {
String req = "https://wiki.flex4grid.eu/rupdate/rupdate_general.yml.gpg.asc?gw=" + raspi;
HttpWebRequest request = WebRequest.CreateHttp(req);
try {
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
this.Update?.Invoke(this, new Flex4gridEvent(req, response.StatusCode.ToString()));
}
} catch (Exception) { }
}
lock (this.requestalivelock) {
String req = "https://wiki.flex4grid.eu/rupdate/rupdate_general.yml?gw=" + raspi;
HttpWebRequest request = WebRequest.CreateHttp(req);
try {
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
this.Update?.Invoke(this, new Flex4gridEvent(req, response.StatusCode.ToString()));
}
} catch (Exception) { }
}
lock (this.requestalivelock) {
String req = "http://swb.pcs.flex4grid.eu/gateway/" + raspi;
HttpWebRequest request = WebRequest.CreateHttp(req);
try {
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
this.Update?.Invoke(this, new Flex4gridEvent(req, response.StatusCode.ToString()));
}
} catch (Exception) { }
}
}
}
public override void Interconnect(Dictionary<String, AModul> moduls) {
if (this.config.ContainsKey("f4g") && this.config["f4g"].ContainsKey("raspi")) {
foreach (KeyValuePair<String, AModul> item in moduls) {
if (item.Value is CronJob) {
item.Value.SetInterconnection("10,40 * * * *", new Action<Object>(this.RequestAlive), null);
}
}
}
}
protected override void UpdateConfig() { }
#region IDisposable Support
private Boolean disposedValue = false;
protected virtual void Dispose(Boolean disposing) {
if (!this.disposedValue) {
if (disposing) {
this.mqtt.Dispose();
}
this.disposedValue = true;
}
}
~Flex4Grid() {
Dispose(false);
}
public override void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}

View File

@ -58,7 +58,6 @@
<Compile Include="Moduls\AModul.cs" />
<Compile Include="Moduls\CronJob.cs" />
<Compile Include="Helper.cs" />
<Compile Include="Moduls\Flex4Grid.cs" />
<Compile Include="Moduls\Mqtt.cs" />
<Compile Include="Moduls\Overtaker.cs" />
<Compile Include="Moduls\StatusPolling.cs" />
@ -71,10 +70,6 @@
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Utils\IoT\Connector\Data\Mosquitto\ConnectorDataMosquitto.csproj">
<Project>{39235fad-ba9d-4b51-82fc-6969967beae9}</Project>
<Name>ConnectorDataMosquitto</Name>
</ProjectReference>
<ProjectReference Include="..\..\Utils\IoT\Connector\Data\Mqtt\ConnectorDataMqtt.csproj">
<Project>{ee6c8f68-ed46-4c1c-abdd-cfcdf75104f2}</Project>
<Name>ConnectorDataMqtt</Name>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.