35 lines
987 B
C#
35 lines
987 B
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Threading.Tasks;
|
|
|
|
var renderer = new MatrixRenderer("192.168.0.150"); // Your WLED IP
|
|
|
|
// Replace these with your actual InfluxDB v2 credentials
|
|
// If Influx is on the same Pi, you can use the Pi's local IP and port 8086
|
|
var influx = new InfluxDataService(
|
|
url: "http://192.168.0.76:8086",
|
|
token: ":",
|
|
org: "-",
|
|
bucket: "sensor_data"
|
|
);
|
|
|
|
Console.WriteLine("Starting DDP stream with live InfluxDB data...");
|
|
|
|
float currentTemp = 1f;
|
|
Stopwatch dbTimer = Stopwatch.StartNew();
|
|
|
|
while (true)
|
|
{
|
|
// Only query the database every 5 seconds (5000 ms)
|
|
if (dbTimer.ElapsedMilliseconds > 5000 || currentTemp == 0f)
|
|
{
|
|
currentTemp = await influx.GetLatestTemperatureAsync();
|
|
Console.WriteLine($"Fetched new temp: {currentTemp}c");
|
|
dbTimer.Restart();
|
|
}
|
|
|
|
// Keep pushing frames to WLED at 30 FPS
|
|
await renderer.DrawAndSendFrameAsync(currentTemp);
|
|
|
|
await Task.Delay(1000 / 30);
|
|
} |