diff --git a/NucuCar.Sensors/Abstractions/SensorMeasurement.cs b/NucuCar.Sensors/Abstractions/SensorMeasurement.cs new file mode 100644 index 0000000..a53c26c --- /dev/null +++ b/NucuCar.Sensors/Abstractions/SensorMeasurement.cs @@ -0,0 +1,20 @@ +using System.Diagnostics.CodeAnalysis; + +namespace NucuCar.Sensors.Abstractions +{ + [SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global")] + [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")] + public class SensorMeasurement + { + public string Name { get; set; } + public string Unit { get; set; } + public double Value { get; set; } + + public SensorMeasurement(string name, string unit, double value) + { + Name = name; + Unit = unit; + Value = value; + } + } +} \ No newline at end of file diff --git a/NucuCar.Sensors/Abstractions/SensorResponse.cs b/NucuCar.Sensors/Abstractions/SensorResponse.cs index 69f362c..049484d 100644 --- a/NucuCar.Sensors/Abstractions/SensorResponse.cs +++ b/NucuCar.Sensors/Abstractions/SensorResponse.cs @@ -1,10 +1,12 @@ -namespace NucuCar.Sensors.Abstractions +using System.Collections.Generic; + +namespace NucuCar.Sensors.Abstractions { public class NucuCarSensorResponse { - // TODO: Fix this class, it is horrible at this moment. // TODO: Fix names in NucuCar.Sensors.Modules. public SensorStateEnum State; - public string JsonData; + public string SensorId; + public List Data; } } \ No newline at end of file diff --git a/NucuCar.Sensors/Modules/Environment/Bme680Sensor.cs b/NucuCar.Sensors/Modules/Environment/Bme680Sensor.cs index 628418a..85b3376 100644 --- a/NucuCar.Sensors/Modules/Environment/Bme680Sensor.cs +++ b/NucuCar.Sensors/Modules/Environment/Bme680Sensor.cs @@ -4,7 +4,6 @@ using System.Device.I2c; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using NucuCar.Sensors.Abstractions; using Iot.Device.Bmxx80; using UnitsNet; @@ -54,11 +53,17 @@ namespace NucuCar.Sensors.Modules.Environment public override NucuCarSensorResponse GetMeasurement() { - var jsonResponse = JsonConvert.SerializeObject(_lastMeasurement); return new NucuCarSensorResponse { + SensorId = GetIdentifier(), State = GetState(), - JsonData = jsonResponse + Data = new List + { + new SensorMeasurement("temperature", "celsius", _lastMeasurement.Temperature), + new SensorMeasurement("humidity", "rh", _lastMeasurement.Humidity), + new SensorMeasurement("pressure", "hPa", _lastMeasurement.Pressure), + new SensorMeasurement("volatileOrganicCoumpounds", "", _lastMeasurement.VolatileOrganicCompounds), + } }; } diff --git a/NucuCar.Sensors/Modules/Health/CpuTempSensor.cs b/NucuCar.Sensors/Modules/Health/CpuTempSensor.cs index e24567b..1ef2024 100644 --- a/NucuCar.Sensors/Modules/Health/CpuTempSensor.cs +++ b/NucuCar.Sensors/Modules/Health/CpuTempSensor.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using NucuCar.Sensors.Abstractions; using Iot.Device.CpuTemperature; @@ -65,14 +64,14 @@ namespace NucuCar.Sensors.Modules.Health public override NucuCarSensorResponse GetMeasurement() { - var jsonResponse = JsonConvert.SerializeObject(new Dictionary - { - ["cpu_temperature"] = _lastTemperatureCelsius, - }); return new NucuCarSensorResponse() { + SensorId = GetIdentifier(), State = CurrentState, - JsonData = jsonResponse + Data = new List + { + new SensorMeasurement("temperature", "celsius", _lastTemperatureCelsius) + } }; } diff --git a/NucuCar.Sensors/Modules/Heartbeat/HeartbeatSensor.cs b/NucuCar.Sensors/Modules/Heartbeat/HeartbeatSensor.cs index 95f4dc3..a9f55f1 100644 --- a/NucuCar.Sensors/Modules/Heartbeat/HeartbeatSensor.cs +++ b/NucuCar.Sensors/Modules/Heartbeat/HeartbeatSensor.cs @@ -41,7 +41,12 @@ namespace NucuCar.Sensors.Modules.Heartbeat public override NucuCarSensorResponse GetMeasurement() { - return null; + return new NucuCarSensorResponse() + { + SensorId = GetIdentifier(), + State = CurrentState, + Data = new List() + }; } public override SensorStateEnum GetState() diff --git a/NucuCar.Sensors/Modules/PMS5003/Pms5003Sensor.cs b/NucuCar.Sensors/Modules/PMS5003/Pms5003Sensor.cs index 5b4d63b..d44cd59 100644 --- a/NucuCar.Sensors/Modules/PMS5003/Pms5003Sensor.cs +++ b/NucuCar.Sensors/Modules/PMS5003/Pms5003Sensor.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; using NucuCar.Sensors.Abstractions; using PMS5003; using PMS5003.Exceptions; @@ -85,11 +84,31 @@ namespace NucuCar.Sensors.Modules.PMS5003 public override NucuCarSensorResponse GetMeasurement() { - var jsonResponse = _pms5003Data != null ? JsonConvert.SerializeObject(_pms5003Data) : "{}"; return new NucuCarSensorResponse() { + SensorId = GetIdentifier(), State = GetState(), - JsonData = jsonResponse + Data = new List + { + new SensorMeasurement("Pm1Atmospheric", "?", _pms5003Data.Pm1Atmospheric), + new SensorMeasurement("Pm1Standard", "?", _pms5003Data.Pm1Standard), + new SensorMeasurement("Pm10Atmospheric", "?", _pms5003Data.Pm10Atmospheric), + new SensorMeasurement("Pm10Standard", "?", _pms5003Data.Pm10Standard), + new SensorMeasurement("Pm2Dot5Atmospheric", "?", _pms5003Data.Pm2Dot5Atmospheric), + new SensorMeasurement("Pm2Dot5Standard", "?", _pms5003Data.Pm2Dot5Standard), + new SensorMeasurement("ParticlesDiameterBeyond0Dot3", "?", + _pms5003Data.ParticlesDiameterBeyond0Dot3), + new SensorMeasurement("ParticlesDiameterBeyond0Dot5", "?", + _pms5003Data.ParticlesDiameterBeyond0Dot5), + new SensorMeasurement("ParticlesDiameterBeyond1Dot0", "?", + _pms5003Data.ParticlesDiameterBeyond1Dot0), + new SensorMeasurement("ParticlesDiameterBeyond2Dot5", "?", + _pms5003Data.ParticlesDiameterBeyond2Dot5), + new SensorMeasurement("ParticlesDiameterBeyond5Dot0", "?", + _pms5003Data.ParticlesDiameterBeyond5Dot0), + new SensorMeasurement("ParticlesDiameterBeyond10Dot0", "?", + _pms5003Data.ParticlesDiameterBeyond10Dot0), + } }; }