[BF] Fehler behoben, das sich die Anwendung nicht beendet
This commit is contained in:
parent
241b0ca00a
commit
3b5b2287b2
@ -5,7 +5,7 @@ using uPLibrary.Networking.M2Mqtt;
|
|||||||
using uPLibrary.Networking.M2Mqtt.Messages;
|
using uPLibrary.Networking.M2Mqtt.Messages;
|
||||||
|
|
||||||
namespace Dashboard.Connector {
|
namespace Dashboard.Connector {
|
||||||
class Mqtt {
|
class Mqtt : IDisposable {
|
||||||
private static Mqtt instance;
|
private static Mqtt instance;
|
||||||
private MqttClient client;
|
private MqttClient client;
|
||||||
|
|
||||||
@ -37,5 +37,29 @@ namespace Dashboard.Connector {
|
|||||||
public void Send(String topic, String data) {
|
public void Send(String topic, String data) {
|
||||||
this.client.Publish(topic, Encoding.UTF8.GetBytes(data));
|
this.client.Publish(topic, Encoding.UTF8.GetBytes(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region IDisposable Support
|
||||||
|
private bool disposedValue = false;
|
||||||
|
protected virtual void Dispose(bool disposing) {
|
||||||
|
if(!disposedValue) {
|
||||||
|
if(disposing) {
|
||||||
|
this.client.MqttMsgPublishReceived -= this.Client_MqttMsgPublishReceived;
|
||||||
|
this.client.Unsubscribe(new String[] { "#" });
|
||||||
|
this.client.Disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.client = null;
|
||||||
|
|
||||||
|
disposedValue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
~Mqtt() {
|
||||||
|
Dispose(false);
|
||||||
|
}
|
||||||
|
public void Dispose() {
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ namespace Dashboard {
|
|||||||
Mqtt.Instance.MessageIncomming += this.Instance_MessageIncomming;
|
Mqtt.Instance.MessageIncomming += this.Instance_MessageIncomming;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GenerateSensors() {
|
private void GenerateSensors() {
|
||||||
InIReader ini = InIReader.GetInstance("sensor.ini");
|
InIReader ini = InIReader.GetInstance("sensor.ini");
|
||||||
List<String> sensorini = ini.GetSections();
|
List<String> sensorini = ini.GetSections();
|
||||||
foreach(String sensor in sensorini) {
|
foreach(String sensor in sensorini) {
|
||||||
@ -68,11 +68,9 @@ namespace Dashboard {
|
|||||||
private new void Dispose() {
|
private new void Dispose() {
|
||||||
this.updateThread.Abort();
|
this.updateThread.Abort();
|
||||||
while (this.updateThread.ThreadState != ThreadState.Aborted) { }
|
while (this.updateThread.ThreadState != ThreadState.Aborted) { }
|
||||||
foreach (String item in this.sensors.Keys) {
|
|
||||||
this.sensors[item] = null;
|
|
||||||
}
|
|
||||||
this.sensors.Clear();
|
this.sensors.Clear();
|
||||||
Mqtt.Instance.MessageIncomming -= this.Instance_MessageIncomming;
|
Mqtt.Instance.MessageIncomming -= this.Instance_MessageIncomming;
|
||||||
|
Mqtt.Instance.Dispose();
|
||||||
this.Dispose(true);
|
this.Dispose(true);
|
||||||
}
|
}
|
||||||
private void Instance_MessageIncomming(Object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e) {
|
private void Instance_MessageIncomming(Object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[Thinkpad]
|
;[Thinkpad]
|
||||||
topic=zway/wohnzimmer/thinkpad/power
|
;topic=zway/wohnzimmer/thinkpad/power
|
||||||
type=Power
|
;type=Power
|
||||||
polling=10
|
;polling=10
|
||||||
|
|
||||||
;[Tv]
|
;[Tv]
|
||||||
;topic=zway/wohnzimmer/tV/power
|
;topic=zway/wohnzimmer/tV/power
|
||||||
@ -12,3 +12,8 @@ polling=10
|
|||||||
;topic=zway/küche/kuehlschrank/power
|
;topic=zway/küche/kuehlschrank/power
|
||||||
;type=Power
|
;type=Power
|
||||||
;polling=10
|
;polling=10
|
||||||
|
|
||||||
|
[Ventilator]
|
||||||
|
topic=zway/power/test/wVentilator
|
||||||
|
type=Power
|
||||||
|
polling=10
|
@ -1,2 +1,2 @@
|
|||||||
[general]
|
[general]
|
||||||
mqtt-server=localhost
|
mqtt-server=129.26.160.65
|
@ -9,3 +9,7 @@
|
|||||||
;[KühlschrankGraph]
|
;[KühlschrankGraph]
|
||||||
;sensor=Kühlschrank
|
;sensor=Kühlschrank
|
||||||
;type=Graph
|
;type=Graph
|
||||||
|
|
||||||
|
[VentilatorGraph]
|
||||||
|
sensor=Ventilator
|
||||||
|
type=Graph
|
Loading…
Reference in New Issue
Block a user