Added temp and water
This commit is contained in:
@@ -51,4 +51,38 @@ public class InfluxDataService
|
||||
|
||||
return 0f; // Fallback value if query fails or no data is found
|
||||
}
|
||||
|
||||
public async Task<int> GetLatestWaterAsync()
|
||||
{
|
||||
// Connect to the InfluxDB container
|
||||
using var client = new InfluxDBClient(_url, _token);
|
||||
var queryApi = client.GetQueryApi();
|
||||
|
||||
// This is a standard Flux query to get the last recorded value in the last 15 mins.
|
||||
// You will need to change "_measurement" and "_field" to match your setup.
|
||||
string flux = $@"
|
||||
from(bucket: ""{_bucket}"")
|
||||
|> range(start: -15m)
|
||||
|> filter(fn: (r) => r[""_measurement""] == ""Motorhome_Water"")
|
||||
|> filter(fn: (r) => r[""_field""] == ""W_Percentage"")
|
||||
|> last()";
|
||||
|
||||
try
|
||||
{
|
||||
var tables = await queryApi.QueryAsync(flux, _org);
|
||||
|
||||
// Check if we actually got data back
|
||||
if (tables != null && tables.Any() && tables[0].Records.Any())
|
||||
{
|
||||
var record = tables[0].Records[0];
|
||||
return Convert.ToInt32(record.GetValue());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error querying InfluxDB: {ex.Message}");
|
||||
}
|
||||
|
||||
return 100; // Fallback value if query fails or no data is found
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user