Compare commits

..

No commits in common. "837f10037dd67c7ed568728781609c606139da0a" and "c85047a57da0a79444beb92271c0a8206ef1fb1e" have entirely different histories.

3 changed files with 10 additions and 15 deletions

View File

@ -22,7 +22,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="MQTTnet" Version="5.0.1.1416" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup> </ItemGroup>

View File

@ -1,6 +1,7 @@
using Api.DBAccess; using Api.DBAccess;
using Api.Models; using Api.Models;
using MQTTnet; using MQTTnet;
using MQTTnet.Extensions.TopicTemplate;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
@ -52,11 +53,9 @@ namespace Api.MQTTReciever
string refernceId = mqttMessageReceive.device_id; string refernceId = mqttMessageReceive.device_id;
var device = _dbAccess.ReadDevice(refernceId); var device = _dbAccess.ReadDevice(refernceId);
if (device == null) { return Task.CompletedTask; }
newLog.Temperature = mqttMessageReceive.temperature; newLog.Temperature = mqttMessageReceive.temperature;
newLog.Date = DateTimeOffset.FromUnixTimeSeconds(mqttMessageReceive.timestamp).DateTime; newLog.Date = DateTimeOffset.FromUnixTimeSeconds(mqttMessageReceive.timestamp).DateTime;
newLog.TempHigh = device.TempHigh; newLog.TempHigh= device.TempHigh;
newLog.TempLow = device.TempLow; newLog.TempLow = device.TempLow;
_dbAccess.CreateLog(newLog, refernceId); _dbAccess.CreateLog(newLog, refernceId);

View File

@ -10,21 +10,18 @@ class Program
{ {
var app = CreateWebHostBuilder(args).Build(); var app = CreateWebHostBuilder(args).Build();
RunMigrations(app);
Task.Run(() => using (var scope = app.Services.CreateScope())
{ {
using (var scope = app.Services.CreateScope()) var services = scope.ServiceProvider;
{ var configuration = services.GetRequiredService<IConfiguration>();
var services = scope.ServiceProvider; var dbAccess = services.GetRequiredService<DbAccess>();
var configuration = services.GetRequiredService<IConfiguration>();
var dbAccess = services.GetRequiredService<DbAccess>();
MQTTReciever mqtt = new MQTTReciever(configuration, dbAccess); MQTTReciever mqtt = new MQTTReciever(configuration, dbAccess);
mqtt.Handle_Received_Application_Message().Wait(); mqtt.Handle_Received_Application_Message();
} }
});
RunMigrations(app);
app.Run(); app.Run();
} }