Skip to content
Snippets Groups Projects
Commit a58f8f38 authored by philip.schell's avatar philip.schell
Browse files

[1.8.1] Add Hostname to MQTT, so you can see from witch device the data is recieved

parent 827d369c
No related branches found
Tags v1.8.1
No related merge requests found
......@@ -5,16 +5,10 @@ namespace Fraunhofer.Fit.Iot.Lora.Events {
public class DataUpdateEvent : TrackerUpdateEvent {
public GpsUpdateEvent Gps { get; private set; }
public DataUpdateEvent(Tracker tracker) : base(tracker) {
this.Gps = new GpsUpdateEvent(tracker.Gps);
}
public DataUpdateEvent(Tracker tracker) : base(tracker) => this.Gps = new GpsUpdateEvent(tracker.Gps);
public override String MqttTopic() {
return "data/" + base.MqttTopic();
}
public override String MqttTopic() => "data/" + base.MqttTopic();
public override String ToString() {
return base.ToString() + " -- " + "GPS: " + this.Gps.ToString();
}
public override String ToString() => base.ToString() + " -- " + "GPS: " + this.Gps.ToString();
}
}
......@@ -25,8 +25,6 @@ namespace Fraunhofer.Fit.Iot.Lora.Events {
this.LastGPSPos = gps.LastGPSPos;
}
public override String ToString() {
return "Lat: " + this.Latitude + " [" + this.LastLatitude + "] Lon: " + this.Longitude + " [" + this.LastLongitude + "] Height: " + this.Height + " -- Time: " + this.Time + " HDOP: " + this.Hdop + " Fix: " + this.Fix;
}
public override String ToString() => "Lat: " + this.Latitude + " [" + this.LastLatitude + "] Lon: " + this.Longitude + " [" + this.LastLongitude + "] Height: " + this.Height + " -- Time: " + this.Time + " HDOP: " + this.Hdop + " Fix: " + this.Fix;
}
}
......@@ -5,16 +5,10 @@ namespace Fraunhofer.Fit.Iot.Lora.Events {
public class PanicUpdateEvent : TrackerUpdateEvent {
public GpsUpdateEvent Gps { get; private set; }
public PanicUpdateEvent(Tracker tracker) : base(tracker) {
this.Gps = new GpsUpdateEvent(tracker.Gps);
}
public PanicUpdateEvent(Tracker tracker) : base(tracker) => this.Gps = new GpsUpdateEvent(tracker.Gps);
public override String MqttTopic() {
return "panic/" + base.MqttTopic();
}
public override String MqttTopic() => "panic/" + base.MqttTopic();
public override String ToString() {
return base.ToString() + " -- " + "GPS: " + this.Gps.ToString();
}
public override String ToString() => base.ToString() + " -- " + "GPS: " + this.Gps.ToString();
}
}
......@@ -20,12 +20,8 @@ namespace Fraunhofer.Fit.Iot.Lora.Events {
this.DeviceStatus = tracker.DeviceStatus.ToString();
}
public override String MqttTopic() {
return "status/" + base.MqttTopic();
}
public override String MqttTopic() => "status/" + base.MqttTopic();
public override String ToString() {
return base.ToString() + " -- " + "Version: " + this.Version + " Ip-Address:" + this.IpAddress + " Wifi-SSID: " + this.WifiSsid + " Wifi-Active: " + this.WifiActive + " Freq-Offset: " + this.FrequencyOffset + " Status:" + this.DeviceStatus;
}
public override String ToString() => base.ToString() + " -- " + "Version: " + this.Version + " Ip-Address:" + this.IpAddress + " Wifi-SSID: " + this.WifiSsid + " Wifi-Active: " + this.WifiActive + " Freq-Offset: " + this.FrequencyOffset + " Status:" + this.DeviceStatus;
}
}
......@@ -21,6 +21,7 @@ namespace Fraunhofer.Fit.Iot.Lora.Events {
public Double Snrmax { get; private set; }
public Double Snrmin { get; private set; }
public UInt32 Time { get; private set; }
public String Host => Environment.MachineName;
public TrackerUpdateEvent(Tracker tracker) {
this.PacketRssi = tracker.PacketRssi;
......@@ -42,14 +43,10 @@ namespace Fraunhofer.Fit.Iot.Lora.Events {
this.Time = tracker.Time;
}
public override String MqttTopic() {
return base.MqttTopic() + this.Name;
}
public override String MqttTopic() => base.MqttTopic() + this.Name;
public override String ToString() {
return this.Name + " -- " + "Packet: PRssi: " + this.PacketRssi + " Rssi: " + this.Rssi + " SNR: (" + this.Snr + "/" + this.Snrmin + "/" + this.Snrmax + ") Time: " + this.Receivedtime.ToString() +
public override String ToString() => this.Name + " -- " + "Packet: PRssi: " + this.PacketRssi + " Rssi: " + this.Rssi + " SNR: (" + this.Snr + "/" + this.Snrmin + "/" + this.Snrmax + ") Time: " + this.Receivedtime.ToString() +
" Battery: " + this.BatteryLevel + " Radio: " + this.Recieverradio + " Interface: " + this.Recieverinterface + " Freq: " + this.Frequency + " BW: " + this.Bandwidth +
" CR: " + this.Codingrate + " SF: " + this.Spreadingfactor + " CRC: " + this.Crcstatus + "(0x" + this.Calculatedcrc.ToString("X4") + ") Time: " + this.Time;
}
}
}
......@@ -8,9 +8,7 @@ using LitJson;
namespace Fraunhofer.Fit.Iot.Lora.Events {
public class UpdateEventHelper : EventArgs, IMqtt {
public String ToJson() {
return JsonMapper.ToJson(this.ToDictionary());
}
public String ToJson() => JsonMapper.ToJson(this.ToDictionary());
public virtual Dictionary<String, Object> ToDictionary() {
Dictionary<String, Object> dictionary = new Dictionary<String, Object>();
......@@ -36,8 +34,6 @@ namespace Fraunhofer.Fit.Iot.Lora.Events {
return dictionary;
}
public virtual String MqttTopic() {
return "";
}
public virtual String MqttTopic() => "";
}
}
......@@ -45,79 +45,71 @@ namespace Fraunhofer.Fit.Iot.Lora {
}
}
private async void ReceivePacket(Object sender, LoraClientEvent e) {
await Task.Run(() => {
Console.WriteLine("Fraunhofer.Fit.Iot.Lora.LoraController.ReceivePacket: " + e.Text.Length.ToString());
String trackerName = "";
Byte[] binaryUpdate = { };
Byte[] binaryPanics = { };
String textStatus = "";
String textUpdate = "";
if (e.Text.Length == 21 && e.Text[0] == 'b') {
//###### Binary Packet, starts with "b" #########
binaryUpdate = e.Text;
trackerName = Tracker.GetName(binaryUpdate);
Console.WriteLine("Fraunhofer.Fit.Iot.Lora.LoraController.ReceivePacket: |" + BitConverter.ToString(binaryUpdate).Replace("-", " ") + "| PRSSI: " + e.Packetrssi + " RSSI:" + e.Rssi + " SNR:" + e.Snr);
} else if (e.Text.Length == 21 && e.Text[0] == 'p') {
//###### Panic Packet, starts with "p" #########
binaryPanics = e.Text;
trackerName = Tracker.GetName(binaryPanics);
Console.WriteLine("Fraunhofer.Fit.Iot.Lora.LoraController.ReceivePacket: |" + BitConverter.ToString(binaryPanics).Replace("-", " ") + "| PRSSI: " + e.Packetrssi + " RSSI:" + e.Rssi + " SNR:" + e.Snr);
} else if (e.Text.Length > 3 && e.Text[0] == 'd' && e.Text[1] == 'e' && e.Text[2] == 'b') {
//###### Debug Packet, three lines #############
String text = System.Text.Encoding.ASCII.GetString(e.Text).Trim();
Console.WriteLine("Fraunhofer.Fit.Iot.Lora.LoraController.ReceivePacket: |" + text + "| PRSSI: " + e.Packetrssi + " RSSI:" + e.Rssi + " SNR:" + e.Snr);
if (Tracker.CheckPacket(text)) {
textStatus = text;
trackerName = Tracker.GetName(textStatus, 1);
} else {
Console.WriteLine("Fraunhofer.Fit.Iot.Lora.LoraController.ReceivePacket: Debug-Packet not Match!");
}
private async void ReceivePacket(Object sender, LoraClientEvent e) => await Task.Run(() => {
Console.WriteLine("Fraunhofer.Fit.Iot.Lora.LoraController.ReceivePacket: " + e.Text.Length.ToString());
String trackerName = "";
Byte[] binaryUpdate = { };
Byte[] binaryPanics = { };
String textStatus = "";
String textUpdate = "";
if(e.Text.Length == 21 && e.Text[0] == 'b') {
//###### Binary Packet, starts with "b" #########
binaryUpdate = e.Text;
trackerName = Tracker.GetName(binaryUpdate);
Console.WriteLine("Fraunhofer.Fit.Iot.Lora.LoraController.ReceivePacket: |" + BitConverter.ToString(binaryUpdate).Replace("-", " ") + "| PRSSI: " + e.Packetrssi + " RSSI:" + e.Rssi + " SNR:" + e.Snr);
} else if(e.Text.Length == 21 && e.Text[0] == 'p') {
//###### Panic Packet, starts with "p" #########
binaryPanics = e.Text;
trackerName = Tracker.GetName(binaryPanics);
Console.WriteLine("Fraunhofer.Fit.Iot.Lora.LoraController.ReceivePacket: |" + BitConverter.ToString(binaryPanics).Replace("-", " ") + "| PRSSI: " + e.Packetrssi + " RSSI:" + e.Rssi + " SNR:" + e.Snr);
} else if(e.Text.Length > 3 && e.Text[0] == 'd' && e.Text[1] == 'e' && e.Text[2] == 'b') {
//###### Debug Packet, three lines #############
String text = System.Text.Encoding.ASCII.GetString(e.Text).Trim();
Console.WriteLine("Fraunhofer.Fit.Iot.Lora.LoraController.ReceivePacket: |" + text + "| PRSSI: " + e.Packetrssi + " RSSI:" + e.Rssi + " SNR:" + e.Snr);
if(Tracker.CheckPacket(text)) {
textStatus = text;
trackerName = Tracker.GetName(textStatus, 1);
} else {
//###### Normal Packet, two lines #############
String text = System.Text.Encoding.ASCII.GetString(e.Text).Trim();
Console.WriteLine("Fraunhofer.Fit.Iot.Lora.LoraController.ReceivePacket: |" + text + "| PRSSI: " + e.Packetrssi + " RSSI:" + e.Rssi + " SNR:" + e.Snr);
if (Tracker.CheckPacket(text)) {
textUpdate = text;
trackerName = Tracker.GetName(textUpdate, 0);
} else {
Console.WriteLine("Fraunhofer.Fit.Iot.Lora.LoraController.ReceivePacket: Packet not Match!");
}
Console.WriteLine("Fraunhofer.Fit.Iot.Lora.LoraController.ReceivePacket: Debug-Packet not Match!");
}
if (trackerName != "") {
if (!this.trackers.ContainsKey(trackerName)) {
this.trackers.Add(trackerName, new Tracker());
this.trackers[trackerName].DataUpdate += this.DataUpdates;
this.trackers[trackerName].StatusUpdate += this.StatusUpdates;
this.trackers[trackerName].PanicUpdate += this.PanicUpdates;
}
if (binaryUpdate.Length > 0) {
this.trackers[trackerName].SetUpdate(e, binaryUpdate);
}
if (binaryPanics.Length > 0) {
this.trackers[trackerName].SetPanics(e, binaryPanics);
}
if (textStatus != "") {
this.trackers[trackerName].SetStatus(e, textStatus);
}
if (textUpdate != "") {
this.trackers[trackerName].SetUpdate(e, textUpdate);
}
} else {
//###### Normal Packet, two lines #############
String text = System.Text.Encoding.ASCII.GetString(e.Text).Trim();
Console.WriteLine("Fraunhofer.Fit.Iot.Lora.LoraController.ReceivePacket: |" + text + "| PRSSI: " + e.Packetrssi + " RSSI:" + e.Rssi + " SNR:" + e.Snr);
if(Tracker.CheckPacket(text)) {
textUpdate = text;
trackerName = Tracker.GetName(textUpdate, 0);
} else {
Console.WriteLine("Fraunhofer.Fit.Iot.Lora.LoraController.ReceivePacket: Packet not Match!");
}
});
}
}
if(trackerName != "") {
if(!this.trackers.ContainsKey(trackerName)) {
this.trackers.Add(trackerName, new Tracker());
this.trackers[trackerName].DataUpdate += this.DataUpdates;
this.trackers[trackerName].StatusUpdate += this.StatusUpdates;
this.trackers[trackerName].PanicUpdate += this.PanicUpdates;
}
if(binaryUpdate.Length > 0) {
this.trackers[trackerName].SetUpdate(e, binaryUpdate);
}
if(binaryPanics.Length > 0) {
this.trackers[trackerName].SetPanics(e, binaryPanics);
}
if(textStatus != "") {
this.trackers[trackerName].SetStatus(e, textStatus);
}
if(textUpdate != "") {
this.trackers[trackerName].SetUpdate(e, textUpdate);
}
}
});
private void PanicUpdates(Object sender, PanicUpdateEvent e) {
this.PanicUpdate?.Invoke(sender, e);
}
private void PanicUpdates(Object sender, PanicUpdateEvent e) => this.PanicUpdate?.Invoke(sender, e);
private void StatusUpdates(Object sender, StatusUpdateEvent e) {
this.StatusUpdate?.Invoke(sender, e);
}
private void StatusUpdates(Object sender, StatusUpdateEvent e) => this.StatusUpdate?.Invoke(sender, e);
private void DataUpdates(Object sender, DataUpdateEvent e) {
this.DataUpdate?.Invoke(sender, e);
}
private void DataUpdates(Object sender, DataUpdateEvent e) => this.DataUpdate?.Invoke(sender, e);
#region IDisposable Support
private Boolean disposedValue = false;
......
......@@ -9,7 +9,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Lora")]
[assembly: AssemblyCopyright("Copyright © 2018 - 29.03.2019")]
[assembly: AssemblyCopyright("Copyright © 2018 - 14.04.2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
......@@ -31,8 +31,8 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.8.0")]
[assembly: AssemblyFileVersion("1.8.0")]
[assembly: AssemblyVersion("1.8.1")]
[assembly: AssemblyFileVersion("1.8.1")]
/*
* 1.1.0 Now awaiing Battery as Double and fix the sending twise issue
......@@ -46,4 +46,5 @@ using System.Runtime.InteropServices;
* 1.6.1 Update to local librarys
* 1.7.0 Add Parsing for new Statusformat and Panic Packet
* 1.8.0 Add field that indicates when the last gps position was recieved, change all times to UTC
* 1.8.1 Add Hostname to MQTT, so you can see from witch device the data is recieved
*/
......@@ -6,7 +6,7 @@ namespace Fraunhofer.Fit.Iot.Lora.Trackers {
public Double LastLatitude { get; private set; }
public Double Longitude { get; private set; }
public Double LastLongitude { get; private set; }
public DateTime LastGPSPos { get; private set; }
public DateTime LastGPSPos { get; private set; }
public DateTime Time { get; private set; }
public Double Hdop { get; private set; }
public Boolean Fix { get; private set; }
......
......@@ -48,10 +48,8 @@ namespace Fraunhofer.Fit.Iot.Lora.Trackers {
Powersave,
Shutdown
}
public Tracker() {
this.Gps = new GpsInfo();
}
public Tracker() => this.Gps = new GpsInfo();
#region Private Parsers and Helpers
private void Parse(Byte[] data, ParseType dataType) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment