[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)
65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using System;
|
|
using BlubbFish.IoT.Zway;
|
|
using BlubbFish.IoT.Zway.Events;
|
|
using BlubbFish.Utils;
|
|
using BlubbFish.Utils.IoT.Connector;
|
|
using BlubbFish.Utils.IoT.Events;
|
|
using BlubbFish.Utils.IoT.Interfaces;
|
|
|
|
namespace ZwayBot.Moduls {
|
|
class Senml : AModul {
|
|
public override event ModulEvent Update;
|
|
private ABackend mqtt;
|
|
private String SenmlGuid;
|
|
|
|
public Senml(ZwayController zway, InIReader settings) : base(zway, settings) {
|
|
if (this.config.ContainsKey("settings")) {
|
|
this.mqtt = ABackend.GetInstance(this.config["settings"], ABackend.BackendType.Data);
|
|
this.mqtt.MessageIncomming += this.EventInput;
|
|
this.zw.Update += this.EventOutput;
|
|
this.SenmlGuid = this.config["settings"]["guid"];
|
|
}
|
|
}
|
|
|
|
#region Events
|
|
private void EventOutput(Object sender, DeviceUpdateEvent e) {
|
|
String topic = "";
|
|
String data = "";
|
|
if (e.Parent.HasInterface(typeof(ISenml))) {
|
|
ISenml sensor = (ISenml)e.Parent;
|
|
topic = sensor.SenmlTopic() + this.SenmlGuid+ "/senml";
|
|
data = sensor.ToSenml();
|
|
}
|
|
if (topic != "" && data != null && data != "") {
|
|
((ADataBackend)this.mqtt).Send(topic, data);
|
|
this.Update?.Invoke(this, new MqttEvent(topic, data));
|
|
}
|
|
}
|
|
|
|
private void EventInput(Object sender, BackendEvent e) { }
|
|
#endregion
|
|
|
|
#region Config
|
|
protected override void UpdateConfig() { }
|
|
#endregion
|
|
|
|
#region IDisposable Support
|
|
private Boolean disposedValue = false;
|
|
|
|
protected virtual void Dispose(Boolean disposing) {
|
|
if (!this.disposedValue) {
|
|
if (disposing) {
|
|
this.mqtt.Dispose();
|
|
}
|
|
this.disposedValue = true;
|
|
}
|
|
}
|
|
|
|
public override void Dispose() {
|
|
Dispose(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|